/**
* Gets all projects
*
* It returns projects with all properties by one query
*
* @param bool $ignoreCache optional Should it ignore cache or not
* @return ArrayCollection Returns collection of all ProjectEntity objects
*/
public function all($ignoreCache = false)
{
if ($this->collection === null || $ignoreCache) {
$this->collection = new ArrayCollection();
$projectEntity = new ProjectEntity();
$ccEntity = new CostCentreEntity();
$idField = $projectEntity->getIterator()->getField('projectId');
$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 LEFT JOIN " . $ccEntity->table('c') . " ON c.`cc_id` = p.`cc_id`\n LEFT JOIN `project_properties` pp ON pp.project_id = p.project_id\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;
}