/**
  * {@inheritdoc}
  */
 public function convertToExportFormat(array $exportedRecord, $skipNullValues = true)
 {
     if ($this->context->getValue('columns')) {
         $columns = $this->context->getValue('columns');
     } elseif ($this->context->hasOption('gridName')) {
         $gridName = $this->context->getOption('gridName');
         $gridConfig = $this->gridManagerLink->getService()->getConfigurationForGrid($gridName);
         $columns = $gridConfig->offsetGet('columns');
     } else {
         throw new InvalidConfigurationException('Configuration of datagrid export processor must contain "gridName" or "columns" options.');
     }
     if ($this->context->hasOption('gridParameters')) {
         $gridParams = $this->context->getOption('gridParameters');
         if ($gridParams->has(ColumnsExtension::COLUMNS_PARAM)) {
             $columnsParams = $gridParams->get(ColumnsExtension::COLUMNS_PARAM);
             $columns = $this->columnsHelper->reorderColumns($columns, $columnsParams);
         }
     }
     $result = [];
     foreach ($columns as $columnName => $column) {
         if (isset($column['renderable']) && false === $column['renderable']) {
             continue;
         }
         $val = isset($exportedRecord[$columnName]) ? $exportedRecord[$columnName] : null;
         $val = $this->applyFrontendFormatting($val, $column);
         $result[$this->translator->trans($column['label'])] = $val;
     }
     return $result;
 }
 /**
  * {@inheritdoc}
  */
 public function convertToImportFormat(array $importedRecord, $skipNullValues = true)
 {
     if ($this->context && $this->context->hasOption('channel')) {
         $importedRecord['channel:id'] = $this->context->getOption('channel');
     }
     return parent::convertToImportFormat($importedRecord, $skipNullValues);
 }
