Untitled

 avatar
FedorovASh
php
2 years ago
1.3 kB
1
Indexable
Never
<?php

class NewFlatAdminFilter
{
    public ?\NewFlat $searchModel;

    /**
     * @return string[]
     */
    public function getObjectItems(): array
    {
        $criteria = $this->getCriteria();
        $criteria->select = 'DISTINCT t.new_object_id';
        $objectIds = $this->searchModel->getCommandBuilder()->createFindCommand($this->searchModel->tableName(), $criteria)->queryColumn();

        if ($objectIds) {
            $newObject = \NewObject::model();
            $newObjectCriteria = new \CDbCriteria();
            $newObjectCriteria->select = 'id, title';
            $newObjectCriteria->addInCondition('id', $objectIds);
            $newObjectCriteria->order = 'title ASC';
            $newObjectRows = $newObject->getCommandBuilder()->createFindCommand($newObject->tableName(), $newObjectCriteria)->queryAll();

            $items = [];

            foreach ($newObjectRows as $row) {
                $items[$row['id']] = $row['title'];
            }

            return $items;
        }
        return [];
    }

    public function getBuildingItems()
    {

    }

    public function  getSectionItems()
    {

    }

    private function getCriteria(): \CDbCriteria
    {
        return $this->searchModel->getSearchCriteria();
    }
}