Exemplo n.º 1
0
 /**
  * testCommentFind
  *
  * @return void
  */
 public function testCommentFind()
 {
     $this->Comment->recursive = -1;
     $results = $this->Comment->find('first');
     $this->assertTrue(!empty($results));
     $expected = array('Comment' => array('id' => '1', 'user_id' => null, 'model' => 'Article', 'foreign_key' => '1', 'parent_id' => '0', 'approved' => 1, 'name' => null, 'title' => '-', 'slug' => '_', 'body' => 'This is a comment', 'lft' => 1, 'rght' => 2, 'modified' => '2008-12-22 16:39:19', 'created' => '2008-12-22 16:39:19', 'author_name' => 'mark story', 'author_email' => '*****@*****.**', 'author_url' => 'http://example.com', 'is_spam' => 'clean', 'comment_type' => 'comment'));
     $this->assertEqual($results, $expected);
 }
Exemplo n.º 2
0
 /**
  * testProcessDisapprove
  *
  * @return void
  */
 public function testProcessDisapprove()
 {
     $data['Comment'] = array('1' => 1, '2' => 0);
     $this->Comment->process('disapprove', $data);
     $comment = $this->Comment->find('first', array('conditions' => array('Comment.id' => 1)));
     $this->assertEqual($comment['Comment']['approved'], false);
 }
Exemplo n.º 3
0
 public function postPostscustom()
 {
     $postsCheked = Input::get('comments');
     if (is_array($postsCheked)) {
         $customposts = Input::get('customposts');
         if ($customposts == 'publish') {
             for ($i = 0; $i < count($postsCheked); $i++) {
                 if (Comment::find($postsCheked[$i])->status == '0') {
                     DB::table('comments')->where('id', $postsCheked[$i])->update(['status' => 1]);
                 }
             }
             return Redirect::to('/teacher/comments');
         } else {
             if ($customposts == 'unpublish') {
                 for ($i = 0; $i < count($postsCheked); $i++) {
                     if (Comment::find($postsCheked[$i])->status == '1') {
                         DB::table('comments')->where('id', $postsCheked[$i])->update(['status' => 0]);
                     }
                 }
                 return Redirect::to('/teacher/comments');
             } else {
                 if ($customposts == 'delete') {
                     for ($i = 0; $i < count($postsCheked); $i++) {
                         Comment::find($postsCheked[$i])->delete();
                     }
                     return Redirect::to('/teacher/comments');
                 } else {
                     return Redirect::to('/teacher/comments');
                 }
             }
         }
     } else {
         return Redirect::to('/teacher/comments');
     }
 }
Exemplo n.º 4
0
 public function post_edit()
 {
     if (!cmsHelper::isCurrentUserAllowedToPerform('comments')) {
         return;
     }
     //Flash current values to session
     Input::flash();
     $id = Input::get('editingMode');
     $editComment = Comment::find($id);
     $editComment->name = Input::get('name');
     $editComment->email = Input::get('email');
     $editComment->content = Input::get('content');
     //Add rules here
     $rules = array('name' => 'required', 'email' => 'required', 'content' => 'required');
     //Get all inputs fields
     $input = Input::all();
     //Apply validaiton rules
     $validation = Validator::make($input, $rules);
     //Validate rules
     if ($validation->fails()) {
         return Redirect::to($_SERVER['PATH_INFO'] . '?id=' . $editComment->id)->with_errors($validation);
     }
     //Update the comment
     $editComment->save();
     return Redirect::to($_SERVER['PATH_INFO'] . '?id=' . $editComment->id)->with('successmessage', 'Comment successfully updated');
 }
