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,249 @@
<?php
/**
* This class has been generated by TheliaStudio
* For more information, see https://github.com/thelia-modules/TheliaStudio
*/
namespace SupportTicket\Controller\Base;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Thelia\Controller\Admin\AbstractCrudController;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Tools\URL;
use SupportTicket\Event\SupportTicketEvent;
use SupportTicket\Event\SupportTicketEvents;
use SupportTicket\Model\SupportTicketQuery;
/**
* Class SupportTicketController
* @package SupportTicket\Controller\Base
* @author TheliaStudio
*/
class SupportTicketController extends AbstractCrudController
{
public function __construct()
{
parent::__construct(
"support_ticket",
"id",
"order",
AdminResources::MODULE,
SupportTicketEvents::CREATE,
SupportTicketEvents::UPDATE,
SupportTicketEvents::DELETE,
null,
null,
"SupportTicket"
);
}
/**
* Return the creation form for this object
*/
protected function getCreationForm()
{
return $this->createForm("support_ticket.create");
}
/**
* Return the update form for this object
*/
protected function getUpdateForm($data = array())
{
if (!is_array($data)) {
$data = array();
}
return $this->createForm("support_ticket.update", "form", $data);
}
/**
* Hydrate the update form for this object, before passing it to the update template
*
* @param mixed $object
*/
protected function hydrateObjectForm($object)
{
$data = array(
"id" => $object->getId(),
"status" => (bool) $object->getStatus(),
"customer_id" => $object->getCustomerId(),
"admin_id" => $object->getAdminId(),
"order_id" => $object->getOrderId(),
"order_product_id" => $object->getOrderProductId(),
"subject" => $object->getSubject(),
"message" => $object->getMessage(),
"response" => $object->getResponse(),
"comment" => $object->getComment(),
);
return $this->getUpdateForm($data);
}
/**
* Creates the creation event with the provided form data
*
* @param mixed $formData
* @return \Thelia\Core\Event\ActionEvent
*/
protected function getCreationEvent($formData)
{
$event = new SupportTicketEvent();
$event->setStatus($formData["status"]);
$event->setCustomerId($formData["customer_id"]);
$event->setAdminId($formData["admin_id"]);
$event->setOrderId($formData["order_id"]);
$event->setOrderProductId($formData["order_product_id"]);
$event->setSubject($formData["subject"]);
$event->setMessage($formData["message"]);
$event->setResponse($formData["response"]);
$event->setComment($formData["comment"]);
return $event;
}
/**
* Creates the update event with the provided form data
*
* @param mixed $formData
* @return \Thelia\Core\Event\ActionEvent
*/
protected function getUpdateEvent($formData)
{
$event = new SupportTicketEvent();
$event->setId($formData["id"]);
$event->setStatus($formData["status"]);
$event->setCustomerId($formData["customer_id"]);
$event->setAdminId($formData["admin_id"]);
$event->setOrderId($formData["order_id"]);
$event->setOrderProductId($formData["order_product_id"]);
$event->setSubject($formData["subject"]);
$event->setMessage($formData["message"]);
$event->setResponse($formData["response"]);
$event->setComment($formData["comment"]);
return $event;
}
/**
* Creates the delete event with the provided form data
*/
protected function getDeleteEvent()
{
$event = new SupportTicketEvent();
$event->setId($this->getRequest()->request->get("support_ticket_id"));
return $event;
}
/**
* Return true if the event contains the object, e.g. the action has updated the object in the event.
*
* @param mixed $event
*/
protected function eventContainsObject($event)
{
return null !== $this->getObjectFromEvent($event);
}
/**
* Get the created object from an event.
*
* @param mixed $event
*/
protected function getObjectFromEvent($event)
{
return $event->getSupportTicket();
}
/**
* Load an existing object from the database
*/
protected function getExistingObject()
{
return SupportTicketQuery::create()
->findPk($this->getRequest()->query->get("support_ticket_id"))
;
}
/**
* Returns the object label form the object event (name, title, etc.)
*
* @param mixed $object
*/
protected function getObjectLabel($object)
{
return '';
}
/**
* Returns the object ID from the object
*
* @param mixed $object
*/
protected function getObjectId($object)
{
return $object->getId();
}
/**
* Render the main list template
*
* @param mixed $currentOrder , if any, null otherwise.
*/
protected function renderListTemplate($currentOrder)
{
$this->getParser()
->assign("order", $currentOrder)
;
return $this->render("support-tickets");
}
/**
* Render the edition template
*/
protected function renderEditionTemplate()
{
$this->getParserContext()
->set(
"support_ticket_id",
$this->getRequest()->query->get("support_ticket_id")
)
;
return $this->render("support-ticket-edit");
}
/**
* Must return a RedirectResponse instance
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
protected function redirectToEditionTemplate()
{
$id = $this->getRequest()->query->get("support_ticket_id");
return new RedirectResponse(
URL::getInstance()->absoluteUrl(
"/admin/module/SupportTicket/support_ticket/edit",
[
"support_ticket_id" => $id,
]
)
);
}
/**
* Must return a RedirectResponse instance
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
protected function redirectToListTemplate()
{
return new RedirectResponse(
URL::getInstance()->absoluteUrl("/admin/module/SupportTicket/support_ticket")
);
}
}

View File

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

View File

@@ -0,0 +1,116 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace SupportTicket\Controller;
use SupportTicket\Event\SupportTicketEvent;
use SupportTicket\Event\SupportTicketEvents;
use SupportTicket\Model\SupportTicket;
use SupportTicket\Model\SupportTicketQuery;
use Thelia\Controller\Front\BaseFrontController;
use Thelia\Core\Translation\Translator;
use Thelia\Form\Exception\FormValidationException;
/**
* Class FrontController
* @package SupportTicket\Controller
* @author Julien Chanséaume <julien@thelia.net>
*/
class FrontController extends BaseFrontController
{
protected $useFallbackTemplate = true;
/** @var Translator $translator */
protected $translator;
public function defaultAction()
{
$this->checkAuth();
return $this->render('support-ticket');
}
public function createAction()
{
$this->checkAuth();
$this->checkXmlHttpRequest();
$responseData = [
"success" => false,
"message" => ''
];
$form = $this->createForm('support_ticket.front.create');
try {
$formData = $this->validateForm($form);
$event = new SupportTicketEvent();
$event->bindForm($formData);
$event->setStatus(SupportTicket::STATUS_NEW);
$this->dispatch(SupportTicketEvents::CREATE, $event);
$responseData['success'] = true;
$responseData['message'] = 'ok';
} catch (FormValidationException $e) {
$responseData['message'] = $e->getMessage();
} catch (\Exception $e) {
$responseData['message'] = $e->getMessage();
}
return $this->jsonResponse(json_encode($responseData));
}
public function deleteAction($supportTicketId)
{
$this->checkAuth();
$supportTicket = SupportTicketQuery::create()->findPk($supportTicketId);
$customerId = $this->getSecurityContext()->getCustomerUser()->getId();
if (null !== $supportTicket && $supportTicket->getCustomerId() == $customerId) {
$event = new SupportTicketEvent();
$event
->setId($supportTicketId)
->setStatus(SupportTicket::STATUS_CLOSED);
$this->dispatch(SupportTicketEvents::UPDATE, $event);
$this->getSession()->getFlashBag()
->add(
'supportticket-message',
$this->trans('Your question has been deleted')
);
} else {
$this->getSession()->getFlashBag()
->add(
'supportticket-message',
$this->trans("Sorry, this question can't be deleted.")
);
}
return $this->generateRedirect('/module/SupportTicket/support');
}
protected function trans($id, $parameters = [])
{
if (null === $this->translator) {
$this->translator = Translator::getInstance();
}
return $this->translator->trans($id, $parameters, \SupportTicket\SupportTicket::MESSAGE_DOMAIN);
}
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* This class has been generated by TheliaStudio
* For more information, see https://github.com/thelia-modules/TheliaStudio
*/
namespace SupportTicket\Controller;
use SupportTicket\Controller\Base\SupportTicketController as BaseSupportTicketController;
use SupportTicket\Event\SupportTicketEvent;
use SupportTicket\Model\SupportTicket;
/**
* Class SupportTicketController
* @package SupportTicket\Controller
*/
class SupportTicketController extends BaseSupportTicketController
{
protected function getUpdateEvent($formData)
{
$event = new SupportTicketEvent();
$event->setId($formData["id"]);
$event->setAdminId($formData["admin_id"]);
$event->setSubject($formData["subject"]);
$event->setMessage($formData["message"]);
$event->setResponse($formData["response"]);
$event->setComment($formData["comment"]);
$event->setStatus(SupportTicket::STATUS_REPLIED);
$event->setRepliedAt(new \DateTime('now'));
return $event;
}
}

View File

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