コード例 #1
0
 /**
  * Get the bread crumb elements.
  *
  * @param GetBreadcrumbEvent $event This event.
  *
  * @return void
  *
  * @SuppressWarnings(PHPMD.LongVariable)
  */
 public function getBreadCrumb(GetBreadcrumbEvent $event)
 {
     $environment = $event->getEnvironment();
     $dataDefinition = $environment->getDataDefinition();
     $inputProvider = $environment->getInputProvider();
     $translator = $environment->getTranslator();
     $modelParameter = $inputProvider->hasParameter('act') ? 'id' : 'pid';
     if ($dataDefinition->getName() !== 'orm_avisota_salutation' || !$inputProvider->hasParameter($modelParameter)) {
         return;
     }
     $salutationModelId = ModelId::fromSerialized($inputProvider->getParameter($modelParameter));
     if (!in_array($salutationModelId->getDataProviderName(), array('orm_avisota_salutation', 'orm_avisota_salutation_group'))) {
         return;
     }
     $elements = $event->getElements();
     $urlSalutationBuilder = new UrlBuilder();
     $urlSalutationBuilder->setPath('contao/main.php')->setQueryParameter('do', $inputProvider->getParameter('do'))->setQueryParameter('ref', TL_REFERER_ID);
     $elements[] = array('icon' => 'assets/avisota/salutation/images/salutation.png', 'text' => $translator->translate('avisota_salutation.0', 'MOD'), 'url' => $urlSalutationBuilder->getUrl());
     if ($modelParameter === 'pid') {
         $event->setElements($elements);
         return;
     }
     $urlSalutationGroupBuilder = new UrlBuilder();
     $urlSalutationGroupBuilder->setPath('contao/main.php')->setQueryParameter('do', $inputProvider->getParameter('do'))->setQueryParameter('table', $inputProvider->getParameter('table'))->setQueryParameter('pid', $inputProvider->getParameter('pid'))->setQueryParameter('ref', TL_REFERER_ID);
     $salutationGroupModelId = ModelId::fromSerialized($inputProvider->getParameter('pid'));
     $dataProvider = $environment->getDataProvider($salutationGroupModelId->getDataProviderName());
     $model = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($salutationGroupModelId->getId()));
     $entity = $model->getEntity();
     $elements[] = array('icon' => 'assets/avisota/subscription-recipient/images/recipients.png', 'text' => $entity->getTitle(), 'url' => $urlSalutationGroupBuilder->getUrl());
     $event->setElements($elements);
 }
コード例 #2
0
ファイル: Subscriber.php プロジェクト: HenryLamorski/core
 /**
  * Retrieve the MetaModel attached to the model condition setting.
  *
  * @param EnvironmentInterface $interface The environment.
  *
  * @return \MetaModels\IMetaModel
  */
 public function getMetaModel(EnvironmentInterface $interface)
 {
     $metaModelId = $this->getDatabase()->prepare('SELECT id FROM tl_metamodel WHERE
             id=(SELECT pid FROM tl_metamodel_dca WHERE
             id=(SELECT pid FROM tl_metamodel_dcasetting WHERE id=?))')->execute(ModelId::fromSerialized($interface->getInputProvider()->getParameter('pid'))->getId());
     return $this->getMetaModelById($metaModelId->id);
 }
コード例 #3
0
ファイル: Helper.php プロジェクト: avisota/contao-message
 /**
  * @return MessageCategory|null
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.ShortVariable)
  */
 public static function resolveCategoryFromInput()
 {
     $id = \Input::get('id');
     $pid = \Input::get('pid');
     $modelId = null;
     $parentModelId = null;
     /** @var MessageCategory $category */
     $category = null;
     /** @var Message $message */
     $message = null;
     /** @var MessageContent $content */
     $content = null;
     if ($id) {
         $modelId = ModelId::fromSerialized($id);
     }
     if ($pid) {
         $parentModelId = ModelId::fromSerialized($pid);
     }
     // $id or $pid is a category ID
     if ($modelId && $modelId->getDataProviderName() == 'orm_avisota_message_category') {
         $repository = EntityHelper::getRepository('Avisota\\Contao:MessageCategory');
         $category = $repository->find($modelId->getId());
     } else {
         if ($parentModelId && $parentModelId->getDataProviderName() == 'orm_avisota_message_category') {
             $repository = EntityHelper::getRepository('Avisota\\Contao:MessageCategory');
             $category = $repository->find($parentModelId->getId());
         } else {
             if ($modelId && $modelId->getDataProviderName() == 'orm_avisota_message') {
                 $repository = EntityHelper::getRepository('Avisota\\Contao:Message');
                 $message = $repository->find($modelId->getId());
                 $category = $message->getCategory();
             } else {
                 if ($parentModelId && $parentModelId->getDataProviderName() == 'orm_avisota_message') {
                     $repository = EntityHelper::getRepository('Avisota\\Contao:Message');
                     $message = $repository->find($parentModelId->getId());
                     $category = $message->getCategory();
                 } else {
                     if ($modelId && $modelId->getDataProviderName() == 'orm_avisota_message_content') {
                         $repository = EntityHelper::getRepository('Avisota\\Contao:MessageContent');
                         $content = $repository->find($modelId->getId());
                         $message = $content->getMessage();
                         $category = $message->getCategory();
                     } else {
                         if ($parentModelId && $parentModelId->getDataProviderName() == 'orm_avisota_message_content') {
                             $repository = EntityHelper::getRepository('Avisota\\Contao:MessageContent');
                             $content = $repository->find($parentModelId->getId());
                             $message = $content->getMessage();
                             $category = $message->getCategory();
                         }
                     }
                 }
             }
         }
     }
     return $category;
 }
コード例 #4
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;
 }
