/** * {@inheritDoc} */ public function initialize(ConfigInterface $objConfig, PanelElementInterface $objElement = null) { if ($objElement === null) { $input = $this->getInputProvider(); $value = null; if ($this->getPanel()->getContainer()->updateValues() && $input->hasValue('tl_sort')) { $value = $input->getValue('tl_sort'); $this->setPersistent($value); } $persistent = $this->getPersistent(); if (!$persistent) { if ($this->getGroupAndSortingDefinition()->hasDefault()) { $persistent = $this->getGroupAndSortingDefinition()->getDefault()->getName(); } $this->setPersistent($value); } $this->setSelected($persistent); } $current = $objConfig->getSorting(); if (!is_array($current)) { $current = array(); } if ($this->getSelectedDefinition()) { foreach ($this->getSelectedDefinition() as $information) { $current[$information->getProperty()] = $information->getSortingMode(); } } $objConfig->setSorting($current); }
/** * Extract the sorting from the given config. * * @param ConfigInterface $config The configuration to be applied. * * @return array */ protected function extractSorting($config) { $sorting = $config->getSorting(); $sortBy = key($sorting); $sortDir = current($sorting) ?: DCGE::MODEL_SORTING_ASC; return array($sortBy, $sortDir); }
/** * Build the order by part of a query. * * @param ConfigInterface $objConfig The configuration to use. * * @return string */ protected function buildSortingQuery($objConfig) { $arrSorting = $objConfig->getSorting(); $strReturn = ''; $arrFields = array(); if ($arrSorting !== null && is_array($arrSorting) && count($arrSorting) > 0) { foreach ($arrSorting as $strField => $strOrder) { if ($strOrder && !in_array(strtoupper($strOrder), array(DCGE::MODEL_SORTING_ASC, DCGE::MODEL_SORTING_DESC))) { $strField = $strOrder; $strOrder = DCGE::MODEL_SORTING_ASC; } else { if (!$strOrder) { $strOrder = DCGE::MODEL_SORTING_ASC; } } $arrFields[] = $strField . ' ' . $strOrder; } $strReturn .= ' ORDER BY ' . implode(', ', $arrFields); } return $strReturn; }
/** * Initialize the sorting from the panel. Fallback to default sorting if nothing given. * * @param PanelContainerInterface $panel The current panel. * * @param ConfigInterface $dataConfig The current config. * * @param ListingConfigInterface $listingConfig The listing config. * * @return void */ public static function initializeSorting($panel, $dataConfig, $listingConfig) { // Store default sorting start initializing the panel with an empty sorting. $sorting = $dataConfig->getSorting(); $dataConfig->setSorting(array()); $panel->initialize($dataConfig); // Restore default sorting if panel did not set any. if ($sorting && !$dataConfig->getSorting()) { $dataConfig->setSorting($sorting); } // Initialize sorting if not present yet. if (!$dataConfig->getSorting() && $listingConfig->getGroupAndSortingDefinition()->hasDefault()) { $newSorting = array(); foreach ($listingConfig->getGroupAndSortingDefinition()->getDefault() as $information) { /** @var GroupAndSortingInformationInterface $information */ $newSorting[$information->getProperty()] = strtoupper($information->getSortingMode()); } $dataConfig->setSorting($newSorting); } }
/** * {@inheritdoc} */ public function fetchAll(ConfigInterface $config) { $entityRepository = $this->getEntityRepository(); $entityManager = $this->getEntityManager(); $queryBuilder = $entityManager->createQueryBuilder(); $queryBuilder->select($config->getIdOnly() ? 'e.id' : 'e')->from($entityRepository->getClassName(), 'e'); if ($config->getFilter()) { $queryBuilder->where($this->buildCondition($queryBuilder, array('operation' => 'AND', 'children' => $config->getFilter()))); } if ($config->getSorting()) { $hiddenIndex = 0; foreach ($config->getSorting() as $sort => $order) { $orderUppercase = strtoupper($order); if ($order && $orderUppercase != 'ASC' && $orderUppercase != 'DESC') { $queryBuilder->addSelect($order . ' AS HIDDEN _virtual_sorting_field_' . $hiddenIndex); $sort = '_virtual_sorting_field_' . $hiddenIndex; $order = null; $hiddenIndex++; } else { $sort = 'e.' . $sort; $order = $orderUppercase; } $queryBuilder->addOrderBy($sort, $order); } } if ($config->getStart()) { $queryBuilder->setFirstResult($config->getStart()); } if ($config->getAmount()) { $queryBuilder->setMaxResults($config->getAmount()); } $query = $queryBuilder->getQuery(); if ($config->getIdOnly()) { $entities = $query->getScalarResult(); } else { $entities = $query->getResult(); $entities = $this->mapEntities($entities); } return $entities; }
/** * {@inheritDoc} */ public function initialize(ConfigInterface $objConfig, PanelElementInterface $objElement = null) { if (is_null($objElement)) { $input = $this->getInputProvider(); $value = null; if ($this->getPanel()->getContainer()->updateValues() && $input->hasValue('tl_sort')) { $value = $input->getValue('tl_sort'); $this->setPersistent($value); $this->setSelected($this->getPersistent()); } else { $this->setSelected($this->getPersistent()); } } $current = $objConfig->getSorting(); if (!is_array($current)) { $current = array(); } $arrSecondOrder = $this->getAdditionalSorting(); if (!$this->getSelected()) { if ($arrSecondOrder) { $filtered = array_intersect(array_keys($arrSecondOrder), $this->getPropertyNames()); $this->setSelected($filtered[0]); } // Still nothing selected? - use the first. if (!$this->getSelected()) { $all = $this->getPropertyNames(); $this->setSelected($all[0]); } } if ($this->getSelected()) { $current[$this->getSelected()] = $this->flagToDirection($this->getFlag()); } $objConfig->setSorting($current); }