/** * swaps positions of two objects * * @access private * @param string $parentID the parentID * @param string $objectID the object to swap * @param string $oldposition the old position * @param string $direction the direction to swap */ function swapPosition($parentID, $objectID, $oldposition, $direction) { if ($parentID == ROOT_BLOCK) { $group = $this->tree->eval; } else { $group =& $this->tree->getGroupObject($parentID); } $numberchildren = $group->getNumberChildren(); $instance = $group->x_instanceof(); if ($direction == "up") { if ($oldposition == 0) { $newposition = $numberchildren - 1; } else { $newposition = $oldposition - 1; } } else { if ($oldposition == $numberchildren - 1) { $newposition = 0; } else { $newposition = $oldposition + 1; } } while ($swapitem = $group->getNextChild()) { if ($swapitem->getPosition() == $newposition) { $swapitem->setPosition($oldposition); $swapitem->save(); } } if ($parentID != ROOT_BLOCK && $group->getChildType() == "EvaluationQuestion") { $object = new EvaluationQuestion($objectID); } else { $object =& $this->tree->getGroupObject($objectID); } $object->setPosition($newposition); $object->save(); if ($swapitem->isError) { return EvalCommon::showErrorReport($swapitem, _("Fehler beim verschieben.")); } if ($object->isError) { return EvalCommon::showErrorReport($object, _("Fehler beim verschieben.")); } }
} } else { $template_answers = array(); } } if (!$template_id) { $template_id = Request::option('template_id'); } /* ---------------------------------------------------------- end: variables */ if (Request::option('onthefly') && ($command == "delete" || $command == "add_answers" || $command == "delete_answers" || $command == "save2")) { $question = new EvaluationQuestion($template_id, NULL, EVAL_LOAD_ALL_CHILDREN); $question->setMultiplechoice($template_multiple); $question->setText(trim($template_name), YES); $question->setType($template_type); $question->setParentID($parentID); $question->setPosition($template_position); while ($answerrem = $question->getChild()) { $id = $answerrem->getObjectID(); $answerrem->delete(); $question->removeChildID($id); } $controlnumber = count($template_answers); for ($i = 0; $i < $controlnumber; $i++) { $text = $template_answers[$i]['text']; $answerID = $template_answers[$i]['answer_id']; $answer = new EvaluationAnswer(); $answer->setObjectID($answerID); $answer->setText(trim($text), YES); $answer->setParentID($template_id); $question->addChild($answer); }