/** * @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; }
protected function findModel($id) { if (($model = Comment::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
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); }
/** * 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; }
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(); }
/** * @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 ''; }
/** * Возвращение комментариев по статусу модерации * в ожидании * * @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]; }
/** * @return \yii\db\ActiveQuery */ public function getComments() { return $this->hasMany(Comment::className(), ['discussionID' => 'id']); }
public function rules() { return ArrayHelper::merge([[['id', 'created_by', 'content', 'status'], 'safe']], parent::rules()); }
/** * @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; }
/** * @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); }
/** * 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); } }
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(); }
public function getCommentNumber() { return Comment::find()->where(['obj_type' => Feed::ACTION_TYPE_FEED, 'obj_id' => $this->id])->count(); }
/** * @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]); }
/** * @return \yii\db\ActiveQuery */ public function getComments() { return $this->hasMany(Comment::className(), ['model_class' => 'id']); }