/** * @param array $rows * * @return array */ protected function applyPagination(array $rows) { $originalTotals = count($rows); $this->grid->getConfig()->offsetAddToArrayByPath(static::PATH_PAGER_ORIGINAL_TOTALS, [$originalTotals]); if (count($rows) > $this->requestPagerParameters['_per_page']) { $offset = ($this->requestPagerParameters['_page'] - 1) * $this->requestPagerParameters['_per_page']; if ($offset < 0) { $offset = 0; } $rows = array_slice($rows, $offset, $this->requestPagerParameters['_per_page']); } return $rows; }
/** * @param DatagridInterface $dataGrid * @return bool */ public function isDatagridApplicable(DatagridInterface $dataGrid) { if (!$dataGrid->getDatasource() instanceof OrmDatasource) { return false; } return $dataGrid->getConfig()->offsetGetByPath(EntityPaginationExtension::ENTITY_PAGINATION_PATH) === true; }
/** * {@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".'); } }
/** * @param DatagridInterface $datagrid * * @return array */ protected function getEntityNameWithAlias(DatagridInterface $datagrid) { $fromItems = $datagrid->getConfig()->offsetGetByPath('[source][query][from]', false); if (empty($fromItems[0]['table'])) { return [$datagrid->getParameters()->get('class_name'), null]; } else { $alias = empty($fromItems[0]['alias']) ? null : $fromItems[0]['alias']; return [$fromItems[0]['table'], $alias]; } }
/** * Set chart data as grid instance * * @param DatagridInterface $datagrid * @return ChartViewBuilder */ public function setDataGrid(DatagridInterface $datagrid) { $this->setData(new DataGridData($datagrid)); $config = $datagrid->getConfig(); $this->datagridColumnsDefinition = $config['columns']; return $this; }
/** * @param MarketingList $marketingList * @param DatagridInterface $dataGrid * @param QueryBuilder $qb */ protected function saveColumnInformation(MarketingList $marketingList, DatagridInterface $dataGrid, QueryBuilder $qb) { /** @var Select[] $selects */ $selects = $qb->getDQLPart('select'); $columnToSelectExpr = []; foreach ($selects as $select) { foreach ($select->getParts() as $selectPart) { $selectData = explode(strrev(' as '), strrev($selectPart), 2); if (count($selectData) === 2) { $columnToSelectExpr[strrev($selectData[0])] = strrev($selectData[1]); } } } $columnAliases = $dataGrid->getConfig()->offsetGetByPath(self::DATAGRID_COLUMN_ALIASES_PATH); $columnInformation = []; foreach ($columnAliases as $alias => $selectAlias) { if (array_key_exists($selectAlias, $columnToSelectExpr)) { $columnInformation[$alias] = $columnToSelectExpr[$selectAlias]; } } $this->columnInformation[$marketingList->getId()] = $columnInformation; }
/** * Method detects type of report's chart 'label' field, and in case of datetime will check dates interval and * set proper type (time, day, date, month or year). Xaxis labels not taken into account - they will be rendered * automatically. Also chart dot labels may overlap if dates are close to each other. * * Should be refactored in scope of BAP-8294. * * @param DatagridInterface $datagrid * @param array $chartOptions * * @return array */ protected function processChartOptions(DatagridInterface $datagrid, array $chartOptions) { $labelFieldName = $chartOptions['data_schema']['label']; $labelFieldType = $datagrid->getConfig()->offsetGetByPath(sprintf('[columns][%s][frontend_type]', $labelFieldName)); /** @var DateHelper $dateTimeHelper */ $dateTimeHelper = $this->get('oro_dashboard.datetime.helper'); $dateTypes = [Type::DATETIME, Type::DATE, Type::DATETIMETZ]; if (in_array($labelFieldType, $dateTypes)) { $data = $datagrid->getData()->offsetGet('data'); $dates = array_map(function ($dataItem) use($labelFieldName) { return $dataItem[$labelFieldName]; }, $data); $minDate = new \DateTime(min($dates)); $maxDate = new \DateTime(max($dates)); $formatStrings = $dateTimeHelper->getFormatStrings($minDate, $maxDate); $chartOptions['data_schema']['label'] = ['field_name' => $chartOptions['data_schema']['label'], 'type' => $formatStrings['viewType']]; } return $chartOptions; }