Example #1
0
 public function actionAddComment()
 {
     if (\Yii::$app->request->isAjax) {
         $model = new Comment();
         if (\Yii::$app->user->isGuest) {
             $model->scenario = 'isGuest';
         }
         $data = ['error' => true];
         if ($model->load(\Yii::$app->request->post())) {
             $parentID = \Yii::$app->request->post('parent_id');
             $root = $model->makeRootIfNotExist();
             if (!$parentID) {
                 $model->appendTo($root);
             } else {
                 $parent = Comment::find()->where(['id' => $parentID])->one();
                 $model->appendTo($parent);
             }
             $articleModel = Article::findOne($model->model_id);
             $data = ['replaces' => [['what' => '#comments', 'data' => $this->renderAjax('@app/themes/basic/modules/article/views/default/_comments', ['model' => $articleModel])]]];
         }
         return Json::encode($data);
     } else {
         throw new NotFoundHttpException(\Yii::t('app', 'Page not found'));
     }
 }
Example #2
0
 /**
  * 
  * @param int $data
  * @return \yii\data\ActiveDataProvider
  */
 public static function findComments($data = array())
 {
     if (!isset($data['limit'])) {
         $data['limit'] = 10;
     }
     $model = new Comment();
     $dataProvider = new ActiveDataProvider(['query' => $model->find()->Where('is_public=:isp and top_id=0 and c_type="article" ', [':isp' => $data['is_public']])->orderBy(" id desc ")->limit($data['limit']), 'pagination' => ['pagesize' => $data['limit']]]);
     return $dataProvider;
 }
Example #3
0
 public function actionComment($id)
 {
     $model = new Comment();
     $model->load(Yii::$app->request->post());
     $model->article_id = $id;
     if ($model->validate()) {
         $model->save();
         Yii::$app->session->setFlash("success", "Ок");
     }
     $this->redirect(["article/view", "id" => $id]);
 }
Example #4
0
 public function actionView($slug)
 {
     $commentForm = new Comment();
     if ($commentForm->load(Yii::$app->request->post())) {
         if ($commentForm->save()) {
             Yii::$app->session->setFlash('success', '评论发表成功');
         } else {
             Yii::$app->session->setFlash('error', '评论发表失败');
         }
     }
     return $this->render('view', ['article' => Page::getInstance()->getBySlug($slug), 'commentForm' => $commentForm]);
 }
Example #5
0
 /**
  * Displays homepage.
  *
  * @return mixed
  */
 public function actionIndex()
 {
     $model = new Comment();
     if ($model->load(Yii::$app->request->post())) {
         $model->is_active = 0;
         $model->created_at = date('Y-m-d H:i:s');
         $model->updated_at = date('Y-m-d H:i:s');
         $model->save();
         Yii::$app->session->setFlash('success', 'Thank you! Your comment has been added successfully. It will be available after moderation ;)');
         return $this->redirect('/');
     }
     return $this->render('comments', ['model' => $model]);
 }
 public function actionAddComment()
 {
     $productId = Yii::$app->request->post('productId');
     $rank = Yii::$app->request->post('rank');
     $content = Yii::$app->request->post('content');
     $comment = new Comment();
     $comment->attributes = ['product_id' => $productId, 'user_id' => Yii::$app->user->identity->id, 'rank' => $rank, 'content' => $content];
     if ($comment->save(true)) {
         return ['status' => true, 'message' => '成功'];
     } else {
         return ['status' => false, 'message' => '失败: ' . Html::errorSummary($comment)];
     }
 }
Example #7
0
 /**
  * 保存商品
  */
 public function save()
 {
     $newComent = new Comment();
     $newComent->setAttributes($this->attributes);
     $newComent->setAttribute('c_type', 'article');
     $newComent->setAttribute("c_addtime", date('Y-m-d H:i:s'));
     if ($newComent->save()) {
         $logisct_id = \Yii::$app->db->lastInsertID;
         return $logisct_id;
     } else {
         return FALSE;
     }
 }
