コード例 #1
0
ファイル: HandlerObjects.php プロジェクト: psesd/cascade-lib
 /**
  * Get data source.
  *
  * @return [[@doctodo return_type:getDataSource]] [[@doctodo return_description:getDataSource]]
  */
 public function getDataSource()
 {
     if (is_null($this->_dataSource)) {
         $typeItem = Yii::$app->collectors['types']->getOne($this->instructions['type']);
         if (!$typeItem || !($type = $typeItem->object)) {
             return $this->_dataSource = false;
         }
         $primaryModel = $type->primaryModel;
         if (isset($this->instructions['parent'])) {
             $registryClass = Yii::$app->classes['Registry'];
             $object = $registryClass::getObject($this->instructions['parent']);
             if (!$object) {
                 return $this->_dataSource = false;
             }
             $this->_dataSource = $object->queryChildObjects($primaryModel, [], []);
         } else {
             $this->_dataSource = $primaryModel::find();
         }
         $dummyModel = new $primaryModel();
         $sortOptions = array_values($dummyModel->sortOptions);
         if ($this->filterQuery) {
             $primaryModel::simpleSearchTermQuery($this->_dataSource, $this->filterQuery);
         } elseif (isset($sortOptions[0])) {
             $this->_dataSource->orderBy($sortOptions[0]);
         }
     }
     return $this->_dataSource;
 }