Example #1
0
 public function run()
 {
     $attr = $this->getAttributes();
     $map = array("module" => $this->getModule(), "table" => $this->getTable(), "rowid" => $attr["rowid"], "isdel" => 0);
     $attr["count"] = Comment::model()->countByAttributes($map);
     $list = $this->getCommentList();
     $isAdministrator = Ibos::app()->user->isadministrator;
     $uid = Ibos::app()->user->uid;
     foreach ($list as &$cm) {
         $cm["isCommentDel"] = $isAdministrator || $uid === $cm["uid"];
         $cm["replys"] = intval(Comment::model()->countByAttributes(array("module" => "message", "table" => "comment", "rowid" => $cm["cid"], "isdel" => 0)));
     }
     $attr["comments"] = $list;
     $attr["lang"] = Ibos::getLangSources(array("message.default"));
     $content = $this->render($this->getParseView("comment"), $attr, true);
     $ajax = $attr["inAjax"];
     $count = $attr["count"];
     unset($attr);
     $return = array("isSuccess" => true, "data" => $content, "count" => $count);
     if ($ajax == 1) {
         $this->getOwner()->ajaxReturn($return);
     } else {
         echo $return["data"];
     }
 }
Example #2
0
 public function actionLike()
 {
     if (Yii::app()->request->isAjaxRequest) {
         $id = (int) $_POST['_id'];
         $type = (string) $_POST['type'];
         if (isset($_POST)) {
             $model = Comment::model()->findByPk($id);
             if ($type == 'up') {
                 $model->like += 1;
             } elseif ($type == 'down') {
                 $model->like -= 1;
             }
             //$model->like->user_id = (!Yii::app()->user->isGuest) ? Yii::app()->user->id : 0;
             if ($model->validate()) {
                 if ($model->save()) {
                     //$like = new CommentLike();
                     //$like->comment_id = $model->id; // Or get the data from the submitted form.
                     // $like->user_id = (!Yii::app()->user->isGuest) ? Yii::app()->user->id : 0;
                     //$like->save();
                 }
                 $json = array('num' => $model->like);
                 echo CJSON::encode($json);
             }
         }
     }
 }
