tableName() public static method

public static tableName ( )
Ejemplo n.º 1
0
 protected function _run()
 {
     $cacheKey = $this->getCacheKey() . 'run';
     $dependency = new TagDependency(['tags' => [$this->className() . (string) $this->namespace, (new CmsContentElement())->getTableCacheTag()]]);
     $result = \Yii::$app->cache->get($cacheKey);
     if ($result === false || $this->enabledRunCache == Cms::BOOL_N) {
         $this->initDataProvider();
         if ($this->createdBy) {
             $this->dataProvider->query->andWhere([CmsContentElement::tableName() . '.created_by' => $this->createdBy]);
         }
         if ($this->active) {
             $this->dataProvider->query->andWhere([CmsContentElement::tableName() . '.active' => $this->active]);
         }
         if ($this->content_ids) {
             $this->dataProvider->query->andWhere([CmsContentElement::tableName() . '.content_id' => $this->content_ids]);
         }
         if ($this->limit) {
             $this->dataProvider->query->limit($this->limit);
         }
         $treeIds = (array) $this->tree_ids;
         if ($this->enabledCurrentTree == Cms::BOOL_Y) {
             $tree = \Yii::$app->cms->getCurrentTree();
             if ($tree) {
                 $treeIds[] = $tree->id;
                 if ($tree->children && $this->enabledCurrentTreeChild == Cms::BOOL_Y) {
                     if ($this->enabledCurrentTreeChildAll) {
                         if ($childrens = $tree->children) {
                             foreach ($childrens as $chidren) {
                                 $treeIds[] = $chidren->id;
                             }
                         }
                     } else {
                         if ($childrens = $tree->children) {
                             foreach ($childrens as $chidren) {
                                 $treeIds[] = $chidren->id;
                             }
                         }
                     }
                 }
             }
         }
         if ($treeIds) {
             foreach ($treeIds as $key => $treeId) {
                 if (!$treeId) {
                     unset($treeIds[$key]);
                 }
             }
             if ($treeIds) {
                 /**
                  * @var $query ActiveQuery
                  */
                 $query = $this->dataProvider->query;
                 $query->joinWith('cmsContentElementTrees');
                 $query->andWhere(['or', [CmsContentElement::tableName() . '.tree_id' => $treeIds], [CmsContentElementTree::tableName() . '.tree_id' => $treeIds]]);
             }
         }
         if ($this->enabledActiveTime == Cms::BOOL_Y) {
             $this->dataProvider->query->andWhere(["<=", CmsContentElement::tableName() . '.published_at', \Yii::$app->formatter->asTimestamp(time())]);
             $this->dataProvider->query->andWhere(['or', [">=", CmsContentElement::tableName() . '.published_to', \Yii::$app->formatter->asTimestamp(time())], [CmsContentElement::tableName() . '.published_to' => null]]);
         }
         /**
          *
          */
         if ($this->with) {
             $this->dataProvider->query->with($this->with);
         }
         $this->dataProvider->query->groupBy([CmsContentElement::tableName() . '.id']);
         if ($this->activeQueryCallback && is_callable($this->activeQueryCallback)) {
             $callback = $this->activeQueryCallback;
             $callback($this->dataProvider->query);
         }
         if ($this->dataProviderCallback && is_callable($this->dataProviderCallback)) {
             $callback = $this->dataProviderCallback;
             $callback($this->dataProvider);
         }
         $result = parent::_run();
         \Yii::$app->cache->set($cacheKey, $result, (int) $this->runCacheDuration, $dependency);
     }
     return $result;
 }
Ejemplo n.º 2
0
 /**
  * Конфигурирование объекта запроса поиска по элементам.
  *
  * @param \yii\db\ActiveQuery $activeQuery
  * @param null $modelClassName
  * @return $this
  */
 public function buildElementsQuery(\yii\db\ActiveQuery $activeQuery)
 {
     $where = [];
     //Нужно учитывать связанные дополнительные данные
     if ($this->enabledElementProperties == Cms::BOOL_Y) {
         $activeQuery->joinWith('cmsContentElementProperties');
         //Нужно учитывать настройки связанные дополнительные данных
         if ($this->enabledElementPropertiesSearchable == Cms::BOOL_Y) {
             $activeQuery->joinWith('cmsContentElementProperties.property');
             $where[] = ['and', ['like', CmsContentElementProperty::tableName() . ".value", '%' . $this->searchQuery . '%', false], [CmsContentProperty::tableName() . ".searchable" => Cms::BOOL_Y]];
         } else {
             $where[] = ['like', CmsContentElementProperty::tableName() . ".value", '%' . $this->searchQuery . '%', false];
         }
     }
     //Поиск по основному набору полей
     if ($this->searchElementFields) {
         foreach ($this->searchElementFields as $fieldName) {
             $where[] = ['like', CmsContentElement::tableName() . "." . $fieldName, '%' . $this->searchQuery . '%', false];
         }
     }
     if ($where) {
         $where = array_merge(['or'], $where);
         $activeQuery->andWhere($where);
     }
     //Отфильтровать только конкретный тип
     if ($this->searchElementContentIds) {
         $activeQuery->andWhere([CmsContentElement::tableName() . ".content_id" => (array) $this->searchElementContentIds]);
     }
     return $this;
 }