コード例 #5
0
ファイル: ParentView.php プロジェクト: zonky2/dc-general
 /**
  * Load the parent model for the current list.
  *
  * @return ModelInterface
  *
  * @throws DcGeneralRuntimeException If the parent view requirements are not fulfilled - either no data provider
  *                                   defined or no parent model id given.
  */
 protected function loadParentModel()
 {
     $environment = $this->getEnvironment();
     $pid = $environment->getInputProvider()->getParameter('pid');
     $pidDetails = ModelId::fromSerialized($pid);
     if (!($objParentProvider = $environment->getDataProvider($pidDetails->getDataProviderName()))) {
         throw new DcGeneralRuntimeException('ParentView needs a proper parent data provider defined, somehow none is defined?', 1);
     }
     $objParentItem = $objParentProvider->fetch($objParentProvider->getEmptyConfig()->setId($pidDetails->getId()));
     if (!$objParentItem) {
         // No parent item found, might have been deleted.
         // We transparently create it for our filter to be able to filter to nothing.
         $objParentItem = $objParentProvider->getEmptyModel();
         $objParentItem->setID($pidDetails->getId());
     }
     return $objParentItem;
 }
コード例 #6
0
 /**
  * Get the bread crumb elements.
  *
  * @param GetBreadcrumbEvent $event This event.
  *
  * @return void
  */
 public function getBreadCrumb(GetBreadcrumbEvent $event)
 {
     $environment = $event->getEnvironment();
     $dataDefinition = $environment->getDataDefinition();
     $inputProvider = $environment->getInputProvider();
     $modelParameter = $inputProvider->hasParameter('act') ? 'id' : 'pid';
     if ($dataDefinition->getName() !== 'orm_avisota_recipient_source' || !$inputProvider->hasParameter($modelParameter)) {
         return;
     }
     $modelId = ModelId::fromSerialized($inputProvider->getParameter($modelParameter));
     if ($modelId->getDataProviderName() !== 'orm_avisota_recipient_source') {
         return;
     }
     $elements = $event->getElements();
     $urlBuilder = new UrlBuilder();
     $urlBuilder->setPath('contao/main.php')->setQueryParameter('do', $inputProvider->getParameter('do'))->setQueryParameter('ref', TL_REFERER_ID);
     $elements[] = array('icon' => 'assets/avisota/core/images/recipient_source.png', 'text' => $GLOBALS['TL_LANG']['MOD']['avisota_recipient_source'][0], 'url' => $urlBuilder->getUrl());
     $event->setElements($elements);
 }
