Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function visitMetadata(DatagridConfiguration $config, MetadataObject $data)
 {
     $currentViewId = $this->getCurrentViewId($config->getName());
     $this->setDefaultParams($config->getName());
     $data->offsetAddToArray('initialState', ['gridView' => self::DEFAULT_VIEW_ID]);
     $data->offsetAddToArray('state', ['gridView' => $currentViewId]);
     $allLabel = null;
     if (isset($config['options'], $config['options']['gridViews'], $config['options']['gridViews']['allLabel'])) {
         $allLabel = $this->translator->trans($config['options']['gridViews']['allLabel']);
     }
     /** @var AbstractViewsList $list */
     $list = $config->offsetGetOr(self::VIEWS_LIST_KEY, false);
     $systemGridView = new View(self::DEFAULT_VIEW_ID);
     $systemGridView->setDefault($this->getDefaultViewId($config->getName()) === null);
     $gridViews = ['choices' => [['label' => $allLabel, 'value' => self::DEFAULT_VIEW_ID]], 'views' => [$systemGridView->getMetadata()]];
     if ($list !== false) {
         $configuredGridViews = $list->getMetadata();
         $configuredGridViews['views'] = array_merge($gridViews['views'], $configuredGridViews['views']);
         $configuredGridViews['choices'] = array_merge($gridViews['choices'], $configuredGridViews['choices']);
         $gridViews = $configuredGridViews;
     }
     if ($this->eventDispatcher->hasListeners(GridViewsLoadEvent::EVENT_NAME)) {
         $event = new GridViewsLoadEvent($config->getName(), $gridViews);
         $this->eventDispatcher->dispatch(GridViewsLoadEvent::EVENT_NAME, $event);
         $gridViews = $event->getGridViews();
     }
     $gridViews['gridName'] = $config->getName();
     $gridViews['permissions'] = $this->getPermissions();
     $data->offsetAddToArray('gridViews', $gridViews);
 }
Ejemplo n.º 2
0
 /**
  * {@inheritDoc}
  */
 public function visitMetadata(DatagridConfiguration $config, MetadataObject $data)
 {
     $params = $this->getParameters()->get(ParameterBag::ADDITIONAL_PARAMETERS, []);
     $currentView = isset($params[self::VIEWS_PARAM_KEY]) ? $params[self::VIEWS_PARAM_KEY] : null;
     $data->offsetAddToArray('initialState', ['gridView' => '__all__']);
     $data->offsetAddToArray('state', ['gridView' => $currentView]);
     $allLabel = null;
     if (isset($config['options']) && isset($config['options']['gridViews']) && isset($config['options']['gridViews']['allLabel'])) {
         $allLabel = $this->translator->trans($config['options']['gridViews']['allLabel']);
     }
     /** @var AbstractViewsList $list */
     $list = $config->offsetGetOr(self::VIEWS_LIST_KEY, false);
     $gridViews = ['choices' => [['label' => $allLabel, 'value' => '__all__']], 'views' => [(new View('__all__'))->getMetadata()]];
     if ($list !== false) {
         $configuredGridViews = $list->getMetadata();
         $configuredGridViews['views'] = array_merge($gridViews['views'], $configuredGridViews['views']);
         $configuredGridViews['choices'] = array_merge($gridViews['choices'], $configuredGridViews['choices']);
         $gridViews = $configuredGridViews;
     }
     if ($this->eventDispatcher->hasListeners(GridViewsLoadEvent::EVENT_NAME)) {
         $event = new GridViewsLoadEvent($config->getName(), $gridViews);
         $this->eventDispatcher->dispatch(GridViewsLoadEvent::EVENT_NAME, $event);
         $gridViews = $event->getGridViews();
     }
     $gridViews['gridName'] = $config->getName();
     $gridViews['permissions'] = $this->getPermissions();
     $data->offsetSet('gridViews', $gridViews);
 }