Exemplo n.º 5
0
 public function actionAdmin()
 {
     // delete comment request
     if (Rays::isPost()) {
         if (isset($_POST['checked_comments'])) {
             $commentIds = $_POST['checked_comments'];
             foreach ($commentIds as $id) {
                 if (!is_numeric($id)) {
                     return;
                 } else {
                     $comment = new Comment();
                     $comment->id = $id;
                     $comment->delete();
                 }
             }
         }
     }
     $curPage = $this->getPage("page");
     $pageSize = $this->getPageSize('pagesize', 10);
     $count = Comment::find()->count();
     $comments = Comment::find()->join("user")->join("topic")->order_desc("id")->range(($curPage - 1) * $pageSize, $pageSize);
     $pager = new RPager('page', $count, $pageSize, RHtml::siteUrl('comment/admin'), $curPage);
     $this->layout = 'admin';
     $this->setHeaderTitle("Comments administration");
     $data = array('count' => $count, 'comments' => $comments, 'pager' => $pager->showPager());
     $this->render('admin', $data, false);
 }
Exemplo n.º 6
0
 public function destroy($id)
 {
     $status = Comment::find($id);
     $status->delete();
     Flash::message('Your comment has been deleted.');
     return Redirect::back();
 }
 public function testCounterIncrementsAndDecrementsWhen()
 {
     $post_with_comments = new Post();
     $post_with_comments->title = 'post 1';
     $this->assertTrue($post_with_comments->save());
     $post_without_comments = new Post();
     $post_without_comments->title = 'post 2';
     $this->assertTrue($post_without_comments->save());
     //Create 10 comments, ensure counter increments
     for ($i = 1; $i <= 10; $i++) {
         $comment = new Comment();
         $comment->postId = $post_with_comments->id;
         $comment->text = 'comment ' . $i;
         $this->assertTrue($comment->save());
         $post_with_comments->refresh();
         $post_without_comments->refresh();
         $this->assertEquals($post_with_comments->commentsCount, $i);
         $this->assertEquals($post_without_comments->commentsCount, 0);
     }
     //Delete all comments, ensure counter decrements
     $comments = Comment::find()->all();
     $count = count($comments);
     foreach ($comments as $comment) {
         $this->assertEquals($comment->delete(), 1);
         $count--;
         $post_with_comments->refresh();
         $this->assertEquals($post_with_comments->commentsCount, $count);
     }
 }
 public function findById($post_id, $id)
 {
     $comment = Comment::find($id);
     if (!$comment || $comment->post_id != $post_id) {
         throw new NotFoundException('Comment Not Found');
     }
     return $comment;
 }
Exemplo n.º 9
0
 /**
  * Find comment parent by id.
  * 
  * @param  int  $id
  * @return \FIIP\Comments\Comment|null
  */
 public function findParent($id)
 {
     $comment = Comment::find($id);
     if ($comment && $comment->parent) {
         return $this->findParent($comment->parent->id);
     }
     return $comment;
 }
 /**
  * Show the form for editing the specified comment.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $comment = Comment::find($id);
     if (Auth::id() != $comment->user_id) {
         return Redirect::action('comments.index');
     }
     return View::make('comments.edit', compact('comment'));
 }
 public function destroy($id)
 {
     $comment = Comment::find($id);
     if (!$comment->hasDefaultPhoto()) {
         File::delete($comment->fullPhotoPath());
     }
     Comment::destroy($id);
     return Response::json(array('success' => true));
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param $comment
  * @return Response
  */
 public function deleteIndex($comment)
 {
     $id = $comment->id;
     if (!$comment->delete()) {
         return Api::json(array('result' => 'error', 'error' => Lang::get('core.delete_error')));
     }
     $comment = Comment::find($id);
     return empty($comment) ? Api::json(array('result' => 'success')) : Api::json(array('result' => 'error', 'error' => Lang::get('core.delete_error')));
 }
Exemplo n.º 13
0
 public function getComments()
 {
     $comments = Comment::find(array("topicId", $this->id, "pid", 0))->all();
     $result = [];
     foreach ($comments as $c) {
         $result[] = ['root' => $c, 'reply' => $c->children()];
     }
     return $result;
 }
Exemplo n.º 14
0
 public function actionDelete($id)
 {
     if ($_POST['action'] == 1) {
         $model = Comment::find($id);
         $model->delete();
         echo json_encode(array('id' => array($id), 'class' => 'alert-success', 'message' => __('delete success')));
         exit;
     }
 }
