public function all($ignoreCache = false, $criteria = null)
{
if ($this->collection === null || $ignoreCache || !is_null($criteria)) {
$this->collection = new ArrayCollection();
$projectEntity = new ProjectEntity();
$ccEntity = new CostCentreEntity();
$projectPropertyEntity = new ProjectPropertyEntity();
$idField = $projectEntity->getIterator()->getField('projectId');
$where = 'WHERE 1=1';
$join = '';
$this->parseFindCriteria($criteria, $join, $where);
$rs = $this->db->Execute("\n SELECT " . $projectEntity->fields('p') . ", " . $ccEntity->fields('c', true) . ",\n pp.name as property_name,\n pp.value as property_value\n FROM " . $projectEntity->table('p') . "\n JOIN " . $ccEntity->table('c') . " ON c.`cc_id` = p.`cc_id`\n LEFT JOIN " . $projectPropertyEntity->table('pp') . " ON pp.project_id = p.project_id " . $join . "\n " . $where . "\n ORDER BY p.project_id\n ");
while ($rec = $rs->FetchRow()) {
$id = $idField->type->toPhp($rec['project_id']);
if (!isset($this->collection[$id])) {
$entity = new ProjectEntity();
$entity->load($rec);
if ($rec['c__cc_id']) {
$cc = new CostCentreEntity();
$cc->load($rec, 'c');
$entity->setCostCenter($cc);
}
$entity->setProperty($rec['property_name'], $rec['property_value']);
$this->collection[$entity->projectId] = $entity;
} else {
$this->collection[$id]->setProperty($rec['property_name'], $rec['property_value']);
}
}
}
return $this->collection;
}