コード例 #7
0
ファイル: Transport.php プロジェクト: avisota/contao-core
 /**
  * Get the bread crumb elements.
  *
  * @param GetBreadcrumbEvent $event This event.
  *
  * @return void
  */
 public function getBreadCrumb(GetBreadcrumbEvent $event)
 {
     $environment = $event->getEnvironment();
     $dataDefinition = $environment->getDataDefinition();
     $inputProvider = $environment->getInputProvider();
     if ($dataDefinition->getName() !== 'orm_avisota_transport' || !$inputProvider->hasParameter('id')) {
         return;
     }
     $modelId = ModelId::fromSerialized($inputProvider->getParameter('id'));
     if ($modelId->getDataProviderName() !== 'orm_avisota_transport') {
         return;
     }
     $elements = $event->getElements();
     $urlBuilder = new UrlBuilder();
     $urlBuilder->setPath('contao/main.php')->setQueryParameter('do', 'avisota_transport')->setQueryParameter('ref', TL_REFERER_ID);
     $translator = $environment->getTranslator();
     $elements[] = array('icon' => 'assets/avisota/core/images/transport.png', 'text' => $translator->translate('avisota_transport.0', 'MOD'), 'url' => $urlBuilder->getUrl());
     $event->setElements($elements);
 }
 /**
  * Handle the action.
  *
  * @return mixed
  *
  * @throws DcGeneralRuntimeException When the definition is not creatable.
  */
 public function process()
 {
     $environment = $this->getEnvironment();
     $event = $this->getEvent();
     $definition = $environment->getDataDefinition();
     $basicDefinition = $definition->getBasicDefinition();
     if (!$basicDefinition->isCreatable()) {
         throw new DcGeneralRuntimeException('DataContainer ' . $definition->getName() . ' is not creatable');
     }
     // We only support flat tables, sorry.
     if (BasicDefinitionInterface::MODE_FLAT !== $basicDefinition->getMode()) {
         return;
     }
     $modelId = ModelId::fromSerialized($environment->getInputProvider()->getParameter('id'));
     $dataProvider = $environment->getDataProvider();
     $model = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($modelId->getId()));
     $clone = $dataProvider->getEmptyModel();
     $editMask = new EditMask($environment, $model, $clone, null, null);
     $event->setResponse($editMask->execute());
 }
コード例 #9
0
ファイル: Preview.php プロジェクト: avisota/contao-message
 /**
  * @param EnvironmentInterface $environment
  *
  * @return string
  * @internal param DC_General $dc
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function renderPreviewView(EnvironmentInterface $environment)
 {
     /** @var EventDispatcher $eventDispatcher */
     $eventDispatcher = $GLOBALS['container']['event-dispatcher'];
     $eventDispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, new LoadLanguageFileEvent('avisota_message_preview'));
     $eventDispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, new LoadLanguageFileEvent('orm_avisota_message'));
     $messageRepository = EntityHelper::getRepository('Avisota\\Contao:Message');
     $messageId = ModelId::fromSerialized(\Input::get('id') ? \Input::get('id') : \Input::get('pid'));
     $message = $messageRepository->find($messageId->getId());
     if (!$message) {
         $eventDispatcher->dispatch(ContaoEvents::CONTROLLER_REDIRECT, new RedirectEvent(preg_replace('#&(act=preview|id=[a-f0-9\\-]+)#', '', \Environment::get('request'))));
     }
     $modules = new StringBuilder();
     /** @var \Avisota\Contao\Message\Core\Send\SendModuleInterface $module */
     foreach ($GLOBALS['AVISOTA_SEND_MODULE'] as $className) {
         $class = new \ReflectionClass($className);
         $module = $class->newInstance();
         $modules->append($module->run($message));
     }
     $context = array('message' => $message, 'modules' => $modules);
     $template = new \TwigTemplate('avisota/backend/preview', 'html5');
     return $template->parse($context);
 }
コード例 #10
0
ファイル: CopyHandler.php プロジェクト: davidmaack/dc-general
 /**
  * {@inheritdoc}
  */
 public function process()
 {
     $event = $this->getEvent();
     if ($event->getAction()->getName() !== 'copy') {
         return;
     }
     $environment = $this->getEnvironment();
     $modelId = ModelId::fromSerialized($environment->getInputProvider()->getParameter('source'));
     $this->guardValidEnvironment($modelId);
     // We want a redirect here if not creatable.
     $this->guardIsCreatable($modelId, true);
     if ($this->isEditOnlyResponse()) {
         return;
     }
     // Manual sorting mode. The ClipboardController should pick it up.
     $manualSortingProperty = ViewHelpers::getManualSortingProperty($environment);
     if ($manualSortingProperty && $this->environment->getDataProvider()->fieldExists($manualSortingProperty)) {
         return;
     }
     $copiedModel = $this->copy($modelId);
     $this->redirect($environment, ModelId::fromModel($copiedModel));
 }