Ejemplo n.º 3
0
 /**
  * {@inheritDoc}
  */
 public function visitMetadata(DatagridConfiguration $config, MetadataObject $data)
 {
     $params = $this->getParameters()->all();
     $gridParams = array_filter($params, function ($param) {
         return !is_array($param) && !is_null($param);
     });
     $data->offsetAddToArray('gridParams', $gridParams);
 }
Ejemplo n.º 4
0
 /**
  * {@inheritDoc}
  */
 public function visitMetadata(DatagridConfiguration $config, MetadataObject $data)
 {
     $defaultPage = 1;
     $defaultPerPage = $config->offsetGetByPath(ToolbarExtension::PAGER_DEFAULT_PER_PAGE_OPTION_PATH, 10);
     $initialState = ['currentPage' => $defaultPage, 'pageSize' => $defaultPerPage];
     $state = ['currentPage' => $this->getOr(PagerInterface::PAGE_PARAM, $defaultPage), 'pageSize' => $this->getOr(PagerInterface::PER_PAGE_PARAM, $defaultPerPage)];
     $data->offsetAddToArray('initialState', $initialState);
     $data->offsetAddToArray('state', $state);
 }
 /**
  * {@inheritDoc}
  */
 public function visitMetadata(DatagridConfiguration $config, MetadataObject $data)
 {
     $params = $this->getRequestParams()->get(RequestParameters::ADDITIONAL_PARAMETERS);
     $currentView = isset($params[self::VIEWS_PARAM_KEY]) ? $params[self::VIEWS_PARAM_KEY] : null;
     $data->offsetAddToArray('state', ['gridView' => $currentView]);
     /** @var AbstractViewsList $list */
     $list = $config->offsetGetOr(self::VIEWS_LIST_KEY, false);
     if ($list !== false) {
         $data->offsetSet('gridViews', $list->getMetadata());
     }
 }
Ejemplo n.º 6
0
 /**
  * {@inheritDoc}
  */
 public function visitMetadata(DatagridConfiguration $config, MetadataObject $data)
 {
     $actionsMetadata = [];
     $actions = $config->offsetGetOr(static::ACTION_KEY, []);
     foreach ($actions as $name => $action) {
         $action = $this->getActionObject($name, $action);
         if ($action !== false) {
             $metadata = $action->getOptions()->toArray([], static::$excludeParams);
             $metadata['label'] = isset($metadata['label']) ? $this->translator->trans($metadata['label']) : null;
             $actionsMetadata[$action->getName()] = $metadata;
         }
     }
     $data->offsetAddToArray(static::METADATA_ACTION_KEY, $actionsMetadata);
 }
 /**
  * {@inheritDoc}
  */
 public function visitMetadata(DatagridConfiguration $config, MetadataObject $data)
 {
     // get only columns here because columns will be represented on frontend
     $columns = $config->offsetGetOr(Configuration::COLUMNS_KEY, []);
     $propertiesMetadata = [];
     foreach ($columns as $name => $fieldConfig) {
         $fieldConfig = PropertyConfiguration::createNamed($name, $fieldConfig);
         $metadata = $this->getPropertyObject($fieldConfig)->getMetadata();
         // translate label on backend
         $metadata['label'] = $this->translator->trans($metadata['label']);
         $propertiesMetadata[] = $metadata;
     }
     $data->offsetAddToArray('columns', $propertiesMetadata);
 }
 public function testVisitMetadata()
 {
     $config = DatagridConfiguration::create([Configuration::BASE_CONFIG_KEY => ['enable' => true]]);
     $data = MetadataObject::create([]);
     $this->extension->visitMetadata($config, $data);
     $this->assertEquals($config->offsetGet(Configuration::BASE_CONFIG_KEY), $data->offsetGet(Configuration::BASE_CONFIG_KEY));
 }
Ejemplo n.º 9
0
 public function testVisitMetadata()
 {
     $config = DatagridConfiguration::create(['options' => ['mode' => ModeExtension::MODE_CLIENT]]);
     $metadata = MetadataObject::create([]);
     $this->extension->visitMetadata($config, $metadata);
     $this->assertEquals(ModeExtension::MODE_CLIENT, $metadata->offsetGetByPath('mode'));
 }
