/**
  * Calculate the resulting list.
  *
  * @return void
  *
  * @throws \RuntimeException When no sorting property has been defined.
  */
 protected function calculate()
 {
     if (isset($this->results) || $this->models->length() == 0) {
         return;
     }
     if (!$this->getSortingProperty()) {
         throw new \RuntimeException('No sorting property defined for ' . $this->models->get(0)->getProviderName());
     }
     $this->results = clone $this->models;
     $this->siblingsCopy = clone $this->siblings;
     $this->scanToDesiredPosition();
     $this->updateSorting();
 }
 /**
  * {@inheritDoc}
  */
 public function pasteTop(CollectionInterface $models, $sortedBy, ModelIdInterface $parentId = null)
 {
     $environment = $this->getEnvironment();
     // Enforce proper sorting now.
     $siblings = $this->assembleSiblingsFor($models->get(0), $sortedBy, $parentId);
     $sortManager = new SortingManager($models, $siblings, $sortedBy, null);
     $newList = $sortManager->getResults();
     $environment->getDataProvider($models->get(0)->getProviderName())->saveEach($newList);
 }
Exemple #3
0
 /**
  * Render the operation buttons for the passed models.
  *
  * @param CollectionInterface $collection The collection containing the models.
  *
  * @return void
  */
 public function renderButtonsForCollection(CollectionInterface $collection)
 {
     // Generate buttons.
     foreach ($collection as $i => $model) {
         $previous = $collection->get($i - 1);
         $next = $collection->get($i + 1);
         /** @var ModelInterface $model */
         $this->renderButtonsFor($model, $previous, $next);
     }
 }
Exemple #4
0
 /**
  * Render the entries for parent view.
  *
  * @param CollectionInterface $collection          The collection to render.
  *
  * @param array               $groupingInformation The grouping information as retrieved via
  *                            BaseView::getGroupingMode().
  *
  * @return void
  */
 protected function renderEntries($collection, $groupingInformation)
 {
     $environment = $this->getEnvironment();
     $view = $this->getViewSection();
     $listing = $view->getListingConfig();
     $remoteCur = null;
     $groupClass = 'tl_folder_tlist';
     $eoCount = -1;
     $objConfig = $environment->getDataProvider()->getEmptyConfig();
     $this->getPanel()->initialize($objConfig);
     // Run each model.
     $i = 0;
     foreach ($collection as $model) {
         /** @var ModelInterface $model */
         $i++;
         // Add the group header.
         if ($groupingInformation) {
             $remoteNew = $this->formatCurrentValue($groupingInformation['property'], $model, $groupingInformation['mode'], $groupingInformation['length']);
             // Add the group header if it differs from the last header.
             if (!$listing->getShowColumns() && $groupingInformation['mode'] !== ListingConfigInterface::GROUP_NONE && ($remoteNew != $remoteCur || $remoteCur === null)) {
                 $eoCount = -1;
                 $model->setMeta($model::GROUP_VALUE, array('class' => $groupClass, 'value' => $remoteNew));
                 $groupClass = 'tl_folder_list';
                 $remoteCur = $remoteNew;
             }
         }
         if ($listing->getItemCssClass()) {
             $model->setMeta($model::CSS_CLASS, $listing->getItemCssClass());
         }
         // Regular buttons.
         if (!$this->isSelectModeActive()) {
             $previous = !is_null($collection->get($i - 1)) ? $collection->get($i - 1) : null;
             $next = !is_null($collection->get($i + 1)) ? $collection->get($i + 1) : null;
             $buttons = $this->generateButtons($model, $previous, $next);
             $model->setMeta($model::OPERATION_BUTTONS, $buttons);
         }
         $event = new ParentViewChildRecordEvent($this->getEnvironment(), $model);
         $this->getEnvironment()->getEventPropagator()->propagate($event::NAME, $event, array($this->getEnvironment()->getDataDefinition()->getName(), $model->getId()));
         $model->setMeta($model::CSS_ROW_CLASS, ++$eoCount % 2 == 0 ? 'even' : 'odd');
         if ($event->getHtml() !== null) {
             $information = array(array('colspan' => 1, 'class' => 'tl_file_list col_1', 'content' => $event->getHtml()));
             $model->setMeta($model::LABEL_VALUE, $information);
         } else {
             $model->setMeta($model::LABEL_VALUE, $this->formatModel($model));
         }
     }
 }
Exemple #5
0
 /**
  * Render the entries for parent view.
  *
  * @param CollectionInterface $collection          The collection to render.
  *
  * @param array               $groupingInformation The grouping information as retrieved via
  *                                                 BaseView::getGroupingMode().
  *
  * @return void
  */
 protected function renderEntries($collection, $groupingInformation)
 {
     $environment = $this->getEnvironment();
     $clipboard = $environment->getClipboard();
     $view = $this->getViewSection();
     $listing = $view->getListingConfig();
     $remoteCur = null;
     $groupClass = 'tl_folder_tlist';
     $eoCount = -1;
     $objConfig = $environment->getDataProvider()->getEmptyConfig();
     $this->getPanel()->initialize($objConfig);
     // Run each model.
     $index = 0;
     foreach ($collection as $model) {
         /** @var ModelInterface $model */
         $index++;
         // Add the group header.
         if ($groupingInformation) {
             $remoteNew = $this->formatCurrentValue($groupingInformation['property'], $model, $groupingInformation['mode'], $groupingInformation['length']);
             // Add the group header if it differs from the last header.
             if (!$listing->getShowColumns() && $groupingInformation['mode'] !== GroupAndSortingInformationInterface::GROUP_NONE && ($remoteNew != $remoteCur || $remoteCur === null)) {
                 $eoCount = -1;
                 $model->setMeta($model::GROUP_VALUE, array('class' => $groupClass, 'value' => $remoteNew));
                 $groupClass = 'tl_folder_list';
                 $remoteCur = $remoteNew;
             }
         }
         if ($listing->getItemCssClass()) {
             $model->setMeta($model::CSS_CLASS, $listing->getItemCssClass());
         }
         // Regular buttons.
         if (!$this->isSelectModeActive()) {
             $previous = $collection->get($index - 1) !== null ? $collection->get($index - 1) : null;
             $next = $collection->get($index + 1) !== null ? $collection->get($index + 1) : null;
             $buttons = $this->generateButtons($model, $previous, $next);
             $model->setMeta($model::OPERATION_BUTTONS, $buttons);
         }
         $event = new ParentViewChildRecordEvent($this->getEnvironment(), $model);
         $environment->getEventDispatcher()->dispatch($event::NAME, $event);
         $cssClasses = array(++$eoCount % 2 == 0 ? 'even' : 'odd');
         $modelId = IdSerializer::fromModel($model);
         if ($clipboard->hasId($modelId)) {
             $cssClasses[] = 'tl_folder_clipped';
         }
         $model->setMeta($model::CSS_ROW_CLASS, implode(' ', $cssClasses));
         if ($event->getHtml() !== null) {
             $information = array(array('colspan' => 1, 'class' => 'tl_file_list col_1', 'content' => $event->getHtml()));
             $model->setMeta($model::LABEL_VALUE, $information);
         } else {
             $event = new FormatModelLabelEvent($this->environment, $model);
             $this->environment->getEventDispatcher()->dispatch(DcGeneralEvents::FORMAT_MODEL_LABEL, $event);
             $model->setMeta($model::LABEL_VALUE, $event->getLabel());
         }
     }
 }