/**
  * {@inheritdoc}
  */
 public function visitResult(DatagridConfiguration $config, ResultsObject $result)
 {
     $rows = $result->offsetGetByPath('[data]');
     if (!is_array($rows)) {
         throw new UnexpectedTypeException($rows, 'array');
     }
     $mappingConfig = $this->mapper->getMappingConfig();
     $rows = array_map(function (ResultRecordInterface $record) use($mappingConfig) {
         $entityClass = $record->getValue('entityName');
         $entityId = $record->getValue('recordId');
         $entityConfig = array_key_exists($entityClass, $mappingConfig) ? $entityConfig = $this->mapper->getEntityConfig($entityClass) : [];
         return new ResultItem($this->em, $entityClass, $entityId, null, null, $entityConfig);
     }, $rows);
     $entities = $this->resultFormatter->getResultEntities($rows);
     $resultRows = [];
     /** @var ResultItem $item */
     foreach ($rows as $item) {
         $entityClass = $item->getEntityName();
         $entityId = $item->getRecordId();
         $entity = $entities[$entityClass][$entityId];
         $this->dispatcher->dispatch(PrepareResultItemEvent::EVENT_NAME, new PrepareResultItemEvent($item, $entity));
         $resultRows[] = new ResultRecord(['entity' => $entity, 'indexer_item' => $item]);
     }
     $result->offsetSet('data', $resultRows);
 }
Exemple #2
0
 /**
  * Advanced search from API
  *
  * @param  string $expression
  * @return Result
  */
 public function advancedSearch($expression)
 {
     $lexer = new Lexer();
     $parser = new ExpressionParser();
     /** @var Query $query */
     $query = $parser->parse($lexer->tokenize($expression));
     $query->setMappingConfig($this->mapper->getMappingConfig());
     /** @var Result $result */
     $result = $this->query($query);
     return $result;
 }
 /**
  * Advanced search from API
  *
  * @param  string $searchString
  * @return Result
  */
 public function advancedSearch($searchString)
 {
     $parser = new Parser($this->mapper->getMappingConfig());
     return $this->query($parser->getQueryFromString($searchString));
 }
 public function testGetMappingConfig()
 {
     $mapping = $this->mappingConfig;
     $this->assertEquals($mapping, $this->mapper->getMappingConfig());
 }