Example #3
0
 public function actionComment($callback, $id = 0)
 {
     $id = (int) $id;
     $callback = strip_tags(trim($callback));
     if (!request()->getIsAjaxRequest() || !request()->getIsPostRequest() || empty($callback)) {
         throw new CHttpException(500);
     }
     $data = array();
     $model = new CommentForm();
     $model->attributes = $_POST['CommentForm'];
     $model->content = h($model->content);
     if ($id > 0 && ($quote = Comment::model()->findByPk($id))) {
         $quoteTitle = sprintf(t('comment_quote_title'), $quote->authorName);
         $html = '<fieldset class="beta-comment-quote"><legend>' . $quoteTitle . '</legend>' . $quote->content . '</fieldset>';
         $model->content = $html . $model->content;
     }
     if ($model->validate() && ($comment = $model->save())) {
         $data['errno'] = 0;
         $data['text'] = t('ajax_comment_done');
         $data['html'] = $this->renderPartial('/comment/_one', array('comment' => $comment), true);
         // @todo 反回此条评论的html代码
     } else {
         $data['errno'] = 1;
         $attributes = array_keys($model->getErrors());
         foreach ($attributes as $attribute) {
             $labels[] = $model->getAttributeLabel($attribute);
         }
         $errstr = join(' ', $labels);
         $data['text'] = sprintf(t('ajax_comment_error'), $errstr);
     }
     echo $callback . '(' . json_encode($data) . ')';
     exit(0);
 }
 /**
  * Fire this notification on given comment object
  *
  * @param type $comment
  */
 public static function fire($comment)
 {
     $targetCreatorId = $comment->content->user_id;
     // gets also an new comment notification
     // Get Users which are also commented this model
     $userIds = array();
     $otherComments = Comment::model()->findAllByAttributes(array('object_model' => $comment->object_model, 'object_id' => $comment->object_id));
     foreach ($otherComments as $otherComment) {
         if ($comment->created_by != $otherComment->created_by && $otherComment->created_by != $targetCreatorId) {
             $userIds[] = $otherComment->created_by;
         }
     }
     $userIds = array_unique($userIds);
     // Write new Notification for them
     foreach ($userIds as $userId) {
         $notification = new Notification();
         $notification->class = "AlsoCommentedNotification";
         $notification->user_id = $userId;
         $notification->space_id = $comment->space_id;
         $notification->source_object_model = "Comment";
         $notification->source_object_id = $comment->id;
         $notification->target_object_model = $comment->object_model;
         $notification->target_object_id = $comment->object_id;
         $notification->save();
     }
 }
 /**
  * Count all comments a content object has received.
  *
  * @param Content $content : The content object
  * @param $userId : The user id
  * @param $cacheId : The cache id
  * @param bool $countOwnComments : Count comments created by same user as content
  * @param bool $forceUpdate : true if cache should be ignored
  * @return Comment[]
  */
 public function getCommentsFromContent(Content $content, $userId, $cacheId, $countOwnComments = false, $forceUpdate = false)
 {
     $comments = Yii::app()->cache->get($cacheId);
     if ($comments === false || $forceUpdate === true) {
         $objectModel = strtolower($content->object_model);
         $comments = array();
         try {
             $criteria = new CDbCriteria();
             $criteria->alias = 'c';
             $criteria->join = 'LEFT JOIN ' . $objectModel . ' o ON c.object_id = o.id';
             $criteria->join .= ' LEFT JOIN content ct ON o.id=ct.object_id';
             if ($countOwnComments === true) {
                 $criteria->condition = 'ct.id=:contentId AND ct.created_by=:userId AND c.object_model=ct.object_model';
             } else {
                 $criteria->condition = 'ct.id=:contentId AND ct.created_by=:userId AND c.created_by!=:userId AND c.object_model=ct.object_model';
             }
             $criteria->params = array(':contentId' => $content->id, ':userId' => $userId);
             $comments = Comment::model()->findAll($criteria);
             Yii::app()->cache->set($cacheId, $comments, ReputationBase::CACHE_TIME_SECONDS);
         } catch (Exception $e) {
             Yii::trace('Couldn\'t count comments from object model: ' . $objectModel);
         }
     }
     return $comments;
 }
 public function run()
 {
     parent::run();
     $data = array();
     $id_listen_cat = Category::model()->findAll("taxonomy_id = " . $this->_id_bai_hoc . " and state = 1");
     $id_listen_cat_array = array();
     foreach ($id_listen_cat as $k) {
         $id_listen_cat_array[] = $k->id;
     }
     $id_news_cat = Category::model()->findAll("taxonomy_id = " . $this->_id__tintuc . " and state = 1");
     $id_news_cat_array = array();
     foreach ($id_news_cat as $k) {
         $id_news_cat_array[] = $k->id;
     }
     $comment = Comment::model()->findAll(array("condition" => "state = 1", "limit" => 5, "order" => "id desc"));
     $options = array();
     $i = 0;
     foreach ($comment as $k) {
         $options[$i]['content'] = Content::model()->findByPk($k->content_id);
         $options[$i]['category'] = Category::model()->findByPk($options[$i]['content']->category_id);
         $options[$i]['parent'] = '';
         if ($options[$i]['category']->parent != 0) {
             $options[$i]['parent'] = Category::model()->findByPk($options[$i]['category']->parent);
         }
         $options[$i]['taxonomy'] = Taxonomy::model()->findByPk($options[$i]['category']->taxonomy_id);
         $i++;
     }
     $data['comments'] = $comment;
     $data['options'] = $options;
     $data['news'] = Content::model()->findAll(array("condition" => "state = 1 and category_id in (" . implode(",", $id_news_cat_array) . ")", "limit" => 10, "order" => "id desc"));
     $data['listen'] = Content::model()->findAll(array("condition" => "state = 1 and category_id in (" . implode(",", $id_listen_cat_array) . ")", "limit" => 10, "order" => "id desc"));
     $this->render('news_lession_comment', $data);
 }
