* @copyright 2004 Stud.IP-Project * @access public * @package evaluation * @modulegroup evaluation_modules */ class EvaluationTreeShowUser { /** * Reference to the tree structure * * @access private * @var object EvaluationTree $tree */ var $tree; /** * contains the item with the current html anchor (currently unused) * * @access public * @var string $anchor */ var $anchor; /** * the item to start with * * @access private * @var string $start_item_id */ var $start_item_id; /** * constructor * @access public * @param string the eval's ID */ public function __construct($evalID) { $this->tree = TreeAbstract::GetInstance("EvaluationTree", ['evalID' => $evalID, 'load_mode' => EVAL_LOAD_ALL_CHILDREN]); } /** * prints out the tree beginning with a given item * * @access public * @param string ID of the start item, shouldnt be needed. */ public function showTree($item_id = "root") { $items = []; if (!is_array($item_id)) { $items[0] = $item_id; $this->start_item_id = $item_id; } else { $items = $item_id; } $num_items = count($items); for ($j = 0; $j < $num_items; ++$j) { $this->printLevelOutput($items[$j]); $this->printItemOutput($items[$j]); if ($this->tree->hasKids($items[$j])) { $this->showTree($this->tree->tree_childs[$items[$j]]); } } return; } /** * prints out ... hmm ... the group's level indentation space, and a table start * * @access private * @param string ID of the item (which is an EvaluationGroup) to print the space for. */ public function printLevelOutput($group_id) { if ($group_id == "root") return; $level_output = ""; $parent_id = $group_id; while ($this->tree->tree_data[$parent_id]['parent_id'] != $this->start_item_id) { $parent_id = $this->tree->tree_data[$parent_id]['parent_id']; /* a little space to indent subgroups */ $level_output .= "" . Assets::img('forumleer.gif', ['size' => INDENT_PIXELS . '@1']) . ""; } echo "\n"; echo "\n"; echo "\n"; echo $level_output; return; } /** * prints out one group * * @access private * @param string ID of the item to print (which is an EvaluationGroup). */ public function printItemOutput($group_id) { if ($group_id == "root") return; $group = &$this->tree->getGroupObject($group_id); echo "\n"; /* show group headline, if it's not a question group */ if ($group->getChildType() != "EvaluationQuestion") { /* add space after a top-level group */ $parent = $group->getParentObject(); if ($parent->x_instanceof() == "Evaluation" && $group->getPosition() != 0) echo ""; echo ""; echo "\n"; } else { echo ""; } echo "\n"; echo "
\n"; echo "
\n"; $parent_id = $group_id; while ($parent_id != "root") { $chapter_num = ($this->tree->tree_data[$parent_id]['priority'] + 1) . "." . $chapter_num; $parent_id = $this->tree->tree_data[$parent_id]['parent_id']; } echo " " . $chapter_num . " "; echo ""; echo htmlReady($this->tree->tree_data[$group_id]['name']); echo ""; echo "\n"; echo Assets::img('forumleer.gif', ['size' => '2@1']); echo "
\n"; $this->printItemDetails($group); return; } /** * prints out the details for a group * * @access private * @param object EvaluationGroup the group object. */ public function printItemDetails($group) { $group_id = $group->getObjectID(); $parent_id = $group_id; while ($this->tree->tree_data[$parent_id]['parent_id'] != $this->start_item_id) { $parent_id = $this->tree->tree_data[$parent_id]['parent_id']; /* a little space to indent subgroups */ $level_output = "" . Assets::img('forumleer.gif', ['size' => INDENT_PIXELS . '@1']) . "" . $level_output; } /* print table */ echo "\n"; echo "\n"; echo "\n" . $level_output; echo "\n"; echo "
getChildType() == "EvaluationQuestion" ? ">" : ">"); echo $this->getGroupContent($group); echo "
\n"; return; } /** * returns html for the content of a group * * @access private * @param object EvaluationGroup the group object. * @return string */ public function getGroupContent($group) { $closeTable = NO; $html = ""; $content = ""; /* get title */ $content .= $group->getChildType() == "EvaluationQuestion" && $group->getTitle() ? "" . formatReady($group->getTitle()) . "
\n" : ""; /* get text */ $content .= $group->getText() ? formatReady($group->getText()) . "
\n" : ""; /* get the content of questions under this group, if any */ foreach ($group->getChildren() as $question) { if ($question->x_instanceof() == INSTANCEOF_EVALQUESTION) { if ($question->getPosition() == 0) { $content .= "\n\n"; } $content .= $this->getQuestionContent($question, $group); $closeTable = YES; } } if ($closeTable) $content .= "
\n"; /* return if there is nothing to show */ if (empty($content)) return ""; /* build table of content */ $style = $group->getChildType() != "EvaluationQuestion" ? "" : ""; $class = $group->getChildType() != "EvaluationQuestion" ? "eval_gray" : "steelgroup7"; $html .= "\n\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "
\n"; $html .= $content; $html .= "
\n"; return $html; } /** * returns html for a question and its answers * * @access private * @param object EvaluationQuestion the question object. * @param object EvaluationGroup the question's parent-group object. * @return string */ public function getQuestionContent($question, $group) { $type = $question->isMultipleChoice() ? "checkbox" : "radio"; $answerBorder = "1px dotted #909090"; $residualBorder = "1px dotted #909090"; $answerArray = $question->getChildren(); $hasResidual = NO; $leftOutStyle = ($group->isMandatory() && Request::submitted('voteButton') && is_array($GLOBALS["mandatories"]) && in_array($question->getObjectID(), $GLOBALS["mandatories"])) ? "background-image:url(" . Assets::image_path("steelgroup1.gif") . "); border-left:3px solid red; border-right:3px solid red;" : ""; /* Skala (one row question) ---------------------------------------- */ if ($question->getType() == EVALQUESTION_TYPE_LIKERT || $question->getType() == EVALQUESTION_TYPE_POL) { if (($numAnswers = $question->getNumberChildren()) > 0) $cellWidth = (int)(40 / $numAnswers); if ($numAnswers > 0 && $answerArray[$numAnswers - 1]->isResidual()) $hasResidual = YES; $lastTextAnswer = $hasResidual ? ($numAnswers - 3) : ($numAnswers - 2); /* Headline, only shown for first question */ if ($question->getPosition() == 0) { $html .= " \n"; $html .= " "; # $html .= mb_strlen( $group->getText() ) < 100 ? formatReady( $group->getText() ) : " "; $html .= " "; $html .= "\n"; foreach ($answerArray as $answer) { $noWrap = NO; if ($answer->x_instanceof() == INSTANCEOF_EVALANSWER) { if (!$answer->getText()) { /* answer has NO text ------------ */ if ($answer->getPosition() <= $lastTextAnswer / 2) //&& $numAnswers > 4 ) $headCell = "<--"; elseif ($answer->getPosition() >= round($lastTextAnswer / 2) + $lastTextAnswer % 2) //&& $numAnswers > 4 ) $headCell = "-->"; else $headCell = "<- ->"; $noWrap = YES; } else { /* answer has its own text ------ */ $headCell = formatReady($answer->getText()); } $extraStyle = ""; if ($answer->isResidual()) { $extraStyle = "border-left: $residualBorder;"; $html .= " "; } $html .= " "; $html .= $headCell; $html .= "\n"; } } $html .= " \n"; } $class = $question->getPosition() % 2 ? "table_row_even" : "table_row_odd"; $extraStyle = ($question->getPosition() == $group->getNumberChildren() - 1 ? "border-bottom: $answerBorder" : ""); $html .= " \n"; $html .= " "; $html .= formatReady($question->getText()); $html .= ($group->isMandatory() ? "**" : ""); $html .= "\n"; foreach ($answerArray as $answer) { $number = $question->isMultipleChoice() ? "[" . $answer->getPosition() . "]" : ""; if ($answer->x_instanceof() == INSTANCEOF_EVALANSWER) { $extraStyle = ""; if ($answer->isResidual()) { $extraStyle = "border-left: $residualBorder;"; $html .= " "; } $extraStyle .= ($question->getPosition() == $group->getNumberChildren() - 1 ? " border-bottom: $answerBorder;" : ""); $answers = Request::getArray('answers'); $checked = $answers[$question->getObjectID()] == $answer->getObjectID() ? "checked" : ""; $html .= " "; $html .= "getObjectID() . "]" . $number . "\" " . "value=\"" . $answer->getObjectID() . "\" " . $checked . ">"; $html .= "\n"; } } $html .= " \n"; /* -------------------------------------------- */ } /* Normal (question with long answers) ----------------------------- */ else { $class = $question->getPosition() % 2 ? "table_row_even" : "table_row_odd"; /* Question ----------------------------------- */ $html .= "" . "" . formatReady($question->getText()) . ($group->isMandatory() ? "**" : "") . "" . "\n"; $html .= ""; $html .= ""; $html .= "\n"; /* -------------------------------------------- */ $numberOfVisibleAnswers = 0; foreach ($answerArray as $answer) if (!($answer->isFreetext() && $answer->getText() != '')) $numberOfVisibleAnswers++; if ($numberOfVisibleAnswers == 0) { $html .= "\n"; $html .= "\n"; $html .= "\n"; } /* Answers ------------------------------------ */ foreach ($answerArray as $answer) { if ($answer->x_instanceof() == INSTANCEOF_EVALANSWER) { $number = $question->isMultipleChoice() ? "[" . $answer->getPosition() . "]" : ""; /* if not a user's answer */ if (!($answer->isFreetext() && $answer->getText() != '')) { $html .= "\n"; /* show text input field ---------- */ if ($answer->isFreetext()) { // not really needed anymore if ($numberOfVisibleAnswers > 1) /* show a check/radio-box */ $html .= "\n"; /* one row input field */ $freetexts = Request::getArray('freetexts'); if ($answer->getRows() == 1) $html .= "\n"; /* multiple row input field (textarea) */ else $html .= "\n"; } /* show normal answer ------------- */ else { $answers = Request::getArray('answers'); /* see if it must be checked */ if ($type == "radio") $checked = $answers[$question->getObjectID()] == $answer->getObjectID() ? "checked" : ""; else $checked = (is_array($answers[$question->getObjectID()]) && in_array($answer->getObjectID(), $answers[$question->getObjectID()])) ? "checked" : ""; /* show a check/radio-box */ $html .= "\n"; $html .= "\n"; } $html .= "\n"; } } /* ------------------------------- End: Answers */ } $html .= "
" . _("Dieser Frage wurden keine Antworten zugeordnet!") . "
" . "getObjectID() . "]" . $number . "\"" . " value=\"" . $answer->getObjectID() . "\">" . "" . "getObjectID() . "]\"" . " value=\"" . htmlReady($freetexts[$question->getObjectID()]) . "\" size=\"60\">" . "" . "getObjectID() . "]\"" . " cols=\"60\" rows=\"" . $answer->getRows() . "\">" . htmlReady($freetexts[$question->getObjectID()]) . "" . "" . "getObjectID() . "]" . $number . "\"" . " value=\"" . $answer->getObjectID() . "\" " . $checked . ">" . "" . formatReady($answer->getText()) . "
\n"; $html .= ""; } return $html; } }