/**
  * @param            $slot
  * @param Lead|array $lead
  *
  * @return string
  */
 public function getDynamicContentForLead($slot, $lead)
 {
     $response = $this->campaignEventModel->triggerEvent('dwc.decision', $slot, 'dwc.decision.' . $slot);
     $content = '';
     if (is_array($response) && !empty($response['action']['dwc.push_content'])) {
         $content = array_shift($response['action']['dwc.push_content']);
     } else {
         $data = $this->dynamicContentModel->getSlotContentForLead($slot, $lead);
         if (!empty($data)) {
             $content = $data['content'];
             $dwc = $this->dynamicContentModel->getEntity($data['id']);
             if ($dwc instanceof DynamicContent) {
                 // Determine a translation based on contact's preferred locale
                 /** @var DynamicContent $translation */
                 list($ignore, $translation) = $this->dynamicContentModel->getTranslatedEntity($dwc, $lead);
                 if ($translation !== $dwc) {
                     // Use translated version of content
                     $dwc = $translation;
                     $content = $dwc->getContent();
                 }
                 $this->dynamicContentModel->createStatEntry($dwc, $lead, $slot);
                 $tokenEvent = new TokenReplacementEvent($content, $lead, ['slot' => $slot, 'dynamic_content_id' => $dwc->getId()]);
                 $this->dispatcher->dispatch(DynamicContentEvents::TOKEN_REPLACEMENT, $tokenEvent);
                 $content = $tokenEvent->getContent();
             }
         }
     }
     return $content;
 }
示例#2
0
 /**
  * @param CampaignExecutionEvent $event
  */
 public function onCampaignTriggerAction(CampaignExecutionEvent $event)
 {
     $eventConfig = $event->getConfig();
     $lead = $event->getLead();
     $slot = $this->session->get('dwc.slot_name.lead.' . $lead->getId());
     $dwc = $this->dynamicContentModel->getRepository()->getEntity($eventConfig['dynamicContent']);
     if ($dwc instanceof DynamicContent) {
         // Use translation if available
         list($ignore, $dwc) = $this->dynamicContentModel->getTranslatedEntity($dwc, $lead);
         if ($slot) {
             $this->dynamicContentModel->setSlotContentForLead($dwc, $lead, $slot);
         }
         $this->dynamicContentModel->createStatEntry($dwc, $lead, $slot);
         $tokenEvent = new TokenReplacementEvent($dwc->getContent(), $lead, ['slot' => $slot, 'dynamic_content_id' => $dwc->getId()]);
         $this->factory->getDispatcher()->dispatch(DynamicContentEvents::TOKEN_REPLACEMENT, $tokenEvent);
         $content = $tokenEvent->getContent();
         $event->stopPropagation();
         $result = $event->setResult($content);
         $event->setChannel('dynamicContent', $dwc->getId());
         return $result;
     }
 }