81 lines
2.8 KiB
PHP
81 lines
2.8 KiB
PHP
<?php
|
|
/*************************************************************************************/
|
|
/* */
|
|
/* Copyright (c) CQFDev */
|
|
/* email : thelia@cqfdev.fr */
|
|
/* web : http://www.cqfdev.fr */
|
|
/* */
|
|
/*************************************************************************************/
|
|
|
|
namespace Beds24\Controller\Back;
|
|
|
|
use Beds24\Beds24;
|
|
use Thelia\Controller\Admin\BaseAdminController;
|
|
use Thelia\Core\Security\AccessManager;
|
|
use Thelia\Core\Security\Resource\AdminResources;
|
|
use Thelia\Form\Exception\FormValidationException;
|
|
use Thelia\Tools\URL;
|
|
|
|
/**
|
|
* @author Franck Allimant <franck@cqfdev.fr>
|
|
*/
|
|
class ConfigurationController extends BaseAdminController
|
|
{
|
|
public function clearCache()
|
|
{
|
|
if (null !== $response = $this->checkAuth(AdminResources::MODULE, 'Beds24', AccessManager::UPDATE)) {
|
|
return $response;
|
|
}
|
|
|
|
(new Beds24\Beds24Request())->clearCache();
|
|
|
|
return $this->generateRedirect(URL::getInstance()->absoluteUrl('/admin/module/Beds24'));
|
|
}
|
|
|
|
public function configure()
|
|
{
|
|
if (null !== $response = $this->checkAuth(AdminResources::MODULE, 'Beds24', AccessManager::UPDATE)) {
|
|
return $response;
|
|
}
|
|
|
|
$configurationForm = $this->createForm('beds24.form.configuration');
|
|
|
|
try {
|
|
$form = $this->validateForm($configurationForm, "POST");
|
|
|
|
// Get the form field values
|
|
$data = $form->getData();
|
|
|
|
foreach ($data as $name => $value) {
|
|
if ($name === 'remises_jours') {
|
|
Beds24::setRemisesParJour($value);
|
|
continue;
|
|
}
|
|
|
|
Beds24::setConfigValue($name, $value);
|
|
}
|
|
|
|
if ($this->getRequest()->get('save_mode') == 'stay') {
|
|
$url = '/admin/module/Beds24';
|
|
} else {
|
|
$url = '/admin/modules';
|
|
}
|
|
|
|
return $this->generateRedirect(URL::getInstance()->absoluteUrl($url));
|
|
} catch (FormValidationException $ex) {
|
|
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
|
|
} catch (\Exception $ex) {
|
|
$error_msg = $ex->getMessage();
|
|
}
|
|
|
|
$this->setupFormErrorContext(
|
|
$this->getTranslator()->trans("Configuration du franco", [], Beds24::DOMAIN_NAME),
|
|
$error_msg,
|
|
$configurationForm,
|
|
$ex
|
|
);
|
|
|
|
return $this->generateRedirect(URL::getInstance()->absoluteUrl('/admin/module/Beds24'));
|
|
}
|
|
}
|