Ejemplo n.º 1
0
 public function handleTask(&$context)
 {
     /* Insert here source code to execute the task */
     $products = $context->exportInventory();
     $products = $products['listitems'];
     $checked = new \Workflow\ConditionCheck();
     $logger = new \Workflow\ConditionLogger();
     $conditions = $this->get('condition');
     $expression = $this->get('expression');
     $environment = $context->getEnvironment();
     foreach ($products as $product) {
         $productContext = \Workflow\VTEntity::getForId($product['productid'], 'Products');
         $productContext->loadEnvironment($environment);
         $checked->setLogger($logger);
         $return = $checked->check($conditions, $productContext);
         $logs = $logger->getLogs();
         $logs[] = "Complete Result: " . intval($return);
         $this->setStat($logs);
         $logger->clearLogs();
         if ($return == true) {
             $parser = new \Workflow\ExpressionParser($expression, $productContext, false);
             # Last Parameter = DEBUG
             $parser->setVariable('quantity', $product['quantity']);
             $parser->setVariable('unitprice', $product['unitprice']);
             $parser->setVariable('discount_amount', $product['discount_amount']);
             $parser->setVariable('discount_percent', $product['discount_percent']);
             try {
                 $parser->run();
             } catch (\Workflow\ExpressionException $exp) {
                 Workflow2::error_handler(E_EXPRESSION_ERROR, $exp->getMessage(), "", "");
             }
             $environment = $productContext->getEnvironment();
             if ($parser->getReturn() === 'stop') {
                 break;
             }
         }
     }
     $context->loadEnvironment($environment);
     return "yes";
 }
Ejemplo n.º 2
0
 public function handleTask(&$context)
 {
     $conditions = $this->get("condition");
     require_once 'modules/Workflow2/VTConditionCheck.php';
     $checked = new \Workflow\ConditionCheck();
     $logger = new \Workflow\ConditionLogger();
     $checked->setLogger($logger);
     $return = $checked->check($conditions, $context);
     $logs = $logger->getLogs();
     $logs[] = "Complete Result: " . intval($return);
     $this->setStat($logs);
     // Debug Mode
     if (isset($_COOKIE["stefanDebug"]) && $_COOKIE["stefanDebug"] >= "2") {
         echo "<pre>";
         /* ONLY DEBUG*/
         var_dump($conditions);
         echo "</pre>";
     }
     if ($return === true) {
         return "yes";
     } else {
         return "no";
     }
 }