Exemple #1
0
 protected function showComment(BaseHookRenderEvent $event)
 {
     list($ref, $refId) = $this->getParams($event);
     $eventDefinition = new CommentDefinitionEvent();
     $eventDefinition->setRef($ref)->setRefId($refId)->setCustomer($this->getCustomer())->setConfig(Comment::getConfig());
     $message = '';
     try {
         $this->dispatcher->dispatch(CommentEvents::COMMENT_GET_DEFINITION, $eventDefinition);
         $eventDefinition->setValid(true);
     } catch (InvalidDefinitionException $ex) {
         if ($ex->isSilent()) {
             return null;
         }
         $eventDefinition->setValid(false);
         $message = $ex->getMessage();
     } catch (\Exception $ex) {
         Tlog::getInstance()->debug($ex->getMessage());
         return null;
     }
     return $this->render("comment.html", ['definition' => $eventDefinition, 'message' => $message]);
 }
Exemple #2
0
 /**
  * Save comment module configuration
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function saveConfiguration()
 {
     if (null !== ($response = $this->checkAuth([AdminResources::MODULE], ['comment'], AccessManager::UPDATE))) {
         return $response;
     }
     $form = new \Comment\Form\ConfigurationForm($this->getRequest());
     $message = "";
     $response = null;
     try {
         $vform = $this->validateForm($form);
         $data = $vform->getData();
         ConfigQuery::write('comment_activated', $data['activated'] ? '1' : '0');
         ConfigQuery::write('comment_moderate', $data['moderate'] ? '1' : '0');
         ConfigQuery::write('comment_ref_allowed', $data['ref_allowed']);
         ConfigQuery::write('comment_only_customer', $data['only_customer'] ? '1' : '0');
         ConfigQuery::write('comment_only_verified', $data['only_verified'] ? '1' : '0');
         ConfigQuery::write('comment_request_customer_ttl', $data['request_customer_ttl']);
         ConfigQuery::write('comment_notify_admin_new_comment', $data['notify_admin_new_comment']);
     } catch (\Exception $e) {
         $message = $e->getMessage();
     }
     if ($message) {
         $form->setErrorMessage($message);
         $this->getParserContext()->addForm($form);
         $this->getParserContext()->setGeneralError($message);
         return $this->render("module-configure", ["module_code" => Comment::getModuleCode()]);
     }
     return RedirectResponse::create(URL::getInstance()->absoluteUrl("/admin/module/" . Comment::getModuleCode()));
 }
Exemple #3
0
 protected function getDefinition($ref, $refId)
 {
     $eventDefinition = new CommentDefinitionEvent();
     $eventDefinition->setRef($ref)->setRefId($refId)->setCustomer($this->getSecurityContext()->getCustomerUser())->setConfig(Comment::getConfig());
     $this->dispatch(CommentEvents::COMMENT_GET_DEFINITION, $eventDefinition);
     return $eventDefinition;
 }
Exemple #4
0
 /**
  * Notify shop managers of a new comment.
  * @param CommentCreateEvent $event
  */
 public function notifyAdminOfNewComment(CommentCreateEvent $event)
 {
     $config = \Comment\Comment::getConfig();
     if (!$config["notify_admin_new_comment"]) {
         return;
     }
     $comment = $event->getComment();
     if ($comment === null) {
         return;
     }
     // get the default shop locale
     $shopLang = LangQuery::create()->findOneByByDefault(true);
     if ($shopLang !== null) {
         $shopLocale = $shopLang->getLocale();
     } else {
         $shopLocale = null;
     }
     $getCommentRefEvent = new CommentReferenceGetterEvent($comment->getRef(), $comment->getRefId(), $shopLocale);
     $event->getDispatcher()->dispatch(CommentEvents::COMMENT_REFERENCE_GETTER, $getCommentRefEvent);
     $this->mailer->sendEmailToShopManagers('new_comment_notification_admin', ['comment_id' => $comment->getId(), 'ref_title' => $getCommentRefEvent->getTitle(), 'ref_type_title' => $getCommentRefEvent->getTypeTitle()]);
 }
Exemple #5
0
 protected function buildForm()
 {
     $form = $this->formBuilder;
     $config = Comment::getConfig();
     $form->add("activated", "checkbox", ['data' => $config['activated'], 'label' => $this->trans("Activated"), 'label_attr' => ['for' => "activated", 'help' => $this->trans("Global activation of comments. You can control activation by product, content.")]])->add("moderate", "checkbox", ['data' => $config['moderate'], 'label' => $this->trans("Moderate"), 'label_attr' => ['for' => "moderate", 'help' => $this->trans("Comments are not validated automatically.")]])->add("ref_allowed", "text", ['constraints' => [new NotBlank()], 'data' => implode(',', $config['ref_allowed']), 'label' => $this->trans("Allowed references"), 'label_attr' => ['for' => "back_office_path", 'help' => $this->trans("which elements could use comments")]])->add("only_customer", "checkbox", ['data' => $config['only_customer'], 'label' => $this->trans("Only customer"), 'label_attr' => ['for' => "only_customer", 'help' => $this->trans("Only registered customers can post comments.")]])->add("only_verified", "checkbox", ['data' => $config['only_verified'], 'label' => $this->trans("Only verified"), 'label_attr' => ['for' => "only_verified", 'help' => $this->trans("For product comments. Only customers that bought the product can post comments.")]])->add("request_customer_ttl", "number", ['data' => $config['request_customer_ttl'], 'label' => $this->trans("Request customer"), 'label_attr' => ['for' => "request_customer_ttl", 'help' => $this->trans("Send an email to request customer comments, x days after a paid order (0 = no request sent).")]])->add("notify_admin_new_comment", "checkbox", ['data' => $config['notify_admin_new_comment'], 'label' => $this->trans("Notify store managers on new comment"), 'label_attr' => ['for' => "notify_admin_new_comment", 'help' => $this->trans("Send an email to the store managers when a new comment is posted.")]]);
 }