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