Ejemplo n.º 1
0
 /**
  * @return Comment|null
  */
 public function saveComment()
 {
     $comment = new Comment();
     $comment->discussionID = $this->discussionID;
     $comment->message = $this->message;
     $comment->userID = $this->userID;
     $comment->email = $this->email;
     if ($comment->save()) {
         return $comment;
     }
     return null;
 }
Ejemplo n.º 2
0
 protected function findModel($id)
 {
     if (($model = Comment::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
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;
 }
Ejemplo n.º 5
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();
 }
Ejemplo n.º 6
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     $class = $this->model;
     /** @var CommentModel $classModel */
     $classModel = CommentModel::findIdentity($class::className());
     if ($classModel) {
         $model = new Comment(['scenario' => 'create']);
         $model->model_id = $this->model->id;
         // NewsPost->id, Page->id
         $model->model_class = $classModel->id;
         // crc32(NewsPost::class), crc32(Page::class)
         $models = Comment::getTree($model->model_id, $model->model_class);
         return $this->render('index', ['models' => $models, 'model' => $model, 'route' => $this->route]);
     }
     return '';
 }
Ejemplo n.º 7
0
 /**
  * Возвращение комментариев по статусу модерации
  * в ожидании
  *
  * @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];
 }
Ejemplo n.º 8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getComments()
 {
     return $this->hasMany(Comment::className(), ['discussionID' => 'id']);
 }
Ejemplo n.º 9
0
 public function rules()
 {
     return ArrayHelper::merge([[['id', 'created_by', 'content', 'status'], 'safe']], parent::rules());
 }
Ejemplo n.º 10
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;
 }
Ejemplo n.º 11
0
 /**
  * @param string $scenario
  */
 public function init($scenario = 'insert')
 {
     $this->material_model_of_namespace = self::MATERIAL_MODEL_OF_NAMESPACE;
     $this->type_of_comment = self::TYPE_OF_COMMENT;
     parent::init($scenario);
 }
Ejemplo n.º 12
0
 /**
  * Find model by ID.
  *
  * @param integer|array $id Comment ID
  *
  * @return Comment Model
  *
  * @throws HttpException 404 error if comment not found
  */
 protected function findModel($id)
 {
     if (is_array($id)) {
         /** @var Comment $model */
         $model = Comment::findAll($id);
     } else {
         /** @var Comment $model */
         $model = Comment::findOne($id);
     }
     if ($model !== null) {
         return $model;
     } else {
         throw new HttpException(404);
     }
 }
Ejemplo n.º 13
0
 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();
 }
Ejemplo n.º 14
0
 public function getCommentNumber()
 {
     return Comment::find()->where(['obj_type' => Feed::ACTION_TYPE_FEED, 'obj_id' => $this->id])->count();
 }
Ejemplo n.º 15
0
 /**
  * @param Comment $model Comment
  *
  * @return string Comments list
  */
 protected function tree($model)
 {
     $models = Comment::getTree($model->model_id, $model->model_class);
     return $this->renderPartial('@app/modules/comment/widgets/views/_index_item', ['models' => $models]);
 }
Ejemplo n.º 16
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getComments()
 {
     return $this->hasMany(Comment::className(), ['model_class' => 'id']);
 }