Loading Please wait...

zOrm_base Class Reference
[Object-relational mapping.]

Inheritance diagram for zOrm_base:

Inheritance graph
[legend]
Collaboration diagram for zOrm_base:

Collaboration graph
[legend]

Public Member Functions

 limit ($l_query)
 Set the limit Query.
 group_by ($g_query)
 Set the Group By Query.
 having ($h_query)
 Set the having Query.
 order ($colAlias, $way=ZIGORM_ORDER_ASC)
 Set the order Query.
 distinct ($flag=true)
 Select Distinct.
 insert ($cleanUp=true)
 remove ($cleanUp=true)
 update ($cleanUp=true)
 delete ($cleanUp=true)
 index ($colAlias)
 export ($cleanUp=true)

Private Member Functions

 isValidEntry ()
 isValidUpdate ()

Detailed Description

handles the Most basic Operations like insert(), delete(), update(), export() e.g. SELECT, limit(), order etc..

Definition at line 30 of file base.php.


Member Function Documentation

zOrm_base::limit ( l_query  ) 

Set the limit Query.

Parameters:
$l_query string

Definition at line 36 of file base.php.

00036                           {
00037     $this->lex['limit'] = trim($l_query);
00038   }

zOrm_base::group_by ( g_query  ) 

Set the Group By Query.

Parameters:
$g_query string

Definition at line 44 of file base.php.

00044                              {
00045     $this->lex['group'] = trim($g_query);
00046   }

zOrm_base::having ( h_query  ) 

Set the having Query.

Parameters:
$h_query string

Definition at line 52 of file base.php.

00052                            {
00053     $this->lex['having'] = trim($h_query);
00054   }

zOrm_base::order ( colAlias,
way = ZIGORM_ORDER_ASC 
)

Set the order Query.

Parameters:
$o_query string

Definition at line 60 of file base.php.

References zOrm_core::alias2Real(), and perror().

Referenced by zOrm_magic::__call().

00060                                                   {
00061     if(!$realColName = $this->alias2Real($colAlias)){
00062       perror("<code>zigmoyd.orm.order()</code><br />Invalid Column Alias Name $colAlias");
00063       return false;
00064     }
00065     switch($way){
00066       case ZIGORM_ORDER_ASC:
00067           $drc = 'ASC';
00068         break;
00069       case ZIGORM_ORDER_DESC:
00070           $drc = 'DESC';
00071         break;
00072       default:
00073         perror("<code>zigmoyd.orm.order()</code><br />Invalid Order the second Argument must be one of these two predefined Constants ZIGORM_ORDER_ASC or ZIGORM_ORDER_DESC");
00074         return false;
00075     }
00076     $this->lex['order'][] = array('col' => $realColName, 'way' => $drc);
00077   }

Here is the call graph for this function:

zOrm_base::distinct ( flag = true  ) 

Select Distinct.

Parameters:
$flag boolean

Definition at line 83 of file base.php.

References zLogger::debug().

00083                                  {
00084     $distinctFlag = $flag ? "Distinct" : "UnDistinct";
00085     zLogger::debug("$distinctFlag Query", 'orm.table.'.$this->realTableName);
00086     $this->lex['distinct'] = $flag;
00087   }

Here is the call graph for this function:

zOrm_base::insert ( cleanUp = true  ) 

Inserts the data on the Table. if $cleanUp Flag is set to true It cleans Up all the Lexims after finishing the Operation. returns boolean success Status. It also Calls the Insert Trigger if exists.

Parameters:
$cleanup boolean Optional defaults to true
Returns:
boolean

Definition at line 96 of file base.php.

References $val, zOrm_core::alias2Real(), zLogger::debug(), zOrm_core::exec(), isValidEntry(), zOrm_core::queryType(), and zOrm_core::real2Alias().