Example #8
0
 /**
  * Displays a single Post model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $list_comment = new ActiveDataProvider(['query' => Comment::find()->where(['post_id' => $id, 'status' => 1])]);
     $model_comment = new Comment();
     if ($model_comment->load(Yii::$app->request->post())) {
         $model_comment->post_id = $id;
         $model_comment->status = 0;
         if ($model_comment->save()) {
             Yii::$app->session->setFlash('success', 'Ваш комментарий был отправлен администраторам сайта и будет опубликован после проверки..');
         } else {
             Yii::$app->session->setFlash('error', 'Ваш комментарий не был отправлен по техническим причинам. Попробуйте ещё раз.');
         }
     }
     return $this->render('view', ['model' => $this->findModel($id), 'list_comment' => $list_comment, 'model_comment' => $model_comment]);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Comment::find();
     $commentTable = Comment::tableName();
     $user = Yii::$app->getModule("user")->model("User");
     // set up query with relation to `user.username`
     $userTable = $user::tableName();
     $query->joinWith(['user' => function ($query) use($userTable) {
         $query->from(['user' => $userTable]);
     }]);
     $profileTable = \common\modules\user\models\Profile::tableName();
     $query->joinWith(['profile' => function ($query) use($profileTable) {
         $query->from(['profile' => $profileTable]);
     }]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     // enable sorting for the related columns
     $addSortAttributes = ["user.username", 'profile.full_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;
     }
     $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]);
     }
     $query->andFilterWhere(["{$commentTable}.id" => $this->id, "{$commentTable}.user_id" => $this->user_id, 'parent_id' => $this->parent_id]);
     $query->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'user.username', $this->getAttribute('user.username')])->andFilterWhere(['like', 'profile.full_name', $this->getAttribute('profile.full_name')]);
     return $dataProvider;
 }
Example #10
0
 public function run()
 {
     $commentModel = new Comment();
     if (\Yii::$app->user->isGuest) {
         $commentModel->scenario = 'isGuest';
     }
     $commentModel->model_name = $this->model->formName();
     $commentModel->model_id = $this->model->id;
     $root = $commentModel->getRoot();
     if ($root) {
         $commentModels = $root->getChildren();
     } else {
         $commentModels = [];
     }
     return $this->render('default', ['commentModel' => $commentModel, 'model' => $this->model, 'commentModels' => $commentModels]);
 }
Example #11
0
 /**
  * 显示一个文章的信息
  * @return type
  */
 public function actionArticle()
 {
     $id = \Yii::$app->request->get('id');
     $idTrue = true;
     if (empty($id)) {
         $idTrue = FALSE;
     }
     if ($idTrue) {
         $articleInfo = Comment::find()->where('id=:id', [':id' => $id])->one();
         if (!$articleInfo) {
             $idTrue = FALSE;
         } else {
             if ($articleInfo->is_public === 0 && \Yii::$app->user->getId() !== $articleInfo->to_user_id && \Yii::$app->user->getId() !== $articleInfo->user_id) {
                 $idTrue = FALSE;
             }
         }
     }
     if (!$idTrue) {
         $error = '当前评论不存在或者已经被禁止显示';
         $notices = array('type' => 2, 'msgtitle' => '错误的访问', 'message' => $error, 'backurl' => Url::toRoute('/say/index'), 'backtitle' => '返回');
         Yii::$app->getSession()->setFlash('wechat_fail', array($notices));
         $this->redirect(Url::toRoute('/public/notices'));
     }
     return $this->render('article', ['articleInfo' => $articleInfo]);
 }
 public function actionIndex()
 {
     $page = $this->helpGquery('page', 1);
     $size = 9;
     $offset = ($page - 1) * $size;
     $comment = new Comment();
     $values = $comment->getComments(null, $offset, $size, null);
     $comments = $values['list'];
     array_walk($comments, function (&$value, $key) {
         $value['addtime'] = date('Y-m-d H:i', $value['addtime']);
     });
     $total = $values['total'];
     $pageHTML = $this->getPageHTML($page, $size, $total);
     $params = ['comments' => $comments, 'pageHTML' => $pageHTML];
     return $this->render('index', $params);
 }
Example #13
0
 /**
  * Возвращает комментарий.
  * @param int $id идентификатор комментария
  * @throws NotFoundHttpException
  * @return Comment
  */
 public function getComment($id)
 {
     if (($model = Comment::findOne($id)) !== null && $model->isPublished()) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested post does not exist.');
     }
 }
 public function actionIndex($id)
 {
     $user = User::findIdentity($id);
     $comments = Comment::getRecentComments();
     $sidebarCategories = Category::getSidebarCategories();
     $tags = Tag::getTagList();
     return $this->render('index', ['user' => $user, 'comments' => $comments, 'sidebarCategories' => $sidebarCategories, 'tags' => $tags]);
 }
