/**
  * {@inheritdoc}
  */
 protected function association(ProxyQueryInterface $queryBuilder, $data)
 {
     $associationMappings = $this->getParentAssociationMappings();
     $associationMappings[] = $this->getAssociationMapping();
     $alias = $queryBuilder->entityJoin($associationMappings);
     return array($alias, false);
 }
 /**
  * {@inheritdoc}
  */
 public function filter(ProxyQueryInterface $query, $alias, $field, $data)
 {
     if (!$data || !is_array($data) || !array_key_exists('type', $data) || !array_key_exists('value', $data)) {
         return;
     }
     $data['type'] = !isset($data['type']) ? ChoiceType::TYPE_CONTAINS : $data['type'];
     list($firstOperator, $secondOperator) = $this->getOperators((int) $data['type']);
     if (is_array($data['value'])) {
         if (count($data['value']) == 0) {
             return;
         }
         if (in_array('all', $data['value'], true)) {
             return;
         }
         $queryBuilder = new \Elastica\Query\Builder();
         $queryBuilder->fieldOpen($secondOperator)->field($field, Util::escapeTerm($data['value']))->fieldClose();
         if ($firstOperator == 'must') {
             $query->addMust($queryBuilder);
         } else {
             $query->addMustNot($queryBuilder);
         }
     } else {
         if ($data['value'] === '' || $data['value'] === null || $data['value'] === false || $data['value'] === 'all') {
             return;
         }
         $queryBuilder = new \Elastica\Query\Builder();
         $queryBuilder->fieldOpen($secondOperator)->field($field, Util::escapeTerm(array($data['value'])))->fieldClose();
         if ($firstOperator == 'must') {
             $query->addMust($queryBuilder);
         } else {
             $query->addMustNot($queryBuilder);
         }
     }
 }
 /**
  * @param ProxyQueryInterface $queryBuilder
  * @param string              $alias
  * @param string              $field
  * @param mixed               $data
  * @return
  */
 public function filter(ProxyQueryInterface $queryBuilder, $alias, $field, $data)
 {
     if (!$data || !is_array($data) || !array_key_exists('type', $data) || !array_key_exists('value', $data)) {
         return;
     }
     if (is_array($data['value'])) {
         if (count($data['value']) == 0) {
             return;
         }
         if (in_array('all', $data['value'])) {
             return;
         }
         if ($data['type'] == ChoiceType::TYPE_NOT_CONTAINS) {
             $queryBuilder->field($field)->notIn($data['value']);
         } else {
             $queryBuilder->field($field)->in($data['value']);
         }
         $this->active = true;
     } else {
         if ($data['value'] === '' || $data['value'] === null || $data['value'] === false || $data['value'] === 'all') {
             return;
         }
         if ($data['type'] == ChoiceType::TYPE_NOT_CONTAINS) {
             $queryBuilder->field($field)->notEqual($data['value']);
         } else {
             $queryBuilder->field($field)->equals($data['value']);
         }
         $this->active = true;
     }
 }
 /**
  * @param ProxyQueryInterface $queryBuilder
  * @param string              $alias
  * @param string              $field
  * @param string              $data
  *
  * @return
  */
 public function filter(ProxyQueryInterface $queryBuilder, $name, $field, $data)
 {
     if (!$data || !is_array($data) || !array_key_exists('value', $data)) {
         return;
     }
     $data['value'] = trim($data['value']);
     if (strlen($data['value']) == 0) {
         return;
     }
     $data['type'] = isset($data['type']) && !empty($data['type']) ? $data['type'] : ChoiceType::TYPE_CONTAINS;
     $obj = $queryBuilder;
     if ($this->condition == self::CONDITION_OR) {
         $obj = $queryBuilder->expr();
     }
     if ($data['type'] == ChoiceType::TYPE_EQUAL) {
         $obj->field($field)->equals($data['value']);
     } elseif ($data['type'] == ChoiceType::TYPE_CONTAINS) {
         $obj->field($field)->equals(new \MongoRegex(sprintf('/%s/i', $data['value'])));
     } elseif ($data['type'] == ChoiceType::TYPE_NOT_CONTAINS) {
         $obj->field($field)->not(new \MongoRegex(sprintf('/%s/i', $data['value'])));
     }
     if ($this->condition == self::CONDITION_OR) {
         $queryBuilder->addOr($obj);
     }
     $this->active = true;
 }
 /**
  * @param ProxyQueryInterface $queryBuilder
  * @param string              $alias
  * @param string              $field
  * @param mixed               $data
  *
  * @return
  */
 public function filter(ProxyQueryInterface $queryBuilder, $alias, $field, $data)
 {
     if (!$data || !is_array($data) || !array_key_exists('type', $data) || !array_key_exists('value', $data)) {
         return;
     }
     if (is_array($data['value'])) {
         $values = array();
         foreach ($data['value'] as $v) {
             if (!in_array($v, array(BooleanType::TYPE_NO, BooleanType::TYPE_YES))) {
                 continue;
             }
             $values[] = $v == BooleanType::TYPE_YES ? true : false;
         }
         if (count($values) == 0) {
             return;
         }
         $queryBuilder->field($field)->in($values);
         $this->active = true;
     } else {
         if (!in_array($data['value'], array(BooleanType::TYPE_NO, BooleanType::TYPE_YES))) {
             return;
         }
         $value = BooleanType::TYPE_YES == $data['value'] ? true : false;
         $queryBuilder->field($field)->equals($value);
         $this->active = true;
     }
 }
 public function batchActionActivate(ProxyQueryInterface $selectedModelQuery)
 {
     $users = $selectedModelQuery->execute();
     $modelManager = $this->admin->getModelManager();
     $hostname = $this->container->getParameter('hostname');
     $hostDirectory = $this->container->getParameter('directory');
     try {
         foreach ($users as $user) {
             $userIsLocked = $user->isLocked();
             if ($userIsLocked == true) {
                 $user->setEnabled(true);
                 $user->setLocked(false);
                 if (null === $user->getConfirmationToken()) {
                     $tokenGenerator = $this->container->get("fos_user.util.token_generator");
                     $user->setConfirmationToken($tokenGenerator->generateToken());
                 }
                 $user->setPasswordRequestedAt(new \DateTime('now'));
                 $modelManager->update($user);
                 $activationUrl = $hostname . $hostDirectory . "resetting/reset/" . $user->getConfirmationToken();
                 $message = \Swift_Message::newInstance()->setSubject('Welcome to Zeega!')->setFrom(array('*****@*****.**' => 'Zeega'))->setTo($user->getEmail())->setBody($this->renderView('ZeegaAdminBundle:Users:account_activated.txt.twig', array('username' => $user->getDisplayName(), 'activationURL' => $activationUrl)));
                 $this->get('mailer')->send($message);
             }
         }
     } catch (\Exception $e) {
         $this->get('session')->setFlash('sonata_flash_error', 'Something went wrong...');
         return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
     }
     $this->get('session')->setFlash('sonata_flash_success', 'The users were activated successfully.');
     return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
 }
 /**
  * {@inheritdoc}
  */
 public function filter(ProxyQueryInterface $query, $alias, $field, $data)
 {
     if (!$data || !is_array($data) || !array_key_exists('type', $data) || !array_key_exists('value', $data)) {
         return;
     }
     if (is_array($data['value'])) {
         $values = array();
         foreach ($data['value'] as $v) {
             if (!in_array($v, array(BooleanType::TYPE_NO, BooleanType::TYPE_YES))) {
                 continue;
             }
             $values[] = $v == BooleanType::TYPE_YES;
         }
         if (count($values) == 0) {
             return;
         }
         $queryBuilder = new \Elastica\Query\Builder();
         $queryBuilder->fieldOpen('terms')->field($field, $values)->fieldClose();
         $query->addMust($queryBuilder);
     } else {
         if (!in_array($data['value'], array(BooleanType::TYPE_NO, BooleanType::TYPE_YES))) {
             return;
         }
         $queryBuilder = new \Elastica\Query\Builder();
         $queryBuilder->fieldOpen('term')->field($field, $data['value'] == BooleanType::TYPE_YES)->fieldClose();
         $query->addMust($queryBuilder);
     }
 }
 /**
  * Because we lack a second variable we select a range covering the entire minute.
  *
  * @param \Sonata\AdminBundle\Datagrid\ProxyQueryInterface $queryBuilder
  * @param string                                           $field
  * @param array                                            $data
  */
 protected function applyTypeIsEqual(ProxyQueryInterface $queryBuilder, $field, $data)
 {
     /** @var \DateTime $end */
     $end = clone $data['value'];
     $end->add(new \DateInterval('PT1M'));
     $queryBuilder->field($field)->range($data['value'], $end);
 }
 public function configureQuery(AdminInterface $admin, ProxyQueryInterface $query, $content = 'list')
 {
     if ($admin instanceof ContactAdmin) {
         $query->andWhere($query->expr()->eq('o.organization', ':org_id'))->andWhere(':school_id MEMBER OF o.schools')->setParameter(':org_id', $this->session->get($this->orgSessionKey))->setParameter(':school_id', $this->session->get($this->schoolSessionKey));
     } else {
         $query->innerJoin('o.contact', 'c', 'WITH', 'c.organization = :org_id AND :school_id MEMBER OF c.schools')->setParameter(':org_id', $this->session->get($this->orgSessionKey))->setParameter(':school_id', $this->session->get($this->schoolSessionKey));
     }
 }
 /**
  * Apply the filter to the ModelCriteria instance.
  *
  * @param ProxyQueryInterface $query
  * @param string              $alias
  * @param string              $field
  * @param string              $value
  */
 public function filter(ProxyQueryInterface $query, $alias, $field, $value)
 {
     $map = $this->getCriteriaMap();
     if (!array_key_exists('value', $value) || !array_key_exists($value['value'], $map)) {
         return;
     }
     /* @var $query ModelCriteria */
     $query->filterBy($field, true, $map[$value['value']]);
 }
 public function preBatchAction($actionName, ProxyQueryInterface $query, array &$idx, $allElements)
 {
     if ($actionName == 'delete') {
         $query->andWhere($query->expr()->in('o.id', '?1'))->setParameter(1, $idx);
         $serviceGroups = $query->execute();
         foreach ($serviceGroups as $serviceGroup) {
             $this->preRemove($serviceGroup);
         }
     }
 }
 /**
  * Deletes a set of $class identified by the provided $idx array
  *
  * @param string                                           $class
  * @param \Sonata\AdminBundle\Datagrid\ProxyQueryInterface $queryProxy
  *
  * @return void
  */
 public function batchDelete($class, ProxyQueryInterface $queryProxy)
 {
     try {
         foreach ($queryProxy->getQuery()->iterate() as $pos => $object) {
             $this->delete($object[0]);
         }
     } catch (\PDOException $e) {
         throw new ModelManagerException('', 0, $e);
     }
 }
 /**
  * @param ProxyQueryInterface $query
  *
  * @throws AccessDeniedException
  *
  * @return RedirectResponse
  */
 public function batchActionCancelled(ProxyQueryInterface $query)
 {
     if (false === $this->admin->isGranted('EDIT')) {
         throw new AccessDeniedException();
     }
     foreach ($query->execute() as $message) {
         $this->getMessageManager()->cancel($message);
     }
     return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
 }
 /**
  * Batch forms deletion
  *
  * @param ProxyQueryInterface $query
  * @param Request $request
  * @return RedirectResponse
  */
 public function batchActionDelete(ProxyQueryInterface $query, Request $request = null)
 {
     /** @var FcForm $fc_form */
     foreach ($query->find() as $fc_form) {
         if ($fc_form->isUsedAsWidget()) {
             $this->addFlash('sonata_flash_error', $this->admin->trans('fc.message.admin.form.is_used_as_widget', array(), 'FenrizbesFormConstructorBundle'));
             return new RedirectResponse($this->admin->generateUrl('list', array('filter' => $this->admin->getFilterParameters())));
         }
     }
     return parent::batchActionDelete($query);
 }
 /**
  * Apply the filter to the ModelCriteria instance.
  *
  * @param ProxyQueryInterface $query
  * @param string              $alias
  * @param string              $field
  * @param string              $value
  */
 public function filter(ProxyQueryInterface $query, $alias, $field, $value)
 {
     $map = $this->getCriteriaMap();
     if ($value['value'] instanceof PropelObjectCollection) {
         $comparison = $value['type'] === ChoiceType::TYPE_NOT_CONTAINS ? $map[$value['type']] : Criteria::IN;
         $query->filterBy($field, $value['value'], $comparison);
     } else {
         $comparison = $map[$value['type'] ?: ChoiceType::TYPE_CONTAINS];
         $query->filterBy($field, $value['value'], $comparison);
     }
 }
 /**
  * @param ProxyQueryInterface $query
  * @param                     $status
  *
  * @return RedirectResponse
  *
  * @throws AccessDeniedException
  */
 protected function commentChangeStatus(ProxyQueryInterface $query, $status)
 {
     if (false === $this->admin->isGranted('EDIT')) {
         throw new AccessDeniedException();
     }
     foreach ($query->execute() as $comment) {
         $comment->setStatus($status);
         $this->admin->getModelManager()->update($comment);
     }
     return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
 }
