コード例 #1
0
function save1($myuserid)
{
    $mineexists = 0;
    /*Existiert Question/Template schon?*/
    $qdb = new EvaluationQuestionDB();
    if (!$template_id) {
        $template_id = Request::option("template_id");
    }
    if ($qdb->exists($template_id)) {
        $question = new EvaluationQuestion($template_id, NULL, EVAL_LOAD_ALL_CHILDREN);
        if ($question->getParentID() != $myuserid) {
            $foreign = TRUE;
            $question = new EvaluationQuestion();
            $question->setParentID($myuserid);
        } else {
            $overwrite = 1;
            //$question->delete();
            //$question = new EvaluationQuestion();
            //$template_id=$question->getObjectID();
        }
    } else {
        $question = new EvaluationQuestion();
    }
    /*Get Vars ----------------------------------------------------*/
    $template_name = Request::get("template_name");
    $template_type = Request::get("template_type");
    $template_multiple = Request::get("template_multiple");
    $template_add_num_answers = Request::option("template_add_num_answers");
    $template_residual = Request::get("template_residual");
    $template_residual_text = Request::get("template_residual_text");
    $template_answers = Request::getArray("template_answers");
    /*end: Get Vars -----------------------------------------------*/
    $question->setParentID($myuserid);
    $question->setMultiplechoice($template_multiple);
    $question->setText(trim($template_name), YES);
    $question->setType($template_type);
    while ($answerrem = $question->getChild()) {
        $id = $answerrem->getObjectID();
        $answerrem->delete();
        $question->removeChildID($id);
    }
    $controlnumber = count($template_answers);
    $ausgleich = 0;
    for ($i = 0; $i < $controlnumber; $i++) {
        $text = $template_answers[$i]['text'];
        $answerID = $template_answers[$i]['answer_id'];
        $answer = new EvaluationAnswer();
        if (!$foreign) {
            $answer->setObjectID($answerID);
        }
        $answer->setText(trim($text), YES);
        $question->addChild($answer);
        /*Anzahl der Antworten bei Polskalen anpassen ------------------------*/
        if ($template_type == EVALQUESTION_TYPE_POL && $i == 0) {
            $answerdiff = $controlnumber - $template_add_num_answers;
            if ($template_residual) {
                //echo "Hust<br>";
                //$answerdiff;
            }
            if ($answerdiff > 0) {
                /*differenz abziehen => answers überspringen*/
                $i = $i + $answerdiff;
                $ausgleich = $ausgleich - $answerdiff;
            }
            while ($answerdiff < 0) {
                $ausgleich = $ausgleich + 1;
                $answer = new EvaluationAnswer();
                $answer->setText("");
                $answer->setParentID($question->getObjectID());
                $answer->setPosition($i + $ausgleich);
                $answer->setValue($i + 1 + $ausgleich);
                $question->addChild($answer);
                $answerdiff++;
            }
        }
        /*end: Polskala antworten angleichen ----------------------------------*/
    }
    /*create residual category-----------------------------------------------*/
    if ($template_residual) {
        $answer = new EvaluationAnswer();
        $answer->setResidual($template_residual);
        $answer->setText(trim($template_residual_text), QUOTED);
        $answer->setParentID($question->getObjectID());
        $answer->setPosition($i + $ausgleich + 1);
        $answer->setValue(-1);
        $question->addChild($answer);
    }
    /*object HIER NOCH NICHT in db speichern!      */
    // $question->save();
    if (!$overwrite) {
        $db = new EvaluationQuestionDB();
        $lib = new EvalTemplateGUI();
        $lib->setUniqueName($question, $db, $myuserid, YES);
    }
    if ($question->isError()) {
        EvalCommon::showErrorReport($question, _("Fehler beim Speichern."));
    }
    return $question;
}
コード例 #2
0
ファイル: show_evaluation.php プロジェクト: ratbird/hope
                /* answer = answer_id */
                voteFor($answer);
            }
        }
    }
    /* process the user's typed-in answers --------------------------------- */
    $freetexts = Request::quotedArray('freetexts');
    if (is_array($freetexts)) {
        foreach ($freetexts as $question_id => $text) {
            if (trim($text) != '') {
                $question = new EvaluationQuestion($question_id);
                $answer = new EvaluationAnswer();
                $answer->setText($text);
                $answer->setRows(1);
                $answer->vote($GLOBALS["userID"]);
                $question->addChild($answer);
                $question->save();
                $debug .= "added answer text <b>" . $answer->getText() . "</b> for question <b>" . $question->getText() . "</b>\n";
            }
        }
    }
    /* connect user with eval */
    $evalDB->connectWithUser($evalID, $auth->auth["uid"]);
    /* header ------ */
    $table->cont($lib->createEvaluationHeader($eval, $votedNow, $votedEarlier));
} elseif ($votedEarlier) {
    /* header ------ */
    $table->cont($lib->createEvaluationHeader($eval, $votedNow, $votedEarlier));
} else {
    /* header ------ */
    $table->cont($lib->createEvaluationHeader($eval, $votedNow, $votedEarlier));