Inheritance: extends common\models\base\Post
Exemplo n.º 1
0
 public function testGetPostsWithCategory()
 {
     $category = $this->categoryModel->findOne(1);
     $expectedPosts = $category->getPosts();
     $actualPosts = $this->postModel->findAll(['category_id' => 1, 'publish_status' => Post::STATUS_PUBLISH]);
     $this->assertEquals($expectedPosts->count, count($actualPosts));
 }
Exemplo n.º 2
0
 public function createPost()
 {
     $newPost = new Post();
     $newPost['title'] = $this->title;
     $newPost['content'] = $this->content;
     $newPost['permit'] = $this->permit[0];
     if ($this->upload()) {
         $newPost['image'] = $this->thumbnail;
     }
     if ($this->date == "") {
         $newPost['create_at'] = date("Y-m-d");
     } else {
         $newPost['create_at'] = $this->date;
     }
     $newPost['user_id'] = $this->user_id;
     $newPost->save();
     if ($newPost['permit'] == 2) {
         foreach ($this->reader as $userId) {
             $newPostProtected = new PostProtected();
             $newPostProtected['create_at'] = $newPost['create_at'];
             $newPostProtected['post_id'] = $newPost['id'];
             $newPostProtected['user_id'] = $userId;
             $newPostProtected->save();
         }
     }
 }
Exemplo n.º 3
0
 public function run()
 {
     parent::run();
     // TODO: Change the autogenerated stub
     $post = new Post();
     $dataPartner = $post->find('image')->where(['category_id' => 18])->all();
     return $this->render('widget/partner', ['nodes' => $dataPartner]);
 }
Exemplo n.º 4
0
 public function testSetTags()
 {
     $sourceTags = [1, 3];
     $post = $this->postModel->findOne(2);
     $post->setTags($sourceTags);
     $this->assertInstanceOf('common\\models\\Post', $post);
     $this->assertTrue($post->save(false));
     $this->assertEquals($sourceTags, $post->getTags());
 }
 public function actionIndex()
 {
     echo "Sending letters to subscribers begin...\n";
     $currentDayTime = time() - 60 * 60 * 24;
     $currentDay = date("Y-m-d H:i:s", $currentDayTime);
     $importantPosts = Post::find()->where(['is_public' => 1, 'is_index' => 1])->andWhere(['>', 'created_at', $currentDay])->orderBy(['created_at' => SORT_DESC])->limit(3)->all();
     $ids = [];
     foreach ($importantPosts as $post) {
         $ids[] = $post->id;
     }
     $maxCommentsPosts = Post::find()->where(['is_public' => 1])->andWhere(['>', 'created_at', $currentDay])->andWhere(['not in', "id", $ids])->orderBy(['id' => SORT_DESC])->limit(3)->all();
     $posts = array_merge($importantPosts, $maxCommentsPosts);
     // sending
     $subscribings = Subscribing::find()->all();
     $count = 0;
     foreach ($subscribings as $subscribing) {
         if (!filter_var($subscribing->email, FILTER_VALIDATE_EMAIL)) {
             echo "Email is not correct: " . $subscribing->email . "\n";
             $subscribing->delete();
             continue;
         }
         $unsubscribeKey = md5($subscribing->id . $subscribing->email);
         $message = Yii::$app->mailer->compose('subscribe-view-html', compact('posts', 'unsubscribeKey'))->setTo($subscribing->email)->setSubject('Новости Динамо');
         $send = $message->send();
         if ($send) {
             $count++;
         }
     }
     echo "Posted {$count} letters. \n";
     echo "Sending letters to subscribers end.\n";
 }
Exemplo n.º 6
0
 /**
  * Displays a model.
  * @param string $id the primary key of the model.
  * @return \yii\db\ActiveRecordInterface the model being displayed
  */
 public function run($id)
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $model = $this->findModel($id);
     $result = \common\models\Post::find()->where(['category_id' => $id])->all();
     return $result;
 }
 public function run()
 {
     parent::run();
     // TODO: Change the autogenerated stub
     $nodes = Post::find()->where(['status' => 10])->limit(3)->all();
     return $this->render('PostBottomTopWidget', ['nodes' => $nodes]);
 }
