Esempio n. 1
0
 /**
  * Relation fields can allow filters on the relations fetched. For now this is limited
  * to the id field because of the possible complexity of fetching and filtering
  * all the related data.
  *
  * For example the following queries:
  *     'pages', {'relationkey'=>'1'}
  *     'pages', {'relationkey'=>'1 || 2 || 3'}.
  *
  * Because the search is actually on the join table, we replace the
  * expression to filter the join side rather than on the main side.
  *
  * @param QueryInterface $query
  * @param ClassMetadata  $metadata
  *
  * @return void
  */
 public function query(QueryInterface $query, ClassMetadata $metadata)
 {
     $field = $this->mapping['fieldname'];
     foreach ($query->getFilters() as $filter) {
         if ($filter->getKey() == $field) {
             $this->rewriteQueryFilterParameters($filter, $query, $field, 'to_id');
         }
     }
 }
Esempio n. 2
0
 /**
  * Relation fields can allow filters on the relations fetched. For now this is limited
  * to the id field because of the possible complexity of fetching and filtering
  * all the related data.
  *
  * For example the following queries:
  *     'pages', {'relationkey'=>'1'}
  *     'pages', {'relationkey'=>'1 || 2 || 3'}.
  *
  * Because the search is actually on the join table, we replace the
  * expression to filter the join side rather than on the main side.
  *
  * @param QueryInterface $query
  * @param ClassMetadata  $metadata
  */
 public function query(QueryInterface $query, ClassMetadata $metadata)
 {
     $field = $this->mapping['fieldname'];
     foreach ($query->getFilters() as $filter) {
         if ($filter->getKey() == $field) {
             // This gets the method name, one of andX() / orX() depending on type of expression
             $method = strtolower($filter->getExpressionObject()->getType()) . 'X';
             $newExpr = $query->getQueryBuilder()->expr()->{$method}();
             foreach ($filter->getParameters() as $k => $v) {
                 $newExpr->add("{$field}.to_id = :{$k}");
             }
             $filter->setExpression($newExpr);
         }
     }
 }