Skip to content

Instantly share code, notes, and snippets.

@bshaffer
Created April 13, 2011 05:58
Show Gist options
  • Save bshaffer/917043 to your computer and use it in GitHub Desktop.
Save bshaffer/917043 to your computer and use it in GitHub Desktop.
Old Admin: from actions.class.php - batchAction
<?php
abstract class autoSf_guard_user_oldActions extends sfActions
{
// ....
public function executeBatch(sfWebRequest $request)
{
$request->checkCSRFProtection();
if (!$ids = $request->getParameter('ids'))
{
$this->getUser()->setFlash('error', 'You must at least select one item.');
$this->redirect('@sf_guard_user_sf_guard_user_old');
}
if (!$action = $request->getParameter('batch_action'))
{
$this->getUser()->setFlash('error', 'You must select an action to execute on the selected items.');
$this->redirect('@sf_guard_user_sf_guard_user_old');
}
if (!method_exists($this, $method = 'execute'.ucfirst($action)))
{
throw new InvalidArgumentException(sprintf('You must create a "%s" method for action "%s"', $method, $action));
}
if (!$this->getUser()->hasCredential($this->configuration->getCredentials($action)))
{
$this->forward(sfConfig::get('sf_secure_module'), sfConfig::get('sf_secure_action'));
}
$validator = new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardUser'));
try
{
// validate ids
$ids = $validator->clean($ids);
// execute batch
$this->$method($request);
}
catch (sfValidatorError $e)
{
$this->getUser()->setFlash('error', 'A problem occurs when deleting the selected items as some items do not exist anymore.');
}
$this->redirect('@sf_guard_user_sf_guard_user_old');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment