/** * @param DC_General $dc */ 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')); $input = \Input::getInstance(); $messageRepository = EntityHelper::getRepository('Avisota\\Contao:Message'); $messageId = IdSerializer::fromSerialized($input->get('id') ? $input->get('id') : $input->get('pid')); $message = $messageRepository->find($messageId->getId()); if (!$message) { $environment = \Environment::getInstance(); $eventDispatcher->dispatch(ContaoEvents::CONTROLLER_REDIRECT, new RedirectEvent(preg_replace('#&(act=preview|id=[a-f0-9\\-]+)#', '', $environment->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); }
/** * @SuppressWarnings(PHPMD.LongVariable) */ public function injectMenu() { global $container, $TL_LANG; // initialize the entity manager and class loaders $container['doctrine.orm.entityManager']; $beModules = array(); if (class_exists('Avisota\\Contao\\Entity\\MessageCategory')) { try { $messageCategoryRepository = EntityHelper::getRepository('Avisota\\Contao:MessageCategory'); $queryBuilder = $messageCategoryRepository->createQueryBuilder('mc'); $queryBuilder->select('mc')->where('mc.showInMenu=:showInMenu')->setParameter('showInMenu', true)->orderBy('mc.title'); $query = $queryBuilder->getQuery(); /** @var MessageCategory[] $messageCategories */ $messageCategories = $query->getResult(); foreach ($messageCategories as $messageCategory) { $id = $messageCategory->getId(); $icon = $messageCategory->getUseCustomMenuIcon() ? $messageCategory->getMenuIcon() : 'assets/avisota/message/images/newsletter.png'; $title = $messageCategory->getTitle(); $beModules['avisota_category_' . $id] = array('callback' => 'Avisota\\Contao\\Message\\Core\\Backend\\CustomMenu', 'icon' => $icon); $TL_LANG['MOD']['avisota_category_' . $id] = array($title); } } catch (\Exception $e) { // silently ignore } } if (count($beModules)) { $GLOBALS['BE_MOD']['avisota'] = array_merge($beModules, $GLOBALS['BE_MOD']['avisota']); } }
/** * @param string $methodName * @param array $args */ public function load($entities, DcCompat $compat) { $providerName = $compat->getModel()->getProviderName(); $enviroment = $compat->getEnvironment(); /** @var EntityDataProvider $dataProvider */ $dataProvider = $enviroment->getDataProvider($providerName); $entityManager = $dataProvider->getEntityManager(); $metaFactory = $entityManager->getMetadataFactory(); $metaData = $metaFactory->getMetadataFor($dataProvider->getEntityRepository()->getClassName()); $associationNames = $metaData->getAssociationNames(); $entityAccessor = EntityHelper::getEntityAccessor(); $ids = array(); if (is_array($entities) || $entities instanceof \Traversable) { foreach ($entities as $entity) { if (is_object($entity)) { $ids[] = $entityAccessor->getPrimaryKey($entity); continue; } if (!empty($associationNames) && in_array($compat->getPropertyName(), $associationNames)) { $ids[] = $entity; } } } return $ids; }
/** * @return EntityRepository */ public function getEntityRepository() { if (!$this->entityRepository) { $this->entityRepository = EntityHelper::getRepository($this->entityClassName); } return $this->entityRepository; }
/** * Auto-Generate an alias for an entity. * * @param string $alias * @param \DC_General $dc * * @return string * @throws Exception */ public static function generateAlias($alias, \DC_General $dc) { /** @var EntityInterface $entity */ $entity = $dc->getCurrentModel()->getEntity(); $autoAlias = false; // Generate alias if there is none if (!strlen($alias)) { $autoAlias = true; if ($entity->__has('title')) { $alias = standardize($entity->getTitle()); } elseif ($entity->__has('name')) { $alias = standardize($entity->getName()); } else { return ''; } } $entityClass = new \ReflectionClass($entity); $keys = explode(',', $entityClass->getConstant('KEY')); $entityManager = EntityHelper::getEntityManager(); $queryBuilder = $entityManager->createQueryBuilder(); $queryBuilder->select('COUNT(e.' . $keys[0] . ')')->from($entityClass->getName(), 'e')->where($queryBuilder->expr()->eq('e.alias', ':alias'))->setParameter(':alias', $alias); static::extendQueryWhereId($queryBuilder, $dc->getCurrentModel()->getID(), $entity); $query = $queryBuilder->getQuery(); $duplicateCount = $query->getResult(Query::HYDRATE_SINGLE_SCALAR); // Check whether the news alias exists if ($duplicateCount && !$autoAlias) { throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $alias)); } // Add ID to alias if ($duplicateCount && $autoAlias) { $alias .= '-' . $dc->getCurrentModel()->getID(); } return $alias; }
/** * Compile the current element. * * @return void * * @SuppressWarnings(PHPMD.Superglobals) */ protected function compile() { /** @var EventDispatcher $eventDispatcher */ $eventDispatcher = $GLOBALS['container']['event-dispatcher']; $eventDispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, new LoadLanguageFileEvent('avisota_outbox')); $queueRepository = EntityHelper::getRepository('Avisota\\Contao:Queue'); $this->executeQueue($queueRepository); $this->addQueuesToTemplate($queueRepository); }
/** * @return MessageCategory|null */ public static function resolveCategoryFromInput() { $input = \Input::getInstance(); $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 = IdSerializer::fromSerialized($id); } if ($pid) { $parentModelId = IdSerializer::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; }
/** * @param array $options * * @return array * @SuppressWarnings(PHPMD.LongVariable) */ public function getMessageCategoryOptions($options = array()) { $messageCategoryRepository = EntityHelper::getRepository('Avisota\\Contao:MessageCategory'); $messageCategories = $messageCategoryRepository->findBy(array(), array('title' => 'ASC')); /** @var \Avisota\Contao\Entity\MessageCategory $messageCategory */ foreach ($messageCategories as $messageCategory) { $options[$messageCategory->getId()] = $messageCategory->getTitle(); } return $options; }
public static function getSalutationGroupOptions() { $arrOptions = array(); $salutationGroupRepository = \Contao\Doctrine\ORM\EntityHelper::getRepository('Avisota\\Contao:SalutationGroup'); /** @var SalutationGroup[] $salutationGroups */ $salutationGroups = $salutationGroupRepository->findAll(); foreach ($salutationGroups as $salutationGroup) { $arrOptions[$salutationGroup->getId()] = $salutationGroup->getTitle(); } return $arrOptions; }
/** * Load multiple mailing lists by ID. * * @param $mailingListIds * * @return array|MailingList[] * @SuppressWarnings(PHPMD.LongVariable) */ protected function loadMailingLists($mailingListIds) { // Todo if the variable $mailingLists in use #$mailingLists = array(); $mailingListRepository = EntityHelper::getRepository('Avisota\\Contao:MailingList'); $queryBuilder = $mailingListRepository->createQueryBuilder('ml'); $expr = $queryBuilder->expr(); $queryBuilder->select('ml')->where($expr->in('ml.id', ':ids'))->setParameter('ids', $mailingListIds); $query = $queryBuilder->getQuery(); /** @var MailingList[] $result */ return $query->getResult(); }
/** * @param CollectSubscriptionListsEvent $event * @SuppressWarnings(PHPMD.LongVariable) * TODO is this method really in use */ public static function collectSubscriptionLists(CollectSubscriptionListsEvent $event) { $mailingListRepository = EntityHelper::getRepository('Avisota\\Contao:MailingList'); /** @var MailingList[] $mailingLists */ $mailingLists = $mailingListRepository->findAll(); $mailingListOptions = array(); foreach ($mailingLists as $mailingList) { $mailingListOptions['mailing_list:' . $mailingList->id()] = $mailingList->getTitle(); } $options = $event->getOptions(); $options['mailing_list'] = $mailingListOptions; }
/** * @param ResolveRecipientEvent $event */ public function resolveRecipient(ResolveRecipientEvent $event) { // some other event listener has already resolved the recipient if ($event->getRecipient()) { return; } $subscription = $event->getSubscription(); if ($subscription->getRecipientType() == 'Avisota\\Contao\\Entity\\Recipient') { $entityManager = EntityHelper::getEntityManager(); $repository = $entityManager->getRepository('Avisota\\Contao\\Entity\\Recipient'); $recipient = $repository->find($subscription->getRecipientId()); $event->setRecipient($recipient); } }
/** * @param null $limit * @param null $offset * * @return array * @SuppressWarnings(PHPMD.CamelCaseVariableName) */ public function getRecipients($limit = null, $offset = null) { global $container, $TL_LANG; $queryBuilder = EntityHelper::getEntityManager()->createQueryBuilder(); $queryBuilder->select('r')->from('Avisota\\Contao:Recipient', 'r'); $this->prepareQuery($queryBuilder); if ($limit > 0) { $queryBuilder->setMaxResults($limit); } if ($offset > 0) { $queryBuilder->setFirstResult($offset); } $queryBuilder->orderBy('r.email'); $query = $queryBuilder->getQuery(); $recipients = $query->getResult(); $entityAccessor = EntityHelper::getEntityAccessor(); $mutableRecipients = array(); /** @var EventDispatcherInterface $eventDispatcher */ $eventDispatcher = $container['event-dispatcher']; /** @var Recipient $recipient */ foreach ($recipients as $recipient) { $properties = $entityAccessor->getPublicProperties($recipient, true); if ($this->manageSubscriptionUrlPattern) { $loadLanguageEvent = new LoadLanguageFileEvent('fe_avisota_subscription'); $eventDispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, $loadLanguageEvent); $url = $this->manageSubscriptionUrlPattern; $url = preg_replace_callback('~##([^#]+)##~', function ($matches) use($properties) { if (isset($properties[$matches[1]])) { return $properties[$matches[1]]; } return $matches[0]; }, $url); $properties['manage_subscription_link'] = array('url' => $url, 'text' => &$TL_LANG['fe_avisota_subscription']['manage_subscription']); } if ($this->unsubscribeUrlPattern) { $loadLanguageEvent = new LoadLanguageFileEvent('fe_avisota_subscription'); $eventDispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, $loadLanguageEvent); $url = $this->unsubscribeUrlPattern; $url = preg_replace_callback('~##([^#]+)##~', function ($matches) use($properties) { if (isset($properties[$matches[1]])) { return $properties[$matches[1]]; } return $matches[0]; }, $url); $properties['unsubscribe_link'] = array('url' => $url, 'text' => &$TL_LANG['fe_avisota_subscription']['unsubscribe_direct']); } $mutableRecipients[] = new MutableRecipient($recipient->getEmail(), $properties); } return $mutableRecipients; }
/** * Compile the current element * @SuppressWarnings(PHPMD.Superglobals) * @SuppressWarnings(PHPMD.LongVariable) */ protected function compile() { if (TL_MODE == 'BE') { return; } if (\Config::get('useAutoItem') && \Input::get('auto_item')) { $messageAlias = \Input::get('auto_item'); } else { $messageAlias = \Input::get('items'); } $repository = EntityHelper::getRepository('Avisota\\Contao:Message'); $queryBuilder = $repository->createQueryBuilder('m'); $expr = $queryBuilder->expr(); $queryBuilder->innerJoin('m.category', 'c')->where($expr->eq(is_numeric($messageAlias) ? 'm.id' : 'm.alias', ':alias'))->andWhere($expr->in('c.id', ':categories'))->andWhere($expr->gt('m.sendOn', 0))->orderBy('m.sendOn', 'DESC')->setParameter('alias', $messageAlias)->setParameter('categories', deserialize($this->avisota_message_categories, true)); $query = $queryBuilder->getQuery(); try { $message = $query->getSingleResult(); $repository = EntityHelper::getRepository('Avisota\\Contao:Layout'); $layout = $repository->find($this->avisota_message_layout); $cells = deserialize($this->avisota_message_cell, true); $contents = array(); /** @var EventDispatcherInterface $eventDispatcher */ $eventDispatcher = $GLOBALS['container']['event-dispatcher']; $event = new CreatePublicEmptyRecipientEvent($message); $eventDispatcher->dispatch(CoreEvents::CREATE_PUBLIC_EMPTY_RECIPIENT, $event); $recipient = $event->getRecipient(); if (!isset($additionalData['recipient'])) { /** @var SynonymizerService $synonymizer */ $synonymizer = $GLOBALS['container']['avisota.recipient.synonymizer']; $additionalData['recipient'] = $synonymizer->expandDetailsWithSynonyms($recipient); } $additionalData['_recipient'] = $recipient; /** @var TagReplacementService $tagReplacementService */ $tagReplacementService = $GLOBALS['container']['avisota.message.tagReplacementEngine']; foreach ($cells as $cell) { /** @var MessageRenderer $renderer */ $renderer = $GLOBALS['container']['avisota.message.renderer']; $content = $renderer->renderCell($message, $cell, $layout); $content = array_map(function ($content) use($tagReplacementService, $additionalData) { return $tagReplacementService->parse($content, $additionalData); }, (array) $content); $contents[$cell] = $content; } $this->Template->message = $message; $this->Template->contents = $contents; } catch (NoResultException $e) { $objHandler = new $GLOBALS['TL_PTY']['error_404'](); $objHandler->generate($GLOBALS['objPage']->id); } }
/** * {@inheritdoc} */ protected function compile() { $repository = EntityHelper::getRepository('Avisota\\Contao:Message'); $queryBuilder = $repository->createQueryBuilder('m'); $expr = $queryBuilder->expr(); $queryBuilder->innerJoin('m.category', 'c')->where($expr->in('c.id', ':categories'))->andWhere($expr->gt('m.sendOn', 0))->orderBy('m.sendOn', 'DESC')->setParameter('categories', deserialize($this->avisota_message_categories, true)); $query = $queryBuilder->getQuery(); $messages = $query->getResult(); $jumpTo = \PageModel::findByPk($this->jumpTo); if (!$jumpTo) { $jumpTo = $GLOBALS['objPage']; } $this->Template->messages = $messages; $this->Template->jumpTo = $jumpTo->row(); }
/** * @SuppressWarnings(PHPMD.ExitExpression) */ public function run() { $messageRepository = EntityHelper::getRepository('Avisota\\Contao:Message'); $messageId = \Input::get('id'); $message = $messageRepository->find($messageId); /** @var \Avisota\Contao\Entity\Message $message */ if (!$message) { header("HTTP/1.0 404 Not Found"); echo '<h1>404 Not Found</h1>'; exit; } $user = \BackendUser::getInstance(); $user->authenticate(); $this->execute($message, $user); }
/** * {@inheritdoc} */ public function renderCell(Message $message, $cell, Layout $layout = null) { $messageContentRepository = EntityHelper::getRepository('Avisota\\Contao:MessageContent'); $queryBuilder = $messageContentRepository->createQueryBuilder('mc'); $queryBuilder->select('mc')->where('mc.message=:message')->andWhere('mc.cell=:cell')->orderBy('mc.sorting')->setParameter('message', $message->getId())->setParameter('cell', $cell); if (TL_MODE != 'BE' && (!defined('BE_USER_LOGGED_IN') || !BE_USER_LOGGED_IN)) { $queryBuilder->andWhere('mc.invisible=:invisible')->setParameter('invisible', false); } $query = $queryBuilder->getQuery(); $contents = $query->getResult(); $elements = array(); foreach ($contents as $content) { $elements[] = $this->renderContent($content, $layout ?: $message->getLayout()); } return $elements; }
/** * @param ModelInterface $objItem * * @return ModelInterface|void * @SuppressWarnings(PHPMD.ExitExpression) */ public function save(ModelInterface $objItem) { $exportSettings = $objItem->getPropertiesAsArray(); $session = \Session::getInstance(); $recipientRepository = EntityHelper::getRepository('Avisota\\Contao:Recipient'); $session->set(static::SESSION_NAME, $exportSettings); switch ($exportSettings['delimiter']) { case 'semicolon': $delimiter = ';'; break; case 'space': $delimiter = ' '; break; case 'tabulator': $delimiter = "\t"; break; case 'linebreak': $delimiter = "\n"; break; default: $delimiter = ','; } switch ($exportSettings['enclosure']) { case 'single': $enclosure = "'"; break; default: $enclosure = '"'; } $length = 0; $csv = tmpfile(); $recipients = $recipientRepository->findAll(); /** @var Recipient $recipient */ foreach ($recipients as $recipient) { $row = $this->generateCSVRows($recipient, $exportSettings); $length += fputcsv($csv, $row, $delimiter, $enclosure); } if (!headers_sent()) { header('Content-Type: text/csv; charset=utf-8'); header('Content-Length: ' . $length); header('Content-Disposition: attachment; filename="export.csv"'); } rewind($csv); fpassthru($csv); fclose($csv); exit; }
public function captureSendImmediate(PostSendImmediateEvent $event) { $entityManager = EntityHelper::getEntityManager(); $historyRepository = $entityManager->getRepository('Avisota\\Contao\\Entity\\MessageHistory'); // get the history $loop = $event->getLoop(); if ($loop) { $history = $historyRepository->findOneBy(array('loop' => $loop)); } //create a new history if none was found if (!$history) { $history = new MessageHistory(); $history->setMessage($event->getMessage()); $history->setLoop($event->getLoop()); } $history->setMailCount($history->getMailCount() + $event->getCount()); $entityManager->persist($history); }
/** * @SuppressWarnings(PHPMD.LongVariable) */ public function regenerateDynamics() { $dynamics = array(); // $mailingListRepository = EntityHelper::getRepository('Avisota\Contao:MailingList'); $recipientSourceRepository = EntityHelper::getRepository('Avisota\\Contao:RecipientSource'); // $themeRepository = EntityHelper::getRepository('Avisota\Contao:Theme'); $transportRepository = EntityHelper::getRepository('Avisota\\Contao:Transport'); $queueRepository = EntityHelper::getRepository('Avisota\\Contao:Queue'); /** @var EntityRepository[] $repositories */ $repositories = array($queueRepository, $recipientSourceRepository, $transportRepository); foreach ($repositories as $repository) { $entityName = $repository->getClassName(); $entityName = str_replace('Avisota\\Contao\\Entity\\', '', $entityName); $entityName = lcfirst($entityName); $entities = $repository->findAll(); $dynamics[$entityName] = array(); foreach ($entities as $entity) { /** @noinspection PhpUndefinedMethodInspection */ $dynamics[$entityName][] = array('id' => $entity->id(), 'alias' => $entity->getAlias(), 'title' => $entity->getTitle()); } } $queryBuilder = EntityHelper::getEntityManager()->createQueryBuilder(); $query = $queryBuilder->select('c')->from('Avisota\\Contao:MessageCategory', 'c')->where('c.showInMenu=:showInMenu')->andWhere('c.boilerplates=:boilerplates')->setParameter(':showInMenu', true)->setParameter(':boilerplates', false)->orderBy('c.title')->getQuery(); $categories = $query->getResult(); $dynamics['category'] = array(); /** @var MessageCategory $category */ foreach ($categories as $category) { /** @noinspection PhpUndefinedMethodInspection */ $dynamics['category'][] = array('id' => $category->id(), 'label' => $category->getTitle(), 'icon' => $category->getUseCustomMenuIcon() ? $category->getMenuIcon() : false); } $array = var_export($dynamics, true); $fileContents = <<<EOF <?php return {$array}; EOF; $tempFile = new \File('system/modules/avisota/config/dynamics.php'); $tempFile->write($fileContents); $tempFile->close(); }
public function run(Request $request) { $queueRepository = \Contao\Doctrine\ORM\EntityHelper::getRepository('Avisota\\Contao:Queue'); $queueId = $request->get('id'); $queue = $queueRepository->find($queueId); /** @var \Avisota\Contao\Entity\Queue $queue */ if (!$queue) { header("HTTP/1.0 404 Not Found"); echo '<h1>404 Not Found</h1>'; exit; } $user = \BackendUser::getInstance(); $user->authenticate(); try { return $this->execute($request, $queue, $user); } catch (\Exception $exception) { $response = new JsonResponse(array('error' => sprintf('%s in %s:%d', $exception->getMessage(), $exception->getFile(), $exception->getLine())), 500); $response->prepare($request); return $response; } }
public function addHeader($add, $dc) { // TODO refactore for DCG return; $newsletterCategoryRepository = EntityHelper::getRepository('Avisota\\Contao:MessageCategory'); /** @var \Avisota\Contao\Entity\MessageCategory $newsletterCategory */ $newsletterCategory = $newsletterCategoryRepository->find($dc->id); $key = $GLOBALS['TL_LANG']['orm_avisota_message_category']['recipients'][0]; if (!$newsletterCategory->getBoilerplates() && $newsletterCategory->getRecipientsMode() != 'byMessage') { $fallback = $newsletterCategory->getRecipientsMode() == 'byMessageOrCategory'; /** @var RecipientSource $recipientSource */ $recipientSource = $newsletterCategory->getRecipients(); if ($recipientSource) { $add[$key] = sprintf('<a href="contao/main.php?do=avisota_recipient_source&act=edit&id=%d">%s</a>%s', $recipientSource->getId(), $recipientSource->getTitle(), $fallback ? ' ' . $GLOBALS['TL_LANG']['orm_avisota_message']['fallback'] : ''); } else { unset($add[$key]); } } else { unset($add[$key]); } $key = $GLOBALS['TL_LANG']['orm_avisota_message_category']['layout'][0]; if (!$newsletterCategory->getBoilerplates() && $newsletterCategory->getLayoutMode() != 'byMessage') { $add[$key] = $newsletterCategory->getLayout()->getTitle(); if ($newsletterCategory->getLayoutMode() == 'byMessageOrCategory') { $add[$key] .= ' ' . $GLOBALS['TL_LANG']['orm_avisota_message']['fallback']; } } else { unset($add[$key]); } $key = $GLOBALS['TL_LANG']['orm_avisota_message_category']['queue'][0]; if (!$newsletterCategory->getBoilerplates() && $newsletterCategory->getQueueMode() != 'byMessage') { $add[$key] = $newsletterCategory->getQueue()->getTitle(); if ($newsletterCategory->getQueueMode() == 'byMessageOrCategory') { $add[$key] .= ' ' . $GLOBALS['TL_LANG']['orm_avisota_message']['fallback']; } } else { unset($add[$key]); } return $add; }
public function handleAction(ActionEvent $event) { $environment = $event->getEnvironment(); if ($environment->getDataDefinition()->getName() != 'orm_avisota_queue') { return; } $action = $event->getAction(); if ($action->getName() == 'clear') { $input = $environment->getInputProvider(); $id = IdSerializer::fromSerialized($input->getParameter('id')); $repository = EntityHelper::getRepository('Avisota\\Contao:Queue'); /** @var \Avisota\Contao\Entity\Queue $queueData */ $queueData = $repository->find($id->getId()); /** @var QueueInterface $queue */ $queue = $GLOBALS['container'][sprintf('avisota.queue.%s', $queueData->getAlias())]; $queue->execute(new NullTransport()); $message = new AddMessageEvent(sprintf($GLOBALS['TL_LANG']['orm_avisota_queue']['queueCleared'], $queueData->getTitle()), AddMessageEvent::TYPE_CONFIRM); $event->getDispatcher()->dispatch(ContaoEvents::MESSAGE_ADD, $message); $redirect = new RedirectEvent('contao/main.php?do=avisota_queue&ref=' . TL_REFERER_ID); $event->getDispatcher()->dispatch(ContaoEvents::CONTROLLER_REDIRECT, $redirect); } }
/** * Return the "toggle visibility" button * * @param array * @param string * @param string * @param string * @param string * @param string * * @return string * @SuppressWarnings(PHPMD.ShortVariable) * @SuppressWarnings(PHPMD.LongVariable) */ public function toggleIcon($row, $href, $label, $title, $icon, $attributes) { $subscriptionRepository = EntityHelper::getRepository('Avisota\\Contao:Subscription'); /** @var \Avisota\Contao\Entity\Subscription $subscription */ if (strlen(\Input::get('tid'))) { $id = \Input::get('tid'); $confirmed = \Input::get('state') == 1; /** @var \Avisota\Contao\Entity\Subscription $subscription */ $subscription = $subscriptionRepository->find($id); $subscription->setConfirmed($confirmed); $entityManager = EntityHelper::getEntityManager(); $entityManager->persist($subscription); $entityManager->flush($subscription); $this->redirect($this->getReferer()); } $subscription = $subscriptionRepository->findOneBy(array('recipient' => $row['recipient'], 'list' => $row['list'])); $href .= '&tid=' . $subscription->id() . '&state=' . ($row['confirmed'] ? '' : 1); if (!$row['confirmed']) { $icon = 'invisible.gif'; } return '<a href="' . $this->addToUrl($href) . '" title="' . specialchars($title) . '"' . $attributes . '>' . $this->generateImage($icon, $label) . '</a> '; }
public function run() { global $container; $general = new \ContaoCommunityAlliance\DcGeneral\DC_General('orm_avisota_message'); $environment = $general->getEnvironment(); $translator = $environment->getTranslator(); /** @var \Symfony\Component\EventDispatcher\EventDispatcher $eventDispatcher */ $eventDispatcher = $GLOBALS['container']['event-dispatcher']; $messageRepository = \Contao\Doctrine\ORM\EntityHelper::getRepository('Avisota\\Contao:Message'); $messageId = \Input::get('id'); /** @var \Avisota\Contao\Entity\Message $message */ $message = $messageRepository->find($messageId); if (!$message) { header("HTTP/1.0 404 Not Found"); echo '<h1>404 Not Found</h1>'; exit; } $GLOBALS['TL_LANGUAGE'] = $message->getLanguage(); $event = new \Avisota\Contao\Core\Event\CreateFakeRecipientEvent($message); $eventDispatcher->dispatch(\Avisota\Contao\Core\CoreEvents::CREATE_FAKE_RECIPIENT, $event); $recipient = $event->getRecipient(); if ($message->getCategory()->getViewOnlinePage()) { // Fixme can rmove this? $event = new LoadLanguageFileEvent('avisota_message'); $eventDispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, $event); $url = sprintf($translator->translate('viewOnline', 'avisota_message'), sprintf('%ssystem/modules/avisota-message/web/preview.php?id=%s', \Environment::get('base'), $message->getId())); } else { $url = false; } $additionalData = array('view_online_link' => $url); /** @var \Avisota\Contao\Message\Core\Renderer\MessageRendererInterface $renderer */ $renderer = $container['avisota.message.renderer']; $messageTemplate = $renderer->renderMessage($message); $messagePreview = $messageTemplate->renderPreview($recipient, $additionalData); header('Content-Type: ' . $messageTemplate->getContentType() . '; charset=' . $messageTemplate->getContentEncoding()); header('Content-Disposition: inline; filename="' . $messageTemplate->getContentName() . '"'); echo $messagePreview; exit; }
/** * @SuppressWarnings(PHPMD.Superglobals) */ public function cronCleanupRecipientList() { if (!$GLOBALS['TL_CONFIG']['avisota_subscription_cleanup']) { return; } /** @var EventDispatcher $eventDispatcher */ $eventDispatcher = $GLOBALS['container']['event-dispatcher']; $cleanupDate = new \DateTime(); $cleanupDate->sub(new \DateInterval('P' . $GLOBALS['TL_CONFIG']['avisota_subscription_cleanup_days'] . 'D')); $entityManager = EntityHelper::getEntityManager(); $repository = $entityManager->getRepository('Avisota\\Contao:Subscription'); $queryBuilder = $repository->createQueryBuilder('s'); $expr = $queryBuilder->expr(); $queryBuilder->select('s')->where($expr->eq('s.confirmed', ':confirmed'))->andWhere($expr->lt('s.updatedAt', ':cleanupDate'))->setParameter('confirmed', true)->setParameter('cleanupDate', $cleanupDate); $query = $queryBuilder->getQuery(); $subscriptions = $query->getResult(); foreach ($subscriptions as $subscription) { $entityManager->remove($subscription); $event = new CleanSubscriptionEvent($subscription); $eventDispatcher->dispatch(SubscriptionEvents::CLEAN_SUBSCRIPTION, $event); } $entityManager->flush(); }
public function generateSchemaSql($return) { $entityManager = EntityHelper::getEntityManager(); $cacheDriver = $entityManager->getConfiguration()->getMetadataCacheImpl(); if ($cacheDriver && !$cacheDriver instanceof ApcCache) { $cacheDriver->deleteAll(); } // force "disconnected" generation of entities $reload = false; EntityGeneration::generate(null, $reload); if ($reload) { $this->reload(); } $metadatas = $entityManager->getMetadataFactory()->getAllMetadata(); $tool = new SchemaTool($entityManager); $queries = $tool->getUpdateSchemaSql($metadatas); $filter = array_map('preg_quote', $GLOBALS['DOCTRINE_MANAGED_TABLE']); $filter = implode('|', $filter); $filter = sprintf('~^(CREATE|ALTER|DROP) TABLE (%s)~', $filter); $queries = array_filter($queries, function ($query) use($filter) { return preg_match($filter, $query); }); return $this->appendQueries($return, $queries); }
/** * Create the transport service. * * @return void * * @SuppressWarnings(PHPMD.Superglobals) */ protected function createTransportService() { global $container; $factory = $this; $verbose = TL_MODE == 'BE'; $session = \Session::getInstance(); try { $transportRepository = EntityHelper::getRepository('Avisota\\Contao:Transport'); /** @var Transport[] $transports */ $transports = $transportRepository->findAll(); foreach ($transports as $transport) { $container[sprintf('avisota.transport.%s', $transport->getId())] = $container->share(function ($container) use($transport, $factory) { return $factory->createTransport($transport); }); $container[sprintf('avisota.transport.%s', $transport->getAlias())] = function ($container) use($transport) { return $container[sprintf('avisota.transport.%s', $transport->getId())]; }; } $container['avisota.transport.default'] = function ($container) { return $container[sprintf('avisota.transport.%s', $GLOBALS['TL_CONFIG']['avisota_default_transport'])]; }; } catch (\Exception $e) { $message = 'Could not create avisota transport service: ' . $e->getMessage(); if ($e instanceof \ReflectionException) { $message .= PHP_EOL . 'You may need to run the database update!'; } if ($verbose) { $tlRaw = $session->get('TL_RAW'); $tlRaw[] = sprintf('<p class="tl_error">%s</p>', nl2br($message)); $session->set('TL_RAW', $tlRaw); } log_message($message . PHP_EOL . $e->getTraceAsString()); } }
/** * Get queue * * @return Queue */ public function getQueue() { if (!$this->getCategory()) { return null; } $category = $this->getCategory(); if ($category->getBoilerplates() || $category->getQueueMode() == 'byMessage') { $queue = $this->queue; } else { if ($category->getQueueMode() == 'byMessageOrCategory') { $queue = $this->queue; if (!$queue) { $queue = $category->getQueue(); } } else { if ($category->getQueueMode() == 'byCategory') { $queue = $category->getQueue(); } else { throw new \RuntimeException('Could not find queue for message ' . $this->getId()); } } } return EntityHelper::callGetterCallbacks($this, 'orm_avisota_message', 'queue', $queue); }
/** * @param $subscriptions * @param $recipient * @SuppressWarnings(PHPMD.CamelCaseVariableName) */ protected function subscribeConfirmationMessage($subscriptions, $recipient) { if (!$this->avisota_subscribe_confirmation_message) { return; } global $container, $objPage, $TL_LANG; /** @var EventDispatcher $eventDispatcher */ $eventDispatcher = $container['event-dispatcher']; /** @var TransportInterface $transport */ $transport = $container['avisota.transport.default']; $messageRepository = EntityHelper::getRepository('Avisota\\Contao:Message'); $message = $messageRepository->find($this->avisota_subscribe_confirmation_message); if ($message) { /** @var MessageRendererInterface $renderer */ $renderer = $container['avisota.message.renderer']; $pageDetails = $objPage->row(); if ($this->avisota_subscribe_activation_page) { $event = new GetPageDetailsEvent($this->avisota_subscribe_activation_page); $eventDispatcher->dispatch(ContaoEvents::CONTROLLER_GET_PAGE_DETAILS, $event); $pageDetails = $event->getPageDetails(); } $event = new GenerateFrontendUrlEvent($pageDetails); $eventDispatcher->dispatch(ContaoEvents::CONTROLLER_GENERATE_FRONTEND_URL, $event); $query = array('token' => array()); foreach ($subscriptions as $subscription) { $query['token'][] = $subscription->getActivationToken(); } $base = \Environment::get('base'); $url = $base . $event->getUrl() . '?' . http_build_query($query); $data = array('link' => array('url' => $url, 'text' => $TL_LANG['fe_avisota_subscription']['confirm']), 'subscriptions' => $subscriptions); $template = $renderer->renderMessage($message); $mail = $template->render($recipient, $data); $transport->send($mail); } }