コード例 #11
0
 /**
  * Handle the "create variant" event.
  *
  * @param ActionEvent $event The action Event being executed.
  *
  * @return void
  *
  * @throws \RuntimeException When the base model can not be found.
  * @throws \InvalidArgumentException When the view in the environment is incompatible.
  */
 public function handleCreateVariantAction(ActionEvent $event)
 {
     if ($event->getAction()->getName() != 'createvariant') {
         return;
     }
     $environment = $event->getEnvironment();
     $view = $environment->getView();
     $dataProvider = $environment->getDataProvider();
     $inputProvider = $environment->getInputProvider();
     $modelId = $inputProvider->hasParameter('id') ? ModelId::fromSerialized($inputProvider->getParameter('id')) : null;
     /** @var \MetaModels\DcGeneral\Data\Driver $dataProvider */
     $model = $dataProvider->createVariant($dataProvider->getEmptyConfig()->setId($modelId->getId()));
     if ($model == null) {
         throw new \RuntimeException(sprintf('Could not find model with id %s for creating a variant.', $modelId));
     }
     $metaModel = $this->getServiceContainer()->getFactory()->getMetaModel($model->getProviderName());
     if (!$metaModel || !$metaModel->hasVariants()) {
         return;
     }
     $preFunction = function ($environment, $model) {
         /** @var EnvironmentInterface $environment */
         $copyEvent = new PreCreateModelEvent($environment, $model);
         $environment->getEventDispatcher()->dispatch($copyEvent::NAME, $copyEvent);
     };
     $postFunction = function ($environment, $model) {
         /** @var EnvironmentInterface $environment */
         $copyEvent = new PostCreateModelEvent($environment, $model);
         $environment->getEventDispatcher()->dispatch($copyEvent::NAME, $copyEvent);
     };
     if (!$view instanceof BackendViewInterface) {
         throw new \InvalidArgumentException('Invalid view registered in environment.');
     }
     $editMask = new EditMask($view, $model, null, $preFunction, $postFunction, $this->breadcrumb($environment));
     $event->setResponse($editMask->execute());
 }
コード例 #12
0
ファイル: BaseView.php プロジェクト: zonky2/dc-general
 /**
  * Create the "new" button.
  *
  * @return null|Command
  */
 protected function getCreateModelCommand()
 {
     $environment = $this->getEnvironment();
     $definition = $environment->getDataDefinition();
     $basicDefinition = $definition->getBasicDefinition();
     $providerName = $environment->getDataDefinition()->getName();
     $mode = $basicDefinition->getMode();
     $config = $this->getEnvironment()->getBaseConfigRegistry()->getBaseConfig();
     if ($serializedPid = $environment->getInputProvider()->getParameter('pid')) {
         $pid = ModelId::fromSerialized($serializedPid);
     } else {
         $pid = null;
     }
     if (!$basicDefinition->isCreatable()) {
         return null;
     }
     $command = new Command();
     $parameters = $command->getParameters();
     $extra = $command->getExtra();
     $extra['class'] = 'header_new';
     $extra['accesskey'] = 'n';
     $extra['attributes'] = 'onclick="Backend.getScrollOffset();"';
     $command->setName('button_new')->setLabel($this->translate('new.0', $providerName))->setDescription($this->translate('new.1', $providerName));
     $this->getPanel()->initialize($config);
     // Add new button.
     if ($mode == BasicDefinitionInterface::MODE_PARENTEDLIST || $mode == BasicDefinitionInterface::MODE_HIERARCHICAL) {
         $filter = new Filter();
         $filter->andModelIsFromProvider($basicDefinition->getDataProvider());
         if ($parentDataProviderName = $basicDefinition->getParentDataProvider()) {
             $filter->andParentIsFromProvider($parentDataProviderName);
         } else {
             $filter->andHasNoParent();
         }
         if ($environment->getClipboard()->isNotEmpty($filter)) {
             return null;
         }
     }
     $parameters['act'] = 'create';
     // Add new button.
     if ($pid) {
         $parameters['pid'] = $pid->getSerialized();
     }
     return $command;
 }
