Esempio n. 1
0
 /**
 * Creates an instance of a question with a given question id
 *
 * @param integer $question_id The question id
 * @return object The question instance
 * @access public
 */
 function &_instanciateQuestion($question_id)
 {
     if ($question_id < 1) {
         return FALSE;
     }
     include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
     $question_type = SurveyQuestion::_getQuestionType($question_id);
     if (strlen($question_type) == 0) {
         return FALSE;
     }
     SurveyQuestion::_includeClass($question_type);
     $question = new $question_type();
     $question->loadFromDb($question_id);
     return $question;
 }
 /**
  * export questions to xml
  */
 function toXML($questions)
 {
     if (!is_array($questions)) {
         $questions =& $this->getQuestions();
     }
     if (count($questions) == 0) {
         $questions =& $this->getQuestions();
     }
     $xml = "";
     include_once "./Services/Xml/classes/class.ilXmlWriter.php";
     $a_xml_writer = new ilXmlWriter();
     // set xml header
     $a_xml_writer->xmlHeader();
     $attrs = array("xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", "xsi:noNamespaceSchemaLocation" => "http://www.ilias.de/download/xsd/ilias_survey_4_2.xsd");
     $a_xml_writer->xmlStartTag("surveyobject", $attrs);
     $attrs = array("id" => "qpl_" . $this->getId(), "label" => $this->getTitle(), "online" => $this->getOnline());
     $a_xml_writer->xmlStartTag("surveyquestions", $attrs);
     $a_xml_writer->xmlElement("dummy", NULL, "dummy");
     // add ILIAS specific metadata
     $a_xml_writer->xmlStartTag("metadata");
     $a_xml_writer->xmlStartTag("metadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "SCORM");
     include_once "./Services/MetaData/classes/class.ilMD.php";
     $md = new ilMD($this->getId(), 0, $this->getType());
     $writer = new ilXmlWriter();
     $md->toXml($writer);
     $metadata = $writer->xmlDumpMem();
     $a_xml_writer->xmlElement("fieldentry", NULL, $metadata);
     $a_xml_writer->xmlEndTag("metadatafield");
     $a_xml_writer->xmlEndTag("metadata");
     $a_xml_writer->xmlEndTag("surveyquestions");
     $a_xml_writer->xmlEndTag("surveyobject");
     $xml = $a_xml_writer->xmlDumpMem(FALSE);
     $questionxml = "";
     foreach ($questions as $key => $value) {
         $questiontype = $this->getQuestiontype($value);
         include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
         SurveyQuestion::_includeClass($questiontype);
         $question = new $questiontype();
         $question->loadFromDb($value);
         $questionxml .= $question->toXML(false);
     }
     $xml = str_replace("<dummy>dummy</dummy>", $questionxml, $xml);
     return $xml;
 }
 /**
  * Creates a question gui representation
  *
  * Creates a question gui representation and returns the alias to the question gui
  * note: please do not use $this inside this method to allow static calls
  *
  * @param string $question_type The question type as it is used in the language database
  * @param integer $question_id The database ID of an existing question to load it into ASS_QuestionGUI
  * @return object The alias to the question object
  * @access public
  */
 static function &_getQuestionGUI($questiontype, $question_id = -1)
 {
     include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
     if (!$questiontype and $question_id > 0) {
         $questiontype = SurveyQuestion::_getQuestiontype($question_id);
     }
     SurveyQuestion::_includeClass($questiontype, 1);
     $question_type_gui = $questiontype . "GUI";
     $question = new $question_type_gui($question_id);
     return $question;
 }
 /**
  * Delete constraint confirmation
  */
 public function confirmDeleteConstraintsObject()
 {
     $id = (int) $_REQUEST["precondition"];
     if (!$this->validateConstraintForEdit($id)) {
         $this->ctrl->redirect($this, "constraints");
     }
     $constraint = $this->object->getPrecondition($id);
     $questions = $this->object->getSurveyQuestions();
     $question = $questions[$constraint["question_fi"]];
     $relation = $questions[$constraint["ref_question_fi"]];
     $relation = $relation["title"];
     // see ilSurveyConstraintsTableGUI
     include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
     $question_type = SurveyQuestion::_getQuestionType($constraint["question_fi"]);
     SurveyQuestion::_includeClass($question_type);
     $question_obj = new $question_type();
     $question_obj->loadFromDb($constraint["question_fi"]);
     $valueoutput = $question_obj->getPreconditionValueOutput($constraint["value"]);
     $title = $question["title"] . " " . $constraint["shortname"] . " " . $valueoutput;
     $this->ctrl->saveParameter($this, "precondition");
     include_once "./Services/Utilities/classes/class.ilConfirmationGUI.php";
     $cgui = new ilConfirmationGUI();
     $cgui->setHeaderText(sprintf($this->lng->txt("survey_sure_delete_constraint"), $title, $relation));
     $cgui->setFormAction($this->ctrl->getFormAction($this, "deleteConstraints"));
     $cgui->setCancel($this->lng->txt("cancel"), "constraints");
     $cgui->setConfirm($this->lng->txt("confirm"), "deleteConstraints");
     $this->tpl->setContent($cgui->getHTML());
 }
Esempio n. 5
0
 /**
  * Creates an instance of a question GUI with a given question id
  *
  * @param integer $question_id The question id
  * @return object The question GUI instance
  * @access public
  */
 function &_instanciateQuestionGUI($question_id)
 {
     $question_type = SurveyQuestion::_getQuestionType($question_id);
     if ($question_type) {
         SurveyQuestion::_includeClass($question_type, 1);
         $guitype = $question_type . "GUI";
         $question = new $guitype($question_id);
         return $question;
     }
 }
 public function constraintForm($step, $postvalues, &$survey_questions, $questions = FALSE)
 {
     if (strlen($_GET["start"])) {
         $this->ctrl->setParameter($this, "start", $_GET["start"]);
     }
     $this->ctrl->saveParameter($this, "precondition");
     include_once "./Services/Form/classes/class.ilPropertyFormGUI.php";
     $form = new ilPropertyFormGUI();
     $form->setFormAction($this->ctrl->getFormAction($this));
     $form->setTableWidth("100%");
     $form->setId("constraintsForm");
     // #9366
     $title = array();
     $title_ids = $_SESSION["includeElements"];
     if (!$title_ids) {
         $title_ids = array($_GET["start"]);
     }
     foreach ($title_ids as $title_id) {
         // question block
         if ($survey_questions[$_SESSION["constraintstructure"][$title_id][0]]["questionblock_id"] > 0) {
             $title[] = $this->lng->txt("questionblock") . ": " . $survey_questions[$_SESSION["constraintstructure"][$title_id][0]]["questionblock_title"];
         } else {
             $title[] = $this->lng->txt($survey_questions[$_SESSION["constraintstructure"][$title_id][0]]["type_tag"]) . ": " . $survey_questions[$_SESSION["constraintstructure"][$title_id][0]]["title"];
         }
     }
     $header = new ilFormSectionHeaderGUI();
     $header->setTitle(implode("<br/>", $title));
     $form->addItem($header);
     $fulfilled = new ilRadioGroupInputGUI($this->lng->txt("constraint_fulfilled"), "c");
     $fulfilled->addOption(new ilRadioOption($this->lng->txt("conjunction_and"), '0', ''));
     $fulfilled->addOption(new ilRadioOption($this->lng->txt("conjunction_or"), '1', ''));
     $fulfilled->setValue(strlen($postvalues['c']) ? $postvalues['c'] : 0);
     $form->addItem($fulfilled);
     $step1 = new ilSelectInputGUI($this->lng->txt("step") . " 1: " . $this->lng->txt("select_prior_question"), "q");
     $options = array();
     if (is_array($questions)) {
         foreach ($questions as $question) {
             $options[$question["question_id"]] = $question["title"] . " (" . SurveyQuestion::_getQuestionTypeName($question["type_tag"]) . ")";
         }
     }
     $step1->setOptions($options);
     $step1->setValue($postvalues["q"]);
     $form->addItem($step1);
     if ($step > 1) {
         $relations = $this->object->getAllRelations();
         $step2 = new ilSelectInputGUI($this->lng->txt("step") . " 2: " . $this->lng->txt("select_relation"), "r");
         $options = array();
         foreach ($relations as $rel_id => $relation) {
             if (in_array($relation["short"], $survey_questions[$postvalues["q"]]["availableRelations"])) {
                 $options[$rel_id] = $relation['short'];
             }
         }
         $step2->setOptions($options);
         $step2->setValue($postvalues["r"]);
         $form->addItem($step2);
     }
     if ($step > 2) {
         $variables =& $this->object->getVariables($postvalues["q"]);
         $question_type = $survey_questions[$postvalues["q"]]["type_tag"];
         include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
         SurveyQuestion::_includeClass($question_type);
         $question = new $question_type();
         $question->loadFromDb($postvalues["q"]);
         $step3 = $question->getPreconditionSelectValue($postvalues["v"], $this->lng->txt("step") . " 3: " . $this->lng->txt("select_value"), "v");
         $form->addItem($step3);
     }
     switch ($step) {
         case 1:
             $cmd_continue = "constraintStep2";
             $cmd_back = "constraints";
             break;
         case 2:
             $cmd_continue = "constraintStep3";
             $cmd_back = "constraintStep1";
             break;
         case 3:
             $cmd_continue = "constraintsAdd";
             $cmd_back = "constraintStep2";
             break;
     }
     $form->addCommandButton($cmd_back, $this->lng->txt("back"));
     $form->addCommandButton($cmd_continue, $this->lng->txt("continue"));
     $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
 }
 /**
  * handler for begin of element
  */
 function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
 {
     $this->depth[$a_xml_parser]++;
     $this->path[$this->depth[$a_xml_parser]] = strtolower($a_name);
     $this->characterbuffer = "";
     $this->activetag = $a_name;
     $this->elements++;
     $this->attributes += count($a_attribs);
     switch ($a_name) {
         case "questionblock":
             $this->in_questionblock = TRUE;
             $this->questionblock = array();
             $this->questionblocktitle = "";
             $this->showQuestiontext = 1;
             foreach ($a_attribs as $attrib => $value) {
                 switch ($attrib) {
                     case "showQuestiontext":
                         $this->showQuestiontext = $value;
                         break;
                 }
             }
             break;
         case "surveyquestions":
             foreach ($a_attribs as $attrib => $value) {
                 switch ($attrib) {
                     case "online":
                         if ($this->spl_id > 0) {
                             include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
                             $spl = new ilObjSurveyQuestionPool($this->spl_id, false);
                             $spl->setOnline($value);
                             $spl->saveToDb();
                         }
                         break;
                 }
             }
             break;
         case "survey":
             $this->in_survey = TRUE;
             foreach ($a_attribs as $attrib => $value) {
                 switch ($attrib) {
                     case "title":
                         if (is_object($this->survey)) {
                             $this->survey->setTitle($value);
                         }
                         break;
                 }
             }
             break;
         case "anonymisation":
             foreach ($a_attribs as $attrib => $value) {
                 switch ($attrib) {
                     case "enabled":
                         $this->anonymisation = $value;
                         break;
                 }
             }
             break;
         case "access":
             foreach ($a_attribs as $attrib => $value) {
                 switch ($attrib) {
                     case "type":
                         $this->surveyaccess = $value;
                         break;
                 }
             }
             break;
         case "constraint":
             array_push($this->constraints, array("sourceref" => $a_attribs["sourceref"], "destref" => $a_attribs["destref"], "relation" => $a_attribs["relation"], "value" => $a_attribs["value"], "conjunction" => (int) $a_attribs["conjuction"]));
             break;
         case "question":
             // start with a new survey question
             $type = $a_attribs["type"];
             // patch due to changes in question types
             switch ($type) {
                 case 'SurveyNominalQuestion':
                     $type = 'SurveyMultipleChoiceQuestion';
                     foreach ($a_attribs as $key => $value) {
                         switch ($key) {
                             case "subtype":
                                 if ($value == 1) {
                                     $type = 'SurveySingleChoiceQuestion';
                                 } else {
                                     $type = 'SurveyMultipleChoiceQuestion';
                                 }
                                 break;
                         }
                     }
                     break;
                 case 'SurveyOrdinalQuestion':
                     $type = 'SurveySingleChoiceQuestion';
                     break;
             }
             if (strlen($type)) {
                 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
                 if (SurveyQuestion::_includeClass($type)) {
                     $this->activequestion = new $type();
                     // if no pool is given, question will reference survey
                     $q_obj_id = $this->spl_id;
                     if ($this->spl_id < 0) {
                         $q_obj_id = $this->survey->getId();
                     }
                     $this->activequestion->setObjId($q_obj_id);
                 }
             } else {
                 $this->activequestion = NULL;
             }
             $this->original_question_id = $a_attribs["id"];
             if ($this->in_questionblock) {
                 array_push($this->questionblock, $this->original_question_id);
             }
             if (is_object($this->activequestion)) {
                 foreach ($a_attribs as $key => $value) {
                     switch ($key) {
                         case "title":
                             $this->activequestion->setTitle($value);
                             break;
                         case "subtype":
                             $this->activequestion->setSubtype($value);
                             break;
                         case "obligatory":
                             $this->activequestion->setObligatory($value);
                             break;
                     }
                 }
             }
             break;
         case "material":
             switch ($this->getParent($a_xml_parser)) {
                 case "question":
                 case "questiontext":
                     $this->material = array();
                     break;
             }
             array_push($this->material, array("text" => "", "image" => "", "label" => $a_attribs["label"]));
             break;
         case "matimage":
         case "label":
             if (array_key_exists("label", $a_attribs)) {
                 if (preg_match("/(il_([0-9]+)_mob_([0-9]+))/", $a_attribs["label"], $matches)) {
                     // import an mediaobject which was inserted using tiny mce
                     if (!is_array($_SESSION["import_mob_xhtml"])) {
                         $_SESSION["import_mob_xhtml"] = array();
                     }
                     array_push($_SESSION["import_mob_xhtml"], array("mob" => $a_attribs["label"], "uri" => $a_attribs["uri"], "type" => $a_attribs["type"], "id" => $a_attribs["id"]));
                 }
             }
             break;
         case "metadata":
             $this->metadata = array();
             break;
         case "metadatafield":
             array_push($this->metadata, array("label" => "", "entry" => ""));
             break;
         case "matrix":
             $this->is_matrix = TRUE;
             $this->matrix = array();
             break;
         case "matrixrow":
             $this->material = array();
             array_push($this->matrix, "");
             $this->matrixrowattribs = array("id" => $a_attribs["id"], "label" => $a_attribs["label"], "other" => $a_attribs["other"]);
             break;
         case "responses":
             $this->material = array();
             $this->responses = array();
             break;
         case "variables":
             $this->variables = array();
             break;
         case "response_single":
             $this->material = array();
             $this->responses[$a_attribs["id"]] = array("type" => "single", "id" => $a_attribs["id"], "label" => $a_attribs["label"], "other" => $a_attribs["other"], "neutral" => $a_attribs["neutral"], "scale" => $a_attribs["scale"]);
             $this->response_id = $a_attribs["id"];
             break;
         case "response_multiple":
             $this->material = array();
             $this->responses[$a_attribs["id"]] = array("type" => "multiple", "id" => $a_attribs["id"], "label" => $a_attribs["label"], "other" => $a_attribs["other"], "neutral" => $a_attribs["neutral"], "scale" => $a_attribs["scale"]);
             $this->response_id = $a_attribs["id"];
             break;
         case "response_text":
             $this->material = array();
             $this->responses[$a_attribs["id"]] = array("type" => "text", "id" => $a_attribs["id"], "columns" => $a_attribs["columns"], "maxlength" => $a_attribs["maxlength"], "rows" => $a_attribs["rows"], "label" => $a_attribs["label"]);
             $this->response_id = $a_attribs["id"];
             break;
         case "response_num":
             $this->material = array();
             $this->responses[$a_attribs["id"]] = array("type" => "num", "id" => $a_attribs["id"], "format" => $a_attribs["format"], "max" => $a_attribs["max"], "min" => $a_attribs["min"], "size" => $a_attribs["size"], "label" => $a_attribs["label"]);
             $this->response_id = $a_attribs["id"];
             break;
         case "response_time":
             $this->material = array();
             $this->responses[$a_attribs["id"]] = array("type" => "time", "id" => $a_attribs["id"], "format" => $a_attribs["format"], "max" => $a_attribs["max"], "min" => $a_attribs["min"], "label" => $a_attribs["label"]);
             $this->response_id = $a_attribs["id"];
             break;
         case "bipolar_adjectives":
             $this->adjectives = array();
             break;
         case "adjective":
             array_push($this->adjectives, array("label" => $a_attribs["label"], "text" => ""));
             break;
     }
 }