public function findByKey($key = null, $criteria = null, $ignoreCache = false)
{
if (is_null($key) || $key === '') {
return $this->all($ignoreCache, $criteria);
}
$collection = new ArrayCollection();
$projectEntity = new ProjectEntity();
//Includes archived projects
$projectPropertyEntity = new ProjectPropertyEntity();
//Cost center entity
$ccEntity = new CostCentreEntity();
$where = '';
$join = '';
$this->parseFindCriteria($criteria, $join, $where);
$rs = $this->db->Execute("\n SELECT " . $projectEntity->fields('p') . ", " . $ccEntity->fields('c', true) . "\n FROM " . $projectEntity->table('p') . "\n JOIN " . $ccEntity->table('c') . " ON c.`cc_id` = p.`cc_id` " . $join . "\n WHERE (p.`name` LIKE ?\n OR EXISTS (\n SELECT 1 FROM " . $projectPropertyEntity->table('pp') . "\n WHERE `pp`.project_id = `p`.`project_id`\n AND `pp`.`name` = ? AND `pp`.`value` LIKE ?\n )) " . $where . "\n ", ['%' . $key . '%', ProjectPropertyEntity::NAME_BILLING_CODE, '%' . $key . '%']);
while ($rec = $rs->FetchRow()) {
$item = new ProjectEntity();
$item->load($rec);
if ($rec['c_cc_id']) {
$cc = new CostCentreEntity();
$cc->load($rec, 'c');
$item->setCostCenter($cc);
}
$collection->append($item);
}
return $collection;
}