コード例 #13
0
ファイル: Subscriber.php プロジェクト: zonky2/core
 /**
  * Handle the add all action event.
  *
  * @param ActionEvent $event The event.
  *
  * @return void
  *
  * @throws \RuntimeException When the MetaModel can not be retrieved.
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 public function handleAddAll(ActionEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_dcasetting') {
         return;
     }
     if ($event->getAction()->getName() !== 'dca_addall') {
         return;
     }
     $environment = $event->getEnvironment();
     $dispatcher = $environment->getEventDispatcher();
     $database = $this->getDatabase();
     $input = $environment->getInputProvider();
     $pid = ModelId::fromSerialized($input->getParameter('pid'));
     $dispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, new LoadLanguageFileEvent('default'));
     $dispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, new LoadLanguageFileEvent('tl_metamodel_dcasetting'));
     $referrer = new GetReferrerEvent(true, 'tl_metamodel_dcasetting');
     $dispatcher->dispatch(ContaoEvents::SYSTEM_GET_REFERRER, $referrer);
     $template = new \BackendTemplate('be_autocreatepalette');
     $template->cacheMessage = '';
     $template->updateMessage = '';
     $template->href = $referrer->getReferrerUrl();
     $template->headline = $GLOBALS['TL_LANG']['tl_metamodel_dcasetting']['addall'][1];
     // Severity is: error, confirm, info, new.
     $messages = array();
     $palette = $database->prepare('SELECT * FROM tl_metamodel_dca WHERE id=?')->execute($pid->getId());
     $metaModel = $this->getMetaModelById($palette->pid);
     if (!$metaModel) {
         throw new \RuntimeException('Could not retrieve MetaModel ' . $palette->pid);
     }
     $alreadyExisting = $database->prepare('SELECT * FROM tl_metamodel_dcasetting WHERE pid=?')->execute($pid->getId());
     $knownAttributes = array();
     $intMax = 128;
     while ($alreadyExisting->next()) {
         $knownAttributes[$alreadyExisting->attr_id] = $alreadyExisting->row();
         if ($intMax < $alreadyExisting->sorting) {
             $intMax = $alreadyExisting->sorting;
         }
     }
     $blnWantPerform = false;
     // Perform the labour work.
     if ($input->getValue('act') == 'perform') {
         $this->perform($metaModel, $knownAttributes, $intMax, $pid->getId(), $messages);
     } else {
         // Loop over all attributes now.
         foreach ($metaModel->getAttributes() as $attribute) {
             if (array_key_exists($attribute->get('id'), $knownAttributes)) {
                 $messages[] = array('severity' => 'info', 'message' => sprintf($GLOBALS['TL_LANG']['tl_metamodel_dcasetting']['addAll_alreadycontained'], $attribute->getName()));
             } else {
                 $messages[] = array('severity' => 'confirm', 'message' => sprintf($GLOBALS['TL_LANG']['tl_metamodel_dcasetting']['addAll_willadd'], $attribute->getName()));
                 $blnWantPerform = true;
             }
         }
     }
     if ($blnWantPerform) {
         $template->action = ampersand(\Environment::get('request'));
         $template->submit = $GLOBALS['TL_LANG']['MSC']['continue'];
     } else {
         $template->action = ampersand($referrer->getReferrerUrl());
         $template->submit = $GLOBALS['TL_LANG']['MSC']['saveNclose'];
     }
     $template->error = $messages;
     $event->setResponse($template->parse());
 }
コード例 #14
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);
     }
 }
コード例 #15
0
 /**
  * Handle "old" add to clipboard actions.
  *
  * @param ActionEvent $event The action event.
  *
  * @return void
  */
 private function addToClipboard(ActionEvent $event)
 {
     $actionName = $event->getAction()->getName();
     $environment = $event->getEnvironment();
     $input = $environment->getInputProvider();
     $clipboard = $environment->getClipboard();
     $parentIdRaw = $input->getParameter('pid');
     if ($parentIdRaw) {
         $parentId = ModelId::fromSerialized($parentIdRaw);
     } else {
         $parentId = null;
     }
     $clipboardActionName = $this->translateActionName($actionName);
     if (!$clipboardActionName) {
         return;
     }
     if ('create' === $actionName) {
         if ($this->isAddingAllowed($environment)) {
             return;
         }
         $providerName = $environment->getDataDefinition()->getBasicDefinition()->getDataProvider();
         $item = new UnsavedItem($clipboardActionName, $parentId, $providerName);
         // Remove other create items, there can only be one create item in the clipboard or many others
         $clipboard->clear();
     } else {
         $modelIdRaw = $input->getParameter('source');
         $modelId = ModelId::fromSerialized($modelIdRaw);
         $filter = new Filter();
         $filter->andActionIs(ItemInterface::CREATE);
         $items = $clipboard->fetch($filter);
         foreach ($items as $item) {
             $clipboard->remove($item);
         }
         // Only push item to clipboard if manual sorting is used.
         if (Item::COPY === $clipboardActionName && !ViewHelpers::getManualSortingProperty($environment)) {
             return;
         }
         // create the new item
         $item = new Item($clipboardActionName, $parentId, $modelId);
     }
     // Let the clipboard save it's values persistent.
     $clipboard->clear()->push($item)->saveTo($environment);
     ViewHelpers::redirectHome($environment);
 }
コード例 #16
0
ファイル: Subscriber.php プロジェクト: metamodels/core
 /**
  * Retrieve the MetaModel attached to the model filter setting.
  *
  * @param EnvironmentInterface $environment The environment.
  *
  * @return \MetaModels\IMetaModel
  */
 public function getMetaModel(EnvironmentInterface $environment)
 {
     $metaModelId = $this->getDatabase()->prepare('SELECT id FROM tl_metamodel WHERE id=(SELECT pid FROM tl_metamodel_dca WHERE id=?)')->execute(ModelId::fromSerialized($environment->getInputProvider()->getParameter('pid'))->getId());
     /** @noinspection PhpUndefinedFieldInspection */
     return $this->getMetaModelById($metaModelId->id);
 }