Ejemplo n.º 10
0
 /**
  * Test method acceptMetadata
  */
 public function testAcceptMetadata()
 {
     $data = MetadataObject::create([]);
     $extMock = $this->getMockForAbstractClass('Oro\\Bundle\\DataGridBundle\\Extension\\ExtensionVisitorInterface');
     $extMock->expects($this->once())->method('visitMetadata')->with($this->config, $data);
     $this->acceptor->addExtension($extMock);
     $this->acceptor->acceptMetadata($data);
 }
Ejemplo n.º 11
0
 /**
  * {@inheritDoc}
  */
 public function visitMetadata(DatagridConfiguration $config, MetadataObject $data)
 {
     $filtersState = $data->offsetGetByPath('[state][filters]', []);
     $initialFiltersState = $filtersState;
     $filtersMetaData = [];
     $filters = $this->getFiltersToApply($config);
     $values = $this->getValuesToApply($config);
     $initialValues = $this->getValuesToApply($config, false);
     foreach ($filters as $filter) {
         $value = isset($values[$filter->getName()]) ? $values[$filter->getName()] : false;
         $initialValue = isset($initialValues[$filter->getName()]) ? $initialValues[$filter->getName()] : false;
         $filtersState = $this->updateFiltersState($filter, $value, $filtersState);
         $initialFiltersState = $this->updateFiltersState($filter, $initialValue, $initialFiltersState);
         $metadata = $filter->getMetadata();
         $filtersMetaData[] = array_merge($metadata, ['label' => $metadata[FilterUtility::TRANSLATABLE_KEY] ? $this->translator->trans($metadata['label']) : $metadata['label']]);
     }
     $data->offsetAddToArray('initialState', ['filters' => $initialFiltersState])->offsetAddToArray('state', ['filters' => $filtersState])->offsetAddToArray('filters', $filtersMetaData)->offsetAddToArray(MetadataObject::REQUIRED_MODULES_KEY, ['orofilter/js/datafilter-builder']);
 }