Exemplo n.º 8
0
 public function beforeSave($insert)
 {
     if ($this->show == 1 && isset($this->oldAttributes['show'])) {
         $this->posted = date('Y-m-d H:i:s');
     }
     return parent::beforeSave($insert);
 }
Exemplo n.º 9
0
 public function init()
 {
     $newPosts = Post::find()->selectNoText()->recentPublished(3)->all();
     foreach ($newPosts as $post) {
         $this->_htmlStr .= Html::tag('div', Html::a($post->title, ['site/post', 'id' => $post->cid], ['class' => 'post-title']) . Html::tag('div', \Yii::$app->formatter->asDate($post->created), ['class' => 'date']), ['class' => 'recent-single-post']);
     }
 }
Exemplo n.º 10
0
 public function actionCreate()
 {
     //$start = microtime();
     parent::actionIndex();
     $postId = (int) Yii::$app->getRequest()->post('post_id');
     $url = Yii::$app->getRequest()->post('post_url');
     if ($postId && $postId != "undefined") {
         $post = Post::findByMySqlId($postId, Yii::$app->getRequest()->post('project_id'));
     } elseif ($url) {
         $post = Post::findByUrl($url);
     } else {
         throw new ForbiddenHttpException("Param url is not provided", self::CODE_NO_URL);
     }
     $postViewModel = new PostView();
     $postViewModel->load(Yii::$app->getRequest()->getBodyParams(), '');
     $postViewModel->post_id = $postId;
     $postViewModel->save();
     if ($post) {
         $total = PostView::find()->where(array('project_id' => (int) Yii::$app->getRequest()->post('project_id'), 'post_id' => $postId))->count();
         //$unique = PostView::find()->where(array('project_id' => (int)Yii::$app->getRequest()->post('project_id'), 'post_id' => (int)$post->getID()))->distinct("uid");
         $response = array('total' => $total, 'unique' => (int) $post->views['unique']);
         $post->views = $response;
         $post->save();
     } else {
         $total = PostView::find()->where(array('project_id' => (int) Yii::$app->getRequest()->post('project_id'), 'post_id' => $postId, 'post_url' => $url))->count();
         $response = array('total' => $total, 'unique' => 0);
     }
     //echo microtime() - $start;
     return $response;
 }
Exemplo n.º 11
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]);
 }
Exemplo n.º 12
0
 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]);
 }
Exemplo n.º 13
0
 public function getPosts($isPublished = true)
 {
     $query = $this->hasMany(Post::className(), ['cid' => 'cid'])->with('categories')->with('tags')->with('author')->orderByCid();
     if ($isPublished) {
         $query = $query->published();
     }
     return $query->viaTable(Relationship::tableName(), ['mid' => 'mid']);
 }
 private static function getPost($categoryID)
 {
     $postModel = Post::find()->where(['category_id' => $categoryID]);
     $count = $postModel->count();
     $pagination = new Pagination(['totalCount' => $count]);
     $nodes = $postModel->offset($pagination->offset)->limit($pagination->limit)->all();
     return ['nodes' => $nodes, 'pagination' => $pagination];
 }
Exemplo n.º 15
0
 /**
  * 概要
  * @return string
  */
 public function actionIndex()
 {
     $recentPublishedPost = Post::find()->selectNoText()->recentPublished()->all();
     $postCount = Post::find()->published()->count();
     $categoryCount = Category::find()->count();
     //todo: 评论数量 最新回复
     return $this->render('index', ['recentPublishedPost' => $recentPublishedPost, 'postCount' => $postCount, 'categoryCount' => $categoryCount]);
 }
