Ejemplo n.º 1
6
 /**
  * @param Request         $request
  * @param FilterInterface $filter
  * @param Criteria        $criteria
  * @param ClassMetadata   $embedClassMeta
  *
  * @return null
  */
 protected function applyFilter(Request $request, FilterInterface $filter, Criteria $criteria, ClassMetadata $embedClassMeta)
 {
     $properties = $filter->getRequestProperties($request);
     if ($filter instanceof OrderFilter && !empty($properties)) {
         $criteria->orderBy($properties);
         return null;
     }
     if ($filter instanceof SearchFilter) {
         foreach ($properties as $name => $propertie) {
             if (in_array($name, $embedClassMeta->getIdentifier())) {
                 continue;
             }
             $expCriterial = Criteria::expr();
             if ($embedClassMeta->hasAssociation($name)) {
                 $associationTargetClass = $embedClassMeta->getAssociationTargetClass($name);
                 $propertyResource = $this->resourceResolver->getResourceForEntity($associationTargetClass);
                 $propertyObj = $this->dataProviderChain->getItem($propertyResource, (int) $propertie['value'], true);
                 if ($propertyObj && $propertyResource instanceof ResourceInterface) {
                     $whereCriteria = $expCriterial->in($name, [$propertyObj]);
                     $criteria->where($whereCriteria);
                 }
             } else {
                 if ($embedClassMeta->hasField($name)) {
                     $fieldMapping = $embedClassMeta->getFieldMapping($name);
                     $type = isset($fieldMapping['type']) ? $fieldMapping['type'] : null;
                     $value = isset($this->mappingFilterVar[$type]) ? filter_var($propertie['value'], $this->mappingFilterVar[$type]) : $propertie['value'];
                     $whereCriteria = isset($propertie['precision']) && $propertie['precision'] === 'exact' ? $expCriterial->eq($name, $value) : $expCriterial->contains($name, $propertie['value']);
                     $criteria->where($whereCriteria);
                 }
             }
         }
     }
 }