Initial commit

This commit is contained in:
2020-01-27 08:56:08 +01:00
commit b7525048d6
27129 changed files with 3409855 additions and 0 deletions

View File

@@ -0,0 +1,166 @@
<?php
/**
* This class has been generated by TheliaStudio
* For more information, see https://github.com/thelia-modules/TheliaStudio
*/
namespace SupportTicket\Action\Base;
use SupportTicket\Model\Map\SupportTicketTableMap;
use SupportTicket\Event\SupportTicketEvent;
use SupportTicket\Event\SupportTicketEvents;
use SupportTicket\Model\SupportTicketQuery;
use SupportTicket\Model\SupportTicket;
use Thelia\Action\BaseAction;
use Thelia\Core\Event\ToggleVisibilityEvent;
use Thelia\Core\Event\UpdatePositionEvent;
use Propel\Runtime\Propel;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\TheliaEvents;
use \Thelia\Core\Event\TheliaFormEvent;
/**
* Class SupportTicketAction
* @package SupportTicket\Action
* @author TheliaStudio
*/
class SupportTicketAction extends BaseAction implements EventSubscriberInterface
{
public function create(SupportTicketEvent $event)
{
$this->createOrUpdate($event, new SupportTicket());
}
public function update(SupportTicketEvent $event)
{
$model = $this->getSupportTicket($event);
$this->createOrUpdate($event, $model);
}
public function delete(SupportTicketEvent $event)
{
$this->getSupportTicket($event)->delete();
}
protected function createOrUpdate(SupportTicketEvent $event, SupportTicket $model)
{
$con = Propel::getConnection(SupportTicketTableMap::DATABASE_NAME);
$con->beginTransaction();
try {
if (null !== $id = $event->getId()) {
$model->setId($id);
}
if (null !== $status = $event->getStatus()) {
$model->setStatus($status);
}
if (null !== $customerId = $event->getCustomerId()) {
$model->setCustomerId($customerId);
}
if (null !== $adminId = $event->getAdminId()) {
$model->setAdminId($adminId);
}
if (null !== $orderId = $event->getOrderId()) {
$model->setOrderId($orderId);
}
if (null !== $orderProductId = $event->getOrderProductId()) {
$model->setOrderProductId($orderProductId);
}
if (null !== $subject = $event->getSubject()) {
$model->setSubject($subject);
}
if (null !== $message = $event->getMessage()) {
$model->setMessage($message);
}
if (null !== $response = $event->getResponse()) {
$model->setResponse($response);
}
if (null !== $comment = $event->getComment()) {
$model->setComment($comment);
}
$model->save($con);
$con->commit();
} catch (\Exception $e) {
$con->rollback();
throw $e;
}
$event->setSupportTicket($model);
}
protected function getSupportTicket(SupportTicketEvent $event)
{
$model = SupportTicketQuery::create()->findPk($event->getId());
if (null === $model) {
throw new \RuntimeException(sprintf(
"The 'support_ticket' id '%d' doesn't exist",
$event->getId()
));
}
return $model;
}
public function beforeCreateFormBuild(TheliaFormEvent $event)
{
}
public function beforeUpdateFormBuild(TheliaFormEvent $event)
{
}
public function afterCreateFormBuild(TheliaFormEvent $event)
{
}
public function afterUpdateFormBuild(TheliaFormEvent $event)
{
}
/**
* Returns an array of event names this subscriber wants to listen to.
*
* The array keys are event names and the value can be:
*
* * The method name to call (priority defaults to 0)
* * An array composed of the method name to call and the priority
* * An array of arrays composed of the method names to call and respective
* priorities, or 0 if unset
*
* For instance:
*
* * array('eventName' => 'methodName')
* * array('eventName' => array('methodName', $priority))
* * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
*
* @return array The event names to listen to
*
* @api
*/
public static function getSubscribedEvents()
{
return array(
SupportTicketEvents::CREATE => array("create", 128),
SupportTicketEvents::UPDATE => array("update", 128),
SupportTicketEvents::DELETE => array("delete", 128),
TheliaEvents::FORM_BEFORE_BUILD . ".support_ticket_create" => array("beforeCreateFormBuild", 128),
TheliaEvents::FORM_BEFORE_BUILD . ".support_ticket_update" => array("beforeUpdateFormBuild", 128),
TheliaEvents::FORM_AFTER_BUILD . ".support_ticket_create" => array("afterCreateFormBuild", 128),
TheliaEvents::FORM_AFTER_BUILD . ".support_ticket_update" => array("afterUpdateFormBuild", 128),
);
}
}

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?>
<dwsync>
<file name="SupportTicketAction.php" server="51.254.220.106//web/" local="131351950200000000" remote="131351950200000000" />
</dwsync>