Example #15
0
 public function actionView($slug)
 {
     $post = Post::findOne(['slug' => $slug]);
     $comment = new Comment();
     $comment->name = '';
     $comment->email = '';
     $comment->body = '';
     if ($comment->load(Yii::$app->request->post())) {
         $comment->status = 0;
         if ($comment->save()) {
             Yii::$app->session->setFlash('success', ['type' => 'success', 'duration' => 12000, 'icon' => 'fa fa-chat', 'message' => 'You\'re comment successfully stored and will shown after approval.', 'title' => 'Saving Comment']);
         } else {
             Yii::$app->session->setFlash('error', ['type' => 'danger', 'duration' => 12000, 'icon' => 'fa fa-chat', 'message' => 'Sorry but we couldn\'t store your comment.', 'title' => 'Saving Comment']);
         }
     }
     return $this->render('view', ['post' => $post, 'comment' => $comment]);
 }
 /**
  * Finds the Comment model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Comment the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Comment::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * @return array
  * Добавление комментария
  */
 public function actionAddComment()
 {
     if (\Yii::$app->request->isAjax) {
         \Yii::$app->response->format = Response::FORMAT_JSON;
         $model = new Comment();
         $model->user_id = \Yii::$app->user->identity->id;
         $model->event_id = $_POST['event_id'];
         $model->message = $_POST['message'];
         $model->created = time();
         if ($model->save()) {
             if (isset($_POST['notify_all']) && $_POST['notify_all'] == 'true') {
                 EventForm::commenatAllNotification($_POST['event_id'], $_POST['message']);
             }
             return ['item' => $model, 'user' => $model->user];
         }
     }
 }
Example #18
0
 public function beforeSave($insert)
 {
     if ($this->checked != 1) {
         $this->checked = 1;
     }
     return parent::beforeSave($insert);
     // TODO: Change the autogenerated stub
 }
Example #19
0
 public function save()
 {
     $comment = Comment::findOne($this->commentID);
     $comment->setAttributes(['author' => $this->author, 'text' => $this->text, 'email' => $this->email, 'published' => $this->published, 'deleted' => $this->deleted]);
     if ($comment->save(false)) {
         \Yii::$app->session->setFlash('saved', 'Комментарий сохранён!');
     } else {
         \Yii::$app->session->setFlash('error', 'Комментарий не сохранён!');
     }
 }
 /**
  * Displays a single Suggestion model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $comment = new Comment();
     if (Yii::$app->request->post()) {
         $comment->sugg_id = $id;
         $comment->part_id = strval(Yii::$app->user->id);
         $comment->content = Yii::$app->request->post('Comment')['content'];
         if ($comment->save()) {
             Yii::$app->session->setFlash('success', '评论成功');
             return $this->redirect(['view', 'id' => $id]);
         } else {
             error_log(print_r($comment->errors, true));
             Yii::$app->session->setFlash('error', '评论失败');
             return $this->redirect(['view', 'id' => $id]);
         }
     }
     $commentsProvider = new ActiveDataProvider(['query' => Comment::find()->where(['sugg_id' => $id])->orderBy('created_at DESC'), 'pagination' => ['pageSize' => 20]]);
     return $this->render('view', ['model' => $this->findModel($id), 'comment' => $comment, 'commentsProvider' => $commentsProvider]);
 }
Example #21
0
 /**
  * Displays homepage.
  *
  * @return mixed
  */
 public function actionIndex()
 {
     $query = Page::find()->where(['live' => 1]);
     $pagination = new Pagination(['defaultPageSize' => 2, 'totalCount' => $query->count()]);
     $pages = $query->offset($pagination->offset)->limit($pagination->limit)->all();
     $comments = Comment::getRecentComments();
     $sidebarCategories = Category::getSidebarCategories();
     $tags = Tag::getTagList();
     return $this->render('index', ['pages' => $pages, 'pagination' => $pagination, 'comments' => $comments, 'sidebarCategories' => $sidebarCategories, 'tags' => $tags]);
 }
 public function actionDetail($id)
 {
     $postModel = new Comment();
     if ($postModel->load(Yii::$app->request->post())) {
         $postModel->status = Comment::STATUS_INACTIVE;
         $postModel->post_id = $id;
         if ($postModel->save()) {
             $this->added = 1;
         }
     }
     $tags = Tag::findTagWeights();
     $cateModel = new Cate();
     $cateDataProvider = $cateModel->getCates();
     $postData = new Post();
     $postDataProvider = $postData->findRecentPosts();
     $commentModel = new Comment();
     $commentDataProvider = $commentModel->findRecentComments();
     return $this->render('detail', ['tags' => $tags, 'added' => $this->added, 'postModel' => $postModel, 'model' => $this->findModel($id), 'postDataProvider' => $postDataProvider, 'cateDataProvider' => $cateDataProvider, 'commentDataProvider' => $commentDataProvider]);
 }