Exemplo n.º 3
0
 /**
  * @param ContextInterface $context
  * @throws InvalidConfigurationException
  */
 protected function initializeFromContext(ContextInterface $context)
 {
     if ($context->hasOption('entityName')) {
         $this->setSourceEntityName($context->getOption('entityName'), $context->getOption('organization'));
     } elseif ($context->hasOption('queryBuilder')) {
         $this->setSourceQueryBuilder($context->getOption('queryBuilder'));
     } elseif ($context->hasOption('query')) {
         $this->setSourceQuery($context->getOption('query'));
     } elseif (!$this->getSourceIterator()) {
         throw new InvalidConfigurationException('Configuration of entity reader must contain either "entityName", "queryBuilder" or "query".');
     }
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 protected function initializeFromContext(ContextInterface $context)
 {
     if (!$context->hasOption('data')) {
         throw new InvalidConfigurationException('Configuration reader must contain "data".');
     } else {
         $this->data = $context->getOption('data');
     }
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 protected function initializeFromContext(ContextInterface $context)
 {
     if (!$context->hasOption('entityName')) {
         throw new InvalidConfigurationException('Configuration of fixture reader must contain "entityName".');
     }
     $this->fixture = $this->templateManager->getEntityFixture($context->getOption('entityName'));
     $this->setSourceIterator($this->fixture->getData());
 }
Exemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 protected function initializeFromContext(ContextInterface $context)
 {
     if (!$context->hasOption('file')) {
         throw new InvalidConfigurationException('Configuration reader must contain "file".');
     } else {
         $this->file = new \SplFileObject($context->getOption('file'));
     }
 }
Exemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function setImportExportContext(ContextInterface $context)
 {
     if (!$context->hasOption('filePath')) {
         throw new InvalidConfigurationException('Configuration of CSV writer must contain "filePath".');
     } else {
         $this->setFilePath($context->getOption('filePath'));
     }
     parent::setImportExportContext($context);
 }
Exemplo n.º 8
0
 /**
  * Ensure that filtering applied and query builder wrapped in buffered iterator
  * if data source is query builder or just an entity name
  *
  * @param ContextInterface $context
  */
 protected function ensureInitialized(ContextInterface $context)
 {
     if (null !== $this->qb) {
         if ($context->hasOption(self::ID_FILTER)) {
             $optionValue = $context->getOption(self::ID_FILTER);
             $em = $this->qb->getEntityManager();
             $entityNames = $this->qb->getRootEntities();
             $classMetadata = $em->getClassMetadata(reset($entityNames));
             $identifier = $classMetadata->getSingleIdentifierFieldName();
             if (is_array($optionValue)) {
                 $this->qb->andWhere($this->qb->expr()->in('o.' . $identifier, ':id'));
                 $this->qb->setParameter('id', $optionValue);
             } else {
                 $this->qb->andWhere('o.' . $identifier . ' = :id');
             }
             $this->qb->setParameter('id', $optionValue);
         }
         $this->setSourceIterator(new BufferedQueryResultIterator($this->qb));
     }
 }
Exemplo n.º 9
0
 /**
  * @param array $importedRecord
  * @param ContextInterface|null $context
  * @return array
  */
 public static function addUnknownAttributes(array $importedRecord, ContextInterface $context = null)
 {
     $channelId = null;
     if ($context && $context->hasOption(self::CHANNEL_KEY)) {
         $channelId = $context->getOption(self::CHANNEL_KEY);
     }
     if (!empty($importedRecord[self::ATTRIBUTES_KEY])) {
         foreach ($importedRecord[self::ATTRIBUTES_KEY] as $attribute) {
             $name = $attribute[self::KEY];
             $value = $attribute[self::VALUE];
             $isIdentifier = substr($name, -strlen(self::ID_MARK)) === self::ID_MARK;
             if ($isIdentifier && $channelId) {
                 $name = Inflector::camelize($name);
                 $importedRecord = self::addAttribute($importedRecord, $name, $value);
                 $name = substr($name, 0, strlen($name) - strlen(self::ID_MARK) + 1);
                 $value = ['originId' => $value, self::CHANNEL_KEY => ['id' => $channelId]];
             }
             $name = Inflector::camelize($name);
             $importedRecord = self::addAttribute($importedRecord, $name, $value);
         }
         unset($importedRecord[self::ATTRIBUTES_KEY]);
     }
     return $importedRecord;
 }
Exemplo n.º 10
0
 /**
  * @param ContextInterface $context
  * @throws InvalidConfigurationException
  */
 protected function initializeFromContext(ContextInterface $context)
 {
     if (!$context->hasOption('filePath')) {
         throw new InvalidConfigurationException('Configuration of CSV reader must contain "filePath".');
     } else {
         $this->setFilePath($context->getOption('filePath'));
     }
     if ($context->hasOption('delimiter')) {
         $this->delimiter = $context->getOption('delimiter');
     }
     if ($context->hasOption('enclosure')) {
         $this->enclosure = $context->getOption('enclosure');
     }
     if ($context->hasOption('escape')) {
         $this->escape = $context->getOption('escape');
     }
     if ($context->hasOption('firstLineIsHeader')) {
         $this->firstLineIsHeader = (bool) $context->getOption('firstLineIsHeader');
     }
     if ($context->hasOption('header')) {
         $this->header = $context->getOption('header');
     }
 }
Exemplo n.º 11
0
 /**
  * @param ContextInterface $context
  * @param \Iterator $iterator
  */
 protected function setPredefinedFilters(ContextInterface $context, \Iterator $iterator)
 {
     $filters = null;
     if ($context->hasOption('filters')) {
         $filters = $context->getOption('filters');
         $context->removeOption('filters');
     }
     $complexFilters = null;
     if ($context->hasOption('complex_filters')) {
         $complexFilters = $context->getOption('complex_filters');
         $context->removeOption('complex_filters');
     }
     if ($filters || $complexFilters) {
         if ($iterator instanceof PredefinedFiltersAwareInterface) {
             $predefinedFilters = new BatchFilterBag((array) $filters, (array) $complexFilters);
             $iterator->setPredefinedFiltersBag($predefinedFilters);
         } else {
             throw new \LogicException('Iterator does not support predefined filters');
         }
     }
 }
Exemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public function setImportExportContext(ContextInterface $context)
 {
     $this->context = $context;
     if ($context->hasOption('gridName')) {
         $this->grid = $this->gridManagerLink->getService()->getDatagrid($context->getOption('gridName'), $context->getOption('gridParameters'));
         $context->setValue('columns', $this->grid->getConfig()->offsetGet('columns'));
     } else {
         throw new InvalidConfigurationException('Configuration of datagrid export reader must contain "gridName".');
     }
 }
Exemplo n.º 13
0
 /**
  * {@inheritdoc}
  */
 public function setImportExportContext(ContextInterface $context)
 {
     if ($context->hasOption('delimiter')) {
         $this->delimiter = $context->getOption('delimiter');
     }
     if ($context->hasOption('enclosure')) {
         $this->enclosure = $context->getOption('enclosure');
     }
     if ($context->hasOption('firstLineIsHeader')) {
         $this->firstLineIsHeader = (bool) $context->getOption('firstLineIsHeader');
     }
     if ($context->hasOption('header')) {
         $this->header = $context->getOption('header');
     }
 }