Inheritance: extends common\components\db\ActiveRecord
コード例 #1
0
ファイル: PostController.php プロジェクト: hdushku/app-cms
 /**
  * Displays a single Post model.
  *
  * @param null    $postslug
  *
  * @param integer $id
  *
  * @throws \yii\web\NotFoundHttpException
  * @return mixed
  */
 public function actionView($id = null, $postslug = null)
 {
     $render = 'view';
     $comment = new Comment();
     if ($id) {
         $model = $this->findModel($id);
     } elseif ($postslug) {
         $model = $this->findModelBySlug($postslug);
     } else {
         throw new NotFoundHttpException(Yii::t('writesdown', 'The requested page does not exist.'));
     }
     if ($comment->load(Yii::$app->request->post()) && $comment->save()) {
         if (!$comment->comment_parent) {
             $model->post_comment_count++;
         }
         if ($model->save()) {
             $this->refresh();
         }
     }
     if ($model->post_password && $model->post_password !== Yii::$app->request->post('password')) {
         return $this->render('protected', ['post' => $model]);
     }
     if (is_file($this->view->theme->basePath . '/post/view-' . $model->postType->post_type_slug . '.php')) {
         $render = 'view-' . $model->postType->post_type_slug . '.php';
     }
     return $this->render($render, ['post' => $model, 'comment' => $comment]);
 }
コード例 #2
0
ファイル: CommentService.php プロジェクト: tqsq2005/getyii
 public function userDoAction($id, $action)
 {
     $comment = PostComment::findComment($id);
     $user = \Yii::$app->user->getIdentity();
     if (in_array($action, ['like'])) {
         return UserService::CommentAction($user, $comment, $action);
     }
 }
