Example #1
0
 function addQuestion(&$node, $instruction)
 {
     // questions only allowed in main routing (not in fill code)
     if ($this->fillclass == true) {
         return;
     }
     if ($this->checkclass == true) {
         return;
     }
     $rule = trim($instruction->getRule());
     $rgid = trim($instruction->getRgid());
     $excluded = array();
     $rule = excludeText($rule, $excluded);
     // check for .INLINE
     $inline = false;
     if (endsWith($rule, ROUTING_IDENTIFY_INLINE)) {
         $inline = true;
         $pos = strripos($rule, ROUTING_IDENTIFY_INLINE);
         //echo $pos;
         $rule = substr($rule, 0, $pos);
     }
     //echo $rule;
     // check for array
     $var = $this->survey->getVariableDescriptiveByName(getBasicName($rule));
     // new VariableDescriptive();
     if ($var->isArray()) {
         if (!contains($rule, "[")) {
             $this->addErrorMessage(Language::errorVariableNoArrayIndex($rule));
         }
     }
     $rule = str_replace("[", TEXT_BRACKET_LEFT, $rule);
     $rule = str_replace("]", TEXT_BRACKET_RIGHT, $rule);
     // hide module dot notations
     $rule = hideModuleNotations($rule, TEXT_MODULE_DOT);
     //echo $rule;
     $rule = includeText($rule, $excluded);
     $parser = new PHPParser_Parser(new PHPParser_Lexer());
     try {
         $stmtstemp = $parser->parse("<?php " . $rule . " ?>");
         // only one statement (no ; allowed in assignment right hand side)
         //print_r($stmtstemp);
         $stmttemp = new PHPParser_Node_Arg($stmtstemp[0]);
         // encapsulate in fake Argument object, since updateVariables looks only at children of entered node
         $this->updateVariables($stmttemp);
         //print_r($stmttemp->value);
         if ($stmttemp->value instanceof PHPParser_Node_Expr_MethodCall) {
             //print_r($stmttemp->value->args[0]);
             $args[] = $stmttemp->value->args[0];
         } else {
             if ($stmttemp->value instanceof PHPParser_Node_Expr_Concat) {
                 //echo $rule . "<br/>";
                 //print_r($stmttemp->value->args[0]);
                 $args[] = $stmttemp->value;
             } else {
                 $rule = showModuleNotations($rule, TEXT_MODULE_DOT);
                 $args[] = new PHPParser_Node_Scalar_String($rule);
                 /* no brackets */
             }
         }
     } catch (PHPParser_Error $e) {
         $this->addErrorMessage(Language::errorVariableInvalid());
         return;
     }
     // not in a group
     if (sizeof($this->groups) == 0) {
         // store where we go next from here
         //echo 'here';
         $nextrgid = $this->findNextStatementAfterQuestion($rgid);
         //echo 'nothere';
         $this->addNext($rgid, $nextrgid);
         // loop action
         if (sizeof($this->loops) > 0 && inArray($rgid, $this->loopactions[end($this->loops)])) {
             $s[] = new PHPParser_Node_Arg(new PHPParser_Node_Scalar_LNumber($rgid));
             $s[] = new PHPParser_Node_Arg(new PHPParser_Node_Scalar_LNumber(sizeof($this->loops) - 1));
             $stmts[] = new PHPParser_Node_Expr_MethodCall(new PHPParser_Node_Expr_Variable(VARIABLE_THIS), new PHPParser_Node_Name(array(FUNCTION_DO_LOOP_LEFTOFF)), $s);
         } else {
             if (sizeof($this->whiles) > 0 && inArray($rgid, $this->whileactions[end($this->whiles)])) {
                 $s[] = new PHPParser_Node_Arg(new PHPParser_Node_Scalar_LNumber($rgid));
                 $s[] = new PHPParser_Node_Arg(new PHPParser_Node_Scalar_LNumber(sizeof($this->whiles) - 1));
                 $stmts[] = new PHPParser_Node_Expr_MethodCall(new PHPParser_Node_Expr_Variable(VARIABLE_THIS), new PHPParser_Node_Name(array(FUNCTION_DO_WHILE_LEFTOFF)), $s);
             }
         }
         /* inline (should never happen since always a group statement.
          * if it does happen, then ignore it so we show the question anyway */
         $args[] = new PHPParser_Node_Arg(new PHPParser_Node_Scalar_LNumber($rgid));
         $stmts[] = new PHPParser_Node_Expr_MethodCall(new PHPParser_Node_Expr_Variable(VARIABLE_THIS), new PHPParser_Node_Name(array(FUNCTION_SHOW_QUESTION)), $args);
         $stmts[] = new PHPParser_Node_Stmt_Break();
         $this->doaction_cases[] = new PHPParser_Node_Stmt_Case(new PHPParser_Node_Scalar_LNumber($rgid), $stmts);
         $this->actions[] = $rgid;
         // add question screen
         $this->addQuestionScreen($rgid);
     } else {
         /* inline, then add as inline field */
         if ($inline == true) {
             $r = trim($instruction->getRule());
             $pos = strripos($r, ROUTING_IDENTIFY_INLINE);
             $r = substr($r, 0, $pos);
             /* add generic */
             $arg = new PHPParser_Node_Arg(new PHPParser_Node_Scalar_String($r));
             $stmts[] = new PHPParser_Node_Expr_MethodCall(new PHPParser_Node_Expr_Variable(VARIABLE_THIS), new PHPParser_Node_Name(array(FUNCTION_ADD_INLINE_FIELD)), array($arg));
             /* add specific if brackets */
             if (contains($r, "[")) {
                 $stmts[] = new PHPParser_Node_Expr_MethodCall(new PHPParser_Node_Expr_Variable(VARIABLE_THIS), new PHPParser_Node_Name(array(FUNCTION_ADD_INLINE_FIELD)), $args);
             }
         }
         /* add fill value statement */
         $stmts[] = new PHPParser_Node_Expr_MethodCall(new PHPParser_Node_Expr_Variable(VARIABLE_THIS), new PHPParser_Node_Name(array(FUNCTION_ADD_FILL_VALUE)), $args);
         /* if this is a loop action, then loop statement will link to the next action, so no need to specify anything */
         $args[] = new PHPParser_Node_Arg(new PHPParser_Node_Scalar_LNumber($rgid));
         if ((sizeof($this->loops) == 0 || !inArray($rgid, $this->loopactions[end($this->loops)])) && (sizeof($this->whiles) == 0 || !inArray($rgid, $this->whileactions[end($this->whiles)]))) {
             $groupendrgid = end($this->groupsend);
             $nextrgid = $this->findNextStatementAfterQuestionInGroup($rgid, $groupendrgid);
             /* we have an action that is not itself a group action */
             //echo '<hr><hr>looking for' . $nextrgid . " before " .$groupendrgid ."<br/>";
             //print_r($this->groupactions);
             //echo "AAAA<hr>";
             if ($nextrgid > 0 && $nextrgid < $groupendrgid && !inArray($nextrgid, $this->groupactions[end($this->groups)]) && !inArray($nextrgid, $this->loopactions[end($this->loops)]) && !inArray($nextrgid, $this->whileactions[end($this->whiles)])) {
                 //echo $rgid . "<br/>";
                 $argsaction[] = new PHPParser_Node_Arg(new PHPParser_Node_Scalar_LNumber($nextrgid));
                 $stmt = new PHPParser_Node_Expr_Assign(new PHPParser_Node_Expr_Variable("temp"), new PHPParser_Node_Expr_MethodCall(new PHPParser_Node_Expr_Variable(VARIABLE_THIS), new PHPParser_Node_Name(array(FUNCTION_DO_ACTION)), $argsaction));
                 $cond = new PHPParser_Node_Expr_NotEqual(new PHPParser_Node_Expr_Variable("temp"), new PHPParser_Node_Scalar_String(""));
                 $stmt1 = new PHPParser_Node_Expr_Concat(new PHPParser_Node_Expr_Concat($args[0], new PHPParser_Node_Scalar_String("~")), new PHPParser_Node_Expr_Variable("temp"));
                 $ifstmt = new PHPParser_Node_Stmt_If($cond, array('stmts' => array(new PHPParser_Node_Stmt_Return($stmt1))));
                 //$stmts[] = new PHPParser_Node_Stmt_Return($stmt1);
                 $stmts[] = $stmt;
                 $stmts[] = $ifstmt;
                 $stmts[] = new PHPParser_Node_Stmt_Return($args[0]);
             } else {
                 $stmts[] = new PHPParser_Node_Stmt_Return($args[0]);
             }
         } else {
             $stmts[] = new PHPParser_Node_Stmt_Return($args[0]);
         }
         $this->doaction_cases[] = new PHPParser_Node_Stmt_Case(new PHPParser_Node_Scalar_LNumber($rgid), $stmts);
     }
 }