00096                                 {
00097     if(method_exists($this, 'onInsert')){
00098       $ret = array();
00099       foreach($this->lex['attributes'] as $realColName => $val){
00100         $ret[$this->real2Alias($realColName)] = $val;
00101       }
00102       $this->onInsert(&$ret);
00103       foreach($ret as $colAliasName => $val){
00104         $this->lex['attributes'][$this->alias2Real($colAliasName)] = $val;
00105       }
00106       $this->trgInsert = true;
00107     }
00108     foreach($this->lex['attributes'] as $realColName => $val){
00109       if(method_exists($this, 'onInsert'.$this->real2Alias($realColName))){
00110         call_user_func(array(&$this, 'onInsert'.$this->real2Alias($realColName)), &$val);
00111         $this->lex['attributes'][$realColName] = $val;
00112         $this->trgInsertCol[$this->real2Alias($realColName)] = true;
00113       }
00114     }
00115     if($this->isValidEntry()){
00116       zLogger::debug("Insertingh Rows successful on Table $this->realTableName (data validatied before insert)", 'orm.insert');
00117       $this->queryType(ZIGORM_Q_INSERT);
00118       return $this->exec($cleanUp);
00119     }else{
00120       zLogger::debug("Inserting Row(s) failed on Table $this->realTableName due to invalid data entry", 'orm.insert');
00121       return false;
00122     }
00123   }

Here is the call graph for this function:

zOrm_base::remove ( cleanUp = true  ) 

Deletes the data on the Table. if $cleanUp Flag is set to true It cleans Up all the Lexims after finishing the Operation. returns boolean success Status. It also Calls the Delete Trigger if exists.

Parameters:
$cleanup boolean Optional defaults to true
Returns:
boolean

Definition at line 132 of file base.php.

References zLogger::debug(), zOrm_core::exec(), and zOrm_core::queryType().

00132                                 {
00133     if(method_exists($this, 'onDelete')){
00134       $this->onDelete();
00135     }
00136     $this->queryType(ZIGORM_Q_REMOVE);
00137     zLogger::debug("Removing Row(s) on Table $this->realTableName", 'orm.remove');
00138     return $this->exec($cleanUp);
00139   }

Here is the call graph for this function:

zOrm_base::update ( cleanUp = true  ) 

Updates the data on the Table. if $cleanUp Flag is set to true It cleans Up all the Lexims after finishing the Operation. returns boolean success Status. It also Calls the Update Trigger if exists.

Parameters:
$cleanup boolean Optional defaults to true
Returns:
boolean

Definition at line 148 of file base.php.

References $val, zOrm_core::alias2Real(), zLogger::debug(), zOrm_core::exec(), zOrm_core::initLex(), isValidUpdate(), zOrm_core::queryType(), and zOrm_core::real2Alias().

00148                                 {
00149     if(method_exists($this, 'onUpdate')){
00150       $ret = array();
00151       foreach($this->lex['attributes'] as $realColName => $val){
00152         $ret[$this->real2Alias($realColName)] = $val;
00153       }
00154       $this->onUpdate(&$ret);
00155       foreach($ret as $colAliasName => $val){
00156         $this->lex['attributes'][$this->alias2Real($colAliasName)] = $val;
00157       }
00158       $this->trgUpdate = true;
00159     }
00160     foreach($this->lex['attributes'] as $realColName => $val){
00161       if(method_exists($this, 'onUpdate'.$this->real2Alias($realColName))){
00162         call_user_func(array(&$this, 'onUpdate'.$this->real2Alias($realColName)), &$val);
00163         $this->lex['attributes'][$realColName] = $val;
00164         $this->trgUpdateCol[$this->real2Alias($realColName)] = true;
00165       }
00166     }
00167     if($this->isValidUpdate()){
00168       zLogger::debug("Updating Row(s) successful on Table $this->realTableName (data validatied before update)", 'orm.update');
00169       $this->queryType(ZIGORM_Q_UPDATE);
00170       return $this->exec($cleanUp);
00171     }else{
00172       zLogger::debug("Updating Row(s) failed on Table $this->realTableName due to invalid data entry", 'orm.update');
00173       $this->initLex();
00174       return false;
00175     }
00176   }

Here is the call graph for this function:

zOrm_base::delete ( cleanUp = true  ) 

Alias of remove()

Parameters:
$cleanup boolean Optional defaults to true
Returns:
boolean

Definition at line 182 of file base.php.

References zLogger::debug(), zOrm_core::exec(), and zOrm_core::queryType().

00182                                 {
00183     if(method_exists($this, 'onDelete')){
00184       $this->onDelete();
00185     }
00186     $this->queryType(ZIGORM_Q_REMOVE);
00187     zLogger::debug("Removing Row(s) on Table $this->realTableName", 'orm.remove');
00188     return $this->exec($cleanUp);
00189   }

Here is the call graph for this function:

zOrm_base::isValidEntry (  )  [private]

