Beispiel #1
0
 /**
  * Set label for list view.
  *
  * @param CollectionInterface $collection          The collection containing the models.
  *
  * @param array               $groupingInformation The grouping information as retrieved via
  *                                                 BaseView::getGroupingMode().
  *
  * @return void
  */
 protected function setListViewLabel($collection, $groupingInformation)
 {
     $clipboard = $this->environment->getClipboard();
     $viewDefinition = $this->getViewSection();
     $listingConfig = $viewDefinition->getListingConfig();
     $remoteCur = null;
     $groupClass = 'tl_folder_tlist';
     $eoCount = -1;
     foreach ($collection as $objModelRow) {
         /** @var ModelInterface $objModelRow */
         // Build the sorting groups.
         if ($groupingInformation) {
             $remoteNew = $this->formatCurrentValue($groupingInformation['property'], $objModelRow, $groupingInformation['mode'], $groupingInformation['length']);
             // Add the group header if it differs from the last header.
             if (!$listingConfig->getShowColumns() && $groupingInformation['mode'] !== GroupAndSortingInformationInterface::GROUP_NONE && ($remoteNew != $remoteCur || $remoteCur === null)) {
                 $eoCount = -1;
                 $objModelRow->setMeta($objModelRow::GROUP_VALUE, array('class' => $groupClass, 'value' => $remoteNew));
                 $groupClass = 'tl_folder_list';
                 $remoteCur = $remoteNew;
             }
         }
         $cssClasses = array(++$eoCount % 2 == 0 ? 'even' : 'odd');
         $modelId = IdSerializer::fromModel($objModelRow);
         if ($clipboard->hasId($modelId)) {
             $cssClasses[] = 'tl_folder_clipped';
         }
         $objModelRow->setMeta($objModelRow::CSS_ROW_CLASS, implode(' ', $cssClasses));
         $event = new FormatModelLabelEvent($this->environment, $objModelRow);
         $this->environment->getEventDispatcher()->dispatch(DcGeneralEvents::FORMAT_MODEL_LABEL, $event);
         $objModelRow->setMeta($objModelRow::LABEL_VALUE, $event->getLabel());
     }
 }
Beispiel #2
0
 /**
  * Retrieve a list of html buttons to use in the top panel (submit area).
  *
  * @param ModelInterface $parentModel The parent model.
  *
  * @return array
  */
 protected function getHeaderEditButtons($parentModel)
 {
     $environment = $this->getEnvironment();
     $parentDefinition = $environment->getParentDataDefinition();
     if ($parentDefinition && $parentDefinition->getBasicDefinition()->isEditable()) {
         $definition = $environment->getDataDefinition();
         $basicDefinition = $definition->getBasicDefinition();
         $parentName = $basicDefinition->getParentDataProvider();
         $propagator = $environment->getEventPropagator();
         $query = array('do' => $environment->getInputProvider()->getParameter('do'), 'act' => 'edit', 'table' => $parentName, 'id' => IdSerializer::fromModel($parentModel)->getSerialized());
         $factory = DcGeneralFactory::deriveFromEnvironment($this->environment);
         $factory->setContainerName($parentDefinition->getName());
         $parentContainer = $factory->createContainer();
         if ($parentContainer->getBasicDefinition()->getParentDataProvider()) {
             $container = $this->environment->getDataDefinition();
             $relationship = $container->getModelRelationshipDefinition()->getChildCondition($parentContainer->getBasicDefinition()->getParentDataProvider(), $parentContainer->getName());
             if ($relationship) {
                 $filter = $relationship->getInverseFilterFor($parentModel);
                 $parentsParentProvider = $this->environment->getDataProvider($parentContainer->getBasicDefinition()->getParentDataProvider());
                 $config = $parentsParentProvider->getEmptyConfig();
                 $config->setFilter($filter);
                 $parents = $parentsParentProvider->fetchAll($config);
                 if ($parents->length() == 1) {
                     $query['pid'] = IdSerializer::fromModel($parents->get(0))->getSerialized();
                 } elseif ($parents->length() > 1) {
                     return null;
                 }
             }
         }
         /** @var GenerateHtmlEvent $imageEvent */
         $imageEvent = $propagator->propagate(ContaoEvents::IMAGE_GET_HTML, new GenerateHtmlEvent('edit.gif', $this->translate('editheader.0', $definition->getName())));
         return sprintf('<a href="%s" title="%s" onclick="Backend.getScrollOffset()">%s</a>', 'contao/main.php?' . http_build_query($query), specialchars($this->translate('editheader.1', $definition->getName())), $imageEvent->getHtml());
     }
     return null;
 }
