Ejemplo n.º 1
0
 /**
  * Load the parent model for the current list.
  *
  * @param InputProviderInterface $input       The input provider.
  *
  * @param EnvironmentInterface   $environment The environment.
  *
  * @return ModelInterface|null
  */
 protected function loadParentModel(InputProviderInterface $input, EnvironmentInterface $environment)
 {
     if (!$input->hasParameter('pid')) {
         return null;
     }
     $pid = ModelId::fromSerialized($input->getParameter('pid'));
     if (!($dataProvider = $environment->getDataProvider($pid->getDataProviderName()))) {
         return null;
     }
     if ($parent = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($pid->getId()))) {
         return $parent;
     }
     return null;
 }
Ejemplo n.º 2
0
 /**
  * Handle the action event.
  *
  * @param ActionEvent $event The event to handle.
  *
  * @return void
  *
  * @throws \RuntimeException When the MetaModel could not be determined.
  */
 public function handleActionEvent(ActionEvent $event)
 {
     $environment = $event->getEnvironment();
     if ($environment->getDataDefinition()->getName() !== static::$table) {
         return;
     }
     if ($event->getAction()->getName() !== static::$actionName) {
         return;
     }
     $this->input = $environment->getInputProvider();
     $referrer = new GetReferrerEvent(true, static::$table);
     $this->dispatcher->dispatch(ContaoEvents::SYSTEM_GET_REFERRER, $referrer);
     $this->environment = $environment;
     $this->translator = $environment->getTranslator();
     $pid = ModelId::fromSerialized($this->input->getParameter('pid'))->getId();
     $this->metaModel = $this->getMetaModelById($this->database->prepare('SELECT * FROM ' . static::$ptable . ' WHERE id=?')->execute($pid)->pid);
     if (!$this->metaModel) {
         throw new \RuntimeException('Could not retrieve MetaModel from ' . $this->input->getParameter('pid'));
     }
     $startSort = 0;
     $this->knownAttributes = array();
     $alreadyExisting = $this->database->prepare('SELECT * FROM ' . static::$table . ' WHERE pid=? ORDER BY sorting ASC')->execute($pid);
     while ($alreadyExisting->next()) {
         $this->knownAttributes[$alreadyExisting->attr_id] = $alreadyExisting->row();
         // Keep the sorting value.
         $startSort = $alreadyExisting->sorting;
     }
     if ($this->input->hasValue('add') || $this->input->hasValue('saveNclose')) {
         $this->perform($startSort + 128, $pid);
     }
     if ($this->input->hasValue('saveNclose')) {
         \Controller::redirect($referrer->getReferrerUrl());
     }
     $this->template = new \BackendTemplate('be_addallattributes');
     $this->template->href = $referrer->getReferrerUrl();
     $this->template->backBt = $this->translator->translate('MSC.backBT');
     $this->template->add = $this->translator->translate('MSC.continue');
     $this->template->saveNclose = $this->translator->translate('MSC.saveNclose');
     $this->template->headline = $this->translator->translate('addall.1', static::$table);
     $this->template->selectAll = $this->translator->translate('MSC.selectAll');
     $this->template->cacheMessage = '';
     $this->template->updateMessage = '';
     $this->template->hasCheckbox = false;
     $this->template->fields = $this->generateForm();
     $event->setResponse($this->template->parse());
 }
Ejemplo n.º 3
0
 /**
  * Obtain the parameter with the given name from the input provider if it exists.
  *
  * @param InputProviderInterface $input The input provider.
  * @param string                 $name  The parameter to retrieve.
  *
  * @return ModelId|null
  */
 private function modelIdFromParameter(InputProviderInterface $input, $name)
 {
     if ($input->hasParameter($name) && ($value = $input->getParameter($name))) {
         return ModelId::fromSerialized($value);
     }
     return null;
 }
Ejemplo n.º 4
0
 /**
  * Handle paste after.
  *
  * @param InputProviderInterface $input      The input provider.
  *
  * @param ControllerInterface    $controller The controller.
  *
  * @param ModelInterface         $model      The model.
  *
  * @return void
  */
 private function handleAfter(InputProviderInterface $input, ControllerInterface $controller, ModelInterface $model)
 {
     $after = ModelId::fromSerialized($input->getParameter('after'));
     $sibling = $controller->fetchModelFromProvider($after);
     if (!$sibling || $controller->isRootModel($sibling)) {
         $controller->setRootModel($model);
     } else {
         $parent = $controller->searchParentOf($sibling);
         $controller->setParent($model, $parent);
     }
 }
Ejemplo n.º 5
0
 /**
  * Check if the given table is the current table.
  *
  * @param string                 $table The name of the table.
  *
  * @param InputProviderInterface $input The input provider in use.
  *
  * @return bool
  */
 protected function isActiveTable($table, InputProviderInterface $input)
 {
     return $input->getParameter('table') == $table;
 }