235 lines
5.7 KiB
PHP
235 lines
5.7 KiB
PHP
<?php
|
|
/**
|
|
* This class has been generated by TheliaStudio
|
|
* For more information, see https://github.com/thelia-modules/TheliaStudio
|
|
*/
|
|
|
|
namespace Contest\Controller\Base;
|
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
|
use Thelia\Controller\Admin\AbstractCrudController;
|
|
use Thelia\Core\Security\Resource\AdminResources;
|
|
use Thelia\Tools\URL;
|
|
use Contest\Event\ParticipateEvent;
|
|
use Contest\Event\ParticipateEvents;
|
|
use Contest\Model\ParticipateQuery;
|
|
|
|
/**
|
|
* Class ParticipateController
|
|
* @package Contest\Controller\Base
|
|
* @author TheliaStudio
|
|
*/
|
|
class ParticipateController extends AbstractCrudController
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct(
|
|
"participate",
|
|
"id",
|
|
"order",
|
|
AdminResources::MODULE,
|
|
ParticipateEvents::CREATE,
|
|
ParticipateEvents::UPDATE,
|
|
ParticipateEvents::DELETE,
|
|
null,
|
|
null,
|
|
"Contest"
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Return the creation form for this object
|
|
*/
|
|
protected function getCreationForm()
|
|
{
|
|
return $this->createForm("participate.create");
|
|
}
|
|
|
|
/**
|
|
* Return the update form for this object
|
|
*/
|
|
protected function getUpdateForm($data = array())
|
|
{
|
|
if (!is_array($data)) {
|
|
$data = array();
|
|
}
|
|
|
|
return $this->createForm("participate.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(),
|
|
"email" => $object->getEmail(),
|
|
"win" => (bool) $object->getWin(),
|
|
"game_id" => $object->getGameId(),
|
|
"customer_id" => $object->getCustomerId(),
|
|
);
|
|
|
|
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 ParticipateEvent();
|
|
|
|
$event->setEmail($formData["email"]);
|
|
$event->setWin($formData["win"]);
|
|
$event->setGameId($formData["game_id"]);
|
|
$event->setCustomerId($formData["customer_id"]);
|
|
|
|
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 ParticipateEvent();
|
|
|
|
$event->setId($formData["id"]);
|
|
$event->setEmail($formData["email"]);
|
|
$event->setWin($formData["win"]);
|
|
$event->setGameId($formData["game_id"]);
|
|
$event->setCustomerId($formData["customer_id"]);
|
|
|
|
return $event;
|
|
}
|
|
|
|
/**
|
|
* Creates the delete event with the provided form data
|
|
*/
|
|
protected function getDeleteEvent()
|
|
{
|
|
$event = new ParticipateEvent();
|
|
|
|
$event->setId($this->getRequest()->request->get("participate_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->getParticipate();
|
|
}
|
|
|
|
/**
|
|
* Load an existing object from the database
|
|
*/
|
|
protected function getExistingObject()
|
|
{
|
|
return ParticipateQuery::create()
|
|
->findPk($this->getRequest()->query->get("participate_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("participates");
|
|
}
|
|
|
|
/**
|
|
* Render the edition template
|
|
*/
|
|
protected function renderEditionTemplate()
|
|
{
|
|
$this->getParserContext()
|
|
->set(
|
|
"participate_id",
|
|
$this->getRequest()->query->get("participate_id")
|
|
)
|
|
;
|
|
|
|
return $this->render("participate-edit");
|
|
}
|
|
|
|
/**
|
|
* Must return a RedirectResponse instance
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
|
*/
|
|
protected function redirectToEditionTemplate()
|
|
{
|
|
$id = $this->getRequest()->query->get("participate_id");
|
|
|
|
return new RedirectResponse(
|
|
URL::getInstance()->absoluteUrl(
|
|
"/admin/module/Contest/participate/edit",
|
|
[
|
|
"participate_id" => $id,
|
|
]
|
|
)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Must return a RedirectResponse instance
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
|
*/
|
|
protected function redirectToListTemplate()
|
|
{
|
|
return new RedirectResponse(
|
|
URL::getInstance()->absoluteUrl("/admin/module/Contest/participate")
|
|
);
|
|
}
|
|
}
|