Skip to content
Snippets Groups Projects
Commit 81f8aa2c authored by Tim Steiner's avatar Tim Steiner
Browse files

Add one eagerloaded row to CourseGenerations

parent fa7a4979
No related branches found
No related tags found
No related merge requests found
......@@ -145,6 +145,63 @@ class CourseGenerations extends Nmc_Db_Table
$childGenerations = $this->fetchAll($where);
return $childGenerations;
}
public function fetchAll($where = null, $order = null, $count = null, $offset = null)
{
$select = $this->getAdapter()->select();
$assetsTable = Assets::getInstance();
$assetsTableInfo = $assetsTable->info();
$detailsTable = CourseDetails::getInstance();
$detailsTableInfo = $detailsTable->info();
$select->from($this->getTableName());
$select->join($detailsTable->getTableName(),
$this->getTableName() . '.' . $this->getPrimaryKeyName() . '='
. $detailsTable->getTableName() . '.generation');
$select->join($assetsTable->getTableName(),
$this->getTableName() . '.assetId = '
. $assetsTable->getTableName() . '.' . $assetsTable->getPrimaryKeyName());
$select->where($where);
$select->order($order);
$select->limit($count, $offset);
$resultData = $this->_db->fetchAll($select);
$config = array();
$config['db'] = $this->_db;
$config['table'] = $this;
$config['data'] = array();
$config['eagerData'] = array();
foreach ($resultData as $resultDatum) {
$config['data'][] = array_intersect_key($resultDatum, array_flip($this->_cols));
$eagerData = array();
$eagerData['db'] = $assetsTable->getAdapter();
$eagerData['table'] = $assetsTable;
$eagerData['data'] = array_intersect_key($resultDatum, array_flip($assetsTableInfo['cols']));
$eagerAssetRow = new Asset($eagerData);
$eagerData = array();
$eagerData['db'] = $detailsTable->getAdapter();
$eagerData['table'] = $detailsTable;
$eagerData['data'] = array_intersect_key($resultDatum, array_flip($detailsTableInfo['cols']));
$eagerDetailRow = new CourseDetail($eagerData);
$config['eagerData'][] = array('asset' => $eagerAssetRow,
'courseDetail' => $eagerDetailRow);
}
$rowsetClass = $this->_rowsetClass;
$rowset = new $rowsetClass($config);
return $rowset;
return parent::fetchAll($where, $order, $count, $offset);
}
}
?>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment