00001 <?php
00026 include_once(ZIGROOT.DRS.MOD_KEY_NAME_EXPLICIT.DRS."orm".DRS."base.php");
00036 class zOrm_noMagic extends zOrm_base{
00049 function identifyBy($colAliasName, $val, $op='=', $mandatory=true){
00050 $cnj = ($mandatory) ? 'and' : 'or';
00051 if(!eregi('pk', $colAliasName)){
00052 if(!isset($this->lex['alias'][strtolower($colAliasName)])){
00053 perror("<code>zigmoyd.orm.identifyBy$colAliasName</code><br />Invalid Column $colAliasName on table $this->tableAlias");
00054 return false;
00055 }
00056 return $this->addAliasCriteria($this->lex['alias'][strtolower($colAliasName)], $val, $op, $cnj, true);
00057 }else{
00058 if(!is_array($val)){
00059 perror("<code>zigmoyd.orm.identifyBy$colAliasName</code><br />2nd Argument for Value must be an array ".gettype($val)." Given");
00060 return false;
00061 }
00062 foreach($this->pk as $i => $pk){
00063 if(!isset($val[$i])){
00064 $useHint = '';
00065 $pkTable = '<table border = "1" style="font: 12px Verdana, Arial, Helvetica, sans-serif;border-collapse: collapse;width: 200px;border: 2px solid #990000;"><tr style="border-top: 1px solid #990000;border-bottom: 1px solid #990000;background: #990000;color: #FFF3F3;"><td>Column Name</td><td>Value</td></tr>';
00066 foreach($this->pk as $j => $pkt){
00067 $pkTable .= "<tr style='border: 1px solid #990000;padding: 0 0.5em;color: #990000'><td>$pkt</td><td>".@$val[$j]."</td></tr>";
00068
00069 }
00070 $useHint = trim($useHint, ",");
00071 $pkTable .= "</table>";
00072 perror('<code>zigmoyd.orm.identifyBy("pk", $value, '.$op.')</code><br />Your Table <code style="background-color: #FFFFFF;font-weight: normal;">'.$this->tableAlias.'</code> Uses Multiple Column Primary Key So the Combination of those fields must be unique.<br />
00073 So you must provide multiple Values for Different Columns (primary Keys) serially<br />
00074 But the Problem is No Value has been supplied for Column Alias <code style="background-color: #FFFFFF;font-weight: normal;">'.$this->lex['aliasProperCaps'][$pk].'</code> Real Column Name <code style="background-color: #FFFFFF;font-weight: normal;">'.$pk.'</code><br />
00075 For a Better help Here is the list of Primary Keys and their values (as Supplied By You)<br />'.$pkTable.'<br />');
00076
00077 return false;
00078 }
00079 $this->addColCriteria($pk, $val[$i], $op, $cnj, true);
00080 }
00081 }
00082 }
00091 function set($colAliasName, $Value, $quote=true){
00092 if(!isset($this->lex['alias'][strtolower($colAliasName)])){
00093 perror("<code>zigmoyd.orm.set$colAliasName</code><br />Invalid Column $colAliasName on table $this->tableAlias");
00094 return false;
00095 }
00096 return $this->writeColAlias($this->lex['alias'][strtolower($colAliasName)], $Value, $quote);
00097 }
00104 function fetch($colAliasName, $flag=true){
00105 if(!eregi('all', $colAliasName)){
00106 if(!isset($this->lex['alias'][strtolower($colAliasName)])){
00107 perror("<code>zigmoyd.orm.fetch$colAliasName</code><br />Invalid Column $colAliasName on table $this->tableAlias");
00108 return false;
00109 }
00110 return $this->readAlias($this->lex['alias'][strtolower($colAliasName)], $flag);
00111 }else{
00112 foreach($this->lex['aliasProperCaps'] as $aliasName){
00113 $this->readAlias($aliasName, $flag);
00114 }
00115 }
00116 return true;
00117 }
00124 function fetchAs($colAliasName, $virtualAliasName){
00125 if(!isset($this->lex['alias'][strtolower($colAliasName)])){
00126 perror("<code>zigmoyd.orm.fetch$colAliasName"."As".$virtualAliasName."</code><br />Invalid Column $colAliasName on table $this->tableAlias");
00127 return false;
00128 }
00129 $realColName = $this->alias2real($this->lex['alias'][strtolower($colAliasName)]);
00130 $realAlias = $this->lex['aliasProperCaps'][$realColName];
00131 $this->lex['aliasProperCaps'][$realColName] = $virtualAliasName;
00132 $retSet = $this->fetch($colAliasName);
00133
00134 return $retSet;
00135 }
00147 function find($colAliasName, $indexKey=null){
00148 if(strlen($indexKey)){
00149 $this->fetch($indexKey);
00150 $this->index($indexKey);
00151 }
00152 if($this->fetch($colAliasName)){
00153 return $this->minExport(eregi('all', $colAliasName), $colAliasName);
00154 }else{
00155 return false;
00156 }
00157 }
00175 function findBy($colAliasName, $searchCol, $val, $op=null, $indexCol=null){
00176 if($op == null)$op = '=';
00177 if($this->isJoined){
00178 $this->joiner->identifyBy($searchCol, $val, $op);
00179 }else{
00180 $this->identifyBy($searchCol, $val, $op);
00181 }
00182 if(!strlen($indexCol)){
00183 return $this->find($colAliasName);
00184 }else{
00185 $this->fetch($indexCol);
00186 $this->index($indexCol);
00187 if($this->fetch($colAliasName)){
00188 return $this->minExport(eregi('all', $colAliasName), $colAliasName);
00189 }else{
00190 return false;
00191 }
00192 }
00193 }
00202 function minExport($fetchAll, $trgCol=false){
00203 $resSet = $this->export();
00204 if(!$resSet)return false;
00205 switch(count($resSet)){
00206 case 0:
00207 return false;
00208 case 1:
00209 switch($fetchAll){
00210 case true:
00211 foreach($resSet as $Row)
00212 return $Row;
00213 case false:
00214 foreach($resSet as $Row)
00215 return $Row->colList[$this->lex['alias'][strtolower($trgCol)]];
00216
00217 }
00218 default:
00219 switch($fetchAll){
00220 case true:
00221 return $resSet;
00222 case false:
00223 $retSet = array();
00224 foreach($resSet as $i => $resObj){
00225 $retSet[$i] = $resSet[$i]->colList[$this->lex['alias'][strtolower($trgCol)]];
00226
00227 }
00228 return $retSet;
00229 }
00230 }
00231 }
00238 function isPk($colAliasName){
00239 if(!isset($this->lex['alias'][strtolower($colAliasName)])){
00240 perror("<code>zigmoyd.isPk()</code><br />non Existing Column $colAliasName");
00241 return false;
00242 }else{
00243 return in_array($this->alias2real($this->lex['alias'][strtolower($colAliasName)]), $this->pk);
00244 }
00245 }
00254 function join($cleanUp=true){
00255 zLogger::debug("Issuing AUTOJOIN to join foreign Tables if exists", 'orm.table'.$this->realTableName);
00256 global $__ZigOrm;
00257 if(is_array($this->fk)){
00258 foreach($this->fk as $srcCol => $refObj){
00259 if(!$this->lex['join']['type']){
00260 $this->lex['join']['type'] = ZIGORM_Q_AUTOJOIN;
00261 }
00262 $this->lex['join']['on'][$refObj->table][$srcCol] = $refObj->col;
00263 }
00264 }
00265 }
00273 function forceJoin($foreignTableName, $foreignCol, $srcCol){
00274 zLogger::debug("Forcing Join $foreignTableName.$foreignCol With $this->realTableName.$srcCol ", 'orm.table'.$this->realTableName);
00275 $this->__rdbmsJoin = true;
00276 global $__ZigOrm;
00277 $tableAliasList = array_flip($__ZigOrm->dataDict->tables);
00278 if(isset($tableAliasList[$foreignTableName])){
00279 if(!$this->colAliasExists($srcCol)){
00280 perror("<code>zigmoyd.orm.get.join</code><br />Failed to join as real column name of Column Alias <code style=\"background-color: #FFFFFF;font-weight: normal;\">$srcCol</code> on table <code style=\"background-color: #FFFFFF;font-weight: normal;\">".$this->lex['table']."</code> could not be fetched");
00281 return false;
00282 }
00283 $srcCol = $this->alias2real($srcCol);
00284 $this->fk[$srcCol] = new stdClass();
00285 $this->fk[$srcCol]->table = $tableAliasList[$foreignTableName];
00286 $this->fk[$srcCol]->col = $this->alias2real($foreignCol);
00287 if(class_exists($foreignTableName)){
00288 $this->{$foreignTableName} = new $foreignTableName();
00289 }else{
00290 perror("<code>zigmoyd.orm.get.join</code><br />Class $foreignTableName not found");
00291 return false;
00292 }
00293 }else{
00294 perror("<code>zigmoyd.orm.get.join</code><br />Failed to join as real table name of Table Alias <code style=\"background-color: #FFFFFF;font-weight: normal;\">$foreignTableName</code> not found<br />Plese make sure that you are joining after Instantiating that Table's OrmClass");
00295 return false;
00296 }
00297 return true;
00298 }
00306 function innerJoin($foreignTable, $foreignCol, $srcCol){
00307 zLogger::debug("Forcing Inner Join $foreignTable.$foreignCol With $this->realTableName.$srcCol ", 'orm.table'.$this->realTableName);
00308 $this->__rdbmsJoin = true;
00309 if($this->forceJoin($foreignTable, $foreignCol, $srcCol)){
00310 $this->lex['join']['type'] = ZIGORM_JOIN_INNER;
00311 }else{
00312 return false;
00313 }
00314 }
00323 function leftJoin($foreignTable, $foreignCol, $srcCol){
00324 zLogger::debug("Forcing Left Join $foreignTable.$foreignCol With $this->realTableName.$srcCol ", 'orm.table'.$this->realTableName);
00325 $this->__rdbmsJoin = true;
00326 if($this->forceJoin($foreignTable, $foreignCol, $srcCol)){
00327 $this->lex['join']['type'] = ZIGORM_JOIN_LEFT;
00328 }else{
00329 return false;
00330 }
00331 }
00340 function rightJoin($foreignTable, $foreignCol, $srcCol){
00341 zLogger::debug("Forcing Right Join $foreignTable.$foreignCol With $this->realTableName.$srcCol ", 'orm.table'.$this->realTableName);
00342 $this->__rdbmsJoin = true;
00343 if($this->forceJoin($foreignTable, $foreignCol, $srcCol)){
00344 $this->lex['join']['type'] = ZIGORM_JOIN_RIGHT;
00345 }else{
00346 return false;
00347 }
00348 }
00356 function crossJoin($foreignTableName){
00357 zLogger::debug("Issuing Cross Join $foreignTableName With $this->realTableName", 'orm.table'.$this->realTableName);
00358 $this->__rdbmsJoin = true;
00359 global $__ZigOrm;
00360 $tableAlias = array_flip($__ZigOrm->dataDict->tables);
00361 $this->lex['join']['on'][$tableAlias[$foreignTableName]] = true;
00362 if(class_exists($foreignTableName)){
00363 $this->fk["zig_orm_c_dummy_src_!<>@#%^&*()+=\."]->table = $tableAlias[$foreignTableName];
00364 $this->fk["zig_orm_c_dummy_src_!<>@#%^&*()+=\."]->col = "zig_orm_c_dummy_fk_!<>@#%^&*()+=\.";
00365 $this->{$foreignTableName} = new $foreignTableName();
00366 $this->lex->join->type = ZIGORM_JOIN_CROSS;
00367 }else{
00368 perror("<code>zigmoyd.orm.get.join</code><br />Class $foreignTableName not found");
00369 return false;
00370 }
00371 }
00375 function byPassRelation(){
00376 $this->__rdbmsJoin = false;
00377 }
00381 function passThroughRelation(){
00382 $this->__rdbmsJoin = true;
00383 }
00384 }
00386 ?>