Exemplo n.º 16
0
 /**
  * Finds the Post model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Post the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Post::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('您所请求的页面不存在');
     }
 }
Exemplo n.º 17
0
 public function getPost($id)
 {
     if (($model = Post::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('Стать не найдена.');
     }
 }
 /**
  * Finds the Post model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $slug
  * @return Post the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function getModel($slug)
 {
     if (($model = Post::findOne(['slug' => $slug])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(Yii::t('yii', 'Page not found.'));
     }
 }
Exemplo n.º 19
0
 public function actionDeletePost($id)
 {
     $post = Post::findOne(['id' => $id, 'user_id' => Yii::$app->user->id]);
     if (!empty($post->id)) {
         return $post->delete();
     }
     return 'Not found post';
 }
 protected function findModel($id)
 {
     if (($model = Post::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 21
0
 public function actionPost($id)
 {
     $post = Post::find()->andWhere(['cid' => $id])->published()->one();
     if (!$post) {
         throw new NotFoundHttpException('页面不存在');
     }
     return $this->render('post', ['post' => $post]);
 }
Exemplo n.º 22
0
 /**
  * @return string
  */
 public function actionIndex()
 {
     /* @var $lastPost \common\models\Post */
     $response = Yii::$app->response;
     $response->headers->set('Content-Type', 'text/xml; charset=UTF-8');
     $response->format = $response::FORMAT_RAW;
     $lastPost = Post::find()->where(['post_status' => 'publish'])->orderBy(['id' => SORT_DESC])->one();
     return $this->renderPartial('index', ['title' => Option::get('sitetitle'), 'description' => Option::get('tagline'), 'link' => Yii::$app->request->absoluteUrl, 'lastBuildDate' => new \DateTime($lastPost->post_date, new \DateTimeZone(Option::get('time_zone'))), 'postTypes' => PostType::find()->all(), 'language' => Yii::$app->language, 'generator' => 'http://www.writesdown.com']);
 }
Exemplo n.º 23
0
 public function getCategory()
 {
     $post = Post::findOne($this->id);
     foreach (explode(',', $post->category_id) as $value) {
         $category = Category::findOne($value);
         $data[] = ['id' => $category->id, 'parent_id' => $category->parent_id, 'title' => $category->title, 'indent' => $this->getIndent($category->indent)];
     }
     return $data;
 }
Exemplo n.º 24
0
 public function actionCreate($url)
 {
     exit;
     $html = SimpleHtmlDom::file_get_html($url);
     foreach ($html->find('ul[id="news_home"] li') as $item) {
         $model = new Post();
         $image = str_replace('_240x144', null, $item->find('img', 0)->src);
         $model['category_id'] = 1;
         $model['title'] = trim($item->find('a[class="title_tin"]', 0)->plaintext);
         $model['image'] = $this->saveImage($image);
         $detail = $item->find('a[class="title_tin"]', 0)->href;
         $html_detail = SimpleHtmlDom::file_get_html($detail);
         $summary = $html_detail->find('p[class="lead"]', 0)->plaintext;
         $content = strip_tags($html_detail->find('div[class="fck_detail width_common"]', 0)->innertext, '<img><strong><br /><br><p>');
         $model['content'] = $summary . $content;
         $model->save();
     }
 }
Exemplo n.º 25
0
 public function actionIndex()
 {
     $topics = Post::find()->limit(20)->where(['status' => 2])->orderBy(['created_at' => SORT_DESC])->all();
     $users = UserService::findActiveUser(12);
     $statistics = array();
     $statistics['post_count'] = Post::find()->count();
     $statistics['comment_count'] = PostComment::find()->count();
     $statistics['online_count'] = Session::find()->where(['>', 'expire', time()])->count();
     return $this->render('index', ['topics' => $topics, 'users' => $users, 'statistics' => $statistics]);
 }
Exemplo n.º 26
0
 public function actionRenderpage($url)
 {
     $category = Category::findOne(['link' => $url]);
     if (empty($category)) {
         return $this->run('site/error');
     }
     $subcategories = Category::findAll(['parent' => $category->id]);
     $posts = Post::findAll(['category' => $category->id]);
     return $this->render('category', ['category' => $category, 'subcategories' => $subcategories, 'postsCount' => sizeof($posts), 'posts' => $posts, 'premiumPosts' => \common\models\Post::find()->where(['>', 'premium', date('d-m-Y H:i:s')])->andWhere(['category' => $category->id])->all()]);
 }