Example #7
0
 /**
  * Displays a particular model.
  * @param integer $id the ID of the model to be displayed
  */
 public function actionProfile($username = '')
 {
     $this->layout = '//layouts/column1';
     if (!$username and Yii::app()->user->isGuest) {
         Yii::app()->user->setReturnUrl(Yii::app()->getRequest()->url);
         $this->redirect(array('site/login'));
     }
     if (!$username) {
         $this->redirect(array('profile/' . Yii::app()->user->name));
     }
     if (!($this->model = User::model()->find('username=:username', array(':username' => $username)))) {
         throw new CHttpException(404, 'The username ' . $username . ' does not exist.');
     }
     //$this->model=$this->loadModel($id);
     $this->model->country = Country::model()->findByPk($this->model->country_id)->name;
     $status = Yii::app()->db->createCommand()->select('*')->from('user_status')->queryRow();
     $this->model->status = $status['name'];
     $type = Yii::app()->db->createCommand()->select('*')->from('user_type')->queryRow();
     $this->model->type = $type['name'];
     $this->model->country_created = Country::model()->findByPk($this->model->country_id_created)->name;
     $stat_subs = Subject::model()->count('user_id=:user_id', array(':user_id' => $this->model->id));
     $stat_comments = Comment::model()->count('user_id=:user_id', array(':user_id' => $this->model->id));
     $stat_usage_counter = Log::model()->count('user_id=:user_id', array(':user_id' => $this->model->id));
     $last_log_line = Log::model()->find(array('limit' => 2, 'offset' => 1, 'order' => 't.id DESC', 'params' => array(':user_id' => $this->model->id)));
     $this->render('view', array('model' => $this->model, 'stat_subs' => $stat_subs, 'stat_comments' => $stat_comments, 'stat_last_online' => $last_log_line->time, 'stat_usage_counter' => $stat_usage_counter));
 }
Example #8
0
 /**
  * Добавляем комментарий
  */
 public function actionAddComment()
 {
     $model = new Comment();
     $app = Yii::app();
     // ajax validation
     if ($app->request->isAjaxRequest and $app->request->getPost('ajax')) {
         echo CActiveForm::validate($model);
         Yii::app()->end();
     }
     if ($post = $app->request->getPost('Comment')) {
         $model->attributes = $post;
         $model->date = date('Y-m-d H:i:s');
         $model->id_object = 1;
         //  тут будет id_post например
         $success = false;
         if ($post['parent']) {
             $parent = Comment::model()->findByPk($post['parent']);
             $success = $model->appendTo($parent);
         }
         $success = $model->saveNode();
         if ($success) {
             echo CJSON::encode(['success' => true]);
             Yii::app()->end();
         }
     }
     echo CActiveForm::validate($model);
 }
Example #9
0
 public function actionView()
 {
     $pid = Yii::app()->request->getParam('pid');
     $cid = Yii::app()->request->getParam('cid');
     $id = Yii::app()->request->getParam('id');
     $category = Category::model()->findByPk($pid);
     if ($category->taxonomy_id == $this->root_id) {
         $data = array();
         $data['item'] = Content::model()->findbyPk($id);
         if ($data['item']->category_id == $cid) {
             $data['cat'] = Category::model()->findbyPk($data['item']->category_id);
             $data['root_cat'] = Taxonomy::model()->findbyPk($data['cat']->taxonomy_id);
             $this->title = $data['item']->title;
             Content::model()->updateByPk($id, array('view' => $data['item']->view + 1));
             $data['comment_model'] = Comment::model()->findAll(array('condition' => 'content_id = :cid and state = 1', 'params' => array(':cid' => $id)));
             if ($data['item']->category_id != $cid) {
                 throw new CHttpException(404, 'PAGE NOT FOUND.');
             }
             $this->render('view', $data);
         } else {
             throw new CHttpException(404, 'PAGE NOT FOUND.');
         }
     } else {
         throw new CHttpException(404, 'PAGE NOT FOUND.');
     }
 }
Example #10
0
 public function run()
 {
     $ids = Yii::app()->request->getParam('id');
     $command = Yii::app()->request->getParam('command');
     empty($ids) && $this->controller->message('error', Yii::t('admin', 'No Select'));
     if (!is_array($ids)) {
         $ids = array($ids);
     }
     $criteria = new CDbCriteria();
     $criteria->addInCondition('id', $ids);
     switch ($command) {
         case 'delete':
             //删除
             Comment::model()->deleteAll($criteria);
             break;
         case 'show':
             //显示
             Comment::model()->updateAll(['status' => Comment::STATUS_SHOW], $criteria);
             break;
         case 'hide':
             //隐藏
             Comment::model()->updateAll(['status' => Comment::STATUS_HIDE], $criteria);
             break;
         default:
             $this->controller->message('error', Yii::t('admin', 'Error Operation'));
     }
     $this->controller->message('success', Yii::t('admin', 'Batch Operate Success'));
 }
