tableName() public static method

public static tableName ( )
コード例 #1
0
 /**
  * @return string
  */
 public function actionIndex()
 {
     /* @var $postType PostType */
     /* @var $post Post */
     /* @var $taxonomies Taxonomy[] */
     /* @var $taxonomy Taxonomy */
     /* @var $lastMedia Media */
     $response = Yii::$app->response;
     $response->headers->set('Content-Type', 'text/xml; charset=UTF-8');
     $response->format = $response::FORMAT_RAW;
     $postTypes = PostType::find()->select(['id', 'post_type_slug'])->all();
     $taxonomies = Taxonomy::find()->select(['id', 'taxonomy_slug'])->all();
     $items = [];
     foreach ($postTypes as $postType) {
         if (!isset($this->_option['post_type'][$postType->id]['enable']) || !$this->_option['post_type'][$postType->id]['enable']) {
             continue;
         }
         if ($post = $postType->getPosts()->andWhere(['post_status' => 'publish'])->orderBy(['id' => SORT_DESC])->one()) {
             $lastmod = new \DateTime($post->post_modified, new \DateTimeZone(Option::get('time_zone')));
             $query = $postType->getPosts()->andWhere(['post_status' => 'publish']);
             $countQuery = clone $query;
             $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $this->_option['entries_per_page']]);
             for ($i = 1; $i <= $pages->pageCount; $i++) {
                 $items[] = ['loc' => Yii::$app->urlManager->hostInfo . Url::to(['view', 'type' => 'p', 'slug' => $postType->post_type_slug, 'page' => $i]), 'lastmod' => $lastmod->format('r')];
             }
         }
     }
     foreach ($taxonomies as $taxonomy) {
         if (!isset($this->_option['taxonomy'][$taxonomy->id]['enable']) || !$this->_option['taxonomy'][$taxonomy->id]['enable']) {
             continue;
         }
         if ($terms = $taxonomy->terms) {
             $post = Post::find()->from(['post' => Post::tableName()])->innerJoinWith(['terms' => function ($query) {
                 /* @var $query \yii\db\ActiveQuery */
                 $query->from(['term' => Term::tableName()]);
             }])->where(['IN', 'term.id', ArrayHelper::getColumn($terms, 'id')])->andWhere(['post.post_status' => 'publish'])->orderBy(['post.id' => SORT_DESC])->one();
             if ($post) {
                 $query = $taxonomy->getTerms();
                 $lastmod = new \DateTime($post->post_modified, new \DateTimeZone(Option::get('time_zone')));
                 $countQuery = clone $query;
                 $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $this->_option['entries_per_page']]);
                 for ($i = 1; $i <= $pages->pageCount; $i++) {
                     $items[] = ['loc' => Yii::$app->urlManager->hostInfo . Url::to(['view', 'type' => 'c', 'slug' => $taxonomy->taxonomy_slug, 'page' => $i]), 'lastmod' => $lastmod->format('r')];
                 }
             }
         }
     }
     if (isset($this->_option['media']['enable']) && $this->_option['media']['enable']) {
         $query = Media::find();
         $countQuery = clone $query;
         $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $this->_option['entries_per_page']]);
         if ($lastMedia = $query->orderBy(['id' => SORT_DESC])->one()) {
             $lastmod = new \DateTime($lastMedia->media_modified, new \DateTimeZone(Option::get('time_zone')));
             for ($i = 1; $i <= $pages->pageCount; $i++) {
                 $items[] = ['loc' => Yii::$app->urlManager->hostInfo . Url::to(['view', 'type' => 'm', 'slug' => 'media', 'page' => $i]), 'lastmod' => $lastmod->format('r')];
             }
         }
     }
     return $this->renderPartial('index', ['items' => $items]);
 }