Exemplo n.º 15
0
 public function delete_destroy()
 {
     $cid = Input::get('cid');
     $pid = Input::get('pid');
     $post = Post::find($pid);
     //$post_id = Comment::find(Input::get('id'))->post->slug;
     Comment::find($cid)->delete();
     return Redirect::to_route('post_view', $post->slug)->with('message', 'Comment has been deleted Successfully!');
 }
Exemplo n.º 16
0
 public function deleteComment()
 {
     if (!Acl::isSuperAdmin()) {
         return Redirect::route('home');
     }
     $id = e(Input::get('id'));
     $comment = Comment::find($id);
     $comment->delete();
     return Redirect::back()->with('success', trans('directory.comment_deleted'));
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param $comment
  * @return Response
  */
 public function deleteIndex($comment)
 {
     $id = $comment->id;
     $comment->delete();
     $comment = Comment::find($id);
     if (empty($comment)) {
         return Response::json(array('result' => 'success'));
     } else {
         return Response::json(array('result' => 'failure', 'error' => Lang::get('admin/comments/messages.delete.error')));
     }
 }
Exemplo n.º 18
0
 /**
  * Add a comment
  *
  * @param Request $request
  * @param string $params
  * @return void
  */
 protected static function post($request, $params)
 {
     static::authorize($request);
     try {
         $data = array('postID' => $request->get('postID'), 'userID' => $request->user->get('id'), 'text' => $request->get('text'), 'created' => time());
         $comment = new Comment($data);
         $comment->save();
         static::response(Comment::find(array('id' => $comment->id), $request->include), 201, '');
     } catch (Exception $e) {
         static::response(array(), 400, $e->getMessage());
     }
 }
Exemplo n.º 19
0
 /**
  * @param $postId
  * @param \User $author
  * @return bool|void
  */
 public static function minus($postId, \User $author)
 {
     $comment = \Comment::find(intval($postId));
     if (!$comment) {
         return false;
     }
     if ($comment->author_id == $author->id) {
         return $comment->author_id;
     }
     if ($comment->author->rate(-1)) {
         return $comment->author_id;
     }
     return false;
 }
Exemplo n.º 20
0
 /**
  * Remove the specified resource from storage.
  *
  * @param $comment
  * @return Response
  */
 public function postDelete($comment)
 {
     $rules = array('id' => 'required|integer');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->passes()) {
         $id = $comment->id;
         $comment->delete();
         $comment = Comment::find($id);
         if (empty($comment)) {
             return Redirect::to('admin/comments')->with('success', Lang::get('admin/comments/messages.delete.success'));
         }
     }
     return Redirect::to('admin/comments')->with('error', Lang::get('admin/comments/messages.delete.error'));
 }
Exemplo n.º 21
0
 public function actionListComment($id)
 {
     $query = Comment::find()->joinWith('topicContent');
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count()]);
     $page = 1;
     if (isset($_GET["page"])) {
         $page = $_GET["page"];
     }
     $limit = 10;
     $offset = $limit * ($page - 1);
     $pageSize = ceil($countQuery->count() / $limit);
     $pages->setPageSize($pageSize);
     $models = $query->offset($offset)->limit($limit)->all();
     return $this->render('list', ['models' => $models, 'pages' => $pages]);
 }
Exemplo n.º 22
0
 /**
  * Delete a comment
  *
  * @param Request $request
  * @param string $params
  * @return void
  */
 protected static function delete($request, $params)
 {
     static::authorize($request);
     try {
         $comment = Comment::find(array('id' => $params));
         $post = Post::find(array('id' => $comment->postID), 'blog');
         if ($comment->userID === $request->user->id || $post->blog->userID === $request->user->id) {
             $comment->delete();
             static::response(array(), 200, '');
         } else {
             static::response(array(), 403, 'No Permission');
         }
     } catch (Exception $e) {
         static::response(array(), 400, $e->getMessage());
     }
 }