Example #11
0
 public function delete()
 {
     $post_id = $_GET['id'];
     Post::model()->delete($post_id);
     Tag::model()->delete($post_id);
     Comment::model()->delete($post_id);
     Application::redirect(array('post' => 'index'));
 }
Example #12
0
 public function getCommentProvider()
 {
     $criteria = new CDbCriteria();
     $criteria->compare('pageId', $this->pageId);
     $criteria->compare('title', $this->text, true);
     $criteria->compare('text', $this->text, true);
     return new ActiveDataProvider(Comment::model(), array('criteria' => $criteria));
 }
Example #13
0
 public function getLastComment()
 {
     $criteria = new CDbCriteria();
     $criteria->condition = "t.commentableEntityId=" . $this->entityId;
     $criteria->order = "addTime desc";
     $result = Comment::model()->find($criteria);
     return $result;
 }
 public function loadModel($id)
 {
     $model = Comment::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Example #15
0
 public function loadComment($id)
 {
     $comment = Comment::model()->findByPk($id);
     if (null === $comment) {
         throw new CHttpException(404, Yii::t('app', 'The requested page does not exist.'));
     }
     return $comment;
 }
 public function run()
 {
     $criteria = new CDbCriteria();
     $criteria->addCondition('level <> 1');
     $dataProvider = new CActiveDataProvider('Comment', ['criteria' => $criteria, 'sort' => ['defaultOrder' => 'id DESC'], 'pagination' => ['pageSize' => (int) $this->limit]]);
     $cacheTime = Yii::app()->controller->yupe->coreCacheTime;
     $this->render('panel-stat', ['commentsCount' => Comment::model()->cache($cacheTime)->count('create_time >= :time AND level <> 1', [':time' => time() - 24 * 60 * 60]), 'allCommentsCnt' => Comment::model()->cache($cacheTime)->all()->count(), 'newCnt' => Comment::model()->cache($cacheTime)->new()->count(), 'dataProvider' => $dataProvider]);
 }
 public function init()
 {
     if (null !== $this->projectId) {
         $this->_comments = Comment::model()->with(array('issue' => array('condition' => 'project_id=' . $this->projectId)))->recent($this->displayLimit)->findAll();
     } else {
         $this->_comments = Comment::model()->recent($this->displayLimit)->findAll();
     }
 }
Example #18
0
 public function getComments($count = 20)
 {
     $criteria = new CDbCriteria();
     $criteria->select = '*';
     $criteria->condition = "`pid` = " . $this->id;
     $criteria->limit = $count;
     $criteria->order = "id desc";
     return Comment::model()->findAll($criteria);
 }
Example #19
0
 public function checkSelf()
 {
     $count = Comment::model()->new()->count();
     $messages = [];
     if ($count) {
         $messages[WebModule::CHECK_NOTICE][] = ['type' => WebModule::CHECK_NOTICE, 'message' => Yii::t('CommentModule.comment', 'You have {{count}} new comments. {{link}}', ['{{count}}' => $count, '{{link}}' => CHtml::link(Yii::t('CommentModule.comment', 'Comments moderation'), ['/comment/commentBackend/index', 'Comment[status]' => Comment::STATUS_NEED_CHECK])])];
     }
     return isset($messages[WebModule::CHECK_NOTICE]) ? $messages : true;
 }
Example #20
0
 public function deleteAllLike($id)
 {
     $ids = array();
     Comment::model()->getAllChilren($id, $ids);
     array_push($ids, $id);
     $ids = implode(',', $ids);
     $results = Yii::app()->db->createCommand()->delete($this->tableName(), 'comment_id IN (' . $ids . ')');
     return $results;
 }
Example #21
0
 public function loadComment($commentId)
 {
     $comment = Comment::model()->findByPk($commentId);
     if ($comment === null) {
         throw new CHttpException(404, Yii::t('application', 'The requested page does not exist.'));
     } else {
         return $comment;
     }
 }
 public function actionAdd()
 {
     $attr = StringHelper::filterArrayString($_POST);
     if (Comment::model()->add($attr['post_id'], $attr['user_id'], $attr['content'])) {
         ResponseHelper::JsonReturnSuccess('', 'success');
     } else {
         ResponseHelper::JsonReturnError('', 'server error');
     }
 }
Example #23
0
 public static function getCommentProgram($thread_id)
 {
     $comment = Comment::model()->findByPk($thread_id);
     if (isset($comment) && !is_null($comment)) {
         $prod = Program::model()->findByPk($comment->content_id);
         return array('id' => $prod->id, 'name' => $prod->name, 'poster' => $prod->poster, 'type' => $prod->pro_type);
     }
     return array('id' => '', 'name' => '', 'poster' => '', 'type' => '');
 }
 public static function findRecentComments($limit = 10, $projectId = null)
 {
     if ($projectId != null) {
         return self::model()->with(array('issue' => array('condition' => 'project_id=' . $projectId)))->findAll(array('order' => 't.create_time DESC', 'limit' => $limit));
     } else {
         //get all comments across all projects
         return Comment::model()->with('issue')->findAll(array('order' => 't.create_time DESC', 'limit' => $limit));
     }
 }
Example #25
0
 public function checkSelf()
 {
     $count = Comment::model()->new()->count();
     $messages = array();
     if ($count) {
         $messages[WebModule::CHECK_NOTICE][] = array('type' => WebModule::CHECK_NOTICE, 'message' => Yii::t('CommentModule.comment', 'You have {{count}} new comments. {{link}}', array('{{count}}' => $count, '{{link}}' => CHtml::link(Yii::t('CommentModule.comment', 'Comments moderation'), array('/comment/commentBackend/index', 'order' => 'tatus.asc', 'Comment_sort' => 'status')))));
     }
     return isset($messages[WebModule::CHECK_NOTICE]) ? $messages : true;
 }
Example #26
0
 /**
  * 删除评论功能
  * @param integer $id        文章ID
  * @param integer $commentId 评论ID
  */
 public function actionDeleteComment($id, $commentId)
 {
     if (Comment::model()->findByPk($commentId)->delete()) {
         Yii::app()->user->setFlash('success', Yii::t('app', '删除成功'));
     } else {
         Yii::app()->user->setFlash('error', Yii::t('app', '删除失败'));
     }
     $this->redirect(array('view', 'id' => $id));
 }
Example #27
0
 private static function fetchRecommendComments()
 {
     $criteria = new CDbCriteria();
     $criteria->select = array('t.id', 't.content', 't.create_time', 't.user_id', 't.user_name', 't.post_id');
     $criteria->limit = param('recommendCommentsCount');
     $criteria->scopes = array('recommend', 'published');
     $criteria->with = array('post' => array('select' => 'id, title'));
     $models = Comment::model()->findAll($criteria);
     return $models;
 }
Example #28
0
 public function actionDelete($id)
 {
     if (null === ($model = Comment::model()->findByPk($id))) {
         throw new CHttpException(404);
     }
     if (!$model->delete()) {
         throw new CException();
     }
     $this->sendResponse(200);
 }
Example #29
0
 private static function fetchHotList($pid)
 {
     if (null === $criteria) {
         $criteria = new CDbCriteria();
     }
     $criteria->order = 'id desc';
     $criteria->limit = param('commentCountOfPage');
     $criteria->addColumnCondition(array('post_id' => $pid, 'state' => Comment::STATE_ENABLED))->addCondition('up_nums > :hot_nums');
     $comments = Comment::model()->findAll($criteria, array(':hot_nums' => param('upNumsOfCommentIsHot')));
     return $comments;
 }
 public function actionList($object_id, $model_id)
 {
     $this->layout = false;
     $criteria = new CDbCriteria();
     $criteria->compare('object_id', $object_id);
     $criteria->compare('model_id', $model_id);
     $criteria->order = '`root`, `left`';
     $criteria->with = array('user');
     $comments = Comment::model()->findAll($criteria);
     $this->render('list', array('comments' => $comments));
 }