コード例 #17
0
 /**
  * Handle "old" add to clipboard actions.
  *
  * @param ActionEvent $event The action event.
  *
  * @return void
  */
 private function addToClipboard(ActionEvent $event)
 {
     $actionName = $event->getAction()->getName();
     $environment = $event->getEnvironment();
     $input = $environment->getInputProvider();
     $clipboard = $environment->getClipboard();
     $parentIdRaw = $input->getParameter('pid');
     if ($parentIdRaw) {
         $parentId = ModelId::fromSerialized($parentIdRaw);
     } else {
         $parentId = null;
     }
     $clipboardActionName = $this->translateActionName($actionName);
     if (!$clipboardActionName) {
         return;
     }
     if ('create' === $actionName) {
         $inputProvider = $environment->getInputProvider();
         // No manual sorting property defined, no need to add it to the clipboard.
         // Or we already have an after attribute, a handler can pick it up.
         if (!ViewHelpers::getManualSortingProperty($environment) || $inputProvider->hasParameter('after')) {
             return;
         }
         $providerName = $environment->getDataDefinition()->getBasicDefinition()->getDataProvider();
         $item = new UnsavedItem($clipboardActionName, $parentId, $providerName);
         // Remove other create items, there can only be one create item in the clipboard or many others
         $clipboard->clear();
     } else {
         $modelIdRaw = $input->getParameter('source');
         $modelId = ModelId::fromSerialized($modelIdRaw);
         $filter = new Filter();
         $filter->andActionIs(ItemInterface::CREATE);
         $items = $clipboard->fetch($filter);
         foreach ($items as $item) {
             $clipboard->remove($item);
         }
         // Only push item to clipboard if manual sorting is used.
         if (Item::COPY === $clipboardActionName && !ViewHelpers::getManualSortingProperty($environment)) {
             return;
         }
         // create the new item
         $item = new Item($clipboardActionName, $parentId, $modelId);
     }
     // Let the clipboard save it's values persistent.
     // TODO remove clear and allow adding multiple items
     // Clipboard get cleared twice so far if being in create mode and partially in others. Don't know why it's here.
     $clipboard->clear()->push($item)->saveTo($environment);
     ViewHelpers::redirectHome($environment);
 }
コード例 #18
0
ファイル: ShowHandler.php プロジェクト: davidmaack/dc-general
 /**
  * Handle the show event.
  *
  * @return void
  *
  * @throws DcGeneralRuntimeException  The error.
  */
 public function process()
 {
     $environment = $this->getEnvironment();
     if ($environment->getDataDefinition()->getBasicDefinition()->isEditOnlyMode()) {
         $this->getEvent()->setResponse($environment->getView()->edit($this->getEvent()->getAction()));
         return;
     }
     $translator = $environment->getTranslator();
     $modelId = ModelId::fromSerialized($environment->getInputProvider()->getParameter('id'));
     $dataProvider = $environment->getDataProvider($modelId->getDataProviderName());
     $model = $this->getModel();
     $data = $this->convertModel($model, $environment);
     $headline = $this->getHeadline($model);
     $template = new ContaoBackendViewTemplate('dcbe_general_show');
     $template->set('headline', $headline)->set('arrFields', $data['values'])->set('arrLabels', $data['labels']);
     if ($dataProvider instanceof MultiLanguageDataProviderInterface) {
         $template->set('languages', $environment->getController()->getSupportedLanguages($model->getId()))->set('currentLanguage', $dataProvider->getCurrentLanguage())->set('languageSubmit', specialchars($translator->translate('MSC.showSelected')))->set('backBT', specialchars($translator->translate('MSC.backBT')));
     } else {
         $template->set('languages', null);
     }
     $this->getEvent()->setResponse($template->parse());
 }
コード例 #19
0
ファイル: ModelIdTest.php プロジェクト: zonky2/dc-general
 /**
  * Test valid model ids.
  *
  * @param string      $testId    The id to test.
  *
  * @param string|null $exception The name of the expected exception class.
  *
  * @dataProvider idProvider
  *
  * @return void
  */
 public function testValidIds($testId, $exception = null)
 {
     if (null !== $exception) {
         $this->setExpectedException($exception);
     }
     $this->assertEquals($testId, ModelId::fromSerialized($testId)->getSerialized());
 }