Beispiel #3
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);
     // Generate buttons - only if not in select mode!
     if (!$this->isSelectModeActive()) {
         $buttonRenderer = new ButtonRenderer($this->environment);
         $buttonRenderer->renderButtonsForCollection($collection);
     }
     // 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());
         }
         $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());
         }
     }
 }
Beispiel #4
0
 /**
  * Render the paste after button.
  *
  * @param GetPasteButtonEvent $event The event that has been triggered.
  *
  * @return string
  */
 public function renderPasteAfterButton(GetPasteButtonEvent $event)
 {
     if ($event->getHtmlPasteAfter() !== null) {
         return $event->getHtmlPasteAfter();
     }
     $model = $event->getModel();
     $modelId = IdSerializer::fromModel($model);
     $environment = $event->getEnvironment();
     $controller = $environment->getController();
     $clipboard = $environment->getClipboard();
     $dataDefinition = $environment->getDataDefinition();
     $basicDefinition = $dataDefinition->getBasicDefinition();
     $pasteAfterIsDisabled = $event->isPasteAfterDisabled();
     if (!$pasteAfterIsDisabled) {
         // pre-build filter, to fetch other items
         $filter = new Filter();
         $filter->andModelIsFromProvider($basicDefinition->getDataProvider());
         if ($parentDataProviderName = $basicDefinition->getParentDataProvider()) {
             $filter->andParentIsFromProvider($parentDataProviderName);
         } else {
             $filter->andHasNoParent();
         }
         $filter->andModelIsNot($modelId);
         /*
          * FIXME to be discussed, allow pasting only in the same grouping
                 }
                 /** @var Filter $filter Prevent IDE from saying $filter may be undefined! ;-D * /
         
                 if (!$pasteAfterIsDisabled) {
         // Determine if the grouping is the same
         $groupingMode = ViewHelpers::getGroupingMode($environment);
         
         if ($groupingMode) {
             $items  = $clipboard->fetch($filter);
             $models = $controller->getModelsFromClipboardItems($items);
             $propertyName = $groupingMode['property'];
             $propertyValue = $model->getProperty($propertyName);
         
             $pasteAfterIsDisabled = true;
             foreach ($models as $clipboardModel) {
                 if ($propertyValue === $clipboardModel->getProperty($propertyName)) {
                     // there exist at least one item, with the same grouping
                     $pasteAfterIsDisabled = false;
                     break;
                 }
             }
         }
                 }
         
                 if (!$pasteAfterIsDisabled) {
         */
         $pasteAfterIsDisabled = $clipboard->isEmpty($filter);
     }
     $strLabel = $this->translate('pasteafter.0', $model->getProviderName());
     if ($pasteAfterIsDisabled) {
         /** @var GenerateHtmlEvent $imageEvent */
         $imageEvent = $environment->getEventDispatcher()->dispatch(ContaoEvents::IMAGE_GET_HTML, new GenerateHtmlEvent('pasteafter_.gif', $strLabel, 'class="blink"'));
         return $imageEvent->getHtml();
     }
     /** @var GenerateHtmlEvent $imageEvent */
     $imageEvent = $environment->getEventDispatcher()->dispatch(ContaoEvents::IMAGE_GET_HTML, new GenerateHtmlEvent('pasteafter.gif', $strLabel, 'class="blink"'));
     $opDesc = $this->translate('pasteafter.1', $environment->getDataDefinition()->getName());
     if (strlen($opDesc)) {
         $title = sprintf($opDesc, $model->getId());
     } else {
         $title = sprintf('%s id %s', $strLabel, $model->getId());
     }
     return sprintf(' <a href="%s" title="%s" %s>%s</a>', $event->getHrefAfter(), specialchars($title), 'onclick="Backend.getScrollOffset()"', $imageEvent->getHtml());
 }
