예제 #1
0
 /**
  * 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);
     }
 }
 /**
  * Parse the sorting part of listing configuration.
  *
  * NOTE: this method currently does NOT support the custom SQL sorting information as supported by DC_Table in
  * Contao.
  *
  * @param ListingConfigInterface $listing The listing configuration definition to populate.
  *
  * @param array                  $listDca The DCA part containing the information to use.
  *
  * @return array
  *
  * @throws DcGeneralRuntimeException In case unsupported values are encountered.
  */
 protected function parseListSorting(ListingConfigInterface $listing, array $listDca)
 {
     $parsedProperties = array();
     $sortingDca = isset($listDca['sorting']) ? $listDca['sorting'] : array();
     if (isset($sortingDca['headerFields'])) {
         $listing->setHeaderPropertyNames((array) $sortingDca['headerFields']);
     }
     if (isset($sortingDca['icon'])) {
         $listing->setRootIcon($sortingDca['icon']);
     }
     if (isset($sortingDca['child_record_class'])) {
         $listing->setItemCssClass($sortingDca['child_record_class']);
     }
     if (empty($sortingDca['fields'])) {
         return $parsedProperties;
     }
     $fieldsDca = $this->getFromDca('fields');
     $definitions = $listing->getGroupAndSortingDefinition();
     if (!$definitions->hasDefault()) {
         $definition = $definitions->add();
         $definitions->markDefault($definition);
     } else {
         $definition = $definitions->getDefault();
     }
     foreach ($sortingDca['fields'] as $field) {
         $groupAndSorting = $definition->add();
         if (isset($sortingDca['flag'])) {
             $this->evalFlag($groupAndSorting, $sortingDca['flag']);
         }
         if (preg_match('~^(\\w+)(?: (.+))?$~', $field, $matches)) {
             $groupAndSorting->setProperty($matches[1])->setSortingMode(isset($matches[2]) ? $matches[2] : GroupAndSortingInformationInterface::SORT_ASC);
             // Special case for field named "sorting" in Contao.
             if ($field === 'sorting') {
                 $groupAndSorting->setManualSorting();
             }
         } else {
             throw new DcGeneralRuntimeException('Custom SQL in sorting fields are currently unsupported');
         }
         if (isset($fieldsDca[$groupAndSorting->getProperty()])) {
             if (isset($fieldsDca[$groupAndSorting->getProperty()]['flag'])) {
                 $flag = $fieldsDca[$groupAndSorting->getProperty()]['flag'];
                 $this->evalFlagGrouping($groupAndSorting, $flag);
                 $this->evalFlagGroupingLength($groupAndSorting, $flag);
             }
             if (count($sortingDca['fields']) === 1) {
                 $definition->setName($groupAndSorting->getProperty());
                 $parsedProperties[] = $groupAndSorting->getProperty();
             }
         }
         if (isset($sortingDca['disableGrouping']) && $sortingDca['disableGrouping']) {
             $groupAndSorting->setGroupingMode(GroupAndSortingInformationInterface::GROUP_NONE);
         }
     }
     return $parsedProperties;
 }
예제 #3
0
파일: Builder.php 프로젝트: zonky2/core
 /**
  * Parse the sorting part of listing configuration.
  *
  * @param ListingConfigInterface $listing The listing configuration.
  *
  * @return void
  */
 protected function parseListSorting(ListingConfigInterface $listing)
 {
     $inputScreen = $this->getInputScreenDetails();
     $listing->setRootIcon($this->getBackendIcon($inputScreen->getIcon()));
     $definitions = $listing->getGroupAndSortingDefinition();
     foreach ($inputScreen->getGroupingAndSorting() as $information) {
         $definition = $definitions->add();
         $definition->setName($information->getName());
         if ($information->isDefault() && !$definitions->hasDefault()) {
             $definitions->markDefault($definition);
         }
         if ($information->isManualSorting()) {
             $propertyInformation = $definition->add();
             $propertyInformation->setManualSorting()->setProperty('sorting')->setSortingMode('ASC');
             // FIXME: allow selection of the manual sorting property and its direction in the backend.
         } elseif ($information->getRenderSortAttribute()) {
             $propertyInformation = $definition->add();
             $propertyInformation->setProperty($information->getRenderSortAttribute())->setSortingMode($information->getRenderSortDirection());
         }
         $groupType = $this->convertRenderGroupType($information->getRenderGroupType());
         if ($groupType !== GroupAndSortingInformationInterface::GROUP_NONE && $information->getRenderGroupAttribute()) {
             $propertyInformation = $definition->add(0);
             $propertyInformation->setProperty($information->getRenderGroupAttribute())->setGroupingMode($groupType)->setGroupingLength($information->getRenderGroupLength())->setSortingMode($information->getRenderSortDirection());
         }
     }
 }