Ejemplo n.º 12
0
 public function testVisitMetadata()
 {
     $metadata = MetadataObject::create([]);
     $this->extension->visitMetadata($this->config, $metadata);
     $totalsData = $metadata->offsetGet('state');
     $initialTotalsData = $metadata->offsetGet('initialState');
     $this->assertEquals($totalsData, $initialTotalsData);
     $this->assertEquals($this->config->offsetGetByPath(Configuration::TOTALS_PATH), $totalsData['totals']);
     $this->assertEquals('orodatagrid/js/totals-builder', $metadata->offsetGet('requireJSModules')[0]);
 }
 /**
  * {@inheritDoc}
  */
 public function visitMetadata(DatagridConfiguration $config, MetadataObject $data)
 {
     $filtersState = $data->offsetGetByPath('[state][filters]', []);
     $filtersMetaData = [];
     $filters = $this->getFiltersToApply($config);
     $values = $this->getValuesToApply($config);
     foreach ($filters as $filter) {
         $value = isset($values[$filter->getName()]) ? $values[$filter->getName()] : false;
         if ($value !== false) {
             $form = $filter->getForm();
             if (!$form->isSubmitted()) {
                 $form->submit($value);
             }
             if ($form->isValid()) {
                 $filtersState[$filter->getName()] = $value;
             }
         }
         $metadata = $filter->getMetadata();
         $filtersMetaData[] = array_merge($metadata, ['label' => $this->translator->trans($metadata['label'])]);
     }
     $data->offsetAddToArray('state', ['filters' => $filtersState])->offsetAddToArray('filters', $filtersMetaData)->offsetAddToArray(MetadataObject::REQUIRED_MODULES_KEY, ['oro/datafilter-builder']);
 }
 /**
  * {@inheritDoc}
  */
 public function visitMetadata(DatagridConfiguration $config, MetadataObject $data)
 {
     /**
      * Default toolbar options
      *  [
      *      'hide'       => false,
      *      'pageSize'   => [
      *          'hide'  => false,
      *          'items' => [10, 25, 50, 100],
      *          'default_per_page' => 10
      *       ],
      *      'pagination' => [
      *          'hide' => false,
      *      ]
      *  ];
      */
     $perPageDefault = $config->offsetGetByPath(self::PAGER_DEFAULT_PER_PAGE_OPTION_PATH);
     $pageSizeItems = $config->offsetGetByPath(self::PAGER_ITEMS_OPTION_PATH);
     $exist = array_filter($pageSizeItems, function ($item) use($perPageDefault) {
         if (is_array($item) && isset($item['size'])) {
             return $perPageDefault == $item['size'];
         } elseif (is_numeric($item)) {
             return $perPageDefault == $item;
         }
         return false;
     });
     if (empty($exist)) {
         throw new \LogicException(sprintf('Default page size "%d" must present in size items array', $perPageDefault));
     }
     $options = $config->offsetGetByPath(ToolbarExtension::OPTIONS_PATH, []);
     // get user specified require js modules from options
     if (isset($options[MetadataObject::REQUIRED_MODULES_KEY])) {
         $data->offsetAddToArray(MetadataObject::REQUIRED_MODULES_KEY, $options[MetadataObject::REQUIRED_MODULES_KEY]);
         unset($options[MetadataObject::REQUIRED_MODULES_KEY]);
     }
     // grid options passed under "options" node
     $data->offsetAddToArray(self::METADATA_KEY, $options);
 }
 /**
  * {@inheritdoc}
  */
 public function visitMetadata(DatagridConfiguration $config, MetadataObject $data)
 {
     $multisort = $config->offsetGetByPath(Configuration::MULTISORT_PATH, false);
     $sorters = $this->getSorters($config);
     $proceed = [];
     foreach ($data->offsetGetOr('columns', []) as $key => $column) {
         if (isset($column['name']) && isset($sorters[$column['name']])) {
             $data->offsetSetByPath(sprintf('[columns][%s][sortable]', $key), true);
             $proceed[] = $column['name'];
         }
     }
     $extraSorters = array_diff(array_keys($sorters), $proceed);
     if (count($extraSorters)) {
         throw new \LogicException(sprintf('Could not found column(s) "%s" for sorting', implode(', ', $extraSorters)));
     }
     $data->offsetAddToArray(MetadataObject::OPTIONS_KEY, ['multipleSorting' => $multisort]);
     $sortersState = $data->offsetGetByPath('[state][sorters]', []);
     $sorters = $this->getSortersToApply($config);
     foreach ($sorters as $column => $definition) {
         list($direction) = $definition;
         $sortersState[$column] = $this->normalizeDirection($direction);
     }
     $data->offsetAddToArray('state', ['sorters' => $sortersState]);
 }
Ejemplo n.º 16
0
 public function testVisitMetadataShouldAddGridViewsFromEvent()
 {
     $this->gridViewsExtension->setParameters(new ParameterBag());
     $data = MetadataObject::create([]);
     $config = DatagridConfiguration::create([DatagridConfiguration::NAME_KEY => 'grid']);
     $this->eventDispatcher->expects($this->once())->method('hasListeners')->with(GridViewsLoadEvent::EVENT_NAME)->will($this->returnValue(true));
     $expectedViews = ['views' => [(new View('name', ['k' => 'v'], ['k2' => 'v2']))->getMetadata()], 'permissions' => ['CREATE' => true, 'EDIT' => true, 'VIEW' => true, 'DELETE' => true, 'SHARE' => true, 'EDIT_SHARED' => true], 'gridName' => 'grid'];
     $this->eventDispatcher->expects($this->once())->method('dispatch')->with(GridViewsLoadEvent::EVENT_NAME)->will($this->returnCallback(function ($eventName, GridViewsLoadEvent $event) use($expectedViews) {
         $event->setGridViews($expectedViews);
         return $event;
     }));
     $this->assertFalse($data->offsetExists('gridViews'));
     $this->gridViewsExtension->visitMetadata($config, $data);
     $this->assertTrue($data->offsetExists('gridViews'));
     $this->assertEquals($expectedViews, $data->offsetGet('gridViews'));
 }
