public static function checkCondition($condition, &$params) { if (isset($condition['name']) && $condition['name'] === 'duration') { if (empty($condition['value'])) { return array($params['model']->dueDate < time(), ''); } return array($params['model']->dueDate < time() - (int) $condition['value'], ''); } return parent::checkCondition($condition, $params); }
public static function checkCondition($condition, &$params) { if (isset($condition['name']) && $condition['name'] === 'duration') { if ($params['model']->hasAttribute('lastActivity')) { return array($params['model']->lastActivity < time() - (int) $condition->value, ''); } elseif ($params['model']->hasAttribute('lastUpdated')) { return array($params['model']->lastUpdated < time() - (int) $condition->value, ''); } else { return array(false, ''); } } else { return parent::checkCondition($condition, $params); } }
public static function evalComparison($subject, $operator, $value = null) { if (is_array($value) && in_array('Anyone', $value)) { if ($operator === 'list') { return true; } elseif ($operator === 'notList') { return false; } } elseif ($value === 'Anyone' && $operator === '=') { return true; } elseif ($value === 'Anyone' && $operator === '<>') { return false; } return parent::evalComparison($subject, $operator, $value); }
/** * Executes a flow, starting by checking the trigger, passing params to each trigger/action, * and calling {@link X2Flow::executeBranch()} * * @param X2Flow &$flow the object representing the flow to run * @param array &$params an associative array of params, usually including 'model'=>$model, * @param mixed $actionId a unique id for the flow action where flow execution should start. * This can also be an array of directions to the flow action (legacy option). * Will skip checking the trigger conditions if not null, otherwise runs the entire flow. */ private static function _executeFlow(&$flow, &$params, $actionId = null, $triggerLogId = null) { $error = ''; //array($flow->name); $flowData = $flow->getFlow(); if ($flowData !== false && isset($flowData['trigger']['type'], $flowData['items'][0]['type'])) { if ($actionId === null) { $trigger = X2FlowTrigger::create($flowData['trigger']); assert($trigger !== null); if ($trigger === null) { $error = array('trace' => array(false, 'failed to load trigger class')); } $validateRetArr = $trigger->validate($params, $flow->id); if (!$validateRetArr[0]) { $error = $validateRetArr; return array('trace' => $error); } else { if (sizeof($validateRetArr) === 3) { // trigger has return value return array('trace' => $validateRetArr, 'retVal' => $validateRetArr[2]); } } $checkRetArr = $trigger->check($params); if (!$checkRetArr[0]) { $error = $checkRetArr; } if (empty($error)) { try { $flowTrace = array(true, $flow->executeBranch($flowData['items'], $params, $triggerLogId)); $flowRetVal = self::extractRetValFromTrace($flowTrace); if (!$flowRetVal) { $flowRetVal = $trigger->getDefaultReturnVal($flow->id); } return array('trace' => $flowTrace, 'retVal' => $flowRetVal); } catch (Exception $e) { return array('trace' => array(false, $e->getMessage())); // whatever. } } else { return array('trace' => $error); } } else { // $actionId provided, skip to the specified position using X2Flow::traverse() try { return array('trace' => array(true, $flow->traverse($actionId, $flowData['items'], $params, $triggerLogId))); } catch (Exception $e) { return array('trace' => array(false, $e->getMessage())); // whatever. } } } else { return array('trace' => array(false, 'invalid flow data')); } }
/** * Executes a flow, starting by checking the trigger, passing params to each trigger/action, * and calling {@link X2Flow::executeBranch()} * * @param X2Flow &$flow the object representing the flow to run * @param array &$params an associative array of params, usually including 'model'=>$model, * @param mixed $flowPath an array of directions to a specific point in the flow. Defaults to * null. * Will skip checking the trigger conditions if not null, otherwise runs the entire flow. */ private static function executeFlow(&$flow, &$params, $flowPath = null, $triggerLogId = null) { $error = ''; //array($flow->name); $flowData = CJSON::decode($flow->flow); // parse JSON flow data // file_put_contents('triggerLog.txt',"\n".print_r($flowData,true),FILE_APPEND); if ($flowData !== false && isset($flowData['trigger']['type'], $flowData['items'][0]['type'])) { if ($flowPath === null) { //AuxLib::debugLogR ('creating trigger'); $trigger = X2FlowTrigger::create($flowData['trigger']); assert($trigger !== null); if ($trigger === null) { $error = array('trace' => array(false, 'failed to load trigger class')); } //AuxLib::debugLogR ('validating'); $validateRetArr = $trigger->validate($params, $flow->id); if (!$validateRetArr[0]) { $error = $validateRetArr; return array('trace' => $error); } else { if (sizeof($validateRetArr) === 3) { // trigger has return value return array('trace' => $validateRetArr, 'retVal' => $validateRetArr[2]); } } //AuxLib::debugLogR ('checking'); $checkRetArr = $trigger->check($params); if (!$checkRetArr[0]) { $error = $checkRetArr; } //AuxLib::debugLogR ('done checking'); if (empty($error)) { try { //AuxLib::debugLogR ('executeBranch'); $flowTrace = array(true, $flow->executeBranch(array(0), $flowData['items'], $params, 0, $triggerLogId)); //AuxLib::debugLog ('executing branch complete'); //AuxLib::debugLogR ($flowTrace); $flowRetVal = self::extractRetValFromTrace($flowTrace); //AuxLib::debugLog ('extractRetValFromTrace ret'); if (!$flowRetVal) { $flowRetVal = $trigger->getDefaultReturnVal($flow->id); } return array('trace' => $flowTrace, 'retVal' => $flowRetVal); } catch (Exception $e) { //AuxLib::debugLogR ($e->getTrace ()); //AuxLib::debugLogR ($e->getMessage ()); return array('trace' => array(false, $e->getMessage())); // whatever. } } else { return array('trace' => $error); } } else { // $flowPath provided, skip to the specified position using X2Flow::traverse() try { return array('trace' => array(true, $flow->traverse($flowPath, $flowData['items'], $params, 0, $triggerLogId))); } catch (Exception $e) { //AuxLib::debugLogR ($e->getTrace ()); //AuxLib::debugLogR ($e->getMessage ()); return array('trace' => array(false, $e->getMessage())); // whatever. } } } else { return array('trace' => array(false, 'invalid flow data')); } }
public function actionGetParams($name, $type) { if ($type === 'action') { $paramRules = X2FlowAction::getParamRules($name); // X2Flow Actions } elseif ($type === 'trigger') { $paramRules = X2FlowTrigger::getParamRules($name); // X2Flow Triggers } elseif ($type === 'condition') { // generic conditions (for triggers and switches) $paramRules = X2FlowTrigger::getGenericCondition($name); } else { $paramRules = false; } if ($paramRules !== false) { if ($type === 'condition') { if (isset($paramRules['options'])) { $paramRules['options'] = AuxLib::dropdownForJson($paramRules['options']); } } else { foreach ($paramRules['options'] as &$option) { // find any dropdowns and reformat them if (isset($option['options'])) { // so the item order is preserved in JSON $option['options'] = AuxLib::dropdownForJson($option['options']); } } // do the same for suboptions, if they're present if (isset($paramRules['suboptions'])) { foreach ($paramRules['suboptions'] as &$subOption) { if (isset($subOption['options'])) { $subOption['options'] = AuxLib::dropdownForJson($subOption['options']); } } } } } echo CJSON::encode($paramRules); }