Beispiel #1
0
 /**
  * @param array      $sorters
  * @param string     $entityClass
  * @param array|null $config
  *
  * @return array
  */
 protected function completeSorters(array $sorters, $entityClass, $config)
 {
     $metadata = $this->doctrineHelper->getEntityMetadataForClass($entityClass);
     $fields = array_merge(array_keys($this->doctrineHelper->getIndexedFields($metadata)), array_keys($this->doctrineHelper->getIndexedAssociations($metadata)));
     foreach ($fields as $fieldName) {
         if (array_key_exists($fieldName, $sorters)) {
             // already defined
             continue;
         }
         $sorters[$fieldName] = null;
     }
     if (!empty($config)) {
         foreach ($sorters as $fieldName => &$fieldConfig) {
             if (ConfigUtil::isExcludedField($config, $fieldName)) {
                 $fieldConfig[ConfigUtil::EXCLUDE] = true;
             }
         }
     }
     return $sorters;
 }
Beispiel #2
0
 /**
  * @param array         $filters
  * @param ClassMetadata $metadata
  *
  * @return array
  */
 protected function getAssociationFilters(array $filters, ClassMetadata $metadata)
 {
     $relations = $this->doctrineHelper->getIndexedAssociations($metadata);
     foreach ($relations as $fieldName => $dataType) {
         if (array_key_exists($fieldName, $filters)) {
             // already defined
             continue;
         }
         $filters[$fieldName] = [ConfigUtil::DATA_TYPE => $dataType, ConfigUtil::ALLOW_ARRAY => true];
     }
     return $filters;
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function process(ContextInterface $context)
 {
     /** @var Context $context */
     $entityClass = $context->getClassName();
     if (!$this->doctrineHelper->isManageableEntityClass($entityClass)) {
         // only manageable entities are supported
         return;
     }
     $indexedAssociations = $this->doctrineHelper->getIndexedAssociations($this->doctrineHelper->getEntityMetadata($entityClass));
     if (!$indexedAssociations) {
         // no associations - no sense to add include filters
         return;
     }
     $filters = $context->getFilters();
     if ($filters->has(self::FILTER_KEY)) {
         // filters have been already set
         return;
     }
     $includeFilter = new IncludeFilter(DataType::STRING, 'Inclusion of related resources. Comma-separated paths, e.g. "articles,comments,author"');
     $includeFilter->setArrayAllowed(true);
     $filters->add(self::FILTER_KEY, $includeFilter);
 }