/** * Gets all cost centres with all theirs properties * * @param bool $addHasProjects optional Should it provide result with hasProjects flag * @param array $criteria optional Search criteria * @param bool $ignoreCache optional Should it ignore cache or not * @return ArrayCollection Returns collection of the CostCentreEntity objects */ public function all($addHasProjects = false, $criteria = null, $ignoreCache = false) { if ($this->collection === null || $ignoreCache) { $this->collection = new ArrayCollection(); $ccEntity = new CostCentreEntity(); $ccPropertyEntity = new CostCentrePropertyEntity(); $projectEntity = new ProjectEntity(); $where = 'WHERE 1=1'; $join = ''; $idField = $ccEntity->getIterator()->getField('ccId'); $this->parseFindCriteria($criteria, $join, $where); $rs = $this->db->Execute("\n SELECT " . $ccEntity->fields('c') . ", cp.name as property_name, cp.value as property_value\n " . ($addHasProjects ? ", EXISTS(SELECT 1 FROM projects pr WHERE pr.cc_id = c.cc_id) AS `hasProjects`" : "") . "\n FROM " . $ccEntity->table('c') . "\n LEFT JOIN " . $ccPropertyEntity->table('cp') . " ON cp.cc_id = c.cc_id\n " . $join . "\n " . $where . "\n ORDER BY c.cc_id\n "); while ($rec = $rs->FetchRow()) { $id = $idField->type->toPhp($rec['cc_id']); if (!isset($this->collection[$id])) { $entity = new CostCentreEntity(); $entity->load($rec); if ($addHasProjects) { $entity->setHasProjects($rec['hasProjects']); } $entity->setProperty($rec['property_name'], $rec['property_value']); $this->collection[$entity->ccId] = $entity; } else { $this->collection[$id]->setProperty($rec['property_name'], $rec['property_value']); } } } return $this->collection; }