Beispiel #1
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see Comment::setDeleted()
  * @see Comment::isDeleted()
  */
 public function delete(ConnectionInterface $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getServiceContainer()->getWriteConnection(CommentTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildCommentQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
Beispiel #2
0
 public function postActivation(ConnectionInterface $con = null)
 {
     // Config
     if (null === ConfigQuery::read('comment_activated')) {
         ConfigQuery::write('comment_activated', Comment::CONFIG_ACTIVATED);
     }
     if (null === ConfigQuery::read('comment_moderate')) {
         ConfigQuery::write('comment_moderate', Comment::CONFIG_MODERATE);
     }
     if (null === ConfigQuery::read('comment_ref_allowed')) {
         ConfigQuery::write('comment_ref_allowed', Comment::CONFIG_REF_ALLOWED);
     }
     if (null === ConfigQuery::read('comment_only_customer')) {
         ConfigQuery::write('comment_only_customer', Comment::CONFIG_ONLY_CUSTOMER);
     }
     if (null === ConfigQuery::read('comment_only_verified')) {
         ConfigQuery::write('comment_only_verified', Comment::CONFIG_ONLY_VERIFIED);
     }
     if (null === ConfigQuery::read('comment_request_customer_ttl')) {
         ConfigQuery::write('comment_request_customer_ttl', Comment::CONFIG_REQUEST_CUSTOMMER_TTL);
     }
     if (null === ConfigQuery::read('comment_notify_admin_new_comment')) {
         ConfigQuery::write('comment_notify_admin_new_comment', Comment::CONFIG_NOTIFY_ADMIN_NEW_COMMENT);
     }
     // Schema
     try {
         CommentQuery::create()->findOne();
     } catch (\Exception $ex) {
         $database = new Database($con->getWrappedConnection());
         $database->insertSql(null, [__DIR__ . DS . 'Config' . DS . 'thelia.sql']);
     }
     // Messages
     // load the email localization files (the module was just loaded so they are not loaded yet)
     $languages = LangQuery::create()->find();
     /** @var Lang $language */
     foreach ($languages as $language) {
         Translator::getInstance()->addResource("php", __DIR__ . "/I18n/email/default/" . $language->getLocale() . ".php", $language->getLocale(), self::MESSAGE_DOMAIN_EMAIL);
     }
     // Request comment from customer
     if (null === MessageQuery::create()->findOneByName('comment_request_customer')) {
         $message = new Message();
         $message->setName('comment_request_customer')->setHtmlTemplateFileName('request-customer-comment.html')->setHtmlLayoutFileName('')->setTextTemplateFileName('request-customer-comment.txt')->setTextLayoutFileName('')->setSecured(0);
         foreach ($languages as $language) {
             $locale = $language->getLocale();
             $message->setLocale($locale);
             $message->setTitle(Translator::getInstance()->trans('Request customer comment', [], self::MESSAGE_DOMAIN));
             $message->setSubject(Translator::getInstance()->trans('', [], self::MESSAGE_DOMAIN));
         }
         $message->save();
     }
     // Notify admin of new comment
     if (null === MessageQuery::create()->findOneByName('new_comment_notification_admin')) {
         $message = new Message();
         $message->setName('new_comment_notification_admin')->setHtmlTemplateFileName('new-comment-notification-admin.html')->setHtmlLayoutFileName('')->setTextTemplateFileName('new-comment-notification-admin.txt')->setTextLayoutFileName('')->setSecured(0);
         foreach ($languages as $language) {
             $locale = $language->getLocale();
             $message->setLocale($locale);
             $message->setTitle(Translator::getInstance()->trans('Notify store admin of new comment', [], self::MESSAGE_DOMAIN_EMAIL, $locale));
             $subject = Translator::getInstance()->trans('New comment on %ref_type_title "%ref_title"', [], self::MESSAGE_DOMAIN_EMAIL, $locale);
             $subject = str_replace('%ref_type_title', '{$ref_type_title|lower}', $subject);
             $subject = str_replace('%ref_title', '{$ref_title}', $subject);
             $message->setSubject($subject);
         }
         $message->save();
     }
 }
Beispiel #3
0
 /**
  * Load an existing object from the database
  */
 protected function getExistingObject()
 {
     $comment_id = $this->getRequest()->get('comment_id');
     if (null === $comment_id) {
         $comment_id = $this->getRequest()->attributes('comment_id');
     }
     return CommentQuery::create()->findPk($comment_id);
 }
Beispiel #4
0
 /**
  * this method returns a Propel ModelCriteria
  *
  * @return \Propel\Runtime\ActiveQuery\ModelCriteria
  */
 public function buildModelCriteria()
 {
     $search = CommentQuery::create();
     $id = $this->getId();
     if (null !== $id) {
         $search->filterById($id, Criteria::IN);
     }
     $customer = $this->getCustomer();
     if (null !== $customer) {
         $search->filterByCustomerId($customer, Criteria::IN);
     }
     $ref = $this->getRef();
     $refId = $this->getRefId();
     if (null !== $ref || null !== $refId) {
         if (null === $ref || null === $refId) {
             throw new \InvalidArgumentException($this->translator->trans("If 'ref' argument is specified, 'ref_id' argument should be specified", [], Comment::MESSAGE_DOMAIN));
         }
         $search->filterByRef($ref);
         $search->filterByRefId($refId, Criteria::IN);
     }
     $status = $this->getStatus();
     if ($status !== null) {
         $search->filterByStatus($status);
     }
     $verified = $this->getVerified();
     if ($verified !== BooleanOrBothType::ANY) {
         $search->filterByVerified($verified ? 1 : 0);
     }
     $locale = $this->getLocale();
     if (null !== $locale) {
         $search->filterByLocale($locale);
     }
     $orders = $this->getOrder();
     if (null !== $orders) {
         foreach ($orders as $order) {
             switch ($order) {
                 case "id":
                     $search->orderById(Criteria::ASC);
                     break;
                 case "id_reverse":
                     $search->orderById(Criteria::DESC);
                     break;
                 case "visible":
                     $search->orderByStatus(Criteria::ASC);
                     break;
                 case "visible_reverse":
                     $search->orderByStatus(Criteria::DESC);
                     break;
                 case "verified":
                     $search->orderByVerified(Criteria::ASC);
                     break;
                 case "verified_reverse":
                     $search->orderByVerified(Criteria::DESC);
                     break;
                 case "abuse":
                     $search->orderByAbuse(Criteria::ASC);
                     break;
                 case "abuse_reverse":
                     $search->orderByAbuse(Criteria::DESC);
                     break;
                 case "rating":
                     $search->orderByRating(Criteria::ASC);
                     break;
                 case "rating_reverse":
                     $search->orderByRating(Criteria::DESC);
                     break;
                 case "created":
                     $search->addAscendingOrderByColumn('created_at');
                     break;
                 case "created_reverse":
                     $search->addDescendingOrderByColumn('created_at');
                     break;
                 case "updated":
                     $search->addAscendingOrderByColumn('updated_at');
                     break;
                 case "updated_reverse":
                     $search->addDescendingOrderByColumn('updated_at');
                     break;
             }
         }
     }
     return $search;
 }
Beispiel #5
0
 public function requestCustomerDemand(CommentCheckOrderEvent $event)
 {
     $config = \Comment\Comment::getConfig();
     $nbDays = $config["request_customer_ttl"];
     if (0 !== $nbDays) {
         $endDate = new DateTime('NOW');
         $endDate->setTime(0, 0, 0);
         $endDate->sub(new DateInterval('P' . $nbDays . 'D'));
         $startDate = clone $endDate;
         $startDate->sub(new DateInterval('P1D'));
         $pseJoin = new Join(OrderProductTableMap::PRODUCT_SALE_ELEMENTS_ID, ProductSaleElementsTableMap::ID, Criteria::INNER_JOIN);
         $products = OrderProductQuery::create()->useOrderQuery()->filterByInvoiceDate($startDate, Criteria::GREATER_EQUAL)->filterByInvoiceDate($endDate, Criteria::LESS_THAN)->addAsColumn('customerId', OrderTableMap::CUSTOMER_ID)->addAsColumn('orderId', OrderTableMap::ID)->endUse()->addJoinObject($pseJoin)->addAsColumn('pseId', OrderProductTableMap::PRODUCT_SALE_ELEMENTS_ID)->addAsColumn('productId', ProductSaleElementsTableMap::PRODUCT_ID)->select(['customerId', 'orderId', 'pseId', 'productId'])->find()->toArray();
         if (empty($products)) {
             return;
         }
         $customerProducts = array_reduce($products, function ($result, $item) {
             if (!array_key_exists($item['customerId'], $result)) {
                 $result[$item['customerId']] = [];
             }
             if (!in_array($item['productId'], $result[$item['customerId']])) {
                 $result[$item['customerId']][] = $item['productId'];
             }
             return $result;
         }, []);
         $customerIds = array_keys($customerProducts);
         // check if comments already exists
         $comments = CommentQuery::create()->filterByCustomerId($customerIds)->filterByRef(MetaData::PRODUCT_KEY)->addAsColumn('customerId', CommentTableMap::CUSTOMER_ID)->addAsColumn('productId', CommentTableMap::REF_ID)->select(['customerId', 'productId'])->find()->toArray();
         $customerComments = array_reduce($comments, function ($result, $item) {
             if (!array_key_exists($item['customerId'], $result)) {
                 $result[$item['customerId']] = [];
             }
             $result[$item['customerId']][] = $item['productId'];
             return $result;
         }, []);
         foreach ($customerIds as $customerId) {
             $send = false;
             if (!array_key_exists($customerId, $customerComments)) {
                 $send = true;
             } else {
                 $noCommentsPosted = array_intersect($customerComments[$customerId], $customerProducts[$customerId]);
                 if (empty($noCommentsPosted)) {
                     $send = true;
                 }
             }
             if ($send) {
                 try {
                     $this->sendCommentRequestCustomerMail($customerId, $customerProducts[$customerId]);
                 } catch (\Exception $ex) {
                     Tlog::getInstance()->error($ex->getMessage());
                 }
             }
         }
     }
 }
Beispiel #6
0
 public function deleteAction($commentId)
 {
     // only ajax
     $this->checkXmlHttpRequest();
     $messageData = ["success" => false];
     try {
         $customer = $this->getSecurityContext()->getCustomerUser();
         // find the comment
         $comment = CommentQuery::create()->findPk($commentId);
         if (null !== $comment) {
             if ($comment->getCustomerId() === $customer->getId()) {
                 $event = new CommentDeleteEvent();
                 $event->setId($commentId);
                 $this->dispatch(CommentEvents::COMMENT_DELETE, $event);
                 if (null !== $event->getComment()) {
                     $messageData["success"] = true;
                     $messageData["message"] = $this->getTranslator()->trans("Your comment has been deleted.", [], Comment::MESSAGE_DOMAIN);
                 }
             }
         }
     } catch (\Exception $ex) {
     }
     if (false === $messageData["success"]) {
         $messageData["message"] = $this->getTranslator()->trans("Comment could not be removed. Please try later.", [], Comment::MESSAGE_DOMAIN);
     }
     return $this->jsonResponse(json_encode($messageData));
 }