View File

@@ -0,0 +1,112 @@
<?php
/**
* This class has been generated by TheliaStudio
* For more information, see https://github.com/thelia-modules/TheliaStudio
*/
namespace SupportTicket\Action;
use SupportTicket\Action\Base\SupportTicketAction as BaseSupportTicketAction;
use SupportTicket\Event\SupportTicketEvent;
use SupportTicket\Model\SupportTicket;
use Thelia\Core\Template\ParserInterface;
use Thelia\Log\Tlog;
use Thelia\Mailer\MailerFactory;
use Thelia\Model\ConfigQuery;
use Thelia\Model\CustomerQuery;
use Thelia\Model\Lang;
use Thelia\Model\MessageQuery;
/**
* Class SupportTicketAction
* @package SupportTicket\Action
*/
class SupportTicketAction extends BaseSupportTicketAction
{
protected $parser;
protected $mailer;
public function __construct(ParserInterface $parser, MailerFactory $mailer)
{
$this->parser = $parser;
$this->mailer = $mailer;
}
public function create(SupportTicketEvent $event)
{
parent::create($event);
// send email
$this->sendMail($event->getSupportTicket(), false);
}
protected function sendMail(SupportTicket $supportTicket, $toCustomer = true)
{
$contactEmail = ConfigQuery::read('store_email');
if (true === $toCustomer) {
$emailTemplate = 'supportticket_customer';
$customer = CustomerQuery::create()->findPk($supportTicket->getCustomerId());
$locale = $customer->getCustomerLang()->getLocale();
$emailTo = $customer->getEmail();
} else {
$emailTemplate = 'supportticket_administrator';
$locale = Lang::getDefaultLanguage()->getLocale();
$emailTo = $contactEmail;
}
if ($contactEmail) {
$message = MessageQuery::create()
->filterByName($emailTemplate)
->findOne();
if (null === $message) {
throw new \Exception(sprintf("Failed to load message '%s'.", $emailTemplate));
}
$this->parser->assign('locale', $locale);
$this->parser->assign('ticket', $supportTicket);
$message
->setLocale($locale);
$instance = \Swift_Message::newInstance()
->addTo($emailTo)
->addFrom($contactEmail, ConfigQuery::read('store_name'));
// Build subject and body
$message->buildMessage($this->parser, $instance);
$this->mailer->send($instance);
Tlog::getInstance()->debug("Sending support ticket mail to " . $emailTo);
} else {
Tlog::getInstance()->debug("Support ticket message no contact email ");
}
}
public function update(SupportTicketEvent $event)
{
$model = $this->getSupportTicket($event);
$sendEmail = false;
if ($model->getStatus() === SupportTicket::STATUS_NEW) {
$sendEmail = true;
} elseif ($model->getStatus() === SupportTicket::STATUS_REPLIED) {
// deactivate the date, already set
$event->setRepliedAt(null);
} else {
$event->setStatus(null);
}
parent::update($event);
if (true === $sendEmail) {
$this->sendMail($event->getSupportTicket(), true);
}
}
}

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?>
<dwsync>
<file name="SupportTicketAction.php" server="51.254.220.106//web/" local="131351950200000000" remote="131351950200000000" />
</dwsync>