示例#1
0
 /**
  * @param CampaignExecutionEvent $event
  */
 public function onCampaignTriggerActionChangeStage(CampaignExecutionEvent $event)
 {
     $stageChange = false;
     $lead = $event->getLead();
     $leadStage = null;
     if ($lead instanceof Lead) {
         $leadStage = $lead->getStage();
     }
     $stageId = (int) $event->getConfig()['stage'];
     $stageToChangeTo = $this->stageModel->getEntity($stageId);
     if ($stageToChangeTo != null && $stageToChangeTo->isPublished()) {
         if ($leadStage && $leadStage->getWeight() <= $stageToChangeTo->getWeight()) {
             $stageChange = true;
         } elseif (!$leadStage) {
             $stageChange = true;
         }
     }
     if ($stageChange) {
         $lead->stageChangeLogEntry($stageToChangeTo, $stageToChangeTo->getId() . ': ' . $stageToChangeTo->getName(), $event->getName());
         $lead->setStage($stageToChangeTo);
         $this->leadModel->saveEntity($lead);
     }
     return $event->setResult($stageChange);
 }