示例#1
0
 public function executeBatch(sfWebRequest $request)
 {
     $request->checkCSRFProtection();
     if (!($ids = $request->getParameter('ids')) && $request->getParameter('batch_action') != 'batchPriority') {
         $this->getUser()->setFlash('error', 'You must at least select one item.');
         $this->redirect('@new_item');
     }
     if (!($action = $request->getParameter('batch_action'))) {
         $this->getUser()->setFlash('error', 'You must select an action to execute on the selected items.');
         $this->redirect('@new_item');
     }
     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' => 'NewItem'));
     try {
         // validate ids
         if ($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('@new_item');
 }
 protected function doClean($value)
 {
     if ('other' !== $value['select']) {
         return array('select' => parent::clean($value['select']));
     }
     if (!isset($value['input'])) {
         throw new sfValidatorError($this, 'invalid', array('value' => $value));
     }
     return array('select' => 'other', 'other' => $value['input']);
 }
示例#3
0
 public function executeBatchOrder(sfWebRequest $request)
 {
     $newparent = $request->getParameter('newparent');
     $ids = array();
     foreach ($newparent as $key => $val) {
         $ids[$key] = true;
         if (!empty($val)) {
             $ids[$val] = true;
         }
     }
     $ids = array_keys($ids);
     $validator = new sfValidatorDoctrineChoice(array('model' => 'peanutCategories', 'multiple' => true));
     try {
         $ids = $validator->clean($ids);
         $count = 0;
         $flash = "";
         foreach ($newparent as $id => $parentId) {
             if (!empty($parentId)) {
                 $node = Doctrine::getTable('peanutCategories')->find($id);
                 $parent = Doctrine::getTable('peanutCategories')->find($parentId);
                 if (!$parent->getNode()->isDescendantOfOrEqualTo($node)) {
                     $node->getNode()->moveAsFirstChildOf($parent);
                     $node->save();
                     $count++;
                     $flash .= "<br/>Moved '" . $node['name'] . "' under '" . $parent['name'] . "'.";
                 }
             }
         }
         if ($count > 0) {
             $this->getUser()->setFlash('notice', sprintf("peanutCategories order updated, moved %s item%s:" . $flash, $count, $count > 1 ? 's' : ''));
         } else {
             $this->getUser()->setFlash('error', "You must at least move one item to update the peanutCategories order");
         }
     } catch (sfValidatorError $e) {
         $this->getUser()->setFlash('error', 'Cannot update the peanutCategories order, maybe some item are deleted, try again');
     }
     $this->redirect('@peanut_categories');
 }
示例#4
0
 public function executeBatch(sfWebRequest $request)
 {
     if (!($ids = $request->getParameter('ids'))) {
         $this->getUser()->setFlash('error', 'You must at least select one item.');
         $this->redirect('@issues');
     }
     $validator = new sfValidatorDoctrineChoice(array('model' => 'Issue', 'multiple' => true));
     try {
         // validate ids
         $ids = $validator->clean($ids);
         // execute batch
         if ($request->hasParameter('_edit')) {
             $this->forward('issues', 'batchEdit');
         }
     } catch (sfValidatorError $e) {
         $this->getUser()->setFlash('error', 'Some of the selected items where not valid.');
         $this->redirect('@issues');
     }
 }
<?php

$app = 'frontend';
$fixtures = 'fixtures/fixtures.yml';
include dirname(__FILE__) . '/../../bootstrap/functional.php';
$t = new lime_test(1);
// ->clean()
$t->diag('->clean()');
$query = Doctrine_Core::getTable('Author')->createQuery();
$validator = new sfValidatorDoctrineChoice(array('model' => 'Author', 'query' => $query));
$author = Doctrine_Core::getTable('Author')->createQuery()->limit(1)->fetchOne();
$validator->clean($author->id);
$t->is(trim($query->getDql()), 'FROM Author', '->clean() does not change the supplied query object');
 public function executeBatch(sfWebRequest $request)
 {
     if (!($ids = $request->getParameter('ids'))) {
         $this->getUser()->setFlash('error', 'You must at least select one item.');
         $this->redirect('@' . $this->getDmModule()->getUnderscore());
     }
     foreach ($request->getParameterHolder()->getAll() as $key => $value) {
         if (strncmp($key, 'batch', 5) === 0) {
             $action = $key;
             break;
         }
     }
     if (!isset($action)) {
         $this->getUser()->setFlash('error', 'You must select an action to execute on the selected items.');
         $this->redirect('@' . $this->etDmModule()->getUnderscore());
     }
     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' => $this->getDmModule()->getModel()));
     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('@' . $this->getDmModule()->getUnderscore());
 }
示例#7
0
 protected function validateBatchKeyValuesExists($ids)
 {
     $validator = new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => $this->getModelName()));
     try {
         $validator->clean($ids);
     } catch (sfValidatorError $e) {
         $this->getUser()->setFlash('error', 'One or more selected items do not exist.');
         $this->redirectToIndex();
     }
 }
