Beispiel #1
0
 function processMap($arguments)
 {
     global $adb, $current_user;
     $xml = $this->getXMLContent();
     $entityId = $arguments[0];
     $holduser = $current_user;
     $current_user = Users::getActiveAdminUser();
     // evaluate condition as admin user
     $entity = new VTWorkflowEntity($current_user, $entityId);
     $current_user = $holduser;
     if (isset($xml->expression)) {
         $testexpression = (string) $xml->expression;
         $parser = new VTExpressionParser(new VTExpressionSpaceFilter(new VTExpressionTokenizer($testexpression)));
         $expression = $parser->expression();
         $exprEvaluater = new VTFieldExpressionEvaluater($expression);
         $exprEvaluation = $exprEvaluater->evaluate($entity);
     } elseif (isset($xml->function)) {
         list($void, $entity->data['record_id']) = explode('x', $entity->data['id']);
         $entity->data['record_module'] = $entity->getModuleName();
         $function = (string) $xml->function->name;
         $testexpression = '$exprEvaluation = ' . $function . '(';
         foreach ($xml->function->parameters->parameter as $k => $v) {
             if (isset($entity->data[(string) $v])) {
                 $testexpression .= "'" . $entity->data[(string) $v] . "',";
             } else {
                 $testexpression .= "'" . (string) $v . "',";
             }
         }
         $testexpression = trim($testexpression, ',') . ');';
         eval($testexpression);
     }
     return $exprEvaluation;
 }
 function processMap($arguments)
 {
     global $adb, $current_user;
     $xml = $this->getXMLContent();
     $entityId = $arguments[0];
     $entity = new VTWorkflowEntity($current_user, $entityId);
     $testexpression = (string) $xml->expression;
     $parser = new VTExpressionParser(new VTExpressionSpaceFilter(new VTExpressionTokenizer($testexpression)));
     $expression = $parser->expression();
     $exprEvaluater = new VTFieldExpressionEvaluater($expression);
     $exprEvaluation = $exprEvaluater->evaluate($entity);
     return $exprEvaluation;
 }
 function addWorkflowConditionsToQueryGenerator($queryGenerator, $conditions)
 {
     $conditionMapping = array('equal to' => 'e', 'less than' => 'l', 'greater than' => 'g', 'does not equal' => 'n', 'less than or equal to' => 'm', 'greater than or equal to' => 'h', 'is' => 'e', 'contains' => 'c', 'does not contain' => 'k', 'starts with' => 's', 'ends with' => 'ew', 'is not' => 'n', 'is empty' => 'y', 'is not empty' => 'ny', 'before' => 'l', 'after' => 'g', 'between' => 'bw', 'less than days ago' => 'bw', 'more than days ago' => 'l', 'in less than' => 'bw', 'in more than' => 'g', 'days ago' => 'e', 'days later' => 'e', 'less than hours before' => 'bw', 'less than hours later' => 'bw', 'more than hours before' => 'l', 'more than hours later' => 'g', 'is today' => 'e', 'exists' => 'exists');
     $noOfConditions = count($conditions);
     //Algorithm :
     //1. If the query has already where condition then start a new group with and condition, else start a group
     //1.5 Open a global parenthesis to encapsulate the whole condition (required to get the or joins correct)
     //2. Foreach of the condition, if its a condition in the same group just append with the existing joincondition
     //3. If its a new group, then start the group with the group join.
     //4. And for the first condition in the new group, dont append any joincondition.
     if ($noOfConditions > 0) {
         if ($queryGenerator->conditionInstanceCount > 0) {
             $queryGenerator->startGroup(QueryGenerator::$AND);
         } else {
             $queryGenerator->startGroup('');
         }
         $queryGenerator->startGroup('');
         $previous_condition = array();
         foreach ($conditions as $index => $condition) {
             $condition = get_object_vars($condition);
             // to convert object to array
             $operation = $condition['operation'];
             //Cannot handle this condition for scheduled workflows
             if ($operation == 'has changed') {
                 continue;
             }
             $value = $condition['value'];
             $valueType = $condition['valuetype'];
             if (in_array($operation, $this->_specialDateTimeOperator())) {
                 $value = $this->_parseValueForDate($condition);
                 $valueType = 'rawtext';
             }
             $columnCondition = $condition['joincondition'];
             $groupId = $condition['groupid'];
             $groupJoin = isset($condition['groupjoin']) ? $condition['groupjoin'] : '';
             $operator = $conditionMapping[$operation];
             $fieldname = $condition['fieldname'];
             if ($index > 0 && $groupId != $previous_condition['groupid']) {
                 // if new group, end older group and start new
                 $queryGenerator->endGroup();
                 if ($groupJoin) {
                     $queryGenerator->startGroup($groupJoin);
                 } else {
                     $queryGenerator->startGroup(QueryGenerator::$AND);
                 }
             }
             if (empty($columnCondition) || $index > 0) {
                 $columnCondition = $previous_condition['joincondition'];
             }
             if ($index > 0 && $groupId != $previous_condition['groupid']) {
                 //if first condition in new group, send empty condition to append
                 $columnCondition = null;
             }
             $referenceField = null;
             if ($valueType == 'expression') {
                 $parser = new VTExpressionParser(new VTExpressionSpaceFilter(new VTExpressionTokenizer($value)));
                 $expression = $parser->expression();
                 $exprEvaluater = new VTFieldExpressionEvaluater($expression);
                 $value = $exprEvaluater->evaluate(false);
             } else {
                 $value = html_entity_decode($value);
                 preg_match('/(\\w+) : \\((\\w+)\\) (\\w+)/', $condition['fieldname'], $matches);
                 if (count($matches) != 0) {
                     list($full, $referenceField, $referenceModule, $fieldname) = $matches;
                 } else {
                     if ($value == 'true:boolean') {
                         $value = '1';
                     }
                     if ($value == 'false:boolean') {
                         $value = '0';
                     }
                 }
             }
             if ($referenceField) {
                 $queryGenerator->addReferenceModuleFieldCondition($referenceModule, $referenceField, $fieldname, $value, $operator, $columnCondition);
             } else {
                 $queryGenerator->addCondition($fieldname, $value, $operator, $columnCondition);
             }
             $previous_condition = $condition;
         }
         $queryGenerator->endGroup();
         $queryGenerator->endGroup();
     }
 }
