Ejemplo n.º 1
0
 /** loads and returns objects that are linked through a proxy table.  Typically, these are 
  * tables of the M-N type, each object is linked to multiple objects in the other table, and
  * each object in the other table is linked to multiple objects in the first table.
  * They are linked with a middle table that contains both IDs, 
  * tbl_linker:
  *  linker_id
  *  linker_test1_id
  *  linker_test2_id
  *  ....
  */
 public function getLinkedObjects($strMiddleTable, $strOtherTable)
 {
     if (!clsDB::isValidFieldName($strMiddleTable)) {
         throw new Exception(ERRORMSG_INVALID);
     }
     if (!clsDB::isValidFieldName($strOtherTable)) {
         throw new Exception(ERRORMSG_INVALID);
     }
     $strName = $this->getName();
     $intID = $this->get('id');
     $SQL = "SELECT `<<tbl><{$strOtherTable}>>`.* \n\t\t\t\t\tFROM `<<tbl><{$strMiddleTable}>>` INNER JOIN `<<tbl><{$strOtherTable}>>` ON `<<foreign><{$strMiddleTable}><{$strOtherTable}>>`=`<<{$strOtherTable}><id>>`\n\t\t\t\t\tWHERE `<<tbl><{$strMiddleTable}>>`.`<<foreign><{$strMiddleTable}><{$strName}>>` = '{$intID}' \n\t\t\t\t\t\tAND `<<isdel><{$strMiddleTable}>>`='0' \n\t\t\t\t\t\tAND `<<isdel><{$strOtherTable}>>`='0' ";
     $arrResults = clsDB::selectQuery($SQL);
     $arrObjects = array();
     foreach ($arrResults as $arrResult) {
         $objNew = new clsDB($strOtherTable);
         $objNew->getFromRow($arrResult);
         $arrObjects[] = $objNew;
     }
     return $arrObjects;
 }