Пример #1
0
 /**
  * Gets the evaluation id for a object id
  * @access  public
  * @param   string   $objectID   The object id
  * @return  string   The evaluation id or nothing
  */
 function getEvalID($objectID)
 {
     if (empty($objectID)) {
         die("FATAL ERROR in getEvalID ;)");
     }
     $type = EvaluationObjectDB::getType($objectID);
     #    echo "Bekomme: $objectID - $type<br>\n";
     switch ($type) {
         case INSTANCEOF_EVALANSWER:
             $parentID = EvaluationAnswerDB::getParentID($objectID);
             break;
         case INSTANCEOF_EVALQUESTION:
             $parentID = EvaluationQuestionDB::getParentID($objectID);
             break;
         case INSTANCEOF_EVALGROUP:
             $parentID = EvaluationGroupDB::getParentID($objectID);
             break;
         default:
             return $objectID;
     }
     $type = EvaluationObjectDB::getType($parentID);
     #    echo "Leite weiter: $parentID - $type<br>\n";
     return EvaluationObjectDB::getEvalID($parentID);
 }
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;
}
Пример #3
0
 /**
 * creates the template selection
 *
 * @access  private
 * @param   string  $selected  the entry to be preselected (optional)
 * @return  string             the html
 */
 function createTemplateSelection($selected = NULL)
 {
     global $user;
     $question_show = new EvaluationQuestionDB();
     $arrayOfTemplateIDs = $question_show->getTemplateID($user->id);
     $arrayOfPolTemplates = array();
     $arrayOfSkalaTemplates = array();
     $arrayOfNormalTemplates = array();
     $arrayOfFreetextTemplates = array();
     if (is_array($arrayOfTemplateIDs)) {
         foreach ($arrayOfTemplateIDs as $templateID) {
             $question = new EvaluationQuestion($templateID, NULL, EVAL_LOAD_FIRST_CHILDREN);
             $question->load();
             $questiontyp = $question->getType();
             $questiontext = $question->getText();
             if ($question->getParentID() == '0') {
                 $questiontext .= " " . EVAL_ROOT_TAG;
             }
             switch ($questiontyp) {
                 case EVALQUESTION_TYPE_POL:
                     array_push($arrayOfPolTemplates, array($question->getObjectID(), $questiontext));
                     break;
                 case EVALQUESTION_TYPE_LIKERT:
                     array_push($arrayOfSkalaTemplates, array($question->getObjectID(), $questiontext));
                     break;
                 case EVALQUESTION_TYPE_MC:
                     $answer = $question->getNextChild();
                     if ($answer && $answer->isFreetext()) {
                         array_push($arrayOfFreetextTemplates, array($question->getObjectID(), $questiontext));
                     } else {
                         array_push($arrayOfNormalTemplates, array($question->getObjectID(), $questiontext));
                     }
                     break;
             }
         }
     }
     // End:  if (is_array ($arrayOfTemplateIDs))
     $select = new HTML("select");
     $select->addAttr("name", "templateID");
     $select->addAttr("style", "vertical-align:middle;");
     $option = new HTML("option");
     $option->addAttr("value", "");
     $option->addContent(NO_TEMPLATE_GROUP);
     $select->addContent($option);
     if (!empty($arrayOfPolTemplates) && is_array($arrayOfPolTemplates)) {
         $optgroup = new HTML("optgroup");
         $optgroup->addAttr("label", _("Polskalen:"));
         foreach ($arrayOfPolTemplates as $template) {
             $option = new HTML("option");
             $option->addAttr("value", $template[0]);
             if ($template[0] == $selected) {
                 $option->addAttr("selected", "selected");
             }
             $option->addHTMLContent($template[1]);
             $optgroup->addContent($option);
         }
         $select->addContent($optgroup);
     }
     if (!empty($arrayOfSkalaTemplates) && is_array($arrayOfSkalaTemplates)) {
         $optgroup = new HTML("optgroup");
         $optgroup->addAttr("label", _("Likertskalen:"));
         foreach ($arrayOfSkalaTemplates as $template) {
             $option = new HTML("option");
             $option->addAttr("value", $template[0]);
             if ($template[0] == $selected) {
                 $option->addAttr("selected", "selected");
             }
             $option->addContent($template[1]);
             $optgroup->addContent($option);
         }
         $select->addContent($optgroup);
     }
     if (!empty($arrayOfNormalTemplates) && is_array($arrayOfNormalTemplates)) {
         $optgroup = new HTML("optgroup");
         $optgroup->addAttr("label", _("Multiple Choice:"));
         foreach ($arrayOfNormalTemplates as $template) {
             $option = new HTML("option");
             $option->addAttr("value", $template[0]);
             if ($template[0] == $selected) {
                 $option->addAttr("selected", "selected");
             }
             $option->addContent($template[1]);
             $optgroup->addContent($option);
         }
         $select->addContent($optgroup);
     }
     if (!empty($arrayOfFreetextTemplates) && is_array($arrayOfFreetextTemplates)) {
         $optgroup = new HTML("optgroup");
         $optgroup->addAttr("label", _("Freitextantworten:"));
         foreach ($arrayOfFreetextTemplates as $template) {
             $option = new HTML("option");
             $option->addAttr("value", $template[0]);
             if ($template[0] == $selected) {
                 $option->addAttr("selected", "selected");
             }
             $option->addContent($template[1]);
             $optgroup->addContent($option);
         }
         $select->addContent($optgroup);
     }
     return $select->createContent();
 }
Пример #4
0
 /**
  * Returns the type of an objectID
  * @access public
  * @param  string  $objectID  The objectID
  * @return string  INSTANCEOF_x, else NO
  */
 function getType($objectID)
 {
     if ($this->exists($objectID)) {
         return INSTANCEOF_EVALGROUP;
     } else {
         $dbObject = new EvaluationQuestionDB();
         return $dbObject->getType($objectID);
     }
 }