Ejemplo n.º 17
0
 /**
  * {@inheritDoc}
  */
 public function visitMetadata(DatagridConfiguration $config, MetadataObject $data)
 {
     $data->offsetAddToArray(static::METADATA_ACTION_KEY, $this->getActionsMetadata($config));
 }
Ejemplo n.º 18
0
 /**
  * {@inheritdoc}
  */
 public function visitMetadata(DatagridConfiguration $config, MetadataObject $data)
 {
     $data->offsetSetByPath('mode', $this->getMode($config));
 }
Ejemplo n.º 19
0
 /**
  * {@inheritDoc}
  */
 public function getMetadata()
 {
     $data = MetadataObject::createNamed($this->getName(), []);
     $this->acceptor->acceptMetadata($data);
     return $data;
 }
 /**
  * Empty implementation should be callable
  */
 public function testVisitMetadata()
 {
     $data = MetadataObject::create([]);
     $config = DatagridConfiguration::create([]);
     $this->extension->visitMetadata($config, $data);
 }
Ejemplo n.º 21
0
 /**
  * Set Default columns data for default grid view __all__
  *
  * @param MetadataObject $data
  * @param array          $columnsData
  */
 protected function setGridViewDefaultOrder(MetadataObject $data, $columnsData)
 {
     $gridViews = $data->offsetGetOr('gridViews');
     if ($gridViews && isset($gridViews['views'])) {
         foreach ($gridViews['views'] as &$gridView) {
             if (GridViewsExtension::DEFAULT_VIEW_ID === $gridView['name']) {
                 $gridView[self::COLUMNS_PATH] = $columnsData;
             }
         }
         unset($gridView);
         $data->offsetSet('gridViews', $gridViews);
     }
 }
Ejemplo n.º 22
0
 /**
  * {@inheritDoc}
  */
 public function visitMetadata(DatagridConfiguration $config, MetadataObject $data)
 {
     $data->offsetSet(Configuration::BASE_CONFIG_KEY, $config->offsetGetOr(Configuration::BASE_CONFIG_KEY, []));
 }