コード例 #3
0
ファイル: DefaultController.php プロジェクト: tqsq2005/getyii
 /**
  * 话题详细页
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $model = Topic::findTopic($id);
     $dataProvider = new ActiveDataProvider(['query' => PostComment::findCommentList($id), 'pagination' => ['pageSize' => self::PAGE_SIZE]]);
     // 文章浏览次数
     Topic::updateAllCounters(['view_count' => 1], ['id' => $id]);
     $user = Yii::$app->user->identity;
     $admin = $user && ($user->isAdmin($user->username) || $user->isSuperAdmin($user->username)) ? true : false;
     return $this->render('view', ['model' => $model, 'dataProvider' => $dataProvider, 'comment' => new PostComment(), 'admin' => $admin]);
 }
コード例 #4
0
ファイル: SiteController.php プロジェクト: RanLee/getyii
 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]);
 }
コード例 #5
0
ファイル: SiteController.php プロジェクト: grutabow/getyii
 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)]);
 }
コード例 #6
0
ファイル: PostComment.php プロジェクト: hdushku/app-cms
 /**
  * Get comment children based on comment ID.
  *
  * @param int $id
  *
  * @return array|null
  */
 protected function getChildren($id)
 {
     /* @var $models \common\models\PostComment[] */
     $comments = [];
     $models = Comment::find()->select(['id', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_date', 'comment_content'])->andWhere(['comment_parent' => $id])->andWhere(['comment_post_id' => $this->model->id])->andWhere(['comment_approved' => 'approved'])->orderBy(['id' => $this->commentOrder])->all();
     if (empty($models)) {
         $comments = null;
     } else {
         foreach ($models as $model) {
             $comments[$model->id] = $model;
             $comments[$model->id]['child'] = $this->getChildren($model->id);
         }
     }
     return $comments;
 }
コード例 #7
0
ファイル: SyncController.php プロジェクト: grutabow/getyii
 public function actionPost()
 {
     $update = Topic::updateAll(['last_comment_time' => new Expression('created_at')], ['and', ['type' => Topic::TYPE], ['or', ['last_comment_username' => ''], ['last_comment_username' => null]]]);
     $this->stdout("同步最后回复时间,同步{$update}条数据\n");
     $subQuery = new Query();
     $subQuery->from(PostComment::tableName())->where(['status' => PostComment::STATUS_ACTIVE])->orderBy(['created_at' => SORT_DESC]);
     $comment = PostComment::find()->from(['tmpA' => $subQuery])->groupBy('post_id')->all();
     Topic::updateAll(['comment_count' => 0], ['type' => Topic::TYPE]);
     $updateComment = [];
     foreach ($comment as $value) {
         $commentCount = PostComment::find()->where(['post_id' => $value->post_id, 'status' => PostComment::STATUS_ACTIVE])->count();
         $updateComment[] = Topic::updateAll(['last_comment_time' => $value->created_at, 'last_comment_username' => $value->user->username, 'comment_count' => $commentCount], ['id' => $value->post_id, 'type' => Topic::TYPE]);
     }
     $this->stdout("校正最后回复时间和回复会员还有评论条数,校正" . count($updateComment) . "条数据\n");
 }
コード例 #8
0
 /**
  * Show user count, post count, post-comment count on index (dashboard).
  *
  * @return string
  */
 public function actionIndex()
 {
     $userQuery = User::find()->andWhere(['status' => '10']);
     $userCloneQuery = clone $userQuery;
     $userCount = $userCloneQuery->count();
     $users = $userQuery->limit(12)->orderBy(['id' => SORT_DESC])->all();
     $postQuery = Post::find()->andWhere(['post_status' => 'publish']);
     $postCloneQuery = clone $postQuery;
     $postCount = $postCloneQuery->count();
     $posts = $postQuery->limit(10)->orderBy(['id' => SORT_DESC])->all();
     $commentQuery = PostComment::find()->andWhere(['comment_approved' => 'approved']);
     $commentCloneQuery = clone $commentQuery;
     $commentCount = $commentCloneQuery->count();
     $comments = $commentQuery->limit(5)->orderBy(['id' => SORT_DESC])->all();
     return $this->render('index', ['users' => $users, 'posts' => $posts, 'comments' => $comments, 'userCount' => $userCount, 'postCount' => $postCount, 'commentCount' => $commentCount]);
 }
コード例 #9
0
ファイル: CommentController.php プロジェクト: nsdown/getyii
 /**
  * 伪删除
  * @param $id
  * @return \yii\web\Response
  * @throws NotFoundHttpException
  */
 public function actionDelete($id)
 {
     $model = PostComment::findComment($id);
     if (!$model->isCurrent()) {
         throw new NotFoundHttpException();
     }
     // 事物 暂时数据库类型不支持 无效
     $transaction = \Yii::$app->db->beginTransaction();
     $updateComment = $model->updateCounters(['status' => -1]);
     $updateNotify = Notification::updateAll(['status' => 0], ['comment_id' => $model->id]);
     $updateTopic = Topic::updateAllCounters(['comment_count' => -1], ['id' => $model->post_id]);
     if ($updateNotify && $updateComment && $updateTopic) {
         $transaction->commit();
     } else {
         $transaction->rollback();
     }
     return $this->redirect(['/topic/default/view', 'id' => $model->post_id]);
 }
コード例 #10
0
ファイル: SiteController.php プロジェクト: writesdown/app-cms
 /**
  * Show user count, post count, post-comment count on index (dashboard).
  *
  * @return string
  */
 public function actionIndex()
 {
     // Get list User model
     $userQuery = User::find()->andWhere(['status' => '10']);
     $userCloneQuery = clone $userQuery;
     $userCount = $userCloneQuery->count();
     $users = $userQuery->limit(8)->orderBy(['id' => SORT_DESC])->all();
     // Get list Post model
     $postQuery = Post::find()->andWhere(['status' => 'publish'])->andWhere(['<=', 'date', date('Y-m-d H:i:s')]);
     $postCloneQuery = clone $postQuery;
     $postCount = $postCloneQuery->count();
     $posts = $postQuery->limit(5)->orderBy(['id' => SORT_DESC])->all();
     // Get list PostComment model
     $commentQuery = PostComment::find()->andWhere(['status' => 'approved']);
     $commentCloneQuery = clone $commentQuery;
     $commentCount = $commentCloneQuery->count();
     $comments = $commentQuery->limit(3)->orderBy(['id' => SORT_DESC])->all();
     return $this->render('index', ['users' => $users, 'posts' => $posts, 'comments' => $comments, 'userCount' => $userCount, 'postCount' => $postCount, 'commentCount' => $commentCount]);
 }
コード例 #11
0
ファイル: UserService.php プロジェクト: nsdown/getyii
 /**
  * 对评论点赞
  * @param User $user
  * @param PostComment $comment
  * @param $action
  * @return array
  */
 public static function CommentAction(User $user, PostComment $comment, $action)
 {
     $data = ['target_id' => $comment->id, 'target_type' => $comment::TYPE, 'user_id' => $user->id, 'value' => '1'];
     if (!UserMeta::deleteOne($data + ['type' => $action])) {
         // 删除数据有行数则代表有数据,无行数则添加数据
         $userMeta = new UserMeta();
         $userMeta->setAttributes($data + ['type' => $action]);
         $result = $userMeta->save();
         if ($result) {
             $comment->updateCounters([$action . '_count' => 1]);
             // 更新个人总统计
             UserInfo::updateAllCounters([$action . '_count' => 1], ['user_id' => $comment->user_id]);
         }
         return [$result, $userMeta];
     }
     $comment->updateCounters([$action . '_count' => -1]);
     // 更新个人总统计
     UserInfo::updateAllCounters([$action . '_count' => -1], ['user_id' => $comment->user_id]);
     return [true, null];
 }
コード例 #12
0
ファイル: PostComment.php プロジェクト: hdushku/app-cms
 /**
  * Creates data provider instance with search query applied
  *
  * @param array    $params
  *
  * @param int      $post_type
  * @param int|null $post_id
  *
  * @return ActiveDataProvider
  */
 public function search($params, $post_type, $post_id = null)
 {
     $query = PostCommentModel::find();
     $query->innerJoinWith(['commentPost' => function ($query) {
         /* @var $query \yii\db\ActiveQuery */
         return $query->from(['post' => Post::tableName()]);
     }]);
     $query->andWhere(['post.post_type' => $post_type]);
     if ($post_id) {
         $query->andWhere(['post.id' => $post_id]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'comment_post_id' => $this->comment_post_id, 'comment_parent' => $this->comment_parent, 'comment_user_id' => $this->comment_user_id]);
     $query->andFilterWhere(['like', 'comment_author', $this->comment_author])->andFilterWhere(['like', 'comment_author_email', $this->comment_author_email])->andFilterWhere(['like', 'comment_author_url', $this->comment_author_url])->andFilterWhere(['like', 'comment_author_ip', $this->comment_author_ip])->andFilterWhere(['like', 'comment_content', $this->comment_content])->andFilterWhere(['like', 'comment_approved', $this->comment_approved])->andFilterWhere(['like', 'comment_agent', $this->comment_agent])->andFilterWhere(['like', 'comment_date', $this->comment_date])->andFilterWhere(['like', 'post.post_title', $this->post_title]);
     return $dataProvider;
 }
コード例 #13
0
ファイル: DefaultController.php プロジェクト: iiyii/getyii
 /**
  * 话题详细页
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $model = Topic::findTopic($id);
     //登录才能访问的节点内容
     if (\Yii::$app->user->isGuest && in_array($model->category->alias, params('loginNode'))) {
         $this->flash('查看本主题需要登录!', 'warning');
         return $this->redirect(['/site/login']);
     }
     $dataProvider = new ActiveDataProvider(['query' => PostComment::findCommentList($id), 'pagination' => ['pageSize' => self::PAGE_SIZE], 'sort' => ['defaultOrder' => ['created_at' => SORT_ASC]]]);
     // 文章浏览次数
     Topic::updateAllCounters(['view_count' => 1], ['id' => $id]);
     //内容页面打赏
     if (in_array($model->category->alias, params('donateNode')) || array_intersect(explode(',', $model->tags), params('donateTag'))) {
         $donate = Donate::findOne(['user_id' => $model->user_id, 'status' => Donate::STATUS_ACTIVE]);
     }
     /** @var User $user */
     $user = Yii::$app->user->identity;
     $admin = $user && ($user->isAdmin($user->username) || $user->isSuperAdmin($user->username)) ? true : false;
     return $this->render('view', ['model' => $model, 'dataProvider' => $dataProvider, 'comment' => new PostComment(), 'admin' => $admin, 'donate' => isset($donate) ? $donate : []]);
 }
コード例 #14
0
 /**
  * Finds the PostComment model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param integer $id
  *
  * @return PostComment the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = PostComment::findOne($id)) !== null) {
         return $model;
     }
     throw new NotFoundHttpException('The requested page does not exist.');
 }
コード例 #15
0
ファイル: DefaultController.php プロジェクト: tqsq2005/getyii
 protected function comment($userId)
 {
     return new ActiveDataProvider(['query' => PostComment::find()->where(['user_id' => $userId, 'status' => 1])->orderBy(['created_at' => SORT_DESC])]);
 }
コード例 #16
0
ファイル: PostCommentCest.php プロジェクト: hdushku/app-cms
 /**
  * @param AcceptanceTester $I
  */
 public function testReply(AcceptanceTester $I)
 {
     $I->wantTo('ensure that reply post-comment works');
     $replyPage = ReplyPage::openBy($I);
     $I->amGoingTo('reply post-comment with no content');
     $replyPage->submit();
     $I->expectTo('see validation error');
     $I->see('Content cannot be blank.', '.help-block');
     $I->amGoingTo('reply post-comment with no empty content');
     $replyPage->submit('Test reply post-comment');
     $I->expect('the reply saved');
     $I->see('Update Post Comment: 2', 'h1');
     PostComment::deleteAll(['comment_content' => 'Test reply post-comment']);
 }
コード例 #17
0
ファイル: PostCommentCest.php プロジェクト: hdushku/app-cms
 /**
  * @param FunctionalTester $I
  */
 public function testUpdate(FunctionalTester $I)
 {
     $I->wantTo('ensure that update post-comment works');
     $updatePage = UpdatePage::openBy($I);
     $I->see('Update Post Comment: 1', 'h1');
     $I->amGoingTo('submit post-comment with no correct email & url');
     $updatePage->submit(['comment_author' => 'Tester', 'comment_author_email' => 'tester.author@test', 'comment_author_url' => 'http://.com']);
     $I->expectTo('see that email & url not correct');
     $I->see('Email is not a valid email address.', '.help-block');
     $I->see('URL is not a valid URL.', '.help-block');
     $I->amGoingTo('submit post-comment with correct data');
     $updatePage->submit(['comment_author' => 'Tester', 'comment_author_email' => '*****@*****.**', 'comment_author_url' => 'http://tester.com']);
     $I->expect('post-comment updated');
     $I->dontSee('Email is not a valid email address.', '.help-block');
     $I->dontSee('URL is not a valid URL.', '.help-block');
     PostComment::findOne(1)->updateAll(['comment_author' => 'Mr. WritesDown', 'comment_author_email' => '*****@*****.**', 'comment_author_url' => 'http://www.writesdown.com']);
 }
コード例 #18
0
ファイル: PostCest.php プロジェクト: hdushku/app-cms
 /**
  * @param AcceptanceTester $I
  */
 public function testComment(AcceptanceTester $I)
 {
     $I->wantTo('ensure that post comment works');
     $postView = PostViewPage::openBy($I);
     // $I->see('Sample Post', 'h1');
     $I->see('Sample Post');
     $I->amGoingTo('submit post comment form with no data');
     $postView->submitComment([]);
     $I->expectTo('see validations error');
     $I->see('Name cannot be blank.', '.help-block');
     $I->see('Email cannot be blank.', '.help-block');
     $I->see('Content cannot be blank.', '.help-block');
     $I->amGoingTo('submit post comment form with no correct email');
     $postView->submitComment(['comment_author' => 'tester', 'comment_author_email' => 'tester.email', 'comment_content' => 'New comment']);
     $I->expectTo('see that email is not correct');
     $I->see('Email is not a valid email address.');
     $I->dontSee('Name cannot be blank.', '.help-block');
     $I->dontSee('Content cannot be blank.', '.help-block');
     $I->amGoingTo('submit post comment form with correct data');
     $postView->submitComment(['comment_author' => 'tester', 'comment_author_email' => '*****@*****.**', 'comment_content' => 'New comment']);
     $I->expect('new comment saved');
     $I->dontSee('Name cannot be blank.', '.help-block');
     $I->dontSee('Email cannot be blank.', '.help-block');
     $I->dontSee('Content cannot be blank.', '.help-block');
     PostComment::deleteAll(['comment_author' => 'tester']);
     Post::findOne(1)->updateAttributes(['post_comment_count' => '1']);
 }
コード例 #19
0
 public function actionSync()
 {
     UserInfo::updateAll(['thanks_count' => 0, 'like_count' => 0, 'hate_count' => 0]);
     $meta = UserMeta::find()->all();
     foreach ($meta as $key => $value) {
         if (in_array($value->type, ['thanks', 'like', 'hate'])) {
             switch ($value->target_type) {
                 case 'topic':
                 case 'post':
                     echo '同步文章操作</br>';
                     $topic = Topic::findOne($value->target_id);
                     UserInfo::updateAllCounters([$value->type . '_count' => 1], ['user_id' => $topic->user_id]);
                     break;
                 case 'comment':
                     echo '同步评论操作</br>';
                     $comment = PostComment::findOne($value->target_id);
                     UserInfo::updateAllCounters([$value->type . '_count' => 1], ['user_id' => $comment->user_id]);
                     break;
                 default:
                     # code...
                     break;
             }
         }
     }
     return;
 }
コード例 #20
0
ファイル: Post.php プロジェクト: pramana08/app-cms
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPostComments()
 {
     return $this->hasMany(PostComment::className(), ['comment_post_id' => 'id']);
 }
コード例 #21
0
ファイル: UserMeta.php プロジェクト: grutabow/getyii
 public function getComment()
 {
     return $this->hasOne(PostComment::className(), ['id' => 'target_id']);
 }