Exemplo n.º 23
0
 public function delete()
 {
     $id = $this->request->data['id'];
     App::uses('Comment', 'Model');
     $Model = new Comment();
     $params = array();
     $params['recursive'] = -1;
     $params['fields'] = array('user_id');
     $params['conditions']['id'] = $id;
     if (!($comment = $Model->find('first', $params))) {
         exit;
     }
     if ($this->user['User']['id'] == $comment['Comment']['user_id'] || $this->user['User']['can']['manage_own_events'] || $this->user['User']['can']['manage_events'] || $this->user['User']['can']['full_permissions']) {
         $Model->delete($id);
     }
     exit;
 }
Exemplo n.º 24
0
 protected function buildCommentsHierarchy($comments)
 {
     $ids = [];
     foreach ($comments as $model) {
         $ids[] = $model->id;
     }
     $parentsId = implode(',', $ids);
     $subComments = Comment::find()->where(['model' => $this->where['model'], 'model_id' => $this->where['model_id'], 'status' => Comment::STATUS_PUBLISHED]);
     if (!empty($parentsId)) {
         $subComments->where("super_parent_id IN ({$parentsId})");
     }
     $subComments = $subComments->all();
     foreach ($comments as $parent) {
         $parent->comments = self::getSubComments($parent, $subComments);
     }
     return $comments;
 }
Exemplo n.º 25
0
 /**
  * 更新请求
  *
  * @param Request $request
  * @param int $id
  * @return void
  */
 public function update(Request $request, $id)
 {
     // 验证
     $this->validate($request, ['topic' => 'string', 'participants' => 'string', 'state' => 'required|in:1,-1', 'reply_message' => 'required|string']);
     $log = Comment::find($id);
     // 更新
     DB::transaction(function () use($request, $log) {
         if (Comment::STATUS['ENABLE'] == $request->state) {
             // 参与人
             $participantIds = [];
             $participantNames = Participant::filterParticipantNames($request->participants);
             if (!empty($participantNames)) {
                 foreach ($participantNames as $name) {
                     $participant = Participant::firstOrCreate(['name' => $name]);
                     $participant->increment('counts', 1);
                     $participantIds[] = $participant->id;
                 }
             }
             // 节目
             $program = Program::where('date', date('Y-m-d', strtotime($log->metas->thread_key)))->first();
             $topic = Program::filterTopic($request->topic);
             if (!empty($topic)) {
                 $program->update(['topic' => $topic]);
             }
             if (!empty($participantIds)) {
                 $program->participants()->sync($participantIds);
             }
         }
         // 刷新首页文件缓存
         Cache::forget(Program::INDEX_CACHE_KEY);
         // 刷新贡献记录页文件缓存
         Cache::forget(Comment::CONTRIBUTION_CACHE_KEY);
         // 记录日志
         Comment::where('id', $log->id)->update(['ext_is_agree' => $request->state]);
     });
     // 回复评论
     $state = Comment::replyPost($request->reply_message, $log->metas->thread_id, $log->metas->post_id, $log->metas->author_email);
     // 跳转
     $status = ['status' => $state ? 'success' : 'error', 'message' => $state ? '审核成功~' : '审核成功,回复失败'];
     return Redirect::to($request->_redirect_url)->with($status['status'], $status['message']);
 }
Exemplo n.º 26
0
 /**
  * testSaveAssociatedHasOneValidation method
  *
  * @return void
  */
 public function testSaveAssociatedHasOneValidation()
 {
     $model = new Comment();
     $model->deleteAll(true);
     $this->assertEquals(array(), $model->find('all'));
     $model->Attachment->deleteAll(true);
     $this->assertEquals(array(), $model->Attachment->find('all'));
     $model->validate = array('comment' => 'notEmpty');
     $model->Attachment->validate = array('attachment' => 'notEmpty');
     $model->Attachment->bindModel(array('belongsTo' => array('Comment')));
     $result = $model->saveAssociated(array('Comment' => array('comment' => '', 'article_id' => 1, 'user_id' => 1), 'Attachment' => array('attachment' => '')));
     $this->assertFalse($result);
     $expected = array('comment' => array('This field cannot be left blank'), 'Attachment' => array('attachment' => array('This field cannot be left blank')));
     $this->assertEquals($expected, $model->validationErrors);
     $this->assertEquals($expected['Attachment'], $model->Attachment->validationErrors);
 }
