/** * Displays a single Post model. * @param integer $id * @return mixed */ public function actionView($id) { $page_size = 10; $model = new Comment(); $pages = new Pagination(['totalCount' => $model->find()->where(['post_id' => $id])->count(), 'pageSize' => $page_size]); $dataProvider = new ActiveDataProvider(['query' => $model->find()->where(['post_id' => $id]), 'pagination' => ['pagesize' => $page_size]]); return $this->render('view', ['data' => $dataProvider, 'model' => $this->findModel($id), 'left_btn' => 'home', 'pages' => $pages]); }
function showAllComment($aid, $pid = 0, $lastId = 0) { $list = Comment::find()->where(['article_id' => $aid, 'pid' => $pid])->asArray()->orderBy('created_at DESC')->all(); $len = count($list) - 1; if ($len < 0) { return; } else { while (isset($list[$len])) { $id = $list[$len]['id']; $uid = $list[$len]['user_id']; $username = $list[$len]['username']; $content = $list[$len]['content']; $comment_time = $list[$len]['created_at']; $GLOBALS['arr'][0] .= 'aCommentList.push(' . $id . ');' . "\n"; $styleClass = $pid == 0 ? 'comment' : 'comment sub'; $GLOBALS['arr'][1] .= '<div class="' . $styleClass . '" id="comment_id_' . $id . '">'; $GLOBALS['arr'][1] .= '<div class=control><span>删除</span> <span>回复</span></div>'; if ($lastId != 0) { $replyTo = '回复'; $last_uid = Comment::find()->where(['user_id' => $pid])->one()->pid; $last_name = Comment::find()->where(['user_id' => $pid])->one()->username; $replyTo .= '<a href="user.php?uid=' . $last_uid . '">' . $last_name . '</a> '; } else { $replyTo = ''; } $GLOBALS['arr'][1] .= '<p>[#' . $id . '楼]<a href="usr.php?uid=' . $uid . '">' . $username . '</a>' . $replyTo . date('Y-m-d H:i:s', $comment_time); $GLOBALS['arr'][1] .= ':</p>'; $GLOBALS['arr'][1] .= $content; $GLOBALS['arr'][1] .= '</div>' . "\n\n"; showAllComment(1, $id, $id); $len--; } } }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { // $comment = Comment::find($id); $comment->delete(); return Redirect::to('admin/comments'); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $forum, $thread, $id) { $comment = Comment::find($id); $this->authorize('update', $comment); $comment->update($request->all()); return redirect(route('intern.discuss.threads.show', [$comment->thread->forum->slug, $comment->thread->slug])); }
/** * Displays a single Journal model. * @param integer $id * @return mixed */ public function actionView($id) { //var_dump($notify); die(); $searchModel = new JournalSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $model = $this->findModel($id); $comment = new Comment(); $comment->user_id = \Yii::$app->user->id; $commentProvider = new ActiveDataProvider(['query' => Comment::find()->where(['journal_id' => $id])]); Yii::$app->notification->viewer($id); if ($comment->load(Yii::$app->request->post())) { $comment->journal_id = $id; $comment->time = date('Y-m-d H:i:s'); if ($comment->save()) { Yii::$app->notification->notify($model->entry, $model, $comment->user, 'comment', $model->shared_with . ',' . $model->user_id); Yii::$app->session->setFlash('success', 'Comment posted successfully.'); return Yii::$app->getResponse()->redirect(array('/journal/view/' . $model->id)); } else { exit; } } else { if (Yii::$app->request->isAjax) { return $this->renderAjax('view', ['model' => $model, 'comment' => $comment, 'dataProvider' => $dataProvider, 'searchModel' => $searchModel, 'commentProvider' => $commentProvider]); } else { return $this->render('view', ['model' => $model, 'comment' => $comment, 'dataProvider' => $dataProvider, 'searchModel' => $searchModel, 'commentProvider' => $commentProvider]); } } }
public static function getPostById($postID) { $p = Post::findOne(['post_id' => $postID]); if (!is_null($p)) { $comments = Comment::find()->where(['post_id' => $postID])->all(); $comms = []; foreach ($comments as $comment) { $author = new UserId($comment->author_id); $date = new \DateTime($comment->comment_date); $comm = new \common\components\Comment($comment->comment_id, $date, $author, $comment->comment_text); $comms[] = $comm; } $attachment = new PostAtt($postID); $attachments = $attachment->getFile() == null ? null : $attachment; $date = new \DateTime($p->post_date); $vis = $p->post_visibility; $visibility = EVisibility::$vis(); $author = new UserId($p->owner_id); $pt = $p->post_type; $ptype = EPostType::$pt(); $post = new \common\components\Post($postID, $author, $p->post_text, $date, $visibility, $ptype, $comms, $attachments); return $post; } else { return null; } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Comment::find()->select('comment.*, video.title, user.username')->innerJoin('video', '`video`.`id` = `comment`.`video_id`')->innerJoin('user', '`user`.`id` = `comment`.`user_id`'); // echo $query->createCommand()->sql;exit; $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => Yii::$app->params['pageSize']]]); /** * Setup your sorting attributes * Note: This is setup before the $this->load($params) * statement below */ $dataProvider->setSort(['attributes' => ['id', 'text' => ['asc' => ['comment.text' => SORT_ASC], 'desc' => ['comment.text' => SORT_DESC]], 'videoTitle' => ['asc' => ['video.title' => SORT_ASC], 'desc' => ['video.title' => SORT_DESC]], 'username' => ['asc' => ['user.username' => SORT_ASC], 'desc' => ['user.username' => SORT_DESC]], 'created_at' => ['asc' => ['comment.created_at' => SORT_ASC], 'desc' => ['comment.created_at' => SORT_DESC]]]]); $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; } /* ---------------------------------------------------------------------/ * Filter * --------------------------------------------------------------------- */ $query->andFilterWhere(['comment.id' => $this->id, 'comment.video_id' => $this->video_id, 'comment.user_id' => $this->user_id, 'comment.created_at' => $this->created_at, 'comment.modified_at' => $this->modified_at]); $query->andFilterWhere(['like', 'text', $this->text]); /** * for related column */ $query->andFilterWhere(['like', 'video.title', $this->videoTitle]); $query->andFilterWhere(['like', 'user.username', $this->username]); return $dataProvider; }
public function actionComments($username) { $user = $this->findUserModel($username, ['userInfo']); $pages = new Pagination(['totalCount' => $user['userInfo']['comment_count'], 'pageSize' => $this->settings['list_pagesize'], 'pageParam' => 'p']); $comments = Comment::find()->select(['id', 'created_at', 'topic_id', 'content'])->where(['user_id' => $user['id']])->orderBy(['id' => SORT_DESC])->offset($pages->offset)->with(['topic.author'])->limit($pages->limit)->asArray()->all(); return $this->render('comments', ['user' => $user, 'comments' => $comments, 'pages' => $pages]); }
public function reply(Request $request, $id) { $comment = Comment::find($id); $comment->reply = $request->reply; $comment->save(); return back()->with('info', '回复成功'); }
public function reply(Request $request, $id) { $admin = Auth::user(); $comment = Comment::find($id); $comment->reply = $request->reply; $comment->admin_id = $admin->id; $comment->save(); return back()->with('info', '回复成功'); }
public function validation() { $id = Input::get('id'); if (!($comment = Comment::find($id))) { throw new Exception('Comment not found => id: ' . $id); } $comment->valid = !$comment->valid; $comment->save(); return $comment; }
/** * @inheritdoc */ public function run() { $commentForm = $this->getNewCommentForm($this->objectType, $this->objectId); if ($commentForm->load(Yii::$app->request->post()) && $commentForm->save()) { // reset form $commentForm = $this->getNewCommentForm($this->objectType, $this->objectId); } $comments = Comment::find()->where(['status' => Comment::STATUS_ACTIVE, 'object_type' => $this->objectType, 'object_id' => $this->objectId])->with('user')->all(); return $this->render('comments', ['comments' => $comments, 'commentForm' => $commentForm]); }
public function toggleCommentOn($id) { $comment = Comment::find($id); if (!$comment) { return new JsonResponse(array('message' => 'Unable to toggle on'), 500); } $comment->is_active = 1; $comment->save(); return new JsonResponse(array('message' => 'Comment successfully toggled on'), 200); }
public static function findCommentsTree($noteId) { $commentsIdsWithoutParents = Yii::$app->db->createCommand('SELECT DISTINCT parent_id FROM comment_closure WHERE parent_id NOT IN (SELECT DISTINCT child_id FROM comment_closure WHERE parent_id != child_id)')->queryAll(\PDO::FETCH_COLUMN); $commentWithStmt = mb_substr(str_repeat('comments.', Yii::$app->db->createCommand('SELECT MAX(comment_closure.depth) FROM comment INNER JOIN comment_closure ON (comment.id = comment_closure.parent_id) WHERE comment.note_id = :noteId', ['noteId' => $noteId])->queryOne(\PDO::FETCH_COLUMN) + 1), 0, -1, 'UTF-8'); $comments = \app\models\Comment::find()->with($commentWithStmt)->where(['note_id' => $noteId])->andWhere(['in', 'id', $commentsIdsWithoutParents])->all(); $sortedComments = []; foreach ($comments as $comment) { static::walkTree($comment, $sortedComments); } return $sortedComments; }
private function _validate($id) { if ($id == null) { return false; } $data = Comment::find($id); if (!$data) { return false; } return $data; }
public function search($params) { $query = Comment::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'author_id' => $this->author_id, 'comment_parent_id' => $this->comment_parent_id, 'create_time' => $this->create_time, 'post_id' => $this->post_id, 'user_id' => $this->user_id]); $query->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'author_name', $this->author_name]); return $dataProvider; }
public function search($params) { $query = Comment::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['create_time' => SORT_DESC]]]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'type' => $this->type, 'up' => $this->up, 'down' => $this->down, 'status' => $this->status, 'create_time' => $this->create_time, 'post_id' => $this->post_id, 'user_id' => $this->user_id]); $query->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'author', $this->author])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'ip', $this->ip]); return $dataProvider; }
public function delete($id) { if ($target = Comment::find($id)) { if ($target->delete()) { return redirect()->back()->with('success', 'delete success'); } else { return redirect()->back()->with('error', 'something wrong happende, please try again or contact your system manager.'); } } else { return redirect()->back()->with('error', 'comment not found'); } }
public function search($params) { $query = Comment::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'pid' => $this->pid, 'uid' => $this->uid, 'replyto' => $this->replyto, 'create_time' => $this->create_time, 'update_time' => $this->update_time, 'user_agent' => $this->user_agent, 'email' => $this->email, 'author' => $this->author, 'type' => $this->type, 'ip' => $this->ip, 'status' => $this->status]); //TODO ext 属性的搜索 $query->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'user_agent', $this->user_agent]); return $dataProvider; }
/** * 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()) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'is_active' => $this->is_active, 'timestamp' => $this->timestamp]); $query->andFilterWhere(['like', 'comment_text', $this->comment_text])->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email]); return $dataProvider; }
/** * @param $params * @return ActiveDataProvider */ public function search($params) { $query = Comment::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => 'id', 'attributes' => ['id', 'product_id', 'user_id', 'rating', 'status', 'created_at']]]); $this->load($params); if (!$this->validate()) { $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['status' => $this->status, 'product_id' => $this->product_id, 'user_id' => $this->user_id, 'rating' => $this->rating]); $query->andFilterWhere(['LIKE', 'body', $this->body]); return $dataProvider; }
protected function findCommentModel($id, $with = null) { $model = Comment::find()->where(['id' => $id]); if (!empty($with)) { $model = $model->with($with); } $model = $model->one(); if ($model !== null) { return $model; } else { throw new NotFoundHttpException('未找到id为[' . $id . ']的回复'); } }
public function answer(Request $request, $id = '') { $model = \App\Models\Comment::find($id); if (!is_null($model)) { $this->validate($request, ['comment' => 'required']); $comment = \Illuminate\Support\Facades\Request::input('comment'); $postId = \Illuminate\Support\Facades\Request::input('postId'); // echo $id; exit; $comment = \App\Models\Comment::create(array('post_id' => $postId, 'parent_id' => $id, 'comment' => $comment, 'user_id' => (int) Auth::user()->id, 'created_at' => date('Y-m-d H:i:s'))); $returnHTML = view('comment.comment')->with('comment', $comment)->with('postId', $postId)->render(); return json_encode(array('success' => true, 'html' => $returnHTML)); } }
/** * Displays a single Video model. * @param integer $id * @param integer $course_id * @return mixed */ public function actionView($id, $course_id) { $video = Video::findOne($id); if (!is_object($video)) { throw new NotFoundHttpException('Video not found.'); } $userCourseIds = OvcCourse::getUserCourseIds(); if (!in_array($video->course_id, $userCourseIds)) { throw new \yii\web\ForbiddenHttpException('Insufficient privileges to access this video.'); } $comments = \app\models\Comment::find()->where(['video_id' => $video->id])->orderBy('id DESC')->all(); return $this->render('view', ['model' => $this->findModel($id, $course_id), 'comments' => $comments]); }
public function delete($id) { $id = intval($id); $userInstance = User::findOrFail($id); $userInstance->comments->each(function ($comment) { Comment::find($comment->id)->delete(); }); if ($userInstance->delete()) { return redirect()->back()->with('success', 'delete success'); } else { return redirect()->back()->with('error', 'this user has already been deleted'); } }
public function getTarget() { $target_type = $this->target_type; switch ($target_type) { case 'user': return User::find($this->target_id); case 'comment': return Comment::find($this->target_id); case 'video': return Video::find($this->target_id); default: return null; } }
/** * 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, 'pagination' => ['pageSize' => 2], 'sort' => ['defaultOrder' => ['updated_at' => SORT_DESC]]]); $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, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'user_id' => $this->user_id, 'parent_id' => $this->parent_id, 'post_id' => $this->post_id]); $query->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'ip', $this->ip])->andFilterWhere(['like', 'agent', $this->agent])->andFilterWhere(['like', 'status', $this->status]); return $dataProvider; }
/** * 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, 'status' => $this->status, 'create_time' => $this->create_time, 'post_id' => $this->post_id]); $query->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'author', $this->author])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'url', $this->url]); return $dataProvider; }
/** * 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, 'user_id' => $this->user_id, 'page_id' => $this->page_id, 'date_entered' => $this->date_entered]); $query->andFilterWhere(['like', 'comment', $this->comment]); return $dataProvider; }
/** * * @param $fid * @return array * @throws CommentApiException */ protected function processLevelAndPath($fid) { $parent = Comment::find($fid); //父元素对象 if ($parent instanceof Collection) { throw new CommentApiException("操作失败,有多个parent~!"); } $data = array("level" => 1, "path" => ""); if ($parent instanceof Comment) { $data["level"] = $parent->level + 1; $data["path"] = implode(",", array($parent->path, $parent->id)); } return $data; }