Ejemplo n.º 23
0
 /**
  * @param bool $isApplicable
  * @param array $state
  * @param string $scope
  * @param array $entityIds
  * @param int $entitiesLimit
  * @return \PHPUnit_Framework_MockObject_MockObject
  */
 protected function buildDataGrid($isApplicable = false, array $state = [], $scope = EntityPaginationManager::VIEW_SCOPE, array $entityIds = [], $entitiesLimit = 0)
 {
     $metadata = ['state' => $state];
     $metadataObject = MetadataObject::create($metadata);
     $permission = EntityPaginationManager::getPermission($scope);
     $identifierField = 'id';
     $this->paginationManager->expects($this->any())->method('isDatagridApplicable')->will($this->returnValue($isApplicable));
     $queryBuilder = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock();
     $queryBuilder->expects($this->any())->method('getRootEntities')->will($this->returnValue([self::ENTITY_NAME]));
     $queryBuilder->expects($this->any())->method('setFirstResult')->with(0);
     $queryBuilder->expects($this->any())->method('setMaxResults')->with($entitiesLimit);
     $entities = [];
     foreach ($entityIds as $id) {
         $entities[] = [$identifierField => $id];
     }
     $query = $this->getMockBuilder('Doctrine\\ORM\\AbstractQuery')->disableOriginalConstructor()->setMethods(['execute'])->getMockForAbstractClass();
     $query->expects($this->any())->method('execute')->will($this->returnValue($entities));
     $this->aclHelper->expects($this->any())->method('apply')->with($queryBuilder, $permission)->will($this->returnValue($query));
     $this->doctrineHelper->expects($this->any())->method('getEntityMetadata')->with(self::ENTITY_NAME)->will($this->returnValue(new ClassMetadata(self::ENTITY_NAME)));
     $this->doctrineHelper->expects($this->any())->method('getSingleEntityIdentifierFieldName')->with(self::ENTITY_NAME)->will($this->returnValue($identifierField));
     $dataSource = $this->getMockBuilder('Oro\\Bundle\\DataGridBundle\\Datasource\\Orm\\OrmDatasource')->disableOriginalConstructor()->getMock();
     $dataSource->expects($this->any())->method('getQueryBuilder')->will($this->returnValue($queryBuilder));
     $acceptor = $this->getMock('Oro\\Bundle\\DataGridBundle\\Extension\\Acceptor');
     if ($isApplicable) {
         $acceptor->expects($this->once())->method('acceptDatasource')->with($dataSource);
     }
     $dataGrid = $this->getMock('Oro\\Bundle\\DataGridBundle\\Datagrid\\DatagridInterface');
     $dataGrid->expects($this->any())->method('getMetadata')->will($this->returnValue($metadataObject));
     $dataGrid->expects($this->any())->method('getAcceptor')->will($this->returnValue($acceptor));
     $dataGrid->expects($this->any())->method('getDatasource')->will($this->returnValue($dataSource));
     $this->pager->expects($this->any())->method('setQueryBuilder')->with($queryBuilder);
     $this->pager->expects($this->any())->method('setAclPermission')->with($permission);
     $this->pager->expects($this->any())->method('computeNbResult')->will($this->returnValue(count($entityIds)));
     $this->datagridManager->expects($this->once())->method('getDatagridByRequestParams')->with(self::GRID_NAME)->will($this->returnValue($dataGrid));
     return $dataGrid;
 }
Ejemplo n.º 24
0
 /**
  * {@inheritDoc}
  */
 public function visitMetadata(DatagridConfiguration $config, MetadataObject $metaData)
 {
     $totals = $config->offsetGetByPath(Configuration::TOTALS_PATH);
     $metaData->offsetAddToArray('initialState', ['totals' => $totals])->offsetAddToArray('state', ['totals' => $totals])->offsetAddToArray(MetadataObject::REQUIRED_MODULES_KEY, ['orodatagrid/js/totals-builder']);
 }
Ejemplo n.º 25
0
 /**
  * {@inheritdoc}
  */
 public function visitMetadata(DatagridConfiguration $config, MetadataObject $data)
 {
     $data->offsetAddToArray(MetadataObject::REQUIRED_MODULES_KEY, ['ororeport/js/view-sql-query-builder']);
 }
Ejemplo n.º 26
0
 /**
  * @param DatagridConfiguration $config
  * @param MetadataObject $data
  * @param bool $readParameters
  * @return array
  */
 protected function getSortersState(DatagridConfiguration $config, MetadataObject $data, $readParameters = true)
 {
     $sortersState = $data->offsetGetByPath('[state][sorters]', []);
     $sorters = $this->getSortersToApply($config, $readParameters);
     foreach ($sorters as $column => $definition) {
         list($direction) = $definition;
         $sortersState[$column] = $this->normalizeDirection($direction);
     }
     return $sortersState;
 }
Ejemplo n.º 27
0
 public function testVisitMetadataNotCurrentUser()
 {
     $this->securityFacade->expects($this->once())->method('getLoggedUser')->will($this->returnValue(null));
     $config = $this->getMockBuilder('Oro\\Bundle\\DataGridBundle\\Datagrid\\Common\\DatagridConfiguration')->disableOriginalConstructor()->getMock();
     $data = MetadataObject::createNamed('test-grid', []);
     $result = $this->extension->visitMetadata($config, $data);
     $this->assertEquals(null, $result);
 }