Checks wheather or not the entry going to be written on db is valid. Creates a public member variable $this->validation Object that holds validation result's details which you can access as $this->db->Table->validation from your controler.

You can use $this->validation->isValid ( boolean) to check wheather the entry is valid or not. each field/column taking part in validation have thier own object of type zRom_fields (planed). so you can use $this->validation->fieldName->isValid() to check wheather or not that particular field is valid and many other things (refer to zRom_fields class docs for more informations)

all invalid entry gets listed in $this->validation->errCols (public member variable) associative array in $this->validation->errCols[invalidFieldName] => "errorMessage" pattern

Note:
Here $this->validation refers to $this->db->Table->validation from your controller.
Warning:
all (both valid and invalid) fields gets listed in $this->validation as an object or zRom_fields class but only invalid fields ar listed in $this->validation->errCols
Note:
you can track the errors in the same way like get/post/fileUpload using triggeredErr() function with $this->db->Table->validation object as handle (from controller) however if you are using it from view then $db becomes local so you need to use $db->Table->validation as handle at that time.

For internal use only.

an associative array that holds the key value pair just like $_GET or $_POST PHP's standard variable.

Definition at line 206 of file base.php.

References $val, and load_module().

Referenced by insert().

00206                          {
00207     load_module('validation');//Load the validation module
00211     $data = array();
00212     $rulesDict = array();
00213     foreach($this->lex['attributes'] as $realColName => $val){
00214       $data[$this->real2alias($realColName)] = $val;
00215       $this->lex['attributes'][$realColName] = ($this->colQuote[$realColName]==ZIGORM_QUOTE) ? "'$val'" : $val;//add Quotes to the Columns
00216       $rulesDict[$this->real2alias($realColName)] = array();
00217       if(isset($this->__struct->Attributes[$realColName]->criteria) && is_array($this->__struct->Attributes[$realColName]->criteria)){
00218         foreach($this->__struct->Attributes[$realColName]->criteria as $ruleName => $errMsg){
00219           $rulesDict[$this->real2alias($realColName)][$ruleName] = $errMsg;
00220         }
00221       }
00222     }
00223     $ormVld = new validation($data);
00224     foreach($rulesDict as $colAliasName => $ruleArray){
00225       $ormVld->addCriteria($colAliasName, $ruleArray);
00226     }
00227     $this->validation->isValid = $ormVld->isValid();//Check wheather or not every column's value is valid
00228     foreach($data as $colAliasName => $dummyValue){
00229       if(isset($this->__struct->Attributes[$this->alias2real($colAliasName)]->criteria)){
00230         $this->validation->{$colAliasName} = new zRom_fields($dummyValue, $ormVld->errtext($colAliasName), $ormVld->isValid($colAliasName), $ormVld->validationStatus($colAliasName));
00231         if(!$this->validation->{$colAliasName}->isValid())$this->validation->errCols[$colAliasName] = $this->validation->{$colAliasName}->errMsg();
00232       }else{
00233         $this->validation->{$colAliasName} = new zRom_fields($data[$dummyValue], true, true, true);
00234       }
00235     }
00236     return $this->validation->isValid;
00237   }

Here is the call graph for this function:

zOrm_base::isValidUpdate (  )  [private]

more or less same as zOrm_base::isValidEntry() however specilized in update

See also:
zOrm_base::isValidEntry()

For internal use only.

Definition at line 244 of file base.php.

References $val, load_module(), and zLogger::udebug().

Referenced by update().