Example #23
0
 /**
  * @inheritdoc
  */
 public function afterDelete()
 {
     Tagging::deleteAll(['taggable_type' => Tagging::TAGGABLE_ALBUM, 'taggable_id' => $this->id]);
     Relation::deleteAll(['relationable_type' => Relation::RELATIONABLE_ALBUM, 'relationable_id' => $this->id]);
     Comment::deleteAll(['commentable_type' => Comment::COMMENTABLE_ALBUM, 'commentable_id' => $this->id]);
     CommentCount::deleteAll(['commentable_type' => CommentCount::COMMENTABLE_ALBUM, 'commentable_id' => $this->id]);
     $assets = Asset::find()->where(['assetable_type' => Asset::ASSETABLE_ALBUM, 'assetable_id' => $this->id])->all();
     foreach ($assets as $asset) {
         $asset->delete();
     }
 }
Example #24
0
 public function run()
 {
     $query = Comment::find();
     if ($this->entity == Comment::ENTITY_ITEM || $this->entity == Comment::ENTITY_EVENT || $this->entity == Comment::ENTITY_SCHOOL) {
         $query = $query->andWhere(['entity' => $this->entity, 'entity_id' => $this->entity_id])->orderBy('date_create DESC');
     }
     $commentsAll = $query->all();
     $commentIds = [];
     $comments = [];
     $commentsParent = [];
     $commentsLink = [];
     /** @var Comment[] $commentsAll */
     foreach ($commentsAll as $comment) {
         if ($comment->parent_id == 0) {
             // Главный комментарий
             $commentsLink[$comment->id] = true;
             $commentIds[] = $comment->id;
             if ($comment->deleted == 0) {
                 $comments[] = $comment;
             }
         } else {
             // Ответ на комментарий
             $commentsLink[$comment->id] = $comment->parent_id;
         }
     }
     foreach ($commentsAll as $comment) {
         if ($comment->deleted == 0) {
             $commentId = $comment->parent_id;
             while (isset($commentsLink[$commentId])) {
                 if ($commentsLink[$commentId] === true) {
                     break;
                 } else {
                     if ($commentsLink[$commentId] != $commentId) {
                         $commentId = $commentsLink[$commentId];
                     } else {
                         $commentId = null;
                     }
                 }
             }
             if (!empty($commentId)) {
                 $commentsParent[$commentId][] = $comment;
                 $commentIds[] = $comment->id;
             }
         }
     }
     $thisUser = User::thisUser();
     /** @var Vote[] $voteItemsAll */
     $voteItemsAll = !empty($thisUser) ? $thisUser->getVotesByEntity(Vote::ENTITY_COMMENT, $commentIds) : [];
     $voteItems = [];
     foreach ($voteItemsAll as $voteItem) {
         $voteItems[$voteItem->entity_id] = $voteItem;
     }
     return $this->render('commentsWidget/list', ['comments' => $comments, 'voteItems' => $voteItems, 'commentsParent' => $commentsParent, 'entity' => $this->entity, 'entity_id' => $this->entity_id, 'showDialog' => $this->showDialog]);
 }
