示例#1
0
 /**
  * {@inheritDoc}
  */
 protected function executeAction($context)
 {
     $workflowName = $this->getName($context);
     $entity = $this->getEntity($context);
     $startTransition = $this->getTransition($context);
     $data = $this->getData($context);
     $workflowItem = $this->workflowManager->startWorkflow($workflowName, $entity, $startTransition, $data);
     $attribute = $this->getAttribute();
     $this->contextAccessor->setValue($context, $attribute, $workflowItem);
 }
示例#2
0
 /**
  * @expectedException \Exception
  * @expectedExceptionMessage Start workflow exception message
  */
 public function testStartWorkflowException()
 {
     $entityManager = $this->createEntityManager();
     $entityManager->expects($this->once())->method('beginTransaction');
     $entityManager->expects($this->once())->method('persist')->will($this->throwException(new \Exception('Start workflow exception message')));
     $entityManager->expects($this->once())->method('rollback');
     $this->registry->expects($this->once())->method('getManager')->will($this->returnValue($entityManager));
     $this->workflowManager->startWorkflow($this->createWorkflow(), null, 'test_transition');
 }
示例#3
0
 /**
  * @param Lead $lead
  */
 protected function loadSalesFlows(Lead $lead)
 {
     $leadWorkflowItem = $this->workflowManager->startWorkflow('b2b_flow_lead', $lead, 'qualify', array('opportunity_name' => $lead->getName(), 'company_name' => $lead->getCompanyName()));
     if ($this->getRandomBoolean()) {
         /** @var Opportunity $opportunity */
         $opportunity = $leadWorkflowItem->getResult()->get('opportunity');
         $salesFlowItem = $this->workflowManager->startWorkflow('b2b_flow_sales', $opportunity, 'develop', array('budget_amount' => mt_rand(10, 10000), 'customer_need' => mt_rand(10, 10000), 'proposed_solution' => mt_rand(10, 10000), 'probability' => round(mt_rand(50, 85) / 100.0, 2)));
         if ($this->getRandomBoolean()) {
             if ($this->getRandomBoolean()) {
                 $this->transit($this->workflowManager, $salesFlowItem, 'close_as_won', array('close_revenue' => mt_rand(100, 1000), 'close_date' => new \DateTime('now')));
             } else {
                 $this->transit($this->workflowManager, $salesFlowItem, 'close_as_lost', array('close_reason_name' => 'cancelled', 'close_revenue' => mt_rand(100, 1000), 'close_date' => new \DateTime('now')));
             }
         }
     }
 }
 /**
  * @param Lead | Opportunity $entity
  * @param User $owner
  */
 protected function loadSalesFlows($entity, $owner)
 {
     if ($entity instanceof Lead) {
         $step = 'start_from_lead';
         $parameters = array('lead' => $entity);
     } else {
         $step = 'start_from_opportunity';
         $parameters = array('opportunity' => $entity);
     }
     $parameters = array_merge(array('sales_funnel' => null, 'sales_funnel_owner' => $owner, 'sales_funnel_start_date' => new \DateTime('now')), $parameters);
     $salesFunnel = new SalesFunnel();
     $salesFunnel->setDataChannel($this->getReference('default_channel'));
     if (!$this->workflowManager->isStartTransitionAvailable('b2b_flow_sales_funnel', $step, $salesFunnel, $parameters)) {
         return;
     }
     $salesFunnelItem = $this->workflowManager->startWorkflow('b2b_flow_sales_funnel', $salesFunnel, $step, $parameters);
     $salesFunnelItem->getData()->set('new_opportunity_name', $entity->getName())->set('new_company_name', $entity->getName());
     if ($entity instanceof Lead) {
         if ($this->isTransitionAllowed($salesFunnelItem, 'qualify')) {
             $this->workflowManager->transit($salesFunnelItem, 'qualify');
         } else {
             return;
         }
     }
     if (rand(1, 100) > 10) {
         $salesFunnelItem->getData()->set('budget_amount', mt_rand(10, 10000))->set('customer_need', mt_rand(10, 10000))->set('proposed_solution', mt_rand(10, 10000))->set('probability', $this->probabilities[array_rand($this->probabilities)]);
         if ($this->isTransitionAllowed($salesFunnelItem, 'develop')) {
             $this->workflowManager->transit($salesFunnelItem, 'develop');
             if ($this->getRandomBoolean()) {
                 $salesFunnelItem->getData()->set('close_revenue', mt_rand(10, 1000))->set('close_date', new \DateTime());
                 if ($this->getRandomBoolean()) {
                     if ($this->isTransitionAllowed($salesFunnelItem, 'close_as_won')) {
                         $this->workflowManager->transit($salesFunnelItem, 'close_as_won');
                     }
                 } else {
                     $salesFunnelItem->getData()->set('close_reason_name', 'cancelled')->set('close_date', new \DateTime('now', new \DateTimeZone('UTC')));
                     if ($this->isTransitionAllowed($salesFunnelItem, 'close_as_lost')) {
                         $this->workflowManager->transit($salesFunnelItem, 'close_as_lost');
                     }
                 }
             }
         }
     }
 }