PointRetrait : création et suppression OK, il reste un peu de boulot sur l'enregistrement.
This commit is contained in:
@@ -2,14 +2,18 @@
|
||||
|
||||
namespace PointRetrait\Controller\backOffice;
|
||||
|
||||
use PointRetrait\Model\PdrPlaces;
|
||||
use PointRetrait\Model\PdrPlacesQuery;
|
||||
use PointRetrait\PointRetrait;
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
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
|
||||
@@ -62,4 +66,63 @@ class PlaceController extends BaseAdminController
|
||||
return $this->render("places-list");
|
||||
}
|
||||
|
||||
|
||||
public function createPlace()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth(AdminResources::MODULE, PointRetrait::getModuleCode(), AccessManager::VIEW))
|
||||
return $response;
|
||||
|
||||
$con = Propel::getConnection();
|
||||
$con->beginTransaction();
|
||||
|
||||
$error_msg = "";
|
||||
$createForm = $this->createForm("pointretrait.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(PointRetrait::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, PointRetrait::getModuleCode(), AccessManager::VIEW))
|
||||
return $response;
|
||||
|
||||
$placeId = $this->getRequest()->get('attr-place-id');
|
||||
$query = PdrPlacesQuery::create()->findById($placeId);
|
||||
if ($query === null)
|
||||
$error_msg = "Place not found by Id";
|
||||
else
|
||||
{
|
||||
$con = Propel::getConnection();
|
||||
$con->beginTransaction();
|
||||
$query->delete($con);
|
||||
$con->commit();
|
||||
}
|
||||
|
||||
if ($this->getRequest()->request->get("success_url") == null) {
|
||||
return new RedirectResponse(URL::getInstance()->absoluteUrl(PointRetrait::MODULE_URL));
|
||||
} else {
|
||||
return new RedirectResponse(URL::getInstance()->absoluteUrl($this->getRequest()->request->get("success_url")));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user