Beispiel #5
0
 /**
  * Compile buttons from the table configuration array and return them as HTML.
  *
  * @param ModelInterface $model    The model for which the buttons shall be generated for.
  * @param ModelInterface $previous The previous model in the collection.
  * @param ModelInterface $next     The next model in the collection.
  * @return string
  */
 protected function generateButtons(ModelInterface $model, ModelInterface $previous = null, ModelInterface $next = null)
 {
     $commands = $this->getViewSection()->getModelCommands();
     $objClipboard = $this->getEnvironment()->getClipboard();
     $propagator = $this->getEnvironment()->getEventPropagator();
     if ($this->getEnvironment()->getClipboard()->isNotEmpty()) {
         $circularIds = $objClipboard->getCircularIds();
         $isCircular = in_array(IdSerializer::fromModel($model)->getSerialized(), $circularIds);
     } else {
         $circularIds = array();
         $isCircular = false;
     }
     $arrButtons = array();
     foreach ($commands->getCommands() as $command) {
         $arrButtons[$command->getName()] = $this->buildCommand($command, $model, $isCircular, $circularIds, $previous, $next);
     }
     if ($this->getManualSortingProperty() && $objClipboard->isEmpty() && $this->getDataDefinition()->getBasicDefinition()->getMode() != BasicDefinitionInterface::MODE_HIERARCHICAL) {
         /** @var AddToUrlEvent $urlEvent */
         $urlEvent = $propagator->propagate(ContaoEvents::BACKEND_ADD_TO_URL, new AddToUrlEvent('act=create&amp;after=' . IdSerializer::fromModel($model)->getSerialized()));
         /** @var GenerateHtmlEvent $imageEvent */
         $imageEvent = $propagator->propagate(ContaoEvents::IMAGE_GET_HTML, new GenerateHtmlEvent('new.gif', $this->translate('pastenew.0', $this->getDataDefinition()->getName())));
         $arrButtons['pasteNew'] = sprintf('<a href="%s" title="%s" onclick="Backend.getScrollOffset()">%s</a>', $urlEvent->getUrl(), specialchars($this->translate('pastenew.1', $this->getDataDefinition()->getName())), $imageEvent->getHtml());
     }
     // Add paste into/after icons.
     if ($objClipboard->isNotEmpty()) {
         // Add ext. information.
         $add2UrlAfter = sprintf('act=%s&after=%s&', $objClipboard->getMode(), IdSerializer::fromModel($model)->getSerialized());
         $add2UrlInto = sprintf('act=%s&into=%s&', $objClipboard->getMode(), IdSerializer::fromModel($model)->getSerialized());
         /** @var AddToUrlEvent $urlAfter */
         $urlAfter = $propagator->propagate(ContaoEvents::BACKEND_ADD_TO_URL, new AddToUrlEvent($add2UrlAfter));
         /** @var AddToUrlEvent $urlInto */
         $urlInto = $propagator->propagate(ContaoEvents::BACKEND_ADD_TO_URL, new AddToUrlEvent($add2UrlInto));
         $buttonEvent = new GetPasteButtonEvent($this->getEnvironment());
         $buttonEvent->setModel($model)->setCircularReference($isCircular)->setPrevious($previous)->setNext($next)->setHrefAfter($urlAfter->getUrl())->setHrefInto($urlInto->getUrl())->setPasteAfterDisabled($objClipboard->isCut() && $isCircular)->setPasteIntoDisabled($objClipboard->isCut() && $isCircular)->setContainedModels($this->getModelsFromClipboard());
         $this->getEnvironment()->getEventPropagator()->propagate($buttonEvent::NAME, $buttonEvent, array($this->getEnvironment()->getDataDefinition()->getName()));
         $arrButtons['pasteafter'] = $this->renderPasteAfterButton($buttonEvent);
         if ($this->getDataDefinition()->getBasicDefinition()->getMode() == BasicDefinitionInterface::MODE_HIERARCHICAL) {
             $arrButtons['pasteinto'] = $this->renderPasteIntoButton($buttonEvent);
         }
     }
     return implode(' ', $arrButtons);
 }
 /**
  * Serialize a model and return its ID.
  *
  * @param ModelInterface $model The model.
  *
  * @return string
  */
 public function serializeModelId(ModelInterface $model)
 {
     $serializer = IdSerializer::fromModel($model);
     return $serializer->getSerialized();
 }