Exemplo n.º 27
0
 public static function getByChannelAction($action)
 {
     if (is_object($action) && isset($action->channel_id)) {
         if ($action->type == 'comment') {
             return Comment::find('first', array('conditions' => array('poster_id' => $action->channel_id, 'timestamp' => $action->timestamp)));
         }
     }
 }
Exemplo n.º 28
0
 /**
  * undocumented function
  *
  * @return void
  */
 public function testBindModelCallsInBehaviors()
 {
     // hasMany
     $Article = new Article();
     $Article->unbindModel(array('hasMany' => array('Comment')));
     $result = $Article->find('first');
     $this->assertFalse(array_key_exists('Comment', $result));
     $Article->Behaviors->attach('Test4');
     $result = $Article->find('first');
     $this->assertTrue(array_key_exists('Comment', $result));
     // belongsTo
     $Article->unbindModel(array('belongsTo' => array('User')));
     $result = $Article->find('first');
     $this->assertFalse(array_key_exists('User', $result));
     $Article->Behaviors->attach('Test5');
     $result = $Article->find('first');
     $this->assertTrue(array_key_exists('User', $result));
     // hasAndBelongsToMany
     $Article->unbindModel(array('hasAndBelongsToMany' => array('Tag')));
     $result = $Article->find('first');
     $this->assertFalse(array_key_exists('Tag', $result));
     $Article->Behaviors->attach('Test6');
     $result = $Article->find('first');
     $this->assertTrue(array_key_exists('Comment', $result));
     // hasOne
     $Comment = new Comment();
     $Comment->unbindModel(array('hasOne' => array('Attachment')));
     $result = $Comment->find('first');
     $this->assertFalse(array_key_exists('Attachment', $result));
     $Comment->Behaviors->attach('Test7');
     $result = $Comment->find('first');
     $this->assertTrue(array_key_exists('Attachment', $result));
 }
Exemplo n.º 29
0
 public function comments()
 {
     $c = new Comment();
     $c->adId = $this->id;
     return $c->find();
 }
Exemplo n.º 30
0
 /**
  * testSaveAllHasOneValidation method
  *
  * @access public
  * @return void
  */
 function testSaveAllHasOneValidation()
 {
     $model = new Comment();
     $model->deleteAll(true);
     $this->assertEqual($model->find('all'), array());
     $model->Attachment->deleteAll(true);
     $this->assertEqual($model->Attachment->find('all'), array());
     $model->validate = array('comment' => 'notEmpty');
     $model->Attachment->validate = array('attachment' => 'notEmpty');
     $model->Attachment->bindModel(array('belongsTo' => array('Comment')));
     $this->assertFalse($model->saveAll(array('Comment' => array('comment' => '', 'article_id' => 1, 'user_id' => 1), 'Attachment' => array('attachment' => '')), array('validate' => 'first')));
     $expected = array('Comment' => array('comment' => 'This field cannot be left blank'), 'Attachment' => array('attachment' => 'This field cannot be left blank'));
     $this->assertEqual($model->validationErrors, $expected['Comment']);
     $this->assertEqual($model->Attachment->validationErrors, $expected['Attachment']);
     $this->assertFalse($model->saveAll(array('Comment' => array('comment' => '', 'article_id' => 1, 'user_id' => 1), 'Attachment' => array('attachment' => '')), array('validate' => 'only')));
     $this->assertEqual($model->validationErrors, $expected['Comment']);
     $this->assertEqual($model->Attachment->validationErrors, $expected['Attachment']);
 }