Beispiel #17
0
 protected function association(ProxyQueryInterface $queryBuilder, $data)
 {
     $types = array(ClassMetadataInfo::ONE_TO_ONE, ClassMetadataInfo::ONE_TO_MANY, ClassMetadataInfo::MANY_TO_MANY, ClassMetadataInfo::MANY_TO_ONE);
     if (!in_array($this->getOption('mapping_type'), $types)) {
         throw new \RunTimeException('Invalid mapping type');
     }
     if (!$this->getOption('field_name')) {
         throw new \RunTimeException('please provide a field_name options');
     }
     return array($this->getOption('alias', $queryBuilder->getRootAlias()), false);
 }
 public function batchActionDelete(ProxyQueryInterface $query)
 {
     $this->admin->checkAccess('batchDelete');
     try {
         $this->deleteItems($query->execute());
         $this->addFlash('sonata_flash_success', 'flash_batch_delete_success');
     } catch (ModelManagerException $e) {
         $this->handleModelManagerException($e);
         $this->addFlash('sonata_flash_error', 'flash_batch_delete_error');
     }
     return new RedirectResponse($this->admin->generateUrl('list', array('filter' => $this->admin->getFilterParameters())));
 }
 public function batchActionSendEmail(ProxyQueryInterface $query)
 {
     if (!$this->admin->isGranted('ROLE_EMAIL_ADMIN')) {
         throw $this->createAccessDeniedException();
     }
     $modelManager = $this->admin->getModelManager();
     $emailSender = $this->get('bcp.email_sender');
     $contactProvider = $this->get('bcp.contact_provider');
     $templating = $this->get('templating');
     $from = $this->getParameter('newsletter_from');
     $selectedEmails = $query->execute();
     $errors = array();
     try {
         foreach ($selectedEmails as $email) {
             if (null === $email->getEmailFrom()) {
                 $email->setEmailFrom($from);
             } else {
                 $from = $email->getEmailFrom();
             }
             $emails = in_array('all', $email->getContacts()) ? $contactProvider->getContactsEmail() : $email->getContacts();
             $subject = sprintf('[BCP] %s', $email->getSubject());
             $body = $templating->render('@App/Utils/email_structure.html.twig', array('body' => $email->getBody()));
             if (!empty($emails)) {
                 foreach ($emails as $to) {
                     $sent = $emailSender->send($from, array($to), $subject, $body);
                     if (!$sent) {
                         $errors[] = sprintf('%s - %s', $subject, $to);
                     }
                 }
                 $email->setSent(new \Datetime());
                 $modelManager->update($email);
             } else {
                 $errors[] = sprintf('%s - %s', $subject, $this->admin->trans('email_to_empty'));
             }
         }
         if (!empty($errors)) {
             $error = $this->admin->trans('flash_batch_send_email_error');
             $error .= '<ul>';
             foreach ($errors as $err) {
                 $error .= sprintf('<li>%s</li>', $err);
             }
             $error .= '</ul>';
             $this->addFlash('sonata_flash_error', $error, $this->admin->flashIcon);
         } else {
             $this->addFlash('sonata_flash_success', $this->admin->trans('flash_batch_send_email_success'), $this->admin->flashIcon);
         }
     } catch (ModelManagerException $e) {
         $this->handleModelManagerException($e);
         $this->addFlash('sonata_flash_error', $this->admin->trans('flash_batch_send_email_error'), $this->admin->flashIcon);
     }
     return $this->redirect($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
 }
 /**
  * {@inheritdoc}
  */
 public function filter(ProxyQueryInterface $query, $alias, $field, $data)
 {
     // check data sanity
     if (!$data || !is_array($data) || !array_key_exists('value', $data)) {
         return;
     }
     $format = array_key_exists('format', $this->getFieldOptions()) ? $this->getFieldOptions()['format'] : 'c';
     $queryBuilder = new \Elastica\Query\Builder();
     if ($this->range) {
         // additional data check for ranged items
         if (!array_key_exists('start', $data['value']) || !array_key_exists('end', $data['value'])) {
             return;
         }
         if (!$data['value']['start'] || !$data['value']['end']) {
             return;
         }
         // transform types
         if ($this->getOption('input_type') == 'timestamp') {
             $data['value']['start'] = $data['value']['start'] instanceof \DateTime ? $data['value']['start']->getTimestamp() : 0;
             $data['value']['end'] = $data['value']['end'] instanceof \DateTime ? $data['value']['end']->getTimestamp() : 0;
         }
         // default type for range filter
         $data['type'] = !isset($data['type']) || !is_numeric($data['type']) ? DateRangeType::TYPE_BETWEEN : $data['type'];
         $queryBuilder->fieldOpen('range')->fieldOpen($field)->field('gte', $data['value']['start']->format($format))->field('lte', $data['value']['end']->format($format))->fieldClose()->fieldClose();
         if ($data['type'] == DateRangeType::TYPE_NOT_BETWEEN) {
             $query->addMustNot($queryBuilder);
         } else {
             $query->addMust($queryBuilder);
         }
     } else {
         if (!$data['value']) {
             return;
         }
         // default type for simple filter
         $data['type'] = !isset($data['type']) || !is_numeric($data['type']) ? DateType::TYPE_GREATER_EQUAL : $data['type'];
         // just find an operator and apply query
         $operator = $this->getOperator($data['type']);
         // transform types
         if ($this->getOption('input_type') == 'timestamp') {
             $data['value'] = $data['value'] instanceof \DateTime ? $data['value']->getTimestamp() : 0;
         }
         // null / not null only check for col
         if (in_array($operator, array('missing', 'exists'))) {
             $queryBuilder->fieldOpen($operator)->field('field', $field)->fieldClose();
         } elseif ($operator == '=') {
             $queryBuilder->fieldOpen('range')->fieldOpen($field)->field('gte', $data['value']->format($format))->field('lte', $data['value']->format($format))->fieldClose()->fieldClose();
         } else {
             $queryBuilder->fieldOpen('range')->fieldOpen($field)->field($operator, $data['value']->format($format))->fieldClose()->fieldClose();
         }
         $query->addMust($queryBuilder);
     }
 }
 /**
  * @param ProxyQueryInterface $queryBuilder
  * @param string              $alias
  * @param string              $field
  * @param string              $data
  * @return
  */
 public function filter(ProxyQueryInterface $queryBuilder, $alias, $field, $data)
 {
     if (!$data || !is_array($data) || !array_key_exists('value', $data) || !is_numeric($data['value'])) {
         return;
     }
     $type = isset($data['type']) ? $data['type'] : false;
     $operator = $this->getOperator($type);
     if (!$operator) {
         $operator = 'equals';
     }
     $queryBuilder->field($field)->{$operator}((double) $data['value']);
     $this->active = true;
 }
 /**
  *
  * @param  ProxyQueryInterface $queryBuilder
  * @param  type                $alias
  * @param  type                $field
  * @param  type                $data
  * @return type
  */
 protected function handleScalar(ProxyQueryInterface $queryBuilder, $alias, $field, $data)
 {
     if (empty($data['value'])) {
         return;
     }
     $id = self::fixIdentifier($data['value']->getId());
     if (isset($data['type']) && $data['type'] == EqualType::TYPE_IS_NOT_EQUAL) {
         $queryBuilder->field($field)->notEqual($id);
     } else {
         $queryBuilder->field($field)->equals($id);
     }
     $this->active = true;
 }
 /**
  * {@inheritdoc}
  */
 public function filter(ProxyQueryInterface $query, $alias, $field, $data)
 {
     if (!$data || !is_array($data) || !array_key_exists('value', $data) || !is_numeric($data['value'])) {
         return;
     }
     $type = isset($data['type']) ? $data['type'] : false;
     $operator = $this->getOperator($type);
     $queryBuilder = new \Elastica\Query\Builder();
     if ($operator === false) {
         // Match query to get equality
         $queryBuilder->fieldOpen('match')->field($field, $data['value'])->fieldClose();
     } else {
         // Range query
         $queryBuilder->range()->fieldOpen($field)->field($operator, $data['value'])->fieldClose()->rangeClose();
     }
     $query->addMust($queryBuilder);
 }
 protected function association(ProxyQueryInterface $queryBuilder, $data)
 {
     $types = array(ClassMetadataInfo::ONE_TO_ONE, ClassMetadataInfo::ONE_TO_MANY, ClassMetadataInfo::MANY_TO_MANY, ClassMetadataInfo::MANY_TO_ONE);
     if (!in_array($this->getOption('mapping_type'), $types)) {
         throw new \RunTimeException('Invalid mapping type');
     }
     if (!$this->getOption('field_name')) {
         throw new \RunTimeException('please provide a field_name options');
     }
     if (!$this->getOption('callback')) {
         $alias = 's_' . $this->getName();
         $queryBuilder->leftJoin(sprintf('%s.%s', $queryBuilder->getRootAlias(), $this->getFieldName()), $alias);
         return array($alias, 'id');
     } else {
         return array($this->getOption('alias', $queryBuilder->getRootAlias()), false);
     }
 }
 public function batchActionExtend(ProxyQueryInterface $selectedModelQuery)
 {
     if ($this->admin->isGranted('EDIT') === false || $this->admin->isGranted('DELETE') === false) {
         throw new AccessDeniedException();
     }
     $modelManager = $this->admin->getModelManager();
     $selectedModels = $selectedModelQuery->execute();
     try {
         foreach ($selectedModels as $selectedModel) {
             $selectedModel->extend();
             $modelManager->update($selectedModel);
         }
     } catch (Exception $e) {
         $this->get('session')->getFlashBag()->add('sonata_flash_error', $e->getMessage());
         return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
     }
     $this->get('session')->getFlashBag()->add('sonata_flash_success', sprintf('The selected jobs validity has been extended until %s.', date('m/d/Y', time() + 86400 * 30)));
     return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
 }
 public function batchActionDeactivate(ProxyQueryInterface $selectedModelQuery)
 {
     if ($this->admin->isGranted('EDIT') === false || $this->admin->isGranted('DELETE') === false) {
         throw new AccessDeniedException();
     }
     $request = $this->get('request');
     $modelManager = $this->admin->getModelManager();
     $selectedModels = $selectedModelQuery->execute();
     try {
         foreach ($selectedModels as $selectedModel) {
             $selectedModel->deactivate();
             $modelManager->update($selectedModel);
         }
     } catch (Exception $e) {
         $this->get('session')->getFlashBag()->add('sonata_flash_error', $e->getMessage());
         return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
     }
     $this->get('session')->getFlashBag()->add('sonata_flash_success', sprintf('The selected accounts have been deactivated'));
     return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
 }
 /**
  * {@inheritdoc}
  */
 protected function association(ProxyQueryInterface $queryBuilder, $data)
 {
     $types = array(ClassMetadataInfo::ONE_TO_ONE, ClassMetadataInfo::ONE_TO_MANY, ClassMetadataInfo::MANY_TO_MANY, ClassMetadataInfo::MANY_TO_ONE);
     if (!in_array($this->getOption('mapping_type'), $types)) {
         throw new \RunTimeException('Invalid mapping type');
     }
     $associationMappings = $this->getParentAssociationMappings();
     $associationMappings[] = $this->getAssociationMapping();
     $alias = $queryBuilder->entityJoin($associationMappings);
     return array($alias, false);
 }
 /**
  * {@inheritdoc}
  */
 public function filter(ProxyQueryInterface $query, $alias, $field, $data)
 {
     if (!$data || !is_array($data) || !array_key_exists('value', $data)) {
         return;
     }
     $data['value'] = trim($data['value']);
     if (strlen($data['value']) == 0) {
         return;
     }
     $data['type'] = !isset($data['type']) ? ChoiceType::TYPE_CONTAINS : $data['type'];
     list($firstOperator, $secondOperator) = $this->getOperators((int) $data['type']);
     // Create a query that match terms (indepedent of terms order) or a phrase
     $queryBuilder = new \Elastica\Query\Builder();
     $queryBuilder->fieldOpen($secondOperator)->fieldOpen($field)->field('query', str_replace(array('\\', '"'), array('\\\\', '\\"'), $data['value']))->field('operator', 'and')->fieldClose()->fieldClose();
     if ($firstOperator == 'must') {
         $query->addMust($queryBuilder);
     } else {
         $query->addMustNot($queryBuilder);
     }
 }
 /**
  * Filters according to a given single date/datetime.
  *
  * @param ProxyQueryInterface $query
  * @param string              $field
  * @param string              $value
  */
 protected function filterDate(ProxyQueryInterface $query, $field, $data)
 {
     // default type for simple filter
     $data['type'] = !isset($data['type']) || !is_numeric($data['type']) ? DateType::TYPE_EQUAL : $data['type'];
     // just find an operator and apply query
     $operator = $this->getOperator($data['type']);
     // transform types
     if ($this->getOption('input_type') === 'timestamp') {
         $data['value'] = $data['value'] instanceof \DateTime ? $data['value']->getTimestamp() : 0;
     }
     $query->filterBy($field, $data['value'], $operator);
 }
 public function batchActionDispatch(ProxyQueryInterface $selectedModelQuery)
 {
     if (!$this->admin->isGranted('EDIT')) {
         throw new AccessDeniedException();
     }
     $modelManager = $this->admin->getModelManager();
     $selectedModels = $selectedModelQuery->execute();
     $eventDispatcher = $this->get('event_dispatcher');
     $i = 0;
     try {
         foreach ($selectedModels as $selectedModel) {
             if ($selectedModel->getDispatchStatus() == Order::DISPATCH_STATUS_DISPATCHED) {
                 $this->addFlash('sonata_flash_error', sprintf('Order %d has already been dispatched.', $selectedModel->getId()));
                 continue;
             }
             if ($selectedModel->getDispatchStatus() == Order::DISPATCH_STATUS_UNDISPATCHABLE) {
                 $this->addFlash('sonata_flash_error', sprintf('Order %d is not dispatchable.', $selectedModel->getId()));
                 continue;
             }
             if ($selectedModel->getStatus() != GetHumanStatus::STATUS_AUTHORIZED) {
                 $this->addFlash('sonata_flash_error', sprintf('Order %d has not been authorized.', $selectedModel->getId()));
                 continue;
             }
             if ($selectedModel->getDispatchStatus() == Order::DISPATCH_STATUS_PROCESSING) {
                 $selectedModel->setDispatchStatus(Order::DISPATCH_STATUS_DISPATCHED);
                 $eventDispatcher->dispatch('event.dispatch', new GenericEvent(null, ['order' => $selectedModel]));
                 $i++;
             }
         }
         $modelManager->update($selectedModel);
     } catch (\Exception $e) {
         $this->addFlash('sonata_flash_error', 'flash_batch_merge_error');
         return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
     }
     if ($i > 0) {
         $this->addFlash('sonata_flash_success', sprintf('Marked %d orders as dispatched.', $i));
     }
     return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
 }