00244                           {
00245     load_module('validation');
00246     $data = array();
00247     $rulesDict = array();
00248     foreach($this->lex['attributes'] as $realColName => $val){
00249       if(!(is_bool($val) && !$val)){
00250         $colAlias = $this->real2Alias($realColName);
00251         $data[$colAlias] = $val;
00252         if(isset($this->__struct->Attributes[$realColName]->criteria) && is_array($this->__struct->Attributes[$realColName]->criteria)){
00253           $rulesDict[$colAlias] = array();
00254           foreach($this->__struct->Attributes[$realColName]->criteria as $ruleName => $errMsg){
00255             $rulesDict[$colAlias][$ruleName] = $errMsg;
00256           }
00257         }
00258         $this->lex['attributes'][$realColName] = ($this->colQuote[$realColName]==ZIGORM_QUOTE) ? "'$val'" : $val;//add Quotes to the Columns
00259       }
00260     }
00261     $ormVld = new validation($data);
00262     foreach($rulesDict as $colAliasName => $ruleArray){
00263       zLogger::udebug("Adding Rules for Column $colAliasName");
00264       $ormVld->addCriteria($colAliasName, $ruleArray);
00265     }
00266     $this->validation->isValid = $ormVld->isValid();//Check wheather or not every column's value is valid
00267     $this->validation->errCols = array();
00268     foreach($data as $colAliasName => $dummyValue){
00269       if(isset($this->__struct->Attributes[$this->alias2real($colAliasName)]->criteria)){
00270         $this->validation->{$colAliasName} = new zRom_fields($dummyValue, $ormVld->errtext($colAliasName), $ormVld->isValid($colAliasName), $ormVld->validationStatus($colAliasName));
00271         if(!$this->validation->{$colAliasName}->isValid())$this->validation->errCols[$colAliasName] = $this->validation->{$colAliasName}->errMsg();
00272       }else{
00273         $this->validation->{$colAliasName} = new zRom_fields($data[$dummyValue], true, true, true);
00274       }
00275     }
00276     return $this->validation->isValid;
00277   }

Here is the call graph for this function:

zOrm_base::index ( colAlias  ) 

if your export() returns an array by default they are numarically serially Indexed. However if you pass an Index Column it will be indexed with corresponding values from that field, e.g. index('Id') Sometimes seems to be very usefull cause you get the corresponding Ids as array index.

Parameters:
$colAlias string Column alias name

Definition at line 284 of file base.php.

References zLogger::debug().

Referenced by zOrm_noMagic::find(), and zOrm_noMagic::findBy().

00284                            {
00285     zLogger::debug("indexing export data with $colAlias Column", 'orm.export.index');
00286     $this->__indexKey = $colAlias;
00287   }

Here is the call graph for this function:

zOrm_base::export ( cleanUp = true  ) 

Executes a select Query and returns the Result as an associative array. if $cleanUp Flag is set to true It cleans Up all the Lexims after finishing the Operation. returns boolean success Status. It also Calls the Export Trigger if exists.

Parameters:
$cleanup boolean Optional defaults to true
Returns:
array

Definition at line 296 of file base.php.

References $val, zLogger::debug(), and perror().

Referenced by zOrm_noMagic::minExport().

00296                                 {
00297     zLogger::debug("Exporting result set", 'orm.export');
00298     if(!$this->__rdbmsJoin){
00299       $this->queryType(ZIGORM_Q_SELECT);
00300     }else{
00301       zLogger::debug("issuing Join before exporting", 'orm.export');
00302       $this->join();
00303       $this->queryType(ZIGORM_Q_JOIN);
00304     }
00305     $this->exec(false);
00306     if(method_exists($this, 'onExport')){
00307       $this->onExport(&$this->rawExported);
00308     }
00309     $rowSetClassName = get_class($this).'RowSet';
00310     $ret = array();
00311     if(!is_array($this->rawExported)){
00312       $this->__indexKey = null;
00313       $this->initLex();
00314       return false;
00315     }
00316     foreach($this->rawExported as $rowId => $rowObj){
00317       if(strlen(trim($this->__indexKey))){
00318         if(!isset($rowObj->colList[$this->__indexKey])){
00319           perror("<code>zigmoyd.orm.export.index</code><br />Invalid Index $this->__indexKey<br />Its worth to mention that you also need to fetch the Index column");
00320           return false;
00321         }
00322         $indx = $rowObj->colList[$this->__indexKey];
00323       }else{
00324         $indx = $rowId;
00325       }
00326       $ret[$indx] = new $rowSetClassName;
00327       foreach($rowObj->colList as $colAlias => $val){
00328         if(method_exists($this, 'onExport'.$colAlias)){
00329            call_user_func(array(&$this, 'onExport'.$colAlias), &$rowObj->colList[$colAlias]);
00330         }
00331       }
00332       $ret[$indx]->colList = $rowObj->colList;
00333       //$ret[$indx]->handle = &$this;//for PHP5
00334       unset($rowObj);
00335     }
00336     if($cleanUp){
00337       $this->__indexKey = null;
00338       $this->initLex();
00339     }
00340     return $ret;
00341   }

Here is the call graph for this function:


The documentation for this class was generated from the following file:

Generated on Mon Oct 27 23:54:16 2008 for zigmoyd.kdevelop by doxygen 1.5.6