Example #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);
 }
Example #2
0
 /**
  * Get the bread crumb elements.
  *
  * @param GetBreadcrumbEvent $event This event.
  *
  * @return void
  */
 public function getBreadCrumb(GetBreadcrumbEvent $event)
 {
     $environment = $event->getEnvironment();
     $inputProvider = $environment->getInputProvider();
     if (!in_array($inputProvider->getParameter('do'), array('avisota_transport', 'avisota_queue', 'avisota_salutation', 'avisota_recipient_source', 'avisota_mailing_list', 'avisota_theme'), null)) {
         return;
     }
     $baseUrl = new UrlBuilder();
     $baseUrl->setPath('contao/main.php')->setQueryParameter('do', 'avisota_config')->setQueryParameter('ref', TL_REFERER_ID);
     $translator = $environment->getTranslator();
     $event->setElements(array(array('icon' => 'assets/avisota/core/images/avisota-breadcrumb.png', 'text' => $translator->translate('avisota_config.0', 'MOD'), 'url' => $baseUrl->getUrl())));
 }
 /**
  * Get the modal page picker for property url.
  *
  * @param ManipulateWidgetEvent $event The event.
  *
  * @return void
  *
  * @SuppressWarnings(PHPMD.LongVariable)
  */
 public function modalPagePickerForPropertyUrl(ManipulateWidgetEvent $event)
 {
     $environment = $event->getEnvironment();
     $property = $event->getProperty();
     if ($environment->getDataDefinition()->getName() !== 'orm_avisota_message_content' || $property->getName() !== 'url') {
         return;
     }
     $inputProvider = $environment->getInputProvider();
     $entity = $event->getModel()->getEntity();
     $translator = $environment->getTranslator();
     $eventDispatcher = $environment->getEventDispatcher();
     $generateImageHtmlEvent = new GenerateHtmlEvent('pickpage.gif', $translator->translate('pagepicker', 'MSC'), 'style="vertical-align:top; cursor:pointer;"');
     $eventDispatcher->dispatch(ContaoEvents::IMAGE_GET_HTML, $generateImageHtmlEvent);
     $urlBuilder = new UrlBuilder();
     $urlBuilder->setPath('contao/page.php')->setQueryParameter('do', $inputProvider->getParameter('do'))->setQueryParameter('table', $inputProvider->getParameter('table'))->setQueryParameter('field', $property->getName())->setQueryParameter('value', '')->setQueryParameter('switch', '1');
     $event->getWidget()->wizard .= ' <a href="' . $urlBuilder->getUrl() . '" title="' . $translator->translate('pagepicker', 'MSC') . '" onclick="Backend.getScrollOffset();Backend.openModalSelector({\'width\':768,\'title\':\'' . str_replace("'", "\\'", $property->getLabel()) . '\',\'url\':this.href,\'id\':\'' . $property->getName() . '\',\'tag\':\'ctrl_' . $property->getName() . ($inputProvider->getParameter('act') === 'editAll' ? '_' . $entity->getId() : '') . '\',\'self\':this});return false">' . $generateImageHtmlEvent->getHtml() . '</a>';
 }
Example #4
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();
     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);
 }
Example #5
0
 /**
  * Clear the button if the User is not admin.
  *
  * @param GetOperationButtonEvent $event The event.
  *
  * @return void
  */
 public function getOperationButton(GetOperationButtonEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel') {
         return;
     }
     $command = $event->getCommand();
     if ($command->getName() == 'dca_combine') {
         $event->setHref(UrlBuilder::fromUrl($event->getHref())->setQueryParameter('id', ModelId::fromValues('tl_metamodel_dca_combine', $event->getModel()->getId())->getSerialized())->getUrl());
     }
 }
 /**
  * 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);
 }
 /**
  * Handle the event.
  *
  * @param HandleSubmitEvent $event The event.
  *
  * @return void
  */
 public function handleEvent(HandleSubmitEvent $event)
 {
     $dispatcher = func_get_arg(2);
     $currentUrl = $this->environment->get('uri');
     switch ($event->getButtonName()) {
         case 'save':
             // Could be a create action, always redirect to current page with edit action and id properly set.
             $url = UrlBuilder::fromUrl($currentUrl)->setQueryParameter('act', 'edit')->setQueryParameter('id', ModelId::fromModel($event->getModel())->getSerialized());
             $dispatcher->dispatch(ContaoEvents::CONTROLLER_REDIRECT, new RedirectEvent($url->getUrl()));
             break;
         case 'saveNcreate':
             // We want to create a new model, set create action and pass the current id as "after" to keep sorting.
             $after = ModelId::fromModel($event->getModel());
             $url = UrlBuilder::fromUrl($currentUrl)->unsetQueryParameter('id')->setQueryParameter('act', 'create')->setQueryParameter('after', $after->getSerialized());
             $dispatcher->dispatch(ContaoEvents::CONTROLLER_REDIRECT, new RedirectEvent($url->getUrl()));
             break;
         default:
             // Do nothing.
     }
 }
 /**
  * Get backend url.
  *
  * @param array $params
  *
  * @return string
  */
 protected function getBackendUrl(array $params)
 {
     $urlBuilder = new UrlBuilder();
     $urlBuilder->setPath('contao/main.php')->setQueryParameter('do', 'news')->setQueryParameter('table', 'tl_content');
     foreach ($params as $param) {
         $urlBuilder->setQueryParameter($param['name'], $param['value']);
     }
     $urlBuilder->setQueryParameter('rt', REQUEST_TOKEN);
     $urlBuilder->setQueryParameter('ref', TL_REFERER_ID);
     return $urlBuilder->getUrl();
 }
