/**
  * {@inheritdoc}
  */
 protected function doWalkComparison($fieldName, $operator, $placeholder)
 {
     switch ($operator) {
         case Comparison::IN:
             return $this->expr->in($fieldName, $placeholder);
         case Comparison::NIN:
             return $this->expr->notIn($fieldName, $placeholder);
         case Comparison::EQ:
         case Comparison::IS:
             if ($placeholder === null) {
                 return $this->expr->isNull($fieldName);
             }
             return $this->expr->eq($fieldName, $placeholder);
         case Comparison::NEQ:
             if ($placeholder === null) {
                 return $this->expr->isNotNull($fieldName);
             }
             return $this->expr->neq($fieldName, $placeholder);
         case Comparison::CONTAINS:
             return $this->expr->like($fieldName, $placeholder);
         default:
             $operator = self::convertComparisonOperator($operator);
             if ($operator) {
                 return $this->expr->comparison($fieldName, $operator, $placeholder);
             }
             throw new \RuntimeException("Unknown comparison operator: " . $operator);
     }
 }
Пример #2
0
 /**
  * Filter field with `LIKE`.
  *
  * @param string $filterName
  * @param string $field
  */
 protected function likeFilter($filterName, $field)
 {
     $info = $this->extract($filterName);
     $info['values'] = explode(',', str_replace('*', '%', $info['values']));
     foreach ($info['values'] as $value) {
         if ($info['cond']) {
             $expr = $this->expr->like($field, "'%{$value}%'");
         } else {
             $expr = $this->expr->notLike($field, "'%{$value}%'");
         }
     }
     $this->builder->andWhere($expr);
     $this->filters[$filterName] = $info;
 }
Пример #3
0
 /**
  * Creates a LIKE() comparison expression with the given arguments.
  *
  * @param string $x Field in string format to be inspected by LIKE() comparison.
  * @param mixed $y Argument to be used in LIKE() comparison.
  *
  * @return string
  */
 public function like($x, $y)
 {
     $x = $this->helper->quoteColumnName($x);
     $y = $this->helper->quoteColumnName($y);
     return $this->expressionBuilder->like($x, $y);
 }
Пример #4
0
 /**
  * @dataProvider dataLike
  *
  * @param mixed $input
  * @param bool $isLiteral
  */
 public function testLike($input, $isLiteral)
 {
     list($doctrineInput, $ocInput) = $this->helpWithLiteral($input, $isLiteral);
     $this->assertEquals($this->doctrineExpressionBuilder->like('`test`', $doctrineInput), $this->expressionBuilder->like('test', $ocInput));
 }
Пример #5
0
 /**
  * Get list of entities for autopopulate fields.
  *
  * @param $type
  * @param $filter
  * @param $limit
  * @param $start
  *
  * @return array
  */
 public function getLookupResults($type, $filter = '', $limit = 10, $start = 0)
 {
     $results = [];
     switch ($type) {
         case 'companyfield':
         case 'lead.company':
             $expr = null;
             if ('lead.company' === $type) {
                 $column = 'companyname';
                 $filterVal = $filter;
             } else {
                 if (is_array($filter)) {
                     $column = $filter[0];
                     $filterVal = $filter[1];
                 } else {
                     $column = $filter;
                 }
             }
             $expr = new ExpressionBuilder($this->em->getConnection());
             $composite = $expr->andX();
             $composite->add($expr->like("comp.{$column}", ':filterVar'));
             // Validate owner permissions
             if (!$this->security->isGranted('lead:leads:viewother')) {
                 $composite->add($expr->orX($expr->andX($expr->isNull('comp.owner_id'), $expr->eq('comp.created_by', (int) $this->userHelper->getUser()->getId())), $expr->eq('comp.owner_id', (int) $this->userHelper->getUser()->getId())));
             }
             $results = $this->em->getRepository('MauticLeadBundle:Company')->getSimpleList($composite, ['filterVar' => $filterVal . '%'], $column);
             break;
     }
     return $results;
 }