예제 #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);
     }
 }
예제 #2
0
 /**
  * {@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);
 }
예제 #3
0
 /**
  * {@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);
 }