コード例 #20
0
ファイル: Message.php プロジェクト: avisota/contao-message
 /**
  * Get the bread crumb elements.
  *
  * @param GetBreadcrumbEvent $event This event.
  *
  * @return void
  */
 public function getBreadCrumb(GetBreadcrumbEvent $event)
 {
     $environment = $event->getEnvironment();
     $dataDefinition = $environment->getDataDefinition();
     $inputProvider = $environment->getInputProvider();
     $translator = $environment->getTranslator();
     $newsletterParameter = $inputProvider->hasParameter('act') ? 'id' : 'pid';
     if ($dataDefinition->getName() !== 'orm_avisota_message' || !$inputProvider->hasParameter($newsletterParameter)) {
         return;
     }
     $newsletterModelId = ModelId::fromSerialized($inputProvider->getParameter($newsletterParameter));
     if ($newsletterModelId->getDataProviderName() !== 'orm_avisota_message') {
         return;
     }
     $elements = $event->getElements();
     $urlNewsletterBuilder = new UrlBuilder();
     $urlNewsletterBuilder->setPath('contao/main.php')->setQueryParameter('do', $inputProvider->getParameter('do'))->setQueryParameter('ref', TL_REFERER_ID);
     $elements[] = array('icon' => 'assets/avisota/message/images/newsletter.png', 'text' => $translator->translate('avisota_newsletter.0', 'MOD'), 'url' => $urlNewsletterBuilder->getUrl());
     $dataProvider = $environment->getDataProvider($newsletterModelId->getDataProviderName());
     $model = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($newsletterModelId->getId()));
     $newsletter = $model->getEntity();
     $newsletterCategory = $newsletter->getCategory();
     $urlNewsletterBuilder = new UrlBuilder();
     $urlNewsletterBuilder->setPath('contao/main.php')->setQueryParameter('do', $inputProvider->getParameter('do'))->setQueryParameter('table', $newsletterModelId->getDataProviderName())->setQueryParameter('pid', ModelId::fromValues('orm_avisota_message_category', $newsletterCategory->getId())->getSerialized())->setQueryParameter('ref', TL_REFERER_ID);
     $elements[] = array('text' => $newsletterCategory->getTitle(), 'url' => $urlNewsletterBuilder->getUrl());
     $event->setElements($elements);
 }
コード例 #21
0
 /**
  * {@inheritDoc}
  */
 public function fetchModelFromProvider($modelId, $providerName = null)
 {
     if ($providerName === null) {
         if (is_string($modelId)) {
             $modelId = ModelId::fromSerialized($modelId);
         }
     } else {
         $modelId = ModelId::fromValues($providerName, $modelId);
     }
     $dataProvider = $this->getEnvironment()->getDataProvider($modelId->getDataProviderName());
     $item = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($modelId->getId()));
     return $item;
 }
コード例 #22
0
 /**
  * Retrieve the base data provider config for the current data definition.
  *
  * This includes parent filter when in parented list mode and the additional filters from the data definition.
  *
  * @param ModelIdInterface|null $parentId The parent to use.
  *
  * @return ConfigInterface
  */
 private function buildBaseConfig($parentId)
 {
     $environment = $this->getEnvironment();
     $config = $environment->getDataProvider()->getEmptyConfig();
     $definition = $environment->getDataDefinition();
     $additional = $definition->getBasicDefinition()->getAdditionalFilter();
     // Custom filter common for all modes.
     if ($additional) {
         $config->setFilter($additional);
     }
     if (!$config->getSorting()) {
         /** @var Contao2BackendViewDefinitionInterface $viewDefinition */
         $viewDefinition = $definition->getDefinition(Contao2BackendViewDefinitionInterface::NAME);
         $config->setSorting($viewDefinition->getListingConfig()->getDefaultSortingFields());
     }
     // Special filter for certain modes.
     if ($parentId) {
         $this->addParentFilter($parentId, $config);
     } elseif ($definition->getBasicDefinition()->getMode() == BasicDefinitionInterface::MODE_PARENTEDLIST) {
         $pid = $environment->getInputProvider()->getParameter('pid');
         $pidDetails = ModelId::fromSerialized($pid);
         $this->addParentFilter($pidDetails, $config);
     }
     return $config;
 }
コード例 #23
0
 /**
  * Get the parent model id.
  *
  * Returns null if no parent id is given.
  *
  * @return ModelIdInterface|null
  */
 protected function getParentId()
 {
     $parentIdRaw = $this->getEnvironment()->getInputProvider()->getParameter('pid');
     if ($parentIdRaw) {
         $parentId = ModelId::fromSerialized($parentIdRaw);
         return $parentId;
     }
     return null;
 }
コード例 #24
0
ファイル: DeleteHandler.php プロジェクト: designs2/dc-general
 /**
  * {@inheritdoc}
  */
 public function process()
 {
     if ($this->getEvent()->getAction()->getName() !== 'delete') {
         return;
     }
     $environment = $this->getEnvironment();
     $modelId = ModelId::fromSerialized($environment->getInputProvider()->getParameter('id'));
     // Guard that we are in the preloaded environment. Otherwise checking the data definition could belong to
     // another model.
     $this->guardValidEnvironment($modelId);
     // Only edit mode is supported. Trigger an edit action.
     if ($this->isEditOnlyResponse()) {
         return;
     }
     // We want a redirect here if not deletable.
     $this->guardIsDeletable($modelId, true);
     $this->delete($modelId);
     ViewHelpers::redirectHome($this->environment);
 }
