Add comments
This commit is contained in:
@@ -267,7 +267,10 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
*/
|
||||
public function defaultAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::VIEW)) return $response;
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::VIEW))
|
||||
return $response;
|
||||
|
||||
return $this->renderList();
|
||||
}
|
||||
|
||||
@@ -279,8 +282,10 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
public function createAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::CREATE)) return $response;
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::CREATE))
|
||||
return $response;
|
||||
|
||||
// Error (Default: false)
|
||||
$error_msg = false;
|
||||
|
||||
// Create the Creation Form
|
||||
@@ -288,24 +293,29 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
|
||||
try {
|
||||
|
||||
// Validate the form, create the event and dispatch it.
|
||||
// Check the form against constraints violations
|
||||
$form = $this->validateForm($creationForm, "POST");
|
||||
|
||||
// Get the form field values
|
||||
$data = $form->getData();
|
||||
|
||||
// Create a new event object with the modified fields
|
||||
$createEvent = $this->getCreationEvent($data);
|
||||
|
||||
// Dispatch Create Event
|
||||
$this->dispatch($this->createEventIdentifier, $createEvent);
|
||||
|
||||
// Check if object exist
|
||||
if (! $this->eventContainsObject($createEvent))
|
||||
throw new \LogicException(
|
||||
$this->getTranslator()->trans("No %obj was created.", array('%obj', $this->objectName)));
|
||||
$this->getTranslator()->trans("No %obj was created.", array('%obj', $this->objectName)));
|
||||
|
||||
// Log object creation
|
||||
if (null !== $createdObject = $this->getObjectFromEvent($createEvent)) {
|
||||
// Log object creation
|
||||
$this->adminLogAppend($this->resourceCode, AccessManager::CREATE, sprintf("%s %s (ID %s) created", ucfirst($this->objectName), $this->getObjectLabel($createdObject), $this->getObjectId($createdObject)));
|
||||
}
|
||||
|
||||
// Execute additional Action
|
||||
$response = $this->performAdditionalCreateAction($createEvent);
|
||||
|
||||
if ($response == null) {
|
||||
@@ -326,7 +336,11 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
}
|
||||
|
||||
$this->setupFormErrorContext(
|
||||
$this->getTranslator()->trans("%obj creation", array('%obj' => $this->objectName)), $error_msg, $creationForm, $ex);
|
||||
$this->getTranslator()->trans("%obj creation", array('%obj' => $this->objectName)),
|
||||
$error_msg,
|
||||
$creationForm,
|
||||
$ex
|
||||
);
|
||||
|
||||
// At this point, the form has error, and should be redisplayed.
|
||||
return $this->renderList();
|
||||
@@ -340,12 +354,11 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
public function updateAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE)) return $response;
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE))
|
||||
return $response;
|
||||
|
||||
// Load the object
|
||||
$object = $this->getExistingObject();
|
||||
|
||||
if ($object != null) {
|
||||
// Load object if exist
|
||||
if (null !== $object = $this->getExistingObject()) {
|
||||
|
||||
// Hydrate the form abd pass it to the parser
|
||||
$changeForm = $this->hydrateObjectForm($object);
|
||||
@@ -366,8 +379,10 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
public function processUpdateAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE)) return $response;
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE))
|
||||
return $response;
|
||||
|
||||
// Error (Default: false)
|
||||
$error_msg = false;
|
||||
|
||||
// Create the form from the request
|
||||
@@ -381,19 +396,23 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
// Get the form field values
|
||||
$data = $form->getData();
|
||||
|
||||
// Create a new event object with the modified fields
|
||||
$changeEvent = $this->getUpdateEvent($data);
|
||||
|
||||
// Dispatch Update Event
|
||||
$this->dispatch($this->updateEventIdentifier, $changeEvent);
|
||||
|
||||
// Check if object exist
|
||||
if (! $this->eventContainsObject($changeEvent))
|
||||
throw new \LogicException(
|
||||
$this->getTranslator()->trans("No %obj was updated.", array('%obj', $this->objectName)));
|
||||
$this->getTranslator()->trans("No %obj was updated.", array('%obj', $this->objectName)));
|
||||
|
||||
// Log object modification
|
||||
if (null !== $changedObject = $this->getObjectFromEvent($changeEvent)) {
|
||||
$this->adminLogAppend($this->resourceCode, AccessManager::UPDATE, sprintf("%s %s (ID %s) modified", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject)));
|
||||
}
|
||||
|
||||
// Execute additional Action
|
||||
$response = $this->performAdditionalUpdateAction($changeEvent);
|
||||
|
||||
if ($response == null) {
|
||||
@@ -417,7 +436,11 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
}
|
||||
|
||||
$this->setupFormErrorContext(
|
||||
$this->getTranslator()->trans("%obj modification", array('%obj' => $this->objectName)), $error_msg, $changeForm, $ex);
|
||||
$this->getTranslator()->trans("%obj modification", array('%obj' => $this->objectName)),
|
||||
$error_msg,
|
||||
$changeForm,
|
||||
$ex
|
||||
);
|
||||
|
||||
// At this point, the form has errors, and should be redisplayed.
|
||||
return $this->renderEditionTemplate();
|
||||
@@ -431,7 +454,8 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
public function updatePositionAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE)) return $response;
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE))
|
||||
return $response;
|
||||
|
||||
try {
|
||||
$mode = $this->getRequest()->get('mode', null);
|
||||
@@ -448,6 +472,7 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
$event = $this->createUpdatePositionEvent($mode, $position);
|
||||
|
||||
$this->dispatch($this->changePositionEventIdentifier, $event);
|
||||
|
||||
} catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
@@ -465,7 +490,8 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
protected function genericUpdatePositionAction($object, $eventName, $doFinalRedirect = true)
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE)) return $response;
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE))
|
||||
return $response;
|
||||
|
||||
if ($object != null) {
|
||||
|
||||
@@ -499,7 +525,8 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
public function setToggleVisibilityAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE)) return $response;
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE))
|
||||
return $response;
|
||||
|
||||
$changeEvent = $this->createToggleVisibilityEvent($this->getRequest());
|
||||
|
||||
@@ -521,7 +548,8 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
public function deleteAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::DELETE)) return $response;
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::DELETE))
|
||||
return $response;
|
||||
|
||||
// Get the currency id, and dispatch the delet request
|
||||
$deleteEvent = $this->getDeleteEvent();
|
||||
|
||||
Reference in New Issue
Block a user