当前位置: 首页>>代码示例>>PHP>>正文


PHP Comment::model方法代码示例

本文整理汇总了PHP中Comment::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Comment::model方法的具体用法?PHP Comment::model怎么用?PHP Comment::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Comment的用法示例。


在下文中一共展示了Comment::model方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: run

 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"];
     }
 }
开发者ID:AxelPanda,项目名称:ibos,代码行数:25,代码来源:IWArticleComment.php

示例2: actionLike

 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);
             }
         }
     }
 }
开发者ID:buildshop,项目名称:bs-common,代码行数:26,代码来源:AjaxController.php

示例3: actionComment

 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);
 }
开发者ID:rainsongsky,项目名称:24beta,代码行数:33,代码来源:PostController.php

示例4: fire

 /**
  * 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();
     }
 }
开发者ID:ahdail,项目名称:humhub,代码行数:31,代码来源:AlsoCommentedNotification.php

示例5: getCommentsFromContent

 /**
  * 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;
 }
开发者ID:plantoschka,项目名称:humhub-modules-reputation,代码行数:35,代码来源:ReputationBase.php

示例6: run

 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);
 }
开发者ID:nctruong,项目名称:inputen,代码行数:33,代码来源:news_lession_comment.php

示例7: actionProfile

 /**
  * 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));
 }
开发者ID:jjsub,项目名称:samesub,代码行数:30,代码来源:UserController.php

示例8: actionAddComment

 /**
  * Добавляем комментарий
  */
 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);
 }
开发者ID:amanukian,项目名称:testcomment,代码行数:30,代码来源:SiteController.php

示例9: actionView

 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.');
     }
 }
开发者ID:nctruong,项目名称:inputen,代码行数:26,代码来源:CollectController.php

示例10: run

 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'));
 }
开发者ID:jerrylsxu,项目名称:yiifcms,代码行数:28,代码来源:BatchAction.php

示例11: delete

 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'));
 }
开发者ID:RomsonApp,项目名称:blog,代码行数:8,代码来源:PostController.php

示例12: getCommentProvider

 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));
 }
开发者ID:arossokha,项目名称:ex-comment,代码行数:8,代码来源:Page.php

示例13: getLastComment

 public function getLastComment()
 {
     $criteria = new CDbCriteria();
     $criteria->condition = "t.commentableEntityId=" . $this->entityId;
     $criteria->order = "addTime desc";
     $result = Comment::model()->find($criteria);
     return $result;
 }
开发者ID:stan5621,项目名称:jp_edu_online,代码行数:8,代码来源:Post.php

示例14: loadModel

 public function loadModel($id)
 {
     $model = Comment::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
开发者ID:tierous,项目名称:yico-commerce,代码行数:8,代码来源:CommentController.php

示例15: loadComment

 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;
 }
开发者ID:mjrouser,项目名称:cityapi,代码行数:8,代码来源:CommentController.php


注:本文中的Comment::model方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。