Пример #1
0
    public function getAccounts(array $role = [])
    {
        $personModel = $this->getSession()->getModel('\\GermBundle\\Model\\Germ\\PersonSchema\\PersonModel');
        $sql = <<<SQL
select
    {projection}
from
    {account} a
    inner join {person} p on (p.id = a.person_id)
where
    {where}
SQL;
        $projection = $this->createProjection()->setField("person_name", "concat(p.lastname, ' ', p.firstname) as person_name", "varchar")->setField("account_id", "a.id as account_id", "varchar");
        $where = new Where();
        if ($role) {
            $where->andWhereIn('role', $role);
        }
        $sql = strtr($sql, ['{account}' => $this->structure->getRelation(), '{person}' => $personModel->getStructure()->getRelation(), '{projection}' => $projection->formatFields('a'), '{where}' => $where]);
        return $this->query($sql, [], $projection);
    }