protected function getResponse(MassActionHandlerArgs $args, $count = 0)
 {
     $massAction = $args->getMassAction();
     $responseMessage = $massAction->getOptions()->offsetGetByPath('[messages][success]', $this->responseMessage);
     $successful = $count > 0;
     $options = ['count' => $count];
     return new MassActionResponse($successful, $this->translator->transChoice($responseMessage, $count, ['%count%' => $count]), $options);
 }
 /**
  * {@inheritdoc}
  */
 public function handle(MassActionHandlerArgs $args)
 {
     $massAction = $args->getMassAction();
     $entityName = $this->actionRepository->getEntityName($args->getDatagrid());
     if (!$this->isMassActionEnabled($entityName)) {
         return $this->getResponse($massAction, 0, 'Action not configured or not allowed');
     }
     $massAction->getOptions()->offsetSet('entityName', $entityName);
     $entitiesCount = $this->actionRepository->batchUpdate($massAction, $args->getResults(), $args->getData());
     return $this->getResponse($massAction, $entitiesCount);
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function handle(MassActionHandlerArgs $args)
 {
     $massAction = $args->getMassAction();
     $options = $massAction->getOptions()->toArray();
     if (empty($options['entity_name'])) {
         throw new InvalidArgumentException('Entity name is missing.');
     }
     $entityIdentifier = $this->doctrineHelper->getSingleIdentifierFieldName($options['entity_name']);
     $entityIds = $this->getIdsFromResult($args->getResults(), $entityIdentifier);
     $entities = $this->doctrineHelper->getEntitiesByIds($options['entity_name'], $entityIds);
     return new MassActionResponse(true, null, array('entities' => $entities, 'entity_name' => $options['entity_name'], 'options' => $options));
 }
예제 #4
0
 /**
  * @param MassActionHandlerArgs $args
  *
  * @throws LogicException
  * @return string
  */
 protected function getEntityIdentifierField(MassActionHandlerArgs $args)
 {
     $massAction = $args->getMassAction();
     $identifier = $massAction->getOptions()->offsetGet('data_identifier');
     if (!$identifier) {
         throw new LogicException(sprintf('Mass action "%s" must define identifier name', $massAction->getName()));
     }
     // if we ask identifier that's means that we have plain data in array
     // so we will just use column name without entity alias
     if (strpos('.', $identifier) !== -1) {
         $parts = explode('.', $identifier);
         $identifier = end($parts);
     }
     return $identifier;
 }
 /**
  * @param MassActionHandlerArgs $args
  * @param int $entitiesCount
  * @param int|null $shoppingListId
  *
  * @return MassActionResponse
  */
 protected function generateResponse(MassActionHandlerArgs $args, $entitiesCount = 0, $shoppingListId = null)
 {
     $transChoiceKey = $args->getMassAction()->getOptions()->offsetGetByPath('[messages][success]', 'orob2b.shoppinglist.actions.add_success_message');
     return new MassActionResponse($entitiesCount > 0, $this->messageGenerator->getSuccessMessage($shoppingListId, $entitiesCount, $transChoiceKey), ['count' => $entitiesCount]);
 }