/**
  * @param QueryDesignerModel                            $model
  * @param \PHPUnit_Framework_MockObject_MockObject|null $doctrine
  * @param \PHPUnit_Framework_MockObject_MockObject|null $functionProvider
  * @param \PHPUnit_Framework_MockObject_MockObject|null $virtualFieldProvider
  * @param array                                         $guessers
  *
  * @return DatagridConfigurationBuilder
  */
 protected function createDatagridConfigurationBuilder(QueryDesignerModel $model, $doctrine = null, $functionProvider = null, $virtualFieldProvider = null, array $guessers = [])
 {
     $builder = new DatagridConfigurationBuilder($functionProvider ?: $this->getFunctionProvider(), $virtualFieldProvider ?: $this->getVirtualFieldProvider(), $doctrine ?: $this->getDoctrine(), new DatagridGuesserMock($guessers));
     $builder->setGridName('test_grid');
     $builder->setSource($model);
     return $builder;
 }
Beispiel #2
0
 /**
  * @ActivityListQueryDesigner $queryDesigner
  *
  * @return DatagridInterface
  */
 public function createGrid(ActivityListQueryDesigner $source)
 {
     $this->datagridConfigurationBuilder->setGridName('related-activity');
     $this->datagridConfigurationBuilder->setSource($source);
     $config = $this->datagridConfigurationBuilder->getConfiguration();
     $stopPropagationListener = function (Event $e) {
         $e->stopPropagation();
     };
     $this->eventDispatcher->addListener(BuildBefore::NAME, $stopPropagationListener, 255);
     $grid = $this->gridBuilderLink->getService()->build($config, new ParameterBag());
     $this->eventDispatcher->removeListener(BuildBefore::NAME, $stopPropagationListener);
     return $grid;
 }
 /**
  * {@inheritdoc}
  */
 public function getConfiguration()
 {
     $configuration = parent::getConfiguration();
     $className = $this->source->getEntity();
     $metadata = $this->configManager->getEntityMetadata($className);
     if (!$metadata || empty($metadata->routeView)) {
         return $configuration;
     }
     $fromPart = $configuration->offsetGetByPath('[source][query][from]');
     $entityAlias = null;
     $doctrineMetadata = $this->doctrine->getManagerForClass($className)->getClassMetadata($className);
     $identifiers = $doctrineMetadata->getIdentifier();
     $primaryKey = array_shift($identifiers);
     foreach ($fromPart as $piece) {
         if ($piece['table'] == $className) {
             $entityAlias = $piece['alias'];
             break;
         }
     }
     if (!$entityAlias || !$primaryKey || count($identifiers) > 1 || !$this->isActionSupported($primaryKey)) {
         return $configuration;
     }
     $viewAction = ['view' => ['type' => 'navigate', 'label' => 'oro.report.datagrid.view', 'acl_resource' => 'VIEW;entity:' . $className, 'icon' => 'eye-open', 'link' => 'view_link', 'rowAction' => true]];
     $properties = [$primaryKey => null, 'view_link' => ['type' => 'url', 'route' => $metadata->routeView, 'params' => [$primaryKey]]];
     $configuration->offsetAddToArrayByPath('[source][query][select]', ["{$entityAlias}.{$primaryKey}"]);
     $configuration->offsetAddToArrayByPath('[properties]', $properties);
     $configuration->offsetAddToArrayByPath('[actions]', $viewAction);
     return $configuration;
 }
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testComplexQuery()
 {
     $gridName = 'test_grid';
     $en = 'Acme\\Entity\\TestEntity';
     $en1 = 'Acme\\Entity\\TestEntity1';
     $en2 = 'Acme\\Entity\\TestEntity2';
     $en3 = 'Acme\\Entity\\TestEntity3';
     $definition = ['columns' => [['name' => 'column1', 'label' => 'lbl1', 'sorting' => 'DESC'], ['name' => 'rc1,' . $en1 . '::column2', 'label' => 'lbl2', 'sorting' => ''], ['name' => 'rc2,' . $en2 . '::column3', 'label' => 'lbl3', 'sorting' => 'ASC']], 'filters' => [['columnName' => 'rc1,' . $en1 . '::column2', 'criterion' => ['filter' => 'string', 'data' => ['type' => '1', 'value' => 'test']]], ['columnName' => 'rc1,' . $en1 . '::rc4,' . $en3 . '::column5', 'criterion' => ['filter' => 'string', 'data' => ['type' => '1', 'value' => 'test']]], ['columnName' => 'rc1,' . $en1 . '::rc4,' . $en3 . '::column6', 'criterion' => ['filter' => 'string', 'data' => ['type' => '1', 'value' => 'test']]]], 'filters_logic' => ' 1  OR  ( 2 And ( ( 3 or 1 ) oR 2) ) '];
     $doctrine = $this->getDoctrine([$en => ['column1' => 'string'], $en1 => ['column2' => 'integer'], $en2 => ['column3' => 'float']]);
     $model = new QueryDesignerModel();
     $model->setEntity($en);
     $model->setDefinition(json_encode($definition));
     $builder = new DatagridConfigurationBuilder($gridName, $model, $doctrine);
     $result = $builder->getConfiguration()->toArray();
     $expected = ['source' => ['type' => 'orm', 'query' => ['select' => ['t1.column1 as c1', 't2.column2 as c2', 't4.column3 as c3'], 'from' => [['table' => $en, 'alias' => 't1']], 'join' => ['left' => [['join' => 't1.rc1', 'alias' => 't2'], ['join' => 't2.rc4', 'alias' => 't3'], ['join' => 't1.rc2', 'alias' => 't4']]]], 'query_config' => ['table_aliases' => ['' => 't1', $en . '::rc1' => 't2', $en . '::rc1,' . $en1 . '::rc4' => 't3', $en . '::rc2' => 't4'], 'column_aliases' => ['column1' => 'c1', 'rc1,' . $en1 . '::column2' => 'c2', 'rc2,' . $en2 . '::column3' => 'c3'], 'filters' => [['column' => 't2.column2', 'filter' => 'string', 'filterData' => ['type' => '1', 'value' => 'test'], 'columnAlias' => 'c2'], 'OR', [['column' => 't3.column5', 'filter' => 'string', 'filterData' => ['type' => '1', 'value' => 'test']], 'AND', [[['column' => 't3.column6', 'filter' => 'string', 'filterData' => ['type' => '1', 'value' => 'test']], 'OR', ['column' => 't2.column2', 'filter' => 'string', 'filterData' => ['type' => '1', 'value' => 'test'], 'columnAlias' => 'c2']], 'OR', ['column' => 't3.column5', 'filter' => 'string', 'filterData' => ['type' => '1', 'value' => 'test']]]]]]], 'columns' => ['c1' => ['label' => 'lbl1', 'frontend_type' => 'string'], 'c2' => ['label' => 'lbl2', 'frontend_type' => 'integer'], 'c3' => ['label' => 'lbl3', 'frontend_type' => 'decimal']], 'sorters' => ['columns' => ['c1' => ['data_name' => 't1.column1'], 'c2' => ['data_name' => 't2.column2'], 'c3' => ['data_name' => 't4.column3']], 'default' => ['c1' => 'DESC', 'c3' => 'ASC']], 'name' => $gridName, 'filters' => ['columns' => ['c1' => ['data_name' => 't1.column1', 'type' => 'string'], 'c2' => ['data_name' => 't2.column2', 'type' => 'number'], 'c3' => ['data_name' => 't4.column3', 'type' => 'number']]]];
     $this->assertEquals($expected, $result);
 }