Scalr\Stats\CostAnalytics\Projects::findByKey PHP Метод

findByKey() публичный Метод

Finds projects by key It searches by name or billing number
public findByKey ( string $key = null, array $criteria = null, $ignoreCache = false ) : ArrayCollection
$key string optional Search key
$criteria array optional Search criteria ['envId' => '', 'accountId' => '', 'accountId' => '']
Результат Scalr\Model\Collections\ArrayCollection Returns collection of the ProjectEntity objects
    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;
    }