当前位置: 首页>>代码示例>>PHP>>正文


PHP AdminInterface::preBatchAction方法代码示例

本文整理汇总了PHP中Sonata\AdminBundle\Admin\AdminInterface::preBatchAction方法的典型用法代码示例。如果您正苦于以下问题:PHP AdminInterface::preBatchAction方法的具体用法?PHP AdminInterface::preBatchAction怎么用?PHP AdminInterface::preBatchAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sonata\AdminBundle\Admin\AdminInterface的用法示例。


在下文中一共展示了AdminInterface::preBatchAction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: batchAction

 /**
  * Batch action.
  *
  * @return Response|RedirectResponse
  *
  * @throws NotFoundHttpException If the HTTP method is not POST
  * @throws \RuntimeException     If the batch action is not defined
  */
 public function batchAction()
 {
     $restMethod = $this->getRestMethod();
     if ('POST' !== $restMethod) {
         throw $this->createNotFoundException(sprintf('Invalid request type "%s", POST expected', $restMethod));
     }
     // check the csrf token
     $this->validateCsrfToken('sonata.batch');
     $confirmation = $this->get('request')->get('confirmation', false);
     if ($data = json_decode($this->get('request')->get('data'), true)) {
         $action = $data['action'];
         $idx = $data['idx'];
         $allElements = $data['all_elements'];
         $this->get('request')->request->replace($data);
     } else {
         $this->get('request')->request->set('idx', $this->get('request')->get('idx', array()));
         $this->get('request')->request->set('all_elements', $this->get('request')->get('all_elements', false));
         $action = $this->get('request')->get('action');
         $idx = $this->get('request')->get('idx');
         $allElements = $this->get('request')->get('all_elements');
         $data = $this->get('request')->request->all();
         unset($data['_sonata_csrf_token']);
     }
     $batchActions = $this->admin->getBatchActions();
     if (!array_key_exists($action, $batchActions)) {
         throw new \RuntimeException(sprintf('The `%s` batch action is not defined', $action));
     }
     $camelizedAction = BaseFieldDescription::camelize($action);
     $isRelevantAction = sprintf('batchAction%sIsRelevant', ucfirst($camelizedAction));
     if (method_exists($this, $isRelevantAction)) {
         $nonRelevantMessage = call_user_func(array($this, $isRelevantAction), $idx, $allElements);
     } else {
         $nonRelevantMessage = count($idx) != 0 || $allElements;
         // at least one item is selected
     }
     if (!$nonRelevantMessage) {
         // default non relevant message (if false of null)
         $nonRelevantMessage = 'flash_batch_empty';
     }
     $datagrid = $this->admin->getDatagrid();
     $datagrid->buildPager();
     if (true !== $nonRelevantMessage) {
         $this->addFlash('sonata_flash_info', $nonRelevantMessage);
         return new RedirectResponse($this->admin->generateUrl('list', array('filter' => $this->admin->getFilterParameters())));
     }
     $askConfirmation = isset($batchActions[$action]['ask_confirmation']) ? $batchActions[$action]['ask_confirmation'] : true;
     if ($askConfirmation && $confirmation != 'ok') {
         $actionLabel = $batchActions[$action]['label'];
         $formView = $datagrid->getForm()->createView();
         return $this->render($this->admin->getTemplate('batch_confirmation'), array('action' => 'list', 'action_label' => $actionLabel, 'datagrid' => $datagrid, 'form' => $formView, 'data' => $data, 'csrf_token' => $this->getCsrfToken('sonata.batch')));
     }
     // execute the action, batchActionXxxxx
     $finalAction = sprintf('batchAction%s', ucfirst($camelizedAction));
     if (!method_exists($this, $finalAction)) {
         throw new \RuntimeException(sprintf('A `%s::%s` method must be created', get_class($this), $finalAction));
     }
     $query = $datagrid->getQuery();
     $query->setFirstResult(null);
     $query->setMaxResults(null);
     $this->admin->preBatchAction($action, $query, $idx, $allElements);
     if (count($idx) > 0) {
         $this->admin->getModelManager()->addIdentifiersToQuery($this->admin->getClass(), $query, $idx);
     } elseif (!$allElements) {
         $query = null;
     }
     return call_user_func(array($this, $finalAction), $query);
 }
开发者ID:stuckiest,项目名称:SymfonyBlog,代码行数:75,代码来源:CRUDController.php


注:本文中的Sonata\AdminBundle\Admin\AdminInterface::preBatchAction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。