Exemplo n.º 27
0
 /**
  * Displaying feed.
  *
  * @return string
  */
 public function actionIndex()
 {
     /* @var $lastPost \common\models\Post */
     $response = Yii::$app->response;
     $response->headers->set('Content-Type', 'text/xml; charset=UTF-8');
     $response->format = $response::FORMAT_RAW;
     // Get first post and all posts
     $lastPost = Post::find()->where(['status' => Post::STATUS_PUBLISH])->andWhere(['<=', 'date', date('Y-m-d H:i:s')])->orderBy(['id' => SORT_DESC])->one();
     $posts = Post::find()->where(['status' => Post::STATUS_PUBLISH])->andWhere(['<=', 'date', date('Y-m-d H:i:s')])->limit(Option::get('posts_per_rss'))->orderBy(['id' => SORT_DESC])->all();
     return $this->renderPartial('index', ['title' => Option::get('sitetitle'), 'description' => Option::get('tagline'), 'link' => Yii::$app->request->absoluteUrl, 'lastBuildDate' => new \DateTime($lastPost->date, new \DateTimeZone(Option::get('time_zone'))), 'language' => Yii::$app->language, 'generator' => 'http://www.writesdown.com', 'posts' => $posts, 'rssUseExcerpt' => Option::get('rss_use_excerpt')]);
 }
Exemplo n.º 28
0
 public function search($params)
 {
     $query = Post::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'category_id' => $this->category_id, 'state_index' => $this->state_index, 'main_flag' => $this->main_flag, 'created_datetime' => $this->created_datetime, 'start_date' => $this->start_date, 'noforeign_id' => $this->noforeign_id]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'intro', $this->intro])->andFilterWhere(['like', 'body', $this->body])->andFilterWhere(['like', 'start_time', $this->start_time])->andFilterWhere(['like', 'preview_image', $this->preview_image])->andFilterWhere(['like', 'doc_file', $this->doc_file])->andFilterWhere(['like', 'my_image', $this->my_image])->andFilterWhere(['like', 'contest_image', $this->contest_image]);
     return $dataProvider;
 }
Exemplo n.º 29
0
 public function actionIndex()
 {
     $topics = Post::find()->limit(20)->where(['status' => 2])->orderBy(['created_at' => SORT_DESC])->all();
     $users = UserService::findActiveUser(12);
     $headline = Arr::getColumn(RightLink::find()->where(['type' => RightLink::RIGHT_LINK_TYPE_HEADLINE])->all(), 'content');
     $statistics = [];
     $statistics['post_count'] = Post::find()->count();
     $statistics['comment_count'] = PostComment::find()->count();
     $statistics['online_count'] = Session::find()->where(['>', 'expire', time()])->count();
     return $this->render('index', ['topics' => $topics, 'users' => $users, 'statistics' => $statistics, 'headline' => Arr::arrayRandomAssoc($headline)]);
 }
Exemplo n.º 30
0
 public function actionIndex()
 {
     $lastPosts = Post::find()->orderBy('created_at desc')->limit(10)->all();
     $featured = Post::featured();
     $drafts = Post::drafts();
     $mostPopularCategory = Category::find()->joinWith('posts')->select('category.id, post.category_id, count(distinct post.title) as qty, category.title')->groupBy('post.category_id')->orderBy('qty desc')->one();
     $mostPopularTag = Tag::find()->joinWith('posts')->select('tags.id, posts_tags.tag_id, count(distinct posts_tags.post_id) as qty, tags.title')->groupBy('posts_tags.tag_id')->orderBy('qty desc')->one();
     $postsCount = Post::find()->where('active = 1')->count();
     $categoryCount = Category::find()->count();
     return $this->render('index', ['lastPosts' => $lastPosts, 'featured' => $featured, 'drafts' => $drafts, 'mostPopularCategory' => $mostPopularCategory, 'mostPopularTag' => $mostPopularTag, 'postsCount' => $postsCount, 'categoryCount' => $categoryCount]);
 }