Example #25
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Comment::find();
     $query->orderBy(['created_at' => SORT_DESC]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if ($this->load($params) && !$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'product_id' => $this->product_id, 'order_id' => $this->order_id, 'star' => $this->star, 'point' => $this->point, 'up' => $this->up, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
Example #26
0
 public function actionAlarm()
 {
     $id = Yii::$app->request->post('id');
     $msg = Yii::$app->request->post('msg');
     $comment = Comment::findOne($id);
     if ($comment && !empty($msg)) {
         if (Alarm::addAlarm(Alarm::ENTITY_COMMENT, $comment->id, $msg)) {
             return json_encode(['content' => \frontend\widgets\CommentsWidget::widget(['entity' => $comment->entity, 'entity_id' => $comment->entity_id, 'showDialog' => false]), 'anchor' => $comment->id]);
         } else {
             return json_encode(['content' => '', 'anchor' => '']);
         }
     }
 }
Example #27
0
 public function actionDeletePost()
 {
     $selection = (array) Yii::$app->request->post('selection');
     foreach ($selection as $id) {
         Post::deleteAll(['id' => $id]);
         Like::deleteAll(['post_id' => $id]);
         Comment::deleteAll(['post_id' => $id]);
         PostTag::deleteAll(['post_id' => $id]);
         PostNotification::deleteAll(['post_id' => $id]);
         PostProtected::deleteAll(['post_id' => $id]);
     }
     return $this->render('post-manage');
 }
Example #28
0
 public function actionView($slug)
 {
     $commentForm = new Comment();
     $article = Content::find()->where(['slug' => $slug, 'type' => Content::TYPE_ARTICLE, 'status' => Content::STATUS_ACTIVE])->with(['createdBy', 'category', 'tags'])->one();
     if (empty($article)) {
         throw new NotFoundHttpException('没有找到相应文章。。。');
     }
     if ($commentForm->load(Yii::$app->request->post())) {
         $commentForm->content_id = $article['id'];
         if ($commentForm->save()) {
             Yii::$app->session->setFlash('success', '评论发表成功');
             return $this->refresh();
         } else {
             Yii::$app->session->setFlash('error', '评论发表失败');
         }
     }
     $article->updateCounters(['view_total' => 1]);
     $model = Comment::find()->where(['content_id' => $article['id'], 'status' => Comment::STATUS_ACTIVE]);
     $countModel = clone $model;
     $commentsPagination = new Pagination(['totalCount' => $countModel->count('id')]);
     $comments = $model->orderBy('created_at')->select(['id', 'ip', 'url', 'text', 'created_at', 'email', 'nickname', 'parent_id'])->asArray()->all();
     return $this->render('view', ['article' => $article, 'commentForm' => $commentForm, 'comments' => $comments, 'commentsPagination' => $commentsPagination]);
 }
Example #29
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Comment::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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;
     }
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'create_time' => $this->create_time, 'post_id' => $this->post_id]);
     $query->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'user_id', $this->user_id])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'url', $this->url]);
     return $dataProvider;
 }
 public function up()
 {
     $comments = new \yii\db\Query();
     $comments = $comments->from(\Yii::$app->params['oldDb'] . '.joom_jcomments');
     $commentsCount = $comments->count();
     echo "    > migrating comments... Almost have {$commentsCount} comments...\r\n";
     echo "    > prepare comments...\r\n";
     $i = 0;
     $prepared = [];
     foreach ($comments->each() as $comment) {
         $i++;
         echo "    > comment {$i} from {$commentsCount}... \r\n";
         $commentModel = new Comment(['newsID' => $comment['object_id'], 'author' => $comment['name'], 'email' => $comment['email'], 'text' => $comment['comment'], 'date' => strtotime($comment['date']), 'isGood' => $comment['isgood'], 'isBad' => $comment['ispoor'], 'published' => $comment['published'], 'deleted' => $comment['deleted'], 'id' => $comment['id']]);
         $commentModel->setIp($comment['ip']);
         if (!empty($commentModel->ip) && mb_strlen($commentModel->author, 'utf8') < 64 && $commentModel->date > 0 && $commentModel->date < time() + 86400) {
             $prepared[] = $commentModel->attributes;
         }
         if (count($prepared) >= 100 || $commentsCount - $i == 0) {
             $this->batchInsert(Comment::tableName(), array_keys($prepared[0]), $prepared);
             $prepared = [];
         }
     }
 }