Esempio n. 1
0
 /**
  * Pick the joined object's current record to the current record
  *
  * @param BizDataObj $joinDataObj
  * @param string $joinName name of join (optional)
  * @return array return a modified record with joined record data
  */
 public function joinRecord($joinDataObj, $joinName = "")
 {
     // get the maintable of the joindataobj
     $joinTable = $joinDataObj->mainTableName;
     $joinRecord = null;
     $returnRecord = array();
     // find the proper join according to join name and the maintable
     foreach ($this->tableJoins as $tableJoin) {
         if (($joinName == $tableJoin->objectName || $joinName == "") && $tableJoin->table == $joinTable) {
             // populate the column-fieldvalue to columnRef-fieldvalue
             // get the field mapping to the column, then get the field value
             $joinFieldName = $joinDataObj->bizRecord->getFieldByColumn($tableJoin->column);
             // joined-main table
             if (!$joinFieldName) {
                 continue;
             }
             if (!$joinRecord) {
                 $joinRecord = $joinDataObj->getActiveRecord();
             }
             $refFieldName = $this->bizRecord->getFieldByColumn($tableJoin->columnRef);
             // join table
             $returnRecord[$refFieldName] = $joinRecord[$joinFieldName];
             // populate joinRecord's field to current record
             foreach ($this->bizRecord as $fld) {
                 if ($fld->join == $tableJoin->objectName) {
                     // use join column to match joinRecord field's column
                     $jfldname = $joinDataObj->bizRecord->getFieldByColumn($fld->column);
                     // joined-main table
                     $returnRecord[$fld->objectName] = $joinRecord[$jfldname];
                 }
             }
             break;
         }
     }
     // return a modified record with joined record data
     return $returnRecord;
 }