コード例 #25
0
 /**
  * Parse the mailing list list.
  *
  * @param EnvironmentInterface $environment The environment.
  *
  * @return string
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.ShortVariable)
  * @SuppressWarnings(PHPMD.LongVariable)
  */
 public function handleListAction(EnvironmentInterface $environment)
 {
     $input = $environment->getInputProvider();
     $id = ModelId::fromSerialized($input->getParameter('id'));
     $repository = EntityHelper::getRepository('Avisota\\Contao:RecipientSource');
     /** @var \Avisota\Contao\Entity\RecipientSource $recipientSourceEntity */
     $recipientSourceEntity = $repository->find($id->getId());
     /** @var RecipientSourceInterface $recipientSource */
     $recipientSource = $GLOBALS['container'][sprintf('avisota.recipientSource.%s', $recipientSourceEntity->getId())];
     if ($input->getValue('page')) {
         /** @var EventDispatcher $eventDispatcher */
         $eventDispatcher = $GLOBALS['container']['event-dispatcher'];
         $addToUrlEvent = new AddToUrlEvent('page=' . (int) $input->getValue('page'));
         $eventDispatcher->dispatch(ContaoEvents::BACKEND_ADD_TO_URL, $addToUrlEvent);
         $redirectEvent = new RedirectEvent($addToUrlEvent->getUrl());
         $eventDispatcher->dispatch(ContaoEvents::CONTROLLER_REDIRECT, $redirectEvent);
     }
     $total = $recipientSource->countRecipients();
     $page = $input->getParameter('page') ?: 0;
     $pages = ceil($total / 30);
     $recipients = $recipientSource->getRecipients(30, $page * 30);
     $template = new \TwigBackendTemplate('avisota/backend/recipient_source_list');
     $template->total = $total;
     $template->page = $page;
     $template->pages = $pages;
     $template->recipients = $recipients;
     return $template->parse();
 }
コード例 #26
0
ファイル: Ajax3X.php プロジェクト: davidmaack/dc-general
 /**
  * Retrieve a model from a serialized id.
  *
  * Exits the script if no model has been found.
  *
  * @param string $serializedId The serialized id.
  *
  * @return ModelInterface
  */
 protected function getModelFromSerializedId($serializedId)
 {
     $modelId = ModelId::fromSerialized($serializedId);
     $dataProvider = $this->getEnvironment()->getDataProvider($modelId->getDataProviderName());
     $model = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($modelId->getId()));
     if ($model === null) {
         $event = new LogEvent('A record with the ID "' . $serializedId . '" does not exist in "' . $this->getEnvironment()->getDataDefinition()->getName() . '"', 'Ajax executePostActions()', TL_ERROR);
         $this->getEnvironment()->getEventDispatcher()->dispatch(ContaoEvents::SYSTEM_LOG, $event);
         header('HTTP/1.1 400 Bad Request');
         echo 'Bad Request';
         $this->exitScript();
     }
     return $model;
 }
コード例 #27
0
 /**
  * {@inheritDoc}
  *
  * @throws \InvalidArgumentException When the model id is invalid.
  */
 public function fetchModelFromProvider($modelId, $providerName = null)
 {
     if ($providerName === null) {
         if (is_string($modelId)) {
             $modelId = ModelId::fromSerialized($modelId);
         }
     } else {
         $modelId = ModelId::fromValues($providerName, $modelId);
     }
     if (!$modelId instanceof ModelIdInterface) {
         throw new \InvalidArgumentException('Invalid model id passed: ' . var_export($modelId, true));
     }
     $dataProvider = $this->getEnvironment()->getDataProvider($modelId->getDataProviderName());
     $item = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($modelId->getId()));
     return $item;
 }
コード例 #28
0
ファイル: PasteHandler.php プロジェクト: zonky2/dc-general
 /**
  * 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;
 }
コード例 #29
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());
 }
コード例 #30
0
ファイル: BreadCrumbBase.php プロジェクト: zonky2/core
 /**
  * Extract the id value from the serialized parameter with the given name.
  *
  * @param EnvironmentInterface $environment   The environment.
  *
  * @param string               $parameterName The parameter name containing the id.
  *
  * @return int
  */
 protected function extractIdFrom(EnvironmentInterface $environment, $parameterName = 'pid')
 {
     $parameter = $environment->getInputProvider()->getParameter($parameterName);
     return ModelId::fromSerialized($parameter)->getId();
 }