示例#8
0
 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('@rfid');
     }
     if (!($action = $request->getParameter('batch_action'))) {
         $this->getUser()->setFlash('error', 'You must select an action to execute on the selected items.');
         $this->redirect('@rfid');
     }
     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' => 'Rfid'));
     try {
         // validate ids
         $ids = $validator->clean($ids);
         // execute batch
         $this->{$method}($request);
         if ($method == "executeBatchAssign_badges") {
             $this->setTemplate("BatchAssignBadges");
             $this->form = new assignGroupeForm();
             $this->form->setDefault('rfid_ids', implode(",", $ids));
             return sfView::SUCCESS;
         }
     } catch (sfValidatorError $e) {
         $this->getUser()->setFlash('error', 'A problem occurs when deleting the selected items as some items do not exist anymore.');
     }
     $this->redirect('@rfid');
 }
 /**
  * Checks if $value is a valid email or if is a valid user. Returns null if none of them.
  * 
  * @param type $value
  * @return null|string 
  */
 static function isUserOrEmail($value, $returnEmail = false)
 {
     $val = new sfValidatorEmail();
     try {
         $val->clean($value);
         return $returnEmail ? $value : 'email';
     } catch (Exception $exc) {
         $val = new sfValidatorDoctrineChoice(array('model' => 'sfGuardUser', 'column' => 'username'));
         try {
             $val->clean($value);
             if ($returnEmail) {
                 $user = Doctrine_Core::getTable('sfGuardUser')->findOneByUsername($value);
                 return $user->getEmailAddress();
             }
             return 'user';
         } catch (Exception $exc) {
             return false;
         }
     }
 }
 public function executeBatch(sfWebRequest $request)
 {
     if (!($ids = $request->getParameter('ids'))) {
         $this->getUser()->setFlash('error', 'You must at least select one item.');
         $this->redirect('@' . $this->getDmModule()->getUnderscore());
     }
     foreach ($request->getParameterHolder()->getAll() as $key => $value) {
         if (strncmp($key, 'batch', 5) === 0) {
             $action = $key;
             break;
         }
     }
     if (!isset($action)) {
         $this->getUser()->setFlash('error', 'You must select an action to execute on the selected items.');
         $this->redirect('@' . $this->getDmModule()->getUnderscore());
     }
     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' => $this->getDmModule()->getModel()));
     try {
         // validate ids
         $ids = $validator->clean($ids);
         //@todo add record security check here ! using dmModuleSecurityManager, create new method in it
         //if there are some ids for which user can't execute the method, remove them, then execute them
         //something like
         $_action = substr($action, 5);
         $_action = dmString::strtolower($_action);
         $authorizedIdsForAction = $this->getDmModule()->getSecurityManager()->getIdsForAuthorizedActionWithinIds($_action, $this->getUser()->getUser(), $ids);
         if (!$authorizedIdsForAction) {
             throw new LogicException('You cannot delete those elements because you are not authorized to do so.', 401);
         }
         if (count($ids) != count($authorizedIdsForAction)) {
             $request->setParameter('excluded_ids', array_diff($ids, $authorizedIdsForAction));
         }
         $request->setParameter('ids', $authorizedIdsForAction);
         // 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. ');
     } catch (LogicException $e) {
         $this->getUser()->setFlash('error', $e->getMessage());
     }
     $this->redirect('@' . $this->getDmModule()->getUnderscore());
 }