136 lines
4.5 KiB
PHP
136 lines
4.5 KiB
PHP
<?php
|
|
|
|
namespace ClickAndCollect\Controller\backOffice;
|
|
|
|
use ClickAndCollect\ClickAndCollect;
|
|
use PointRetrait\Model\PdrPlacesQuery;
|
|
use PointRetrait\Model\PdrPlaces;
|
|
use PointRetrait\Model\PdrScheduleQuery;
|
|
use Propel\Runtime\Map\TableMap;
|
|
use Propel\Runtime\Propel;
|
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
|
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;
|
|
|
|
/**
|
|
* Class PlaceController
|
|
* @package ClickAndCollect\Controller
|
|
*/
|
|
class PlaceController extends BaseAdminController
|
|
{
|
|
|
|
public function viewPlace()
|
|
{
|
|
$selectedPlace = PdrPlacesQuery::create()->findOneById($this->getRequest()->query->get("place_id"));
|
|
|
|
return $this->render("cnc-place-edit", array('module_code' => ClickAndCollect::getModuleCode(),
|
|
'place_id' => $selectedPlace));
|
|
}
|
|
|
|
|
|
public function editPlace()
|
|
{
|
|
// Check current user authorization
|
|
if (null !== $response = $this->checkAuth(AdminResources::MODULE, ClickAndCollect::getModuleCode(), AccessManager::VIEW))
|
|
return $response;
|
|
|
|
$con = Propel::getConnection();
|
|
$con->beginTransaction();
|
|
|
|
$error_msg = "";
|
|
$changeForm = $this->createForm("cnc.place.view.main", "form");
|
|
|
|
try {
|
|
$form = $this->validateForm($changeForm, "POST");
|
|
|
|
$data = $form->getData();
|
|
$place = PdrPlacesQuery::create()->findOneById($data['place_id']);
|
|
if ($place === null) {
|
|
$error_msg = "Click and Collect place not found by Id";
|
|
}
|
|
else {
|
|
$place->fromArray($data, TableMap::TYPE_FIELDNAME);
|
|
$place->save();
|
|
$con->commit();
|
|
}
|
|
} catch (FormValidationException $ex) {
|
|
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
|
|
}
|
|
|
|
if ($this->getRequest()->get('save_mode') == 'stay')
|
|
return $this->render("cnc-place-edit");
|
|
|
|
return $this->render("cnc-places-list");
|
|
}
|
|
|
|
|
|
public function createPlace()
|
|
{
|
|
// Check current user authorization
|
|
if (null !== $response = $this->checkAuth(AdminResources::MODULE, ClickAndCollect::getModuleCode(), AccessManager::VIEW))
|
|
return $response;
|
|
|
|
$con = Propel::getConnection();
|
|
$con->beginTransaction();
|
|
|
|
$error_msg = "";
|
|
$createForm = $this->createForm("cnc.place.create", "form");
|
|
|
|
try {
|
|
$form = $this->validateForm($createForm, "POST");
|
|
$data = $form->getData();
|
|
|
|
$newPlace = new PdrPlaces();
|
|
$newPlace->fromArray($data, TableMap::TYPE_FIELDNAME);
|
|
$newPlace->save();
|
|
$con->commit();
|
|
|
|
} catch (FormValidationException $ex) {
|
|
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
|
|
}
|
|
|
|
if ($this->getRequest()->request->get("success_url") == null) {
|
|
return new RedirectResponse(URL::getInstance()->absoluteUrl(ClickAndCollect::MODULE_URL));
|
|
} else {
|
|
return new RedirectResponse(URL::getInstance()->absoluteUrl($this->getRequest()->request->get("success_url")));
|
|
}
|
|
}
|
|
|
|
|
|
public function deletePlace()
|
|
{
|
|
// Check current user authorization
|
|
if (null !== $response = $this->checkAuth(AdminResources::MODULE, ClickAndCollect::getModuleCode(), AccessManager::VIEW))
|
|
return $response;
|
|
|
|
$placeId = $this->getRequest()->get('attr-place-id');
|
|
$query1 = PdrScheduleQuery::create()->findByIdPlace($placeId);
|
|
if ($query1 === null)
|
|
$error_msg = "Place not found by Id";
|
|
else {
|
|
$con = Propel::getConnection();
|
|
$con->beginTransaction();
|
|
$query1->delete($con);
|
|
$con->commit();
|
|
|
|
$query2 = PdrPlacesQuery::create()->findById($placeId);
|
|
if ($query2 === null)
|
|
$error_msg = "Place not found by Id";
|
|
else {
|
|
$con->beginTransaction();
|
|
$query2->delete($con);
|
|
$con->commit();
|
|
}
|
|
}
|
|
|
|
if ($this->getRequest()->request->get("success_url") == null) {
|
|
return new RedirectResponse(URL::getInstance()->absoluteUrl(ClickAndCollect::MODULE_URL));
|
|
} else {
|
|
return new RedirectResponse(URL::getInstance()->absoluteUrl($this->getRequest()->request->get("success_url")));
|
|
}
|
|
}
|
|
|
|
} |