/** * Controller action for viewing a questions. * Also provides functionality for creating an answer, * adding a comment and voting. */ public function actionView() { error_reporting(E_ALL); ini_set("display_errors", 1); $question = Question::model()->findByPk(Yii::app()->request->getParam('id')); if (isset($_POST['Answer'])) { $answerModel = new Answer(); $answerModel->attributes = $_POST['Answer']; $answerModel->created_by = Yii::app()->user->id; $answerModel->post_type = "answer"; $answerModel->question_id = $question->id; if ($answerModel->validate()) { $answerModel->save(); $this->redirect($this->createUrl('//questionanswer/main/view', array('id' => $question->id))); } } if (isset($_POST['Comment'])) { $commentModel = new Comment(); $commentModel->attributes = $_POST['Comment']; $commentModel->created_by = Yii::app()->user->id; $commentModel->post_type = "comment"; $commentModel->question_id = $question->id; if ($commentModel->validate()) { $commentModel->save(); $this->redirect($this->createUrl('//questionanswer/main/view', array('id' => $question->id))); } } // User has just voted on a question if (isset($_POST['QuestionVotes'])) { $questionVotesModel = new QuestionVotes(); $questionVotesModel->attributes = $_POST['QuestionVotes']; QuestionVotes::model()->castVote($questionVotesModel, $question->id); } $this->render('view', array('author' => $question->user->id, 'question' => $question, 'answers' => Answer::model()->overview($question->id), 'related' => Question::model()->related($question->id))); }
public function actionAdd() { if (Yii::app()->request->isPostRequest && isset($_POST['Comment'])) { $redirect = isset($_POST['redirectTo']) ? $_POST['redirectTo'] : Yii::app()->user->returnUrl; $comment = new Comment(); $module = Yii::app()->getModule('comment'); $comment->setAttributes($_POST['Comment']); $comment->status = $module->defaultCommentStatus; if (Yii::app()->user->isAuthenticated()) { $comment->setAttributes(array('user_id' => Yii::app()->user->getId(), 'name' => Yii::app()->user->getState('nick_name'), 'email' => Yii::app()->user->getState('email'))); if ($module->autoApprove) { $comment->status = Comment::STATUS_APPROVED; } } if ($comment->save()) { if (Yii::app()->request->isAjaxRequest) { Yii::app()->ajax->success(Yii::t('comment', 'Комментарий добавлен!')); } $message = $comment->status !== Comment::STATUS_APPROVED ? Yii::t('comment', 'Спасибо, Ваш комментарий добавлен и ожидает проверки!') : Yii::t('comment', 'Спасибо, Ваш комментарий добавлен!'); Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, $message); $this->redirect($redirect); } else { if (Yii::app()->request->isAjaxRequest) { Yii::app()->ajax->failure(Yii::t('comment', 'Комментарий не добавлен!')); } Yii::app()->user->setFlash(YFlashMessages::ERROR_MESSAGE, Yii::t('comment', 'Комментарий не добавлен! Заполните форму корректно!')); $this->redirect($redirect); } } throw new CHttpException(404, Yii::t('comment', 'Страница не найдена!')); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $input = Input::all(); $validation = Validator::make($input, Comment::$rules); if ($validation->passes()) { $last_comment = Comment::where('user_id', '=', Auth::user()->id)->orderBy('created_at', 'desc')->first(); $current_date = new DateTime(date("Y-m-d H:i:s")); if (empty($last_comment)) { $interval = 5; } else { $interval = $current_date->diff($last_comment->created_at); $interval = intval($interval->format('%i')); } if ($interval >= 3) { $this->add_daily_comment_points(); $comment = new Comment(); $comment->media_id = $input['media_id']; $comment->comment = htmlspecialchars($input['comment']); $comment->user_id = Auth::user()->id; $comment->save(); echo $comment; } else { echo 0; } } else { echo 0; } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate($bookId = null, $seriesId = null) { $model = new Comment(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Comment'])) { $_POST['Comment']['author'] = Yii::app()->user->name; $_POST['Comment']['date'] = date('d M Y H:i:s'); $model->attributes = $_POST['Comment']; if ($model->save()) { if (isset($bookId)) { $commentsBooks = new CommentsBooks(); $commentsBooks->commnet_id = $model->id; $commentsBooks->book_id = $bookId; $commentsBooks->save(); $this->redirect(array('book/view/' . $bookId)); } if (isset($seriesId)) { $commentsSeries = new CommentsSeries(); $commentsSeries->comment_id = $model->id; $commentsSeries->series_id = $seriesId; $commentsSeries->save(); $this->redirect(array('series/view/' . $seriesId)); } } } $this->render('create', array('model' => $model)); }
public function actionDoAddComment() { $mid = $_POST['mid']; $id = $_POST['id']; $type = $_POST['type']; $object_id = $_POST['object_id']; $comment = $_POST['comment']; $quietly = $_POST['quietly']; $toId = $_POST['toId']; $model = new Comment(); $params = array('type' => $type, 'object_id' => $object_id, 'comment' => $comment, 'toId' => $toId, 'quietly' => $quietly); $model->attributes = $params; $model->save(); if (!empty($model->errors)) { echo -1; exit; } // $data = $model->attributes; // $data['face']=$model->user->getUserFace(); // echo CJSON::encode($data); $comment = $model->attributes; $comment['face'] = $model->user->getUserFace(); if (!$comment[toId]) { $data['comment'] = $comment; $this->renderPartial('comment_li', $data); } else { $data['subcomment'] = $comment; $this->renderPartial('subcomment_li', $data); } }
public function add_comment() { $record = RegisterRecord::find(Input::get('record_id')); if (!isset($record)) { return Response::json(array('error_code' => 2, 'message' => '无该记录')); } $user_id = RegisterAccount::find($record->account_id)->user_id; if ($user_id != Session::get('user.id')) { return Response::json(array('error_code' => 3, 'message' => '无效记录')); } if (!Input::has('content')) { return Response::json(array('error_code' => 4, 'message' => '请输入评价')); } $old_comment = $record->comment()->get(); if (isset($old_comment)) { return Response::json(array('error_code' => 5, 'message' => '已评论')); } $comment = new Comment(); $comment->record_id = $record->id; $comment->content = Input::get('content'); if (!$comment->save()) { return Response::json(array('error_code' => 1, 'message' => '添加失败')); } return Response::json(array('error_code' => 0, 'message' => '添加成功')); }
public function posts($id) { $this->load->helper('form'); $this->load->model(['post', 'comment']); $post = NULL; try { $post = Post::findOrFail($id); } catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) { show_404(); } $data = ['menu' => 'blog', 'post' => $post]; $this->load->library('form_validation'); $this->form_validation->set_error_delimiters('<p class="text-danger"><strong><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> ', '</strong></p>'); if ($this->form_validation->run('create-comment') == FALSE) { $this->load->view('front/blog-post', $data); } else { $comment = new Comment(); $comment->post_id = $this->input->post('id'); $comment->name = $this->input->post('name'); $comment->content = $this->input->post('comment'); $comment->save(); $this->session->set_flashdata('message', 'Successfully save!'); redirect('posts/' . $id . '#comments'); } }
/** * executeDo_add_new_comment * * @access public * @return void */ public function executeDoAdd(sfWebRequest $request) { // Pull associated model $record_id = $request->getParameter('record_id'); $model = $request->getParameter('model'); $this->record = Doctrine::getTable($model)->find($record_id); $commentForm = new CommentForm(); $commentForm->bind($request->getParameter('comment')); // return bound form with errors if form is invalid if (!$commentForm->isValid()) { return $this->renderPartial('csComments/add_comment', array('commentForm' => $commentForm)); } // save the object /* SHOULD USE IMBEDDED FORMS Used this hack instead. Need to fix -B.Shaffer */ $commentVals = $commentForm->getValues(); $commenter = new Commenter(); $commenter->fromArray($commentVals['Commenter']); $commenter->save(); $comment = new Comment(); $comment['body'] = $commentVals['body']; $comment['Commenter'] = $commenter; $comment->save(); $this->comment = $comment; // Pass parent comment id if comment is nested $parent_id = $this->getRequestParameter('comment_id'); $this->record->addComment($this->comment, $parent_id); $this->record->save(); }
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); } }
/** * 提交评论 * @param string $slug 文章缩略名 * @return response */ public function postBlogComment($slug) { // 获取评论内容 $content = e(Input::get('content')); // 字数检查 if (mb_strlen($content) < 3) { return Redirect::back()->withInput()->withErrors($this->messages->add('content', '评论不得少于3个字符。')); } // 查找对应文章 $article = Article::where('slug', $slug)->first(); // 创建文章评论 $comment = new Comment(); $comment->content = $content; $comment->article_id = $article->id; $comment->user_id = Auth::user()->id; if ($comment->save()) { // 创建成功 // 更新评论数 $article->comments_count = $article->comments->count(); $article->save(); // 返回成功信息 return Redirect::back()->with('success', '评论成功。'); } else { // 创建失败 return Redirect::back()->withInput()->with('error', '评论失败。'); } }
public static function saveComment($userId) { $comment = new Comment(); $comment->text = $_POST['text']; $comment->user_id = $userId; $comment->save(); }
public function post() { // Only permit logged in users to comment if (Auth::check()) { // Add a rule to verify the particular item exists Validator::extend('itemExists', function ($attribute, $value, $parameters) { $type = ucfirst(Input::get('type')); $item = $type::find($value); return $item; }); // Validate the data $validator = Validator::make(Input::all(), array('id' => 'itemExists', 'type' => 'in:doctor,companion,enemy,episode', 'title' => 'required|min:5', 'email' => 'required|email', 'content' => 'required'), array('required' => 'You forgot to include the :attribute on your comment!', 'itemExists' => 'If you can see this, the universe is broken because that ' . Input::get('type') . ' does not exist.')); if ($validator->fails()) { return Redirect::to(URL::previous() . '#comments')->withErrors($validator)->withInput(); } else { $comment = new Comment(); $comment->user_id = Auth::id(); $comment->item_id = Input::get('id'); $comment->item_type = Input::get('type'); $comment->title = Input::get('title'); $comment->content = Input::get('content'); $comment->save(); return Redirect::to(URL::previous() . '#comments')->with('message', 'Comment posted'); } } }
/** * @param $model * @return Comment */ public function processRequest($model) { $comment = new Comment(); if (Yii::app()->request->isPostRequest) { $comment->attributes = Yii::app()->request->getPost('Comment'); if (!Yii::app()->user->isGuest) { $comment->name = Yii::app()->user->name; $comment->email = Yii::app()->user->email; } if ($comment->validate()) { $pkAttr = $model->getObjectPkAttribute(); $comment->class_name = $model->getClassName(); $comment->object_pk = $model->{$pkAttr}; $comment->user_id = Yii::app()->user->isGuest ? 0 : Yii::app()->user->id; $comment->save(); $url = Yii::app()->getRequest()->getUrl(); if ($comment->status == Comment::STATUS_WAITING) { $url .= '#'; Yii::app()->user->setFlash('messages', Yii::t('CommentsModule.core', 'Ваш комментарий успешно добавлен. Он будет опубликован после проверки администратором.')); } elseif ($comment->status == Comment::STATUS_APPROVED) { $url .= '#comment_' . $comment->id; } // Refresh page Yii::app()->request->redirect($url, true); } } return $comment; }
public function actionView() { if (!isset($_GET['id'])) { throw new CHttpException(404, 'Страница не найденa'); } else { $site_id = $_GET['id']; $site = Site::model()->findByPk($site_id); if ($site == null) { throw new CHttpException(404, 'Страница не найденa'); } else { $value = ''; if (!Yii::app()->user->isGuest) { $mark = Mark::model()->find('site_id = :site_id AND user_id = :user_id', array('site_id' => $site->site_id, 'user_id' => Yii::app()->user->id)); if ($mark != null) { $value = $mark->value; } if ($_POST) { $comment = new Comment(); $comment->attributes = $_POST['Comment']; $comment->user_id = Yii::app()->user->id; $comment->site_id = $site->site_id; $comment->date = date('Y-m-d H:i:s'); $comment->save(); $this->redirect(array('view', 'id' => $site->site_id)); } } $this->render('view', array('site' => $site, 'value' => $value)); } } }
/** * Test * * @return void */ public function testSaveWithIdShouldReturnTrue() { $this->object->setContent('test'); $this->object->setTemplateId(1); $this->object->save(); $this->assertTrue($this->object->save()); $this->object->delete(); }
public function updateComment(Comment $comment) { $comment->approved = Input::get('status'); $comment->save(); $comment->post->comment_count = Comment::where('post_id', '=', $comment->post->id)->where('approved', '=', 1)->count(); $comment->post->save(); return Redirect::back()->withMessage('Commentaire ' . ($comment->approved === 'yes' ? 'approuvé' : 'refusé')); }
public function addComment(Comment $comment) { $comment->set('record_model', $this->_invoker->getTable()->getComponentName()); $comment->set('record_id', $this->_invoker->get('id')); $comment->save(); return $this->_invoker; }
public function updateComment(Comment $comment) { $comment->approved = Input::get('status'); $comment->save(); $comment->post->comment_count = Comment::where('post_id', '=', $comment->post->id)->where('approved', '=', 1)->count(); $comment->post->save(); return Redirect::back()->with('success', 'Comment ' . ($comment->approved === 'yes' ? 'Approved' : 'Disapproved')); }
/** * @param $model * @return Comment */ public function processRequest($model) { Yii::import('application.modules.users.models.User'); Yii::import('application.modules.catalog.models.Orgs'); $comment = new Comment; if(Yii::app()->request->getPost('Comment')) { $comment->attributes = Yii::app()->request->getPost('Comment'); $ratingAjax = null; if(isset($_POST['Comment']['rating'])){ $ratingAjax = (int)$_POST['Comment']['rating']; if($ratingAjax == 0) $ratingAjax = null; } $comment->rating = $ratingAjax; if(!Yii::app()->user->isGuest) { $comment->name = Yii::app()->user->username; $comment->email = Yii::app()->user->email; } $comment->status = Comment::STATUS_WAITING; if($comment->validate()) { // $pkAttr = $model->getObjectPkAttribute(); // $comment->class_name = $model->getClassName(); $comment->object_pk = $model->id; $comment->user_id = Yii::app()->user->isGuest ? 0 : Yii::app()->user->id; if(!$comment->save()){ // VarDumper::dump($comment->errors); die(); // Ctrl + X Delete line } $url = Yii::app()->getRequest()->getUrl(); // if($comment->rating) { // $this->starRating($comment->object_pk, $comment->rating); // } if($comment->status==Comment::STATUS_WAITING) { $url.='#'; Yii::app()->user->setFlash('messages', 'Ваш комментарий успешно добавлен. '); } elseif($comment->status==Comment::STATUS_APPROVED){ $url.='#comment_'.$comment->id; } if(Yii::app()->request->isAjaxRequest){ echo '[]'; Yii::app()->end(); } else { // Refresh page Yii::app()->request->redirect($url, true); } } } return $comment; }
public function create_comment($data) { $comment = new Comment(); $comment->name = $data['name']; $comment->text = $data['text']; $comment->time_created = time(); $comment->save(); $this->save_comment($comment); }
function addComment() { $c = new Comment(); $c->comment = $this->input->post("comment"); $c->campaign_id = $this->input->post("campaign_id"); $c->user_id = $this->input->post('user_id'); $c->save(); echo "1"; }
static function createComment($container_guid, $comment_body) { $owner_guid = getLoggedInUserGuid(); $comment = new Comment(); $comment->container_guid = $container_guid; $comment->body = $comment_body; $comment->owner_guid = $owner_guid; $comment->save(); }
public function run() { $user = User::all()->random(); $post1 = new Comment(); $post1->user_id = $user->id; $post1->post_id = 2; $post1->comment = "That's Awsome man"; $post1->save(); }
public function createComment($conversation) { $user = Confide::user(); $comment = new Comment(); $comment->conversation_id = $conversation->id; $comment->user_id = $user->id; $comment->fill(Input::all()); $comment->save(); return Redirect::route('conversation.show', array($conversation->id)); }
public function create($commentRequest) { $new = new Comment(); $new->user_id = $_SESSION['id']; $new->posted_at = date("Y-m-d H:i:s"); $new->post_id = $commentRequest['post_id']; $new->title = $commentRequest['title']; $new->comment = $commentRequest['comment']; $new->save(); }
public function testAddComment() { $comment = new Comment(); $comment->id_user = $this->user->id; $errors = $comment->validateController(); $this->assertEquals(3, sizeof($errors)); // username, repository, comment required $nbComments = sizeof($comments = $this->user->comments()); $this->assertEquals(0, $nbComments); $comment->setUsername("jessylenne"); $comment->setRepository("jessylenne"); $this->setExpectedExceptionRegExp('Exception', '/Veuillez fournir un commentaire valide/'); $comment->setComment('<script type="text/javascript">console.log("Yeah Fail!")</script>'); $this->assertFalse($comment->save()); $comment->setComment("comment"); $this->assertTrue($comment->save()); $this->assertEquals($nbComments + 1, sizeof($this->user->comments())); $comment->delete(); }
protected function renderContent() { $model = new Comment(); if (isset($_POST['Comment'])) { $model->attributes = $_POST['Comment']; if ($model->save()) { user()->setFlash('success', t('cms', 'Created Successfully!')); } } $this->render('cmswidgets.views.comment.comment_create_widget', array('model' => $model)); }
public static function sendComment($name, $msg, $news_id) { // TODO 判断空串 $comment = new Comment(); $comment->name = $name; $comment->msg = $msg; $comment->ip = self::getIp(); $comment->news_id = $news_id; $comment->name = $name; return $comment->save(); }
public function run() { $faker = Faker::create(); for ($i = 0; $i < 25; $i++) { $comment = new Comment(); $comment->description = $faker->sentence($nbWords = 10); $comment->profile_id = $faker->randomElement($array = array('7', '8', '9', '10')); $comment->status = 1; $comment->save(); } }
public function postComments() { $posted = Input::get(); $comment = new Comment(); $comment->username = $posted['username']; $comment->comments = $posted['comments']; $comment->location = $posted['location']; $comment->date = $posted['date']; $comment->time = $posted['time']; $comment->save(); }