Beispiel #4
0
 /**
  * $arguments[0] origin column_fields array
  * $arguments[1] target column_fields array
  */
 function processMap($arguments)
 {
     global $adb, $current_user;
     $mapping = $this->convertMap2Array();
     $ofields = $arguments[0];
     if (!empty($ofields['record_id'])) {
         $setype = getSalesEntityType($ofields['record_id']);
         $wsidrs = $adb->pquery('SELECT id FROM vtiger_ws_entity WHERE name=?', array($setype));
         $entityId = $adb->query_result($wsidrs, 0, 0) . 'x' . $ofields['record_id'];
     }
     $tfields = $arguments[1];
     foreach ($mapping['fields'] as $targetfield => $sourcefields) {
         $value = '';
         $delim = isset($sourcefields['delimiter']) ? $sourcefields['delimiter'] : '';
         foreach ($sourcefields['merge'] as $pos => $fieldinfo) {
             $idx = array_keys($fieldinfo);
             if (strtoupper($idx[0]) == 'CONST') {
                 $const = array_pop($fieldinfo);
                 $value .= $const . $delim;
             } elseif (strtoupper($idx[0]) == 'EXPRESSION') {
                 $testexpression = array_pop($fieldinfo);
                 $parser = new VTExpressionParser(new VTExpressionSpaceFilter(new VTExpressionTokenizer($testexpression)));
                 $expression = $parser->expression();
                 $exprEvaluater = new VTFieldExpressionEvaluater($expression);
                 if (empty($ofields['record_id'])) {
                     $exprEvaluation = $exprEvaluater->evaluate(false);
                 } else {
                     $entity = new VTWorkflowEntity($current_user, $entityId);
                     $exprEvaluation = $exprEvaluater->evaluate($entity);
                 }
                 $value .= $exprEvaluation . $delim;
             } else {
                 $fieldname = array_pop($fieldinfo);
                 $value .= $ofields[$fieldname] . $delim;
             }
         }
         $value = rtrim($value, $delim);
         $tfields[$targetfield] = $value;
     }
     return $tfields;
 }