php Sonata-AdminBundle-Datagrid-ProxyQueryInterface类(方法)实例源码

下面列出了php Sonata-AdminBundle-Datagrid-ProxyQueryInterface 类(方法)源码代码实例,从而了解它的用法。

作者:netoune    项目:SonataDoctrineORMAdminBundl   
/**
  * {@inheritdoc}
  */
 protected function association(ProxyQueryInterface $queryBuilder, $data)
 {
     $associationMappings = $this->getParentAssociationMappings();
     $associationMappings[] = $this->getAssociationMapping();
     $alias = $queryBuilder->entityJoin($associationMappings);
     return array($alias, false);
 }

作者:Kertude    项目:SonataAdminSearchBundl   
/**
  * {@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);
         }
     }
 }

作者:chovan-zolta    项目:SonataDoctrineMongoDBAdminBundl   
/**
  * @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;
     }
 }

作者:zajc    项目:SonataDoctrineMongoDBAdminBundl   
/**
  * @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;
 }

作者:zajc    项目:SonataDoctrineMongoDBAdminBundl   
/**
  * @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;
     }
 }

作者:holtchesle    项目:Zeeg   
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('noreply@zeega.org' => '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()));
 }

作者:Kertude    项目:SonataAdminSearchBundl   
/**
  * {@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);
     }
 }

作者:kamillo188    项目:SonataDoctrineMongoDBAdminBundl   
/**
  * 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);
 }

作者:sgh198691    项目:symfony-ts   
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));
     }
 }

作者:kosolapovv    项目:SonataPropelAdminBundl   
/**
  * 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']]);
 }

作者:mdstorag    项目:simplesho   
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);
         }
     }
 }

作者:novate    项目:SonataMediaBundl   
/**
  * 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);
     }
 }

作者:Neodor    项目:SonataNotificationBundl   
/**
  * @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()));
 }

作者:it-blaste    项目:form-constructor-bundl   
/**
  * 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);
 }

作者:kosolapovv    项目:SonataPropelAdminBundl   
/**
  * 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);
     }
 }

作者:Neodor    项目:SonataNewsBundl   
/**
  * @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()));
 }

作者:hisi    项目:UsefulBundl   
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);
 }

作者:alpixe    项目:AlpixelMenuBundl   
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())));
 }

作者:nathix8    项目:bcp-websit   
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()));
 }

作者:Kertude    项目:SonataAdminSearchBundl   
/**
  * {@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);
     }
 }


问题


面经


文章

微信
公众号

扫码关注公众号