コード例 #2
0
ファイル: SiteController.php プロジェクト: hdushku/app-cms
 /**
  * Render home page of the site.
  *
  * @throws \yii\web\NotFoundHttpException
  * @return string
  */
 public function actionIndex()
 {
     /* @var $post \common\models\Post */
     $query = Post::find()->from(['t' => Post::tableName()])->andWhere(['post_status' => 'publish'])->orderBy(['t.id' => SORT_DESC]);
     if (Option::get('show_on_front') == 'page' && ($frontPage = Option::get('front_page'))) {
         $render = '/post/view';
         $comment = new PostComment();
         $query = $query->andWhere(['id' => $frontPage]);
         if ($post = $query->one()) {
             if (is_file($this->view->theme->basePath . '/post/view-' . $post->postType->post_type_slug . '.php')) {
                 $render = '/post/view-' . $post->postType->post_type_slug;
             }
             return $this->render($render, ['post' => $post, 'comment' => $comment]);
         }
         throw new NotFoundHttpException(Yii::t('writesdown', 'The requested page does not exist.'));
     } else {
         if (Option::get('front_post_type') !== 'all') {
             $query->innerJoinWith(['postType'])->andWhere(['post_type_name' => Option::get('front_post_type')]);
         }
         $countQuery = clone $query;
         $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => Option::get('posts_per_page')]);
         $query->offset($pages->offset)->limit($pages->limit);
         if ($posts = $query->all()) {
             return $this->render('index', ['posts' => $posts, 'pages' => isset($pages) ? $pages : null]);
         }
         throw new NotFoundHttpException(Yii::t('writesdown', 'The requested page does not exist.'));
     }
 }
コード例 #3
0
ファイル: DefaultController.php プロジェクト: tqsq2005/getyii
 public function actionIndex()
 {
     $searchModel = new TweetSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     $dataProvider->query->andWhere([Post::tableName() . '.type' => Tweet::TYPE, 'status' => [Post::STATUS_ACTIVE, Post::STATUS_EXCELLENT]]);
     $model = new Tweet();
     return $this->render('index', ['model' => $model, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
コード例 #4
0
ファイル: PostSearch.php プロジェクト: grutabow/getyii
 /**
  * @param $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Post::find()->joinWith(['category', 'user']);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 20], 'sort' => ['defaultOrder' => ['order' => SORT_ASC, 'updated_at' => SORT_DESC]]]);
     $dataProvider->sort->attributes['category_name'] = ['asc' => ['name' => SORT_ASC], 'desc' => ['name' => SORT_DESC]];
     $dataProvider->sort->attributes['username'] = ['asc' => ['username' => SORT_ASC], 'desc' => ['username' => SORT_DESC]];
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'post_meta_id' => $this->post_meta_id, 'user_id' => $this->user_id, 'view_count' => $this->view_count, 'comment_count' => $this->comment_count, 'favorite_count' => $this->favorite_count, 'like_count' => $this->like_count, 'thanks_count' => $this->thanks_count, 'hate_count' => $this->hate_count, Post::tableName() . '.status' => $this->status, 'order' => $this->order, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', Post::tableName() . '.type', $this->type])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'author', $this->author])->andFilterWhere(['like', 'excerpt', $this->excerpt])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'tags', $this->tags])->andFilterWhere(['like', 'name', $this->category_name])->andFilterWhere(['like', 'username', $this->username]);
     return $dataProvider;
 }
コード例 #5
0
ファイル: DefaultController.php プロジェクト: iiyii/getyii
 /**
  * 话题列表
  * @return mixed
  */
 public function actionIndex()
 {
     $searchModel = new PostSearch();
     // 话题或者分类筛选
     $params = Yii::$app->request->queryParams;
     empty($params['tag']) ?: ($params['PostSearch']['tags'] = $params['tag']);
     if (isset($params['node'])) {
         $postMeta = PostMeta::findOne(['alias' => $params['node']]);
         $postMeta ? $params['PostSearch']['post_meta_id'] = $postMeta->id : '';
     }
     $dataProvider = $searchModel->search($params);
     $dataProvider->query->andWhere([Post::tableName() . '.type' => 'topic', 'status' => [Post::STATUS_ACTIVE, Post::STATUS_EXCELLENT]]);
     // 排序
     $sort = $dataProvider->getSort();
     $sort->attributes = array_merge($sort->attributes, ['hotest' => ['asc' => ['comment_count' => SORT_DESC, 'created_at' => SORT_DESC]], 'excellent' => ['asc' => ['status' => SORT_DESC, 'comment_count' => SORT_DESC, 'created_at' => SORT_DESC]], 'uncommented' => ['asc' => ['comment_count' => SORT_ASC, 'created_at' => SORT_DESC]]]);
     return $this->render('index', ['searchModel' => $searchModel, 'sorts' => $this->sorts, 'dataProvider' => $dataProvider]);
 }
コード例 #6
0
ファイル: PostSearch.php プロジェクト: lanfp/testgit2
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Post::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     // grid filtering conditions
     $post = Post::tableName();
     $user = User::tableName();
     $query->andFilterWhere([$post . '.id' => $this->id, $post . '.status' => $this->status, 'create_time' => $this->create_time, 'update_time' => $this->update_time, 'author_id' => $this->author_id]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'tags', $this->tags]);
     $query->join('INNER JOIN', $user, $post . '.author_id = User.id');
     $query->andFilterWhere(['like', $user . '.username', $this->username]);
     return $dataProvider;
 }
コード例 #7
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = SelectedBlog::find();
     $selectedBlogTable = SelectedBlog::tableName();
     $blogTable = Post::tableName();
     $query->joinWith(['post' => function ($query) use($blogTable) {
         $query->from(['post' => $blogTable]);
     }]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
     // enable sorting for the related columns
     $addSortAttributes = ["post.title"];
     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, 'post_id' => $this->post_id]);
     $query->andFilterWhere(['like', 'post.title', $this->getAttribute('post.title')]);
     return $dataProvider;
 }
