/** * * @param $comment * @return Comment */ private function buildComment($comment) { $cmt = new Comment($comment['datetime'], $comment['title'], $comment['text']); $user = new User($comment['nameUser'], null); $cmt->setUser($user); return $cmt; }
/** * Create new comment. This function is used by ProjectForms to post comments * to the messages * * @param string $content * @param boolean $is_private * @return Comment or NULL if we fail to save comment * @throws DAOValidationError */ function addComment($content, $is_private = false) { $comment = new Comment(); $comment->setText($content); $comment->setIsPrivate($is_private); return $this->attachComment($comment); }
public static function saveComment($userId) { $comment = new Comment(); $comment->text = $_POST['text']; $comment->user_id = $userId; $comment->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); } }
function moderateComment($id, $action, $fullUser) { global $dbConnectionInfo; $toReturn = ""; $act = false; if ($action == "approved") { $act = true; } $cmt = new Comment($dbConnectionInfo, "", $fullUser); $return = $cmt->moderate($id, $action); $toReturn = $return['page']; if ($return['page'] != "" && $act && $return['oldState'] == 'new') { // notify users $user = new User($dbConnectionInfo); $usersToNotify = $user->getUsersToNotify($toReturn, $id); $cmtInfo = $cmt->getInfo($id); $productTranslate = defined("__PRODUCT_NAME__") ? __PRODUCT_NAME__ : $cmtInfo['product']; $template = new Template("./templates/newComment.html"); $confirmationMsg = $template->replace(array("page" => __BASE_URL__ . $toReturn . "#" . $id, "text" => $cmtInfo['text'], "user" => $cmtInfo['name'], "productName" => $productTranslate)); foreach ($usersToNotify as $key => $value) { $mail = new Mail(); $subject = "[" . $productTranslate . "] " . Utils::translate('newCommentApproved'); $subject .= " [" . $toReturn . "]"; $mail->Subject($subject); $mail->To($value); $mail->From(__EMAIL__); $mail->Body($confirmationMsg); $mail->Send(); //$toReturn = "\nSEND to ".$value."user email='".$userEmail."'"; } } return $toReturn; }
/** * @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 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); }
/** * 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(); }
/** * 提交评论 * @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', '评论失败。'); } }
function add() { $response = new Response(); try { $workOrderId = $this->input->post("workOrderId"); $commentText = $this->input->post("comment"); $workOrder = $this->findById("Workorder", $workOrderId); $loggedInUser = $this->getLoggedInUser(); $comment = new Comment(); $comment->setCreated(new DateTime()); $comment->setCommentedBy($loggedInUser); $comment->setComment($commentText); $workOrder->getComments()->add($comment); $this->save($workOrder); $cmt = new Commentdto(); $cmt->setId($comment->getId()); $cmt->setComment($comment->getComment()); $cmt->setCommentedBy($comment->getCommentedBy()->getFirstName() . " " . $comment->getCommentedBy()->getLastName()); $cmt->setCreated(date_format($comment->getCreated(), "d-M-Y")); $response->setData($cmt); } catch (Exception $e) { $response->setStatus(false); $response->setErrorMessage($e->getMessage()); } $this->output->set_content_type('application/json')->set_output(json_encode($response)); }
/** * get a list of all parent comments * * Starts with the rubric as the top level and ends with the parent of this comment. * * @return array */ public function parents() { if (!$this->parent) return array($this->rubric); $parent = new Comment($this->parent); $parents = $parent->parents(); $parents[] = $this->parent; return $parents; }
/** * @Route("/ajax/add-comment", name="add_comment") */ public function addCommentAction() { $request = $this->get('request'); if ($request->isXmlHttpRequest()) { $akismet = $this->get('ornicar_akismet'); $name = $request->get('name'); $email = $request->get('email'); $commentContent = $request->get('comment'); $id = $request->get('id'); $isSpam = $akismet->isSpam(array('comment_author' => $name, 'comment_content' => $commentContent)); if ($isSpam === false) { $em = $this->getDoctrine()->getManager(); $article = $em->getRepository('CoreBundle:Article')->find($id); if (!$article) { throw $this->createNotFoundException('Unable to find Article entity.'); } $comment = new Comment(); $comment->setCommentAuthor($name); $comment->setCommentAuthorEmail($email); $comment->setCommentContent($commentContent); $article->addComment($comment); $em->persist($article); $em->flush(); $message = \Swift_Message::newInstance()->setSubject('Hello Author, New Comment added')->setFrom('*****@*****.**')->setTo('*****@*****.**')->setBody('You have a new Comment! please check your blog'); $this->get('mailer')->send($message); return new JsonResponse(1); } } }
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'); } } }
public function run() { $controller = $this->getController(); $controller->_seoTitle = Yii::t('common', 'User Center') . ' - ' . Yii::t('common', 'My Replys') . ' - ' . $controller->_setting['site_name']; //我的回复 $uid = Yii::app()->user->id; $comment_mod = new Comment(); $reply_mod = new Reply(); $criteria = new CDbCriteria(); $criteria->addColumnCondition(array('t.user_id' => $uid)); $criteria->order = 't.id DESC'; //分页 $count = $reply_mod->count($criteria); $pages = new CPagination($count); $pages->pageSize = 15; $pages->applyLimit($criteria); $datalist = $reply_mod->findAll($criteria); foreach ((array) $datalist as $k => $v) { $reply = $comment_mod->findByPk($v->cid); if ($reply) { $c_mod_class = $controller->_content_models[$reply->type]; $c_mod_name = strtolower($c_mod_class); $content_mod = new $c_mod_class(); $content = $content_mod->findByPk($reply->content_id); $datalist[$k]['title'] = $content->title; $datalist[$k]['url'] = $controller->createUrl($c_mod_name . '/view', array('id' => $reply->content_id)); } } $controller->render('my_replys', array('datalist' => $datalist, 'pages' => $pages)); }
public function run() { $controller = $this->getController(); $this->_setting = $controller->_setting; $this->_stylePath = $controller->_stylePath; $this->_static_public = $controller->_static_public; $controller->_seoTitle = Yii::t('common', 'User Center') . ' - ' . Yii::t('common', 'My Comments') . ' - ' . $this->_setting['site_name']; //加载css,js Yii::app()->clientScript->registerCssFile($this->_stylePath . "/css/user.css"); Yii::app()->clientScript->registerScriptFile($this->_static_public . "/js/jquery/jquery.js"); //我的评论 $uid = Yii::app()->user->id; $comment_mod = new Comment(); $model_type = new ModelType(); $uid = Yii::app()->user->id; $criteria = new CDbCriteria(); $criteria->condition = 't.user_id=' . $uid; $criteria->order = 't.id DESC'; //分页 $count = $comment_mod->count($criteria); $pages = new CPagination($count); $pages->pageSize = 15; $criteria->limit = $pages->pageSize; $criteria->offset = $pages->currentPage * $pages->pageSize; $datalist = $comment_mod->findAll($criteria); foreach ((array) $datalist as $k => $v) { $c_mod_class = $controller->_content_models[$v->type]; $c_mod_name = strtolower($c_mod_class); $content_mod = new $c_mod_class(); $content = $content_mod->findByPk($v->topic_id); $datalist[$k]['title'] = $content->title; $datalist[$k]['url'] = $controller->createUrl($c_mod_name . '/view', array('id' => $content->id)); } $controller->render('my_comments', array('datalist' => $datalist)); }
/** * View a blog post. * * @param string $slug * @return Redirect */ public function postView($slug) { // The user needs to be logged in, make that check please if (!Sentry::check()) { return Redirect::to("blog/{$slug}#comments")->with('error', Lang::get('post.messages.login')); } // Get this blog post data $post = $this->post->where('slug', $slug)->first(); // get the data $new = Input::all(); $comment = new Comment(); // If validation fails, we'll exit the operation now if ($comment->validate($new)) { // Save the comment $comment->user_id = Sentry::getUser()->id; $comment->content = e(Input::get('comment')); // Was the comment saved with success? if ($post->comments()->save($comment)) { // Redirect to this blog post page return Redirect::to("blog/{$slug}#comments")->with('success', 'Your comment was successfully added.'); } } else { // failure, get errors return Redirect::to("blog/{$slug}#comments")->withInput()->withErrors($comment->errors()); } // Redirect to this blog post page return Redirect::to("blog/{$slug}#comments")->with('error', Lang::get('post.messages.generic')); }
public function comments() { require_once 'class.mt_comment.php'; $comment = new Comment(); $comments = $comment->Find("comment_entry_id = " . $this->entry_id); return $comments; }
public function actionUpdate() { $comment = new Comment(); $id = $_POST['id']; $data['comment'] = $comment->get_comment_by_id($id); $this->renderPartial('//comment/update', $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' => '添加成功')); }
/** * * @param Comment $comment_ * @param array $arrayFilter * @throws InvalidArgumentException */ public function insertComment(Comment $comment_, array $arrayFilter = array()) { try { if (is_null($this->table)) { throw new InvalidArgumentException('Attribute "table" can\'t be NULL !'); } $userMapper = new UserMapper(); $announcementMapper = new AnnouncementMapper(); $userMapper->setId($comment_->getIdUser()); $user = $userMapper->selectUser(); $announcementMapper->setId($comment_->getIdAnnouncement()); $announcement = $announcementMapper->selectAnnouncement(); if (!is_null($user->getId()) && !is_null($announcement->getId())) { return parent::insert($this->table, $comment_, $arrayFilter); } elseif (is_null($user->getId())) { throw new Exception('User is inexistant !'); } elseif (is_null($announcement->getId())) { throw new Exception('Announcement is inexistant !'); } } catch (InvalidArgumentException $e) { print $e->getMessage(); exit; } catch (Exception $e) { print $e->getMessage(); exit; } }
public function run() { $model = new Comment(); //条件 $criteria = new CDbCriteria(); $type = trim(Yii::app()->request->getParam('type')); $type && $criteria->addColumnCondition(array('type' => $type)); $status = trim(Yii::app()->request->getParam('status')); $status && $criteria->addColumnCondition(array('status' => $status)); $title = trim(Yii::app()->request->getParam('content')); $title && $criteria->addSearchCondition('content', $title); $criteria->order = 't.id DESC'; $count = $model->count($criteria); //分页 $pages = new CPagination($count); $pages->pageSize = 10; $pages->applyLimit($criteria); //查询 $result = $model->findAll($criteria); //全部类型 $model_types = ModelType::model()->findAll(); Yii::app()->clientScript->registerCssFile($this->controller->_static_public . "/js/kindeditor/code/prettify.css"); Yii::app()->clientScript->registerScriptFile($this->controller->_static_public . "/js/kindeditor/code/prettify.js", CClientScript::POS_END); $this->controller->render('index', array('model' => $model, 'model_types' => $model_types, 'datalist' => $result, 'pagebar' => $pages)); }
public function edit_post() { $data = $this->data; //取得公用數據 //基本post欄位 $orderid_Num = $this->input->post('orderid_Num', TRUE); $paycheck_status_Num = $this->input->post('paycheck_status_Num', TRUE); $product_status_Num = $this->input->post('product_status_Num', TRUE); $receive_name_Str = $this->input->post('receive_name_Str', TRUE); $receive_phone_Str = $this->input->post('receive_phone_Str', TRUE); $receive_time_Str = $this->input->post('receive_time_Str'); $receive_address_Str = $this->input->post('receive_address_Str'); $receive_remark_Str = $this->input->post('receive_remark_Str', TRUE); $transport_id_Str = $this->input->post('transport_id_Str', TRUE); $sendtime_Str = $this->input->post('sendtime_Str', TRUE); $order_status_Num = $this->input->post('order_status_Num', TRUE); $content_Str = $this->input->post('content_Str', TRUE); //建構OrderShop物件,並且更新 $OrderShop = new OrderShop(); $OrderShop->construct(array('orderid_Num' => $orderid_Num, 'paycheck_status_Num' => $paycheck_status_Num, 'product_status_Num' => $product_status_Num, 'receive_name_Str' => $receive_name_Str, 'receive_phone_Str' => $receive_phone_Str, 'receive_time_Str' => $receive_time_Str, 'receive_address_Str' => $receive_address_Str, 'receive_remark_Str' => $receive_remark_Str, 'transport_id_Str' => $transport_id_Str, 'sendtime_Str' => $sendtime_Str, 'updatetime_Str' => '', 'order_status_Num' => $order_status_Num)); $OrderShop->update(array('db_update_Arr' => array('paycheck_status', 'product_status', 'receive_name', 'receive_phone', 'receive_time', 'receive_address', 'receive_remark', 'transport_id', 'sendtime', 'updatetime', 'order_status'))); if (!empty($content_Str)) { $Comment = new Comment(); $Comment->construct(['uid_Num' => $data['User']->uid_Num, 'typename_Str' => 'order', 'id_Num' => $OrderShop->orderid_Num, 'content_Str' => $content_Str]); $Comment->update(); } //送出成功訊息 $this->load->model('Message'); $this->Message->show(array('message' => '設定成功', 'url' => 'admin/shop/order_shop/order_shop/tablelist')); }
/** * @expectedException InvalidArgumentException */ public function testSetParentNotPersisted() { $parent = $this->getMock('FOS\\CommentBundle\\Entity\\Comment'); $parent->expects($this->any())->method('getId')->will($this->returnValue(null)); $comment = new Comment(); $comment->setParent($parent); }
public function controlerJob($maincont) { if ($maincont->isLoggued()) { /*$_POST["author"]="gg42"; $_POST["body"]="move Ur body4242"; $_POST["published"]="1"; $_POST["postid"]="2"; $_POST["id"]=3; $_SESSION["backmod"]="comment"; $_SESSION["backact"]="admin";*/ if (isset($_POST["id"])) { $p = new Comment($_POST["id"]); $p->setAuthor($_POST["author"]); $p->setBody($_POST["body"]); //$p->setHour(date("h:i:s")); //$p->setDate(date("Y-m-d")); $p->setPublished($_POST["published"]); $p->setPostid($_POST["postid"]); } $maincont->goModule("comment", "admin"); //$maincont->goModule($_SESSION["backmod"],$_SESSION["backact"]); } else { $maincont->goModule("admin", "loginform"); } }
public function Fire() { if ($this->input->do == 'submit') { $bug = new Bug($this->input->bug_id); try { $bug->FetchInto(); } catch (phalanx\data\ModelException $e) { EventPump::Pump()->RaiseEvent(new StandardErrorEvent(l10n::S('BUG_ID_NOT_FOUND'))); return; } $body = trim($this->input->body); if (empty($body)) { EventPump::Pump()->RaiseEvent(new StandardErrorEvent(l10n::S('COMMENT_MISSING_BODY'))); return; } $comment = new Comment(); $comment->bug_id = $bug_id; $comment->post_user_id = Bugdar::$auth->current_user(); $comment->post_date = time(); $comment->body = $body; $comment->Insert(); $this->comment_id = $comment->comment_id; $search = new SearchEngine(); $search->IndexBug($bug); EventPump::Pump()->PostEvent(new StandardSuccessEvent('view_bug/' . $bug_id, l10n::S('USER_REGISTER_SUCCESS'))); } }
/** * Ссылка на удаление комментария * * @param Comment $comment */ function link_to_comment_delete($comment, $title = null) { $user = sfContext::getInstance()->getUser(); if ($user->isAuthenticated() && $user->getGuardUser()->getId() == $comment->getUserId() && $comment->hasDeletable()) { return jq_link_to_remote($title ? $title : 'Удалить', array('method' => 'post', 'url' => url_for('comment_delete', $comment), 'success' => 'jQuery("#comment-' . $comment->id . '").remove();', 'confirm' => 'Вы точно хотите удалить свой комментарий?')); } }
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', 'Страница не найдена!')); }
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'); } }
public function makeAll(&$demoDataHelper) { assert('$demoDataHelper instanceof DemoDataHelper'); assert('$demoDataHelper->isSetRange("User")'); $missions = array(); foreach (self::getMissionData() as $randomMissionData) { $postData = array(); $mission = new Mission(); $mission->setScenario('importModel'); $mission->status = Mission::STATUS_AVAILABLE; $mission->owner = $demoDataHelper->getRandomByModelName('User'); $mission->createdByUser = $mission->owner; $mission->description = $randomMissionData['description']; $mission->reward = $randomMissionData['reward']; //Add some comments foreach ($randomMissionData['comments'] as $commentDescription) { $comment = new Comment(); $comment->setScenario('importModel'); $comment->createdByUser = $demoDataHelper->getRandomByModelName('User'); $comment->description = $commentDescription; $mission->comments->add($comment); } $mission->addPermissions(Group::getByName(Group::EVERYONE_GROUP_NAME), Permission::READ_WRITE); $saved = $mission->save(); assert('$saved'); $mission = Mission::getById($mission->id); ReadPermissionsOptimizationUtil::securableItemGivenPermissionsForGroup($mission, Group::getByName(Group::EVERYONE_GROUP_NAME)); $mission->save(); $missions[] = $mission->id; } $demoDataHelper->setRangeByModelName('Mission', $missions[0], $missions[count($missions) - 1]); }
/** * Notify admin of new comment * * @param Comment $comment */ public function onAfterPostComment(Comment $comment) { // Determine recipient $recipient = CommentsNotifications::get_recipient($comment->getParent()); if (empty($recipient)) { return; } // Check moderation status if (Config::inst()->get('CommentsNotifications', 'only_unmoderated') && $comment->Moderated) { return; } // Generate email $email = new Email(); $email->setSubject(Config::inst()->get('CommentsNotifications', 'email_subject')); $email->setTo($recipient); $email->setTemplate(Config::inst()->get('CommentsNotifications', 'email_template')); $email->populateTemplate($comment); // Corretly set sender and from as per email convention $sender = Config::inst()->get('CommentsNotifications', 'email_sender'); if (!empty($comment->Email)) { $email->setFrom($comment->Email); $email->addCustomHeader('Reply-To', $comment->Email); } else { $email->setFrom($sender); } $email->addCustomHeader('X-Sender', $sender); $email->addCustomHeader('Sender', $sender); $this->owner->extend('updateEmail', $email); // Send $email->send(); }