예제 #1
0
파일: Comment.php 프로젝트: quynhvv/stepup
 public function run()
 {
     $module = ArrayHelper::getValue($this->_params, 'module');
     $view = ArrayHelper::getValue($this->_params, 'view');
     $comment = \app\modules\comment\models\Comment::find();
     $comment->orderBy('create_time DESC');
     $comment->where(['status' => 1, 'item_id' => ArrayHelper::getValue($this->_params, 'parent_id'), 'module' => !empty($module) ? $module : 'comment']);
     $dataProvider = new ActiveDataProvider(['query' => $comment, 'pagination' => false]);
     $this->_params['model'] = $dataProvider;
     return $this->render(!empty($view) ? $view : 'comment', $this->_params);
 }
예제 #2
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, 'parent_id' => $this->parent_id, 'material_id' => $this->material_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'public' => $this->public, 'moder' => $this->moder]);
     $query->andFilterWhere(['like', 'type', $this->type])->andFilterWhere(['like', 'author', $this->author])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'site', $this->site])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'text', $this->text]);
     return $dataProvider;
 }
예제 #3
0
 public function init()
 {
     parent::init();
     $assets = \Yii::$app->assetManager->publish('@app/modules/comment/assets/', ['forceCopy' => YII_DEBUG]);
     $this->getView()->registerJsFile($assets['1'] . '/comment.js', ['depends' => [JqueryAsset::className()]]);
     if ($this->needForm) {
         $this->model = new Comment();
         $this->model->obj_id = $this->obj_id;
         $this->model->obj_type = $this->obj_type;
         $this->model->parent_id = $this->parent_id;
     }
     $this->comments = Comment::find()->with('author')->where(['obj_type' => $this->obj_type, 'obj_id' => $this->obj_id])->limit(20)->orderBy('id desc')->offset($this->offset)->all();
     $this->number = Comment::find()->where(['obj_type' => $this->obj_type, 'obj_id' => $this->obj_id])->count();
 }
예제 #4
0
파일: Comment.php 프로젝트: Dominus77/blog
 /**
  * Возвращение комментариев по статусу модерации
  * в ожидании
  *
  * @param $moder
  * @param $type
  * @return array
  */
 public function getModerComments($moder = self::COMMENT_MODER_PENDING, $type = null)
 {
     if ($type) {
         $query = Comment::find()->where(['moder' => $moder])->andWhere(['type' => $type])->orderBy(['material_id' => SORT_ASC, 'created_at' => SORT_DESC]);
     } else {
         $query = Comment::find()->where(['moder' => $moder])->orderBy(['material_id' => SORT_ASC, 'created_at' => SORT_DESC]);
     }
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'defaultPageSize' => \Yii::$app->getModule('comment')->adminPageSize]);
     $comments = $query->offset($pages->offset)->limit($pages->limit)->all();
     return ['comments' => $comments, 'pages' => $pages];
 }
예제 #5
0
 /**
  * @param $commentID
  * @return Comment|array|null
  * @throws ForbiddenHttpException
  */
 private function findComment($commentID)
 {
     $comment = Comment::find()->currentUser()->byID($commentID)->one();
     if ($comment === null) {
         throw new ForbiddenHttpException();
     }
     return $comment;
 }
예제 #6
0
파일: Comment.php 프로젝트: awebc/web_xbf
 public static function getItemsByObj($obj_type, $obj_id, $offset = 0, $limit = 10)
 {
     return Comment::find()->where(['obj_type' => $obj_type, 'obj_id' => $obj_id])->limit($limit)->offset($offset)->with('author')->orderBy('id desc')->all();
 }
예제 #7
0
파일: Feed.php 프로젝트: awebc/web_xbf
 public function getCommentNumber()
 {
     return Comment::find()->where(['obj_type' => Feed::ACTION_TYPE_FEED, 'obj_id' => $this->id])->count();
 }