コード例 #8
0
ファイル: Section.php プロジェクト: resurtm/forum
 public static function findRoots()
 {
     /** @var Section[] $sections */
     $sections = static::find()->with(['children' => function ($q) {
         $q->indexBy('id');
     }])->where(['section_id' => null])->orderBy('title')->all();
     $ids = [];
     foreach ($sections as $section) {
         $ids = array_merge($ids, array_keys($section->children));
     }
     $query = new Query();
     $counts = $query->select('COUNT(id)')->from(Post::tableName())->where(['section_id' => $ids])->groupBy('section_id')->indexBy('section_id')->column(static::getDb());
     foreach ($sections as $section) {
         $section->postCount = 0;
         foreach ($section->children as $id => $child) {
             $child->postCount = isset($counts[$id]) ? $counts[$id] : 0;
             $section->postCount += $child->postCount;
         }
     }
     return $sections;
 }
コード例 #9
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;
 }
コード例 #10
0
 /**
  * Display list of blogs in json format
  *
  * @param string $query Query for search
  * @return mixed Json data
  */
 public function actionBlogList($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, title as text')->from(Post::tableName())->where(['like', 'title', $search])->andWhere(['=', 'content_category_id', Post::CATEGORY_BLOG])->limit(10);
     $command = $query->createCommand();
     $data = $command->queryAll();
     $out = array_values($data);
     echo Json::encode($out);
 }
コード例 #11
0
 /**
  * Get block with video reviews
  * @return array Data
  */
 public static function getVideoNews()
 {
     $postTable = Post::tableName();
     $assetTable = Asset::tableName();
     // Video review
     $videoReviewNews = VideoPost::find()->where(['is_public' => 1])->orderBy(['created_at' => SORT_DESC])->limit(3)->all();
     if (count($videoReviewNews) == 0) {
         return false;
     }
     $block = ['view' => '@frontend/views/blocks/review_news_block', 'data' => compact('videoReviewNews')];
     return $block;
 }
コード例 #12
0
 /**
  * Url: /match/{$id}/report
  * @param $id
  * @return mixed
  * @throws NotFoundHttpException
  */
 public function actionMatchReport($id)
 {
     $match = Match::findOne($id);
     if (!isset($match)) {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
     $postTable = Post::tableName();
     $relationTable = Relation::tableName();
     $post = Post::find()->innerJoin($relationTable, "{$postTable}.id = {$relationTable}.relationable_id")->where(['is_public' => 1, "{$relationTable}.relation_type_id" => Relation::RELATION_REPORT, "{$relationTable}.relationable_type" => Relation::RELATIONABLE_POST, "{$relationTable}.parent_id" => $match->id])->one();
     $options = ['templateType' => 'col2', 'title' => 'Dynamomania.com | Отчет по матчу: ' . $match->name, 'columnFirst' => ['menu' => ['view' => '@frontend/views/translation/menu', 'data' => compact('match')]], 'columnSecond' => ['short_news' => SiteBlock::getshortNews(50)]];
     if (isset($post)) {
         $image = $post->getAsset(Asset::THUMBNAIL_CONTENT);
         $options['columnFirst']['post'] = ['view' => '@frontend/views/site/post', 'data' => compact('post', 'image'), 'weight' => 3];
         if ($post->allow_comment) {
             $options['columnFirst']['comments'] = Comment::getCommentsBlock($post->id, Comment::COMMENTABLE_POST);
             $options['columnFirst']['comments']['weight'] = 5;
         }
     } else {
         $options['columnFirst']['post'] = ['view' => '@frontend/views/site/empty', 'data' => [], 'weight' => 3];
     }
     usort($options['columnFirst'], 'self::cmp');
     return $this->render('@frontend/views/site/index', $options);
 }