Example #2
0
 function addQuestion($instruction)
 {
     // questions only allowed in main routing (not in fill code)
     if ($this->fillclass == true) {
         return;
     }
     $rule = trim($instruction->getRule());
     $rgid = trim($instruction->getRgid());
     $excluded = array();
     $rule = excludeText($rule, $excluded);
     // check for .INLINE
     $inline = false;
     if (endsWith($rule, ROUTING_IDENTIFY_INLINE)) {
         $inline = true;
         $pos = strripos($rule, ROUTING_IDENTIFY_INLINE);
         //echo $pos;
         $rule = substr($rule, 0, $pos);
     }
     //echo $rule;
     // check for array
     $var = $this->survey->getVariableDescriptiveByName(getBasicName($rule));
     // new VariableDescriptive();
     if ($var->isArray()) {
         if (!contains($rule, "[")) {
             $this->addErrorMessage(Language::errorVariableNoArrayIndex($rule));
         }
     }
     $rule = str_replace("[", TEXT_BRACKET_LEFT, $rule);
     $rule = str_replace("]", TEXT_BRACKET_RIGHT, $rule);
     // hide module dot notations
     $rule = hideModuleNotations($rule, TEXT_MODULE_DOT);
     //echo $rule;
     $rule = includeText($rule, $excluded);
     $parser = new PHPParser_Parser(new PHPParser_Lexer());
     try {
         $stmtstemp = $parser->parse("<?php " . $rule . " ?>");
         // only one statement (no ; allowed in assignment right hand side)
         //print_r($stmtstemp);
         $stmttemp = new PHPParser_Node_Arg($stmtstemp[0]);
         // encapsulate in fake Argument object, since updateVariables looks only at children of entered node
         $this->updateVariables($stmttemp);
         $cleanup = false;
         //print_r($stmttemp);
         //print_r($stmttemp->value);
         if ($stmttemp->value instanceof PHPParser_Node_Expr_MethodCall) {
             $st = new PHPParser_Node_Expr_MethodCall($stmttemp->value->var, FUNCTION_XI_ASK);
             $cleanup = true;
         } else {
             if ($stmttemp->value instanceof PHPParser_Node_Expr_Concat) {
                 //echo $rule . "<br/>";
                 //print_r($stmttemp->value->args[0]);
                 $st = new PHPParser_Node_Expr_MethodCall($stmttemp->value, FUNCTION_XI_ASK);
             } else {
                 $rule = showModuleNotations($rule, TEXT_MODULE_DOT);
                 $st = new PHPParser_Node_Expr_MethodCall(new PHPParser_Node_Expr_Variable($rule), FUNCTION_XI_ASK);
                 /* no brackets */
             }
         }
     } catch (PHPParser_Error $e) {
         $this->addErrorMessage(Language::errorVariableInvalid());
         return;
     }
     $fillcall = $this->printer->prettyPrint(array($st));
     // clean up
     if ($cleanup) {
         $fillcall = str_replace(" . (", "", $fillcall);
         $fillcall = str_replace(" . ])", "]", $fillcall);
     }
     if ($this->group == false) {
         $this->routing_output[$this->seid][] = $fillcall . "\r\n";
     } else {
         $this->routing_output[$this->seid][] = "\$" . $this->lastgroup . "->addQuestion(" . str_replace("->ask();", "", $fillcall) . ");\r\n";
     }
 }