public function handleTask(&$context) { $conditions = $this->get("condition"); $parser = new \Workflow\ExpressionParser($conditions, $context, false); # Last Parameter = DEBUG try { $parser->run(); } catch (\Workflow\ExpressionException $exp) { \Workflow2::error_handler(E_EXPRESSION_ERROR, $exp->getMessage(), "", ""); } $return = $parser->getReturn(); if ($return != "yes" && $return != "no") { $return = "no"; } return $return; }
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"; }
/** * @param $context \Workflow\VTEntity * @return string */ public function handleTask(&$context) { global $adb; $currentTime = microtime(true); $benchmark = array(); if ($this->get("search_module") == -1) { return "no"; } $found_rows = $this->get("found_rows"); if (empty($found_rows) || $found_rows == -1) { $found_rows = 1; } $parts = explode("#~#", $this->get("search_module")); $functionName = $parts[0]; $related_module = VtUtils::getModuleName($parts[1]); $logger = new \Workflow\ConditionLogger(); $objMySQL = new \Workflow\ConditionMysql($related_module, $context); $objMySQL->setLogger($logger); $main_module = \CRMEntity::getInstance($related_module); #$sqlTables = $main_module->generateReportsQuery($related_module); if ($related_module == "Calendar") { #$sqlTables .= " LEFT JOIN vtiger_seactivityrel ON(vtiger_seactivityrel.activityid = vtiger_crmentity.crmid)"; } $sqlCondition = $objMySQL->parse($this->get("condition")); $newTime = microtime(true); $benchmark[] = round($newTime - $currentTime, 3); $currentTime = $newTime; $sqlTables = $objMySQL->generateTables(); if (strlen($sqlCondition) > 3) { $sqlCondition .= " AND vtiger_crmentity.deleted = 0"; } else { $sqlCondition .= " vtiger_crmentity.deleted = 0"; } $logs = $logger->getLogs(); $this->setStat($logs); $sqlCondition .= " GROUP BY vtiger_crmentity.crmid "; $idColumn = $main_module->table_name . "." . $main_module->table_index; $sqlQuery = "SELECT {$idColumn} as `idCol` " . $sqlTables . " WHERE " . (strlen($sqlCondition) > 3 ? $sqlCondition : ""); $sortField = $this->get("sort_field"); if (!empty($sortField) && $sortField != -1) { $sortField = VtUtils::getColumnName($sortField); $sortDirection = $this->get("sortDirection"); $sqlQuery .= " ORDER BY " . $sortField . " " . $sortDirection; } $numRows = $this->get("found_rows"); if (!empty($numRows) && $numRows != -1) { $sqlQuery .= " LIMIT " . $found_rows; } #var_dump(nl2br($sqlQuery));exit(); $this->addStat("MySQL Query: " . $sqlQuery); $result = $adb->query($sqlQuery); $newTime = microtime(true); $benchmark[] = round($newTime - $currentTime, 3); $currentTime = $newTime; $this->addStat("num Rows: " . $adb->num_rows($result)); # If no records are found, fo other way if ($adb->num_rows($result) == 0) { return "no"; } $environment = $context->getEnvironment(); while ($row = $adb->fetchByAssoc($result)) { $expression = $this->get("expression"); if (!empty($expression)) { $tmpContext = \Workflow\VTEntity::getForId($row["idcol"], $related_module); $tmpContext->loadEnvironment($environment); $parser = new \Workflow\ExpressionParser($expression, $tmpContext, false); # Last Parameter = DEBUG try { $parser->run(); } catch (ExpressionException $exp) { Workflow2::error_handler(E_EXPRESSION_ERROR, $exp->getMessage(), "", ""); } $environment = $tmpContext->getEnvironment(); } } # while $newTime = microtime(true); $benchmark[] = round($newTime - $currentTime, 3); $currentTime = $newTime; $context->loadEnvironment($environment); $this->addStat("Benchmark: " . implode("/", $benchmark)); return "yes"; }