module modification

This commit is contained in:
Etienne Roudeix
2013-11-08 11:26:06 +01:00
parent c6cd32fec2
commit 422a80fcce
19 changed files with 424 additions and 193 deletions

View File

@@ -23,12 +23,15 @@
namespace Thelia\Controller\Admin;
use Thelia\Core\Event\Module\ModuleEvent;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Core\Event\Module\ModuleDeleteEvent;
use Thelia\Core\Event\Module\ModuleToggleActivationEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Security\AccessManager;
use Thelia\Form\ModuleModificationForm;
use Thelia\Model\ModuleQuery;
use Thelia\Module\ModuleManagement;
/**
@@ -36,25 +39,155 @@ use Thelia\Module\ModuleManagement;
* @package Thelia\Controller\Admin
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class ModuleController extends BaseAdminController
class ModuleController extends AbstractCrudController
{
public function __construct()
{
parent::__construct(
'module',
null,
null,
AdminResources::MODULE,
null,
TheliaEvents::MODULE_UPDATE,
null
);
}
protected function getCreationForm()
{
return null;
}
protected function getUpdateForm()
{
return new ModuleModificationForm($this->getRequest());
}
protected function getCreationEvent($formData)
{
return null;
}
protected function getUpdateEvent($formData)
{
$event = new ModuleEvent();
$event->setLocale($formData['locale']);
$event->setId($formData['id']);
$event->setTitle($formData['title']);
$event->setChapo($formData['chapo']);
$event->setDescription($formData['description']);
$event->setPostscriptum($formData['postscriptum']);
return $event;
}
protected function getDeleteEvent()
{
return null;
}
protected function eventContainsObject($event)
{
return $event->hasModule();
}
protected function hydrateObjectForm($object)
{
$object->setLocale($this->getCurrentEditionLocale());
$data = array(
'id' => $object->getId(),
'locale' => $object->getLocale(),
'title' => $object->getTitle(),
'chapo' => $object->getChapo(),
'description' => $object->getDescription(),
'postscriptum' => $object->getPostscriptum(),
);
// Setup the object form
return new ModuleModificationForm($this->getRequest(), "form", $data);
}
protected function getObjectFromEvent($event)
{
return $event->hasModule() ? $event->getModule() : null;
}
protected function getExistingObject()
{
return ModuleQuery::create()
->joinWithI18n($this->getCurrentEditionLocale())
->findOneById($this->getRequest()->get('module_id'));
}
protected function getObjectLabel($object)
{
return $object->getTitle();
}
protected function getObjectId($object)
{
return $object->getId();
}
protected function getViewArguments()
{
return array();
}
protected function getRouteArguments($module_id = null)
{
return array(
'module_id' => $module_id === null ? $this->getRequest()->get('module_id') : $module_id,
);
}
protected function renderListTemplate($currentOrder)
{
// We always return to the feature edition form
return $this->render(
'modules',
array()
);
}
protected function renderEditionTemplate()
{
// We always return to the feature edition form
return $this->render('module-edit', array_merge($this->getViewArguments(), $this->getRouteArguments()));
}
protected function redirectToEditionTemplate($request = null, $country = null)
{
// We always return to the module edition form
$this->redirectToRoute(
"admin.module.update",
$this->getViewArguments(),
$this->getRouteArguments()
);
}
protected function redirectToListTemplate()
{
$this->redirectToRoute(
"admin.module"
);
}
public function indexAction()
{
if (null !== $response = $this->checkAuth(AdminResources::MODULE, AccessManager::VIEW)) return $response;
$modulemanagement = new ModuleManagement();
$modulemanagement->updateModules();
$moduleManagement = new ModuleManagement();
$moduleManagement->updateModules();
return $this->render("modules");
}
public function updateAction($module_id)
{
return $this->render("module-edit", array(
"module_id" => $module_id
));
}
public function toggleActivationAction($module_id)
{
if (null !== $response = $this->checkAuth(AdminResources::MODULE, AccessManager::UPDATE)) return $response;