24 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
64 $this->db = $DIC->database();
65 $this->lng = $DIC->language();
69 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
115 $this->label =
$data[
'label'];
120 include_once(
"./Services/RTE/classes/class.ilRTE.php");
126 $this->use_min_answers = (
$data[
'use_min_answers']) ?
true :
false;
127 $this->nr_min_answers =
$data[
'nr_min_answers'];
128 $this->nr_max_answers =
$data[
'nr_max_answers'];
130 $this->categories->flushCategories();
132 "SELECT svy_variable.*, svy_category.title, svy_category.neutral FROM svy_variable, svy_category WHERE svy_variable.question_fi = %s AND svy_variable.category_fi = svy_category.category_id ORDER BY sequence ASC",
138 $this->categories->addCategory(
$data[
"title"],
$data[
"other"],
$data[
"neutral"], null, (
$data[
'scale']) ?
$data[
'scale'] : (
$data[
'sequence'] + 1));
142 parent::loadFromDb(
$id);
157 $this->categories->getCategoryCount()
174 $affectedRows = parent::saveToDb($original_id);
175 if ($affectedRows == 1) {
176 $affectedRows =
$ilDB->manipulateF(
181 $affectedRows =
$ilDB->manipulateF(
182 "INSERT INTO " . $this->
getAdditionalTableName() .
" (question_fi, orientation, use_min_answers, nr_min_answers, nr_max_answers) VALUES (%s, %s, %s, %s, %s)",
183 array(
'integer',
'text',
'integer',
'integer',
'integer'),
187 ($this->use_min_answers) ? 1 : 0,
188 ($this->nr_min_answers > 0) ? $this->nr_min_answers : null,
189 ($this->nr_max_answers > 0) ? $this->nr_max_answers : null
203 $affectedRows =
$ilDB->manipulateF(
204 "DELETE FROM svy_variable WHERE question_fi = %s",
209 for (
$i = 0;
$i < $this->categories->getCategoryCount();
$i++) {
210 $cat = $this->categories->getCategory(
$i);
212 $next_id =
$ilDB->nextId(
'svy_variable');
213 $affectedRows =
$ilDB->manipulateF(
214 "INSERT INTO svy_variable (variable_id, category_fi, question_fi, value1, other, sequence, scale, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
215 array(
'integer',
'integer',
'integer',
'float',
'integer',
'integer',
'integer',
'integer'),
216 array($next_id, $category_id, $this->
getId(), (
$i + 1), $cat->other,
$i, ($cat->scale > 0) ? $cat->scale : null,
time())
228 public function toXML($a_include_header =
true, $obligatory_state =
"")
230 include_once(
"./Services/Xml/classes/class.ilXmlWriter.php");
233 $this->
insertXML($a_xml_writer, $a_include_header, $obligatory_state);
234 $xml = $a_xml_writer->xmlDumpMem(
false);
235 if (!$a_include_header) {
236 $pos = strpos(
$xml,
"?>");
249 public function insertXML(&$a_xml_writer, $a_include_header =
true)
252 "id" => $this->
getId(),
254 "type" => $this->getQuestiontype(),
257 $a_xml_writer->xmlStartTag(
"question", $attrs);
259 $a_xml_writer->xmlElement(
"description", null, $this->
getDescription());
260 $a_xml_writer->xmlElement(
"author", null, $this->
getAuthor());
261 if (strlen($this->label)) {
263 "label" => $this->label,
268 $a_xml_writer->xmlStartTag(
"questiontext", $attrs);
270 $a_xml_writer->xmlEndTag(
"questiontext");
272 $a_xml_writer->xmlStartTag(
"responses");
274 for (
$i = 0;
$i < $this->categories->getCategoryCount();
$i++) {
278 if (strlen($this->categories->getCategory(
$i)->other)) {
279 $attrs[
'other'] = $this->categories->getCategory(
$i)->other;
281 if (strlen($this->categories->getCategory(
$i)->neutral)) {
282 $attrs[
'neutral'] = $this->categories->getCategory(
$i)->neutral;
284 if (strlen($this->categories->getCategory(
$i)->label)) {
285 $attrs[
'label'] = $this->categories->getCategory(
$i)->label;
287 if (strlen($this->categories->getCategory(
$i)->scale)) {
288 $attrs[
'scale'] = $this->categories->getCategory(
$i)->scale;
290 $a_xml_writer->xmlStartTag(
"response_multiple", $attrs);
291 $this->
addMaterialTag($a_xml_writer, $this->categories->getCategory(
$i)->title);
292 $a_xml_writer->xmlEndTag(
"response_multiple");
295 $a_xml_writer->xmlEndTag(
"responses");
297 if (count($this->material)) {
298 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $this->material[
"internal_link"], $matches)) {
300 "label" => $this->material[
"title"]
302 $a_xml_writer->xmlStartTag(
"material", $attrs);
303 $intlink =
"il_" . IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
304 if (strcmp($matches[1],
"") != 0) {
305 $intlink = $this->material[
"internal_link"];
307 $a_xml_writer->xmlElement(
"mattext", null, $intlink);
308 $a_xml_writer->xmlEndTag(
"material");
312 $a_xml_writer->xmlStartTag(
"metadata");
313 $a_xml_writer->xmlStartTag(
"metadatafield");
314 $a_xml_writer->xmlElement(
"fieldlabel", null,
"orientation");
315 $a_xml_writer->xmlElement(
"fieldentry", null, $this->
getOrientation());
316 $a_xml_writer->xmlEndTag(
"metadatafield");
317 $a_xml_writer->xmlStartTag(
"metadatafield");
318 $a_xml_writer->xmlElement(
"fieldlabel", null,
"use_min_answers");
319 $a_xml_writer->xmlElement(
"fieldentry", null, $this->use_min_answers);
320 $a_xml_writer->xmlEndTag(
"metadatafield");
321 $a_xml_writer->xmlStartTag(
"metadatafield");
322 $a_xml_writer->xmlElement(
"fieldlabel", null,
"nr_min_answers");
323 $a_xml_writer->xmlElement(
"fieldentry", null, $this->nr_min_answers);
324 $a_xml_writer->xmlEndTag(
"metadatafield");
325 $a_xml_writer->xmlStartTag(
"metadatafield");
326 $a_xml_writer->xmlElement(
"fieldlabel", null,
"nr_max_answers");
327 $a_xml_writer->xmlElement(
"fieldentry", null, $this->nr_max_answers);
328 $a_xml_writer->xmlEndTag(
"metadatafield");
329 $a_xml_writer->xmlEndTag(
"metadata");
331 $a_xml_writer->xmlEndTag(
"question");
342 return "SurveyMultipleChoiceQuestion";
364 $entered_value = $post_data[$this->
getId() .
"_value"];
366 if (is_array($entered_value)) {
367 foreach ($entered_value as $idx => $value) {
368 array_push(
$data,
array(
"value" => $value,
"textanswer" => $post_data[$this->
getId() .
'_' . $value .
'_other']));
371 for (
$i = 0;
$i < $this->categories->getCategoryCount();
$i++) {
372 $cat = $this->categories->getCategory(
$i);
375 if (!is_array($entered_value) || !in_array(
$i, $entered_value)) {
376 if (strlen($post_data[$this->
getId() .
"_" .
$i .
"_other"])) {
377 array_push(
$data,
array(
"value" =>
$i,
"textanswer" => $post_data[$this->
getId() .
'_' .
$i .
'_other'],
"uncheck" =>
true));
396 $entered_value = (
array) $post_data[$this->
getId() .
"_value"];
400 if ($this->use_min_answers && $this->nr_min_answers > 0 && $this->nr_max_answers > 0 && $this->nr_min_answers == $this->nr_max_answers && count($entered_value) != $this->nr_max_answers) {
401 return sprintf($this->lng->txt(
"err_no_exact_answers"), $this->nr_min_answers);
403 if ($this->use_min_answers && $this->nr_min_answers > 0 && count($entered_value) < $this->nr_min_answers) {
404 return sprintf($this->lng->txt(
"err_no_min_answers"), $this->nr_min_answers);
406 if ($this->use_min_answers && $this->nr_max_answers > 0 && count($entered_value) > $this->nr_max_answers) {
407 return sprintf($this->lng->txt(
"err_no_max_answers"), $this->nr_max_answers);
409 if (count($entered_value) == 0) {
410 return $this->lng->txt(
"question_mr_not_checked");
412 for (
$i = 0;
$i < $this->categories->getCategoryCount();
$i++) {
413 $cat = $this->categories->getCategory(
$i);
415 if (in_array(
$i, $entered_value)) {
416 if (array_key_exists($this->
getId() .
"_" .
$i .
"_other", $post_data) && !strlen($post_data[$this->
getId() .
"_" .
$i .
"_other"])) {
417 return $this->lng->txt(
"question_mr_no_other_answer");
420 if (strlen($post_data[$this->
getId() .
"_" .
$i .
"_other"])) {
421 return $this->lng->txt(
"question_mr_no_other_answer_checked");
434 $return_data =
array();
436 if (is_array($post_data[$this->
getId() .
"_value"])) {
437 foreach ($post_data[$this->
getId() .
"_value"] as $entered_value) {
438 if (strlen($entered_value) > 0) {
440 $next_id =
$ilDB->nextId(
'svy_answer');
444 $fields[
'answer_id'] =
array(
"integer", $next_id);
445 $fields[
'question_fi'] =
array(
"integer", $this->
getId());
446 $fields[
'active_fi'] =
array(
"integer", $active_id);
447 $fields[
'value'] =
array(
"float", (strlen($entered_value)) ? $entered_value : null);
448 $fields[
'textanswer'] =
array(
"clob", ($post_data[$this->
getId() .
"_" . $entered_value .
"_other"]) ? $post_data[$this->
getId() .
"_" . $entered_value .
"_other"] : null);
449 $fields[
'tstamp'] =
array(
"integer",
time());
451 $affectedRows =
$ilDB->insert(
"svy_answer", $fields);
453 $return_data[] =
array(
"value"=>$entered_value,
454 "textanswer"=>$post_data[$this->
getId() .
"_" . $entered_value .
"_other"]);
474 foreach ($a_meta as
$key => $value) {
475 switch ($value[
"label"]) {
479 case "use_min_answers":
480 $this->use_min_answers = $value[
"entry"];
482 case "nr_min_answers":
483 $this->nr_min_answers = $value[
"entry"];
485 case "nr_max_answers":
486 $this->nr_max_answers = $value[
"entry"];
503 $categorytext .= $material[
"text"];
505 $this->categories->addCategory(
508 strlen($data[
'neutral']) ? $data[
'neutral'] : 0,
509 strlen($data[
'label']) ? $data[
'label'] : null,
510 strlen($data[
'scale']) ? $data[
'scale'] : null
534 return array(
"=",
"<>");
547 for (
$i = 0;
$i < $this->categories->getCategoryCount();
$i++) {
548 $category = $this->categories->getCategory(
$i);
549 $options[$category->scale-1] = $category->scale .
" - " . $category->title;
562 include_once
"./Services/Form/classes/class.ilSelectInputGUI.php";
566 $step3->setValue($default);
580 $category = $this->categories->getCategoryForScale($value+1);
583 return $category->scale .
585 ((strlen($category->title)) ? $category->title : $this->lng->txt(
'other_answer'));
getPreconditionOptions()
Returns the options for preconditions.
getQuestionType()
Returns the question type of the question.
saveCategoryToDb($categorytext, $neutral=0)
Saves a category to the database.
saveUserInput($post_data, $active_id, $a_return=false)
saveCompletionStatus($original_id="")
Saves the complete flag to the database.
importAdditionalMetadata($a_meta)
Import additional meta data from the question import file.
getAuthor()
Gets the authors name of the SurveyQuestion object.
getTitle()
Gets the title string of the SurveyQuestion object.
getObligatory($survey_id="")
Gets the obligatory state of the question.
setObligatory($obligatory=1)
Sets the obligatory state of the question.
setOrientation($orientation=0)
Sets the orientation of the question output.
& getWorkingDataFromUserInput($post_data)
Creates the user data of the svy_answer table from the POST data.
setId($id=-1)
Sets the id of the SurveyQuestion object.
loadFromDb($id)
Loads a SurveyMultipleChoiceQuestion object from the database.
getQuestionDataArray($id)
Returns the question data fields from the database.
getQuestiontext()
Gets the questiontext of the SurveyQuestion object.
getOrientation()
Gets the orientation of the question output.
toXML($a_include_header=true, $obligatory_state="")
Returns an xml representation of the question.
checkUserInput($post_data, $survey_id)
Checks the input of the active user for obligatory status and entered values.
getAdditionalTableName()
Returns the name of the additional question data table in the database.
static _replaceMediaObjectImageSrc($a_text, $a_direction=0, $nic=IL_INST_ID)
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
setOwner($owner="")
Sets the creator/owner ID of the SurveyQuestion object.
setComplete($a_complete)
Sets the complete state of the question.
importResponses($a_data)
Import response data from the question import file.
__construct($title="", $description="", $author="", $questiontext="", $owner=-1, $orientation=0)
The constructor takes possible arguments an creates an instance of the SurveyMultipleChoiceQuestion o...
setOriginalId($original_id)
setQuestiontext($questiontext="")
Sets the questiontext of the SurveyQuestion object.
getId()
Gets the id of the SurveyQuestion object.
saveToDb($original_id="")
Saves a SurveyMultipleChoiceQuestion object to a database.
addMaterialTag(&$a_xml_writer, $a_material, $close_material_tag=true, $add_mobs=true, $a_attrs=null)
Creates an XML material tag from a plain text or xhtml text.
Basic class for all survey question types.
saveMaterial()
save material to db
insertXML(&$a_xml_writer, $a_include_header=true)
Adds the question XML to a given XMLWriter object.
xmlHeader()
Writes xml header public.
usableForPrecondition()
Returns if the question is usable for preconditions.
getPreconditionValueOutput($value)
Returns the output for a precondition value.
Create styles array
The data for the language used.
getAvailableRelations()
Returns the available relations for the question.
setAuthor($author="")
Sets the authors name of the SurveyQuestion object.
setDescription($description="")
Sets the description string of the SurveyQuestion object.
getPreconditionSelectValue($default="", $title, $variable)
Creates a form property for the precondition value.
isComplete()
Returns true if the question is complete for use.
MultipleChoice survey question.
getDescription()
Gets the description string of the SurveyQuestion object.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
setObjId($obj_id=0)
Set the reference id of the container object.
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
setTitle($title="")
Sets the title string of the SurveyQuestion object.