Example #9
0
 /**
  * Get the base URL.
  *
  * @param string[]    $pageDetails The page details.
  *
  * @param null|string $path        Additional path settings.
  *
  * @param bool        $ignoreSSL   If active the system will ignore the 'rootUseSSL' flag.
  *
  * @return UrlBuilder
  */
 private function getBaseUrl($pageDetails, $path = null, $ignoreSSL = false)
 {
     $url = new UrlBuilder();
     // Set the domain (see contao/core#6421)
     if ($pageDetails['domain']) {
         $url->setHost($pageDetails['domain']);
     } else {
         $url->setHost(\Environment::get('host'));
     }
     if ($pageDetails['rootUseSSL'] && !$ignoreSSL) {
         $url->setScheme('https');
     } else {
         $url->setScheme('http');
     }
     // Make a array for the parts.
     $fullPath = array();
     $fullPath[] = TL_PATH;
     // Get the path.
     if ($path === null) {
         $event = new GenerateFrontendUrlEvent($pageDetails, null, $pageDetails['language']);
         $this->getEventDispatcher()->dispatch(ContaoEvents::CONTROLLER_GENERATE_FRONTEND_URL, $event);
         $fullPath[] = $event->getUrl();
     } else {
         $fullPath[] = $path;
     }
     $url->setPath(implode('/', $fullPath));
     return $url;
 }
Example #10
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();
     $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);
 }
Example #11
0
 /**
  * Generate an url from the given parameters.
  *
  * @param string $tableName  The name of the table to link to.
  *
  * @param string $itemId     The id of the item in the given table.
  *
  * @param bool   $keepAction Flag if the "act" and "id" parameter shall be preserved in the URL.
  *
  * @return string The generated URL.
  */
 public function generateUrl($tableName, $itemId, $keepAction = false)
 {
     $urlEvent = new AddToUrlEvent(sprintf('do=metamodels&table=%s&pid=%s', $tableName, $itemId));
     $this->getServiceContainer()->getEventDispatcher()->dispatch(ContaoEvents::BACKEND_ADD_TO_URL, $urlEvent);
     $builder = new UrlBuilder($urlEvent->getUrl());
     if (!$keepAction) {
         $builder->unsetQueryParameter('act');
         $builder->unsetQueryParameter('id');
     }
     return ampersand($builder->getUrl());
 }
Example #12
0
 /**
  * Generate an URL for downloading the given file.
  *
  * @param string $strFile The file that shall be downloaded.
  *
  * @return string
  */
 protected function getDownloadLink($strFile)
 {
     return UrlBuilder::fromUrl(\Environment::get('request'))->setQueryParameter('file', urlencode($strFile))->getUrl();
 }
Example #13
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();
     if ($dataDefinition->getName() !== 'orm_avisota_message_content' || (!$inputProvider->hasParameter('act') || $inputProvider->getParameter('act') === 'create') || !$inputProvider->hasParameter('id')) {
         return;
     }
     $messageContentModelId = ModelId::fromSerialized($inputProvider->getParameter('id'));
     if ($messageContentModelId->getDataProviderName() !== 'orm_avisota_message_content') {
         return;
     }
     $elements = $event->getElements();
     $dataProvider = $environment->getDataProvider($messageContentModelId->getDataProviderName());
     $model = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($messageContentModelId->getId()));
     $messageContent = $model->getEntity();
     $message = $messageContent->getMessage();
     $messageCategory = $message->getCategory();
     $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());
     global $container;
     $entityManager = $container['doctrine.orm.entityManager'];
     $messageMeta = $entityManager->getClassMetadata(get_class($message));
     $messageCategoryMeta = $entityManager->getClassMetadata(get_class($messageCategory));
     $messageContentMeta = $entityManager->getClassMetadata(get_class($messageContent));
     $urlMessageCategoryBuilder = new UrlBuilder();
     $urlMessageCategoryBuilder->setPath('contao/main.php')->setQueryParameter('do', $inputProvider->getParameter('do'))->setQueryParameter('table', $messageMeta->getTableName())->setQueryParameter('pid', ModelId::fromValues($messageCategoryMeta->getTableName(), $messageCategory->getId())->getSerialized())->setQueryParameter('ref', TL_REFERER_ID);
     $elements[] = array('text' => $messageCategory->getTitle(), 'url' => $urlMessageCategoryBuilder->getUrl());
     $urlMessageBuilder = new UrlBuilder();
     $urlMessageBuilder->setPath('contao/main.php')->setQueryParameter('do', $inputProvider->getParameter('do'))->setQueryParameter('table', $messageContentMeta->getTableName())->setQueryParameter('pid', ModelId::fromValues($messageMeta->getTableName(), $message->getId())->getSerialized())->setQueryParameter('ref', TL_REFERER_ID);
     $elements[] = array('text' => $message->getSubject(), 'url' => $urlMessageBuilder->getUrl());
     $event->setElements($elements);
 }