tableName() публичный статический Метод

public static tableName ( )
Пример #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = TopTag::find();
     $topTagTable = TopTag::tableName();
     $tagTable = Tag::tableName();
     $query->joinWith(['tag' => function ($query) use($tagTable) {
         $query->from(['tag' => $tagTable]);
     }]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
     // enable sorting for the related columns
     $addSortAttributes = ["tag.name"];
     foreach ($addSortAttributes as $addSortAttribute) {
         $dataProvider->sort->attributes[$addSortAttribute] = ['asc' => [$addSortAttribute => SORT_ASC], 'desc' => [$addSortAttribute => SORT_DESC]];
     }
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'tag_id' => $this->tag_id]);
     $query->andFilterWhere(['like', 'tag.name', $this->getAttribute('tag.name')]);
     return $dataProvider;
 }
Пример #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $user = Yii::$app->getModule("user")->model("User");
     $query = Post::find();
     $postTable = Post::tableName();
     // set up query with relation to `user.username`
     $userTable = $user::tableName();
     $query->joinWith(['user' => function ($query) use($userTable) {
         $query->from(['user' => $userTable]);
     }]);
     $tagTable = Tag::tableName();
     $taggingTable = Tagging::tableName();
     $query->leftJoin($taggingTable, "{$taggingTable}.taggable_id = {$postTable}.id AND {$taggingTable}.taggable_type = '" . Tagging::TAGGABLE_POST . "'");
     $query->leftJoin($tagTable, "{$tagTable}.id = {$taggingTable}.tag_id");
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10], 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]]]);
     // enable sorting for the related columns
     $addSortAttributes = ["user.username"];
     foreach ($addSortAttributes as $addSortAttribute) {
         $dataProvider->sort->attributes[$addSortAttribute] = ['asc' => [$addSortAttribute => SORT_ASC], 'desc' => [$addSortAttribute => SORT_DESC]];
     }
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(["{$postTable}.id" => $this->id, 'user_id' => $this->user_id, 'is_public' => $this->is_public, 'is_index' => $this->is_index, 'is_top' => $this->is_top, 'is_pin' => $this->is_pin, 'with_video' => $this->with_video, 'with_photo' => $this->with_photo, 'content_category_id' => $this->content_category_id, 'is_yandex_rss' => $this->is_yandex_rss, 'allow_comment' => $this->allow_comment]);
     $createdTime = strtotime($this->created_at);
     $startDay = date("Y-m-d 00:00:00", $createdTime);
     $endDay = date("Y-m-d 00:00:00", $createdTime + 60 * 60 * 24);
     if ($this->created_at) {
         $query->andFilterWhere(['between', 'created_at', $startDay, $endDay]);
     }
     $updatedTime = strtotime($this->updated_at);
     $startDay = date("Y-m-d 00:00:00", $updatedTime);
     $endDay = date("Y-m-d 00:00:00", $updatedTime + 60 * 60 * 24);
     if ($this->updated_at) {
         $query->andFilterWhere(['between', 'updated_at', $startDay, $endDay]);
     }
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'source_title', $this->source_title])->andFilterWhere(['like', 'source_url', $this->source_url])->andFilterWhere(['like', 'cached_tag_list', $this->cached_tag_list])->andFilterWhere(['like', 'user.username', $this->getAttribute('user.username')])->andFilterWhere(['like', "{$tagTable}.name", $this->getAttribute('tag.name')]);
     return $dataProvider;
 }
Пример #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Tagging::find();
     // set up query with relation to `tag.name`
     $tagTable = Tag::tableName();
     $query->joinWith(['tag' => function ($query) use($tagTable) {
         $query->from(['tag' => $tagTable]);
     }]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     // enable sorting for the related columns
     $addSortAttributes = ["tag.name"];
     foreach ($addSortAttributes as $addSortAttribute) {
         $dataProvider->sort->attributes[$addSortAttribute] = ['asc' => [$addSortAttribute => SORT_ASC], 'desc' => [$addSortAttribute => SORT_DESC]];
     }
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'tag_id' => $this->tag_id, 'taggable_id' => $this->taggable_id]);
     $query->andFilterWhere(['like', 'taggable_type', $this->taggable_type]);
     return $dataProvider;
 }
Пример #4
0
 /**
  * Display list of tags in json format
  *
  * @param string $query Query for search
  * @return mixed Json data
  */
 public function actionTagList($query = null)
 {
     if ($query == null) {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
     $search = urldecode($query);
     $query = new Query();
     $query->select('id as value, name as text')->from(Tag::tableName())->where(['like', 'name', $search])->limit(10);
     $command = $query->createCommand();
     $data = $command->queryAll();
     $out = array_values($data);
     echo Json::encode($out);
 }
Пример #5
0
 /**
  * Url: /search?t={$t}
  * Url: /search?q={$q}
  * @param bool|string $t Tag name slug
  * @param bool|string $q Search words
  * @return mixed Content
  * @internal param string $date Searching by date
  */
 public function actionSearch($t = false, $q = false)
 {
     $t = str_replace('-+-', '-#%#-', $t);
     $t = str_replace('+', ' ', $t);
     $t = str_replace('-#%#-', '+', $t);
     $postTable = Post::tableName();
     $query = Post::find()->where(['is_public' => 1]);
     if (isset($t) && trim($t) != '') {
         $taggingTable = Tagging::tableName();
         $tagTable = Tag::tableName();
         $query->innerJoin($taggingTable, "{$postTable}.id = {$taggingTable}.taggable_id");
         $query->innerJoin($tagTable, "{$taggingTable}.tag_id = {$tagTable}.id");
         $query->andWhere(["{$taggingTable}.taggable_type" => Tagging::TAGGABLE_POST, "{$tagTable}.name" => $t]);
     } elseif (isset($q) && trim($q) != '') {
         $search = addslashes($q);
         $query->andWhere(['or', "MATCH (content) AGAINST ('{$search}')", ['like', 'title', $q]]);
     }
     $query->orderBy(["{$postTable}.created_at" => SORT_DESC]);
     if (!isset($_GET['page']) || $_GET['page'] == 1) {
         Yii::$app->session['news_post_time_last'] = 1;
     }
     $newsDataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 15]]);
     return $this->render('@frontend/views/site/index', ['templateType' => 'col2', 'title' => 'Dynamomania.com | Поиск по сайту', 'columnFirst' => ['news' => ['view' => '@frontend/views/search/search_posts', 'data' => compact('newsDataProvider')]], 'columnSecond' => ['blog_column' => SiteBlock::getBlogPosts(), 'banner1' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner2' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner3' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner4' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner5' => SiteBlock::getBanner(Banner::REGION_NEWS)]]);
 }