Beispiel #1
0
 /**
  * @param PageDisplayEvent $event
  */
 public function onPageDisplay(PageDisplayEvent $event)
 {
     $content = $event->getContent();
     $page = $event->getPage();
     $regex = '/' . $this->formRegex . '/i';
     preg_match_all($regex, $content, $matches);
     if (count($matches[0])) {
         foreach ($matches[1] as $k => $id) {
             $form = $this->formModel->getEntity($id);
             if ($form !== null && ($form->isPublished(false) || $this->security->hasEntityAccess('form:forms:viewown', 'form:forms:viewother', $form->getCreatedBy()))) {
                 $formHtml = $form->isPublished() ? $this->formModel->getContent($form) : '<div class="mauticform-error">' . $this->translator->trans('mautic.form.form.pagetoken.notpublished') . '</div>';
                 //add the hidden page input
                 $pageInput = "\n<input type=\"hidden\" name=\"mauticform[mauticpage]\" value=\"{$page->getId()}\" />\n";
                 $formHtml = preg_replace('#</form>#', $pageInput . '</form>', $formHtml);
                 //pouplate get parameters
                 //priority populate value order by: query string (parameters) -> with lead
                 if (!$form->getInKioskMode()) {
                     $this->formModel->populateValuesWithLead($form, $formHtml);
                 }
                 $this->formModel->populateValuesWithGetParameters($form, $formHtml);
                 $content = preg_replace('#{form=' . $id . '}#', $formHtml, $content);
             } else {
                 $content = preg_replace('#{form=' . $id . '}#', '', $content);
             }
         }
     }
     $event->setContent($content);
 }
Beispiel #2
0
 /**
  * @param      $focus
  * @param bool $preview
  * @param bool $ignoreMinify
  *
  * @return string
  */
 public function generateJavascript($focus, $preview = false, $ignoreMinify = false)
 {
     if ($focus instanceof Focus) {
         $focus = $focus->toArray();
     }
     if (!empty($focus['form'])) {
         $form = $this->formModel->getEntity($focus['form']);
     } else {
         $form = null;
     }
     if ($preview) {
         $content = ['style' => '', 'html' => $this->templating->getTemplating()->render('MauticFocusBundle:Builder:content.html.php', ['focus' => $focus, 'form' => $form, 'preview' => $preview])];
     } else {
         // Generate link if applicable
         $url = '';
         if ($focus['type'] == 'link') {
             $trackable = $this->trackableModel->getTrackableByUrl($focus['properties']['content']['link_url'], 'focus', $focus['id']);
             $url = $this->trackableModel->generateTrackableUrl($trackable, ['channel' => ['focus', $focus['id']]]);
         }
         $content = $this->templating->getTemplating()->render('MauticFocusBundle:Builder:generate.js.php', ['focus' => $focus, 'form' => $form, 'preview' => $preview, 'ignoreMinify' => $ignoreMinify, 'clickUrl' => $url]);
         if (!$ignoreMinify) {
             $content = \JSMin::minify($content);
         }
     }
     return $content;
 }
Beispiel #3
0
 /**
  * Compile events for the lead timeline
  *
  * @param LeadTimelineEvent $event
  */
 public function onTimelineGenerate(LeadTimelineEvent $event)
 {
     // Set available event types
     $eventTypeKey = 'form.submitted';
     $eventTypeName = $this->translator->trans('mautic.form.event.submitted');
     $event->addEventType($eventTypeKey, $eventTypeName);
     if (!$event->isApplicable($eventTypeKey)) {
         return;
     }
     /** @var \Mautic\FormBundle\Entity\SubmissionRepository $submissionRepository */
     $submissionRepository = $this->em->getRepository('MauticFormBundle:Submission');
     $rows = $submissionRepository->getSubmissions($event->getQueryOptions());
     // Add total to counter
     $event->addToCounter($eventTypeKey, $rows);
     if (!$event->isEngagementCount()) {
         // Add the submissions to the event array
         foreach ($rows['results'] as $row) {
             // Convert to local from UTC
             $form = $this->formModel->getEntity($row['form_id']);
             $submission = $submissionRepository->getEntity($row['id']);
             $event->addEvent(['event' => $eventTypeKey, 'eventLabel' => ['label' => $form->getName(), 'href' => $this->router->generate('mautic_form_action', ['objectAction' => 'view', 'objectId' => $form->getId()])], 'eventType' => $eventTypeName, 'timestamp' => $row['dateSubmitted'], 'extra' => ['submission' => $submission, 'form' => $form, 'page' => $this->pageModel->getEntity($row['page_id'])], 'contentTemplate' => 'MauticFormBundle:SubscribedEvents\\Timeline:index.html.php', 'icon' => 'fa-pencil-square-o']);
         }
     }
 }