24 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
67 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
82 $categories = array();
83 $result = $ilDB->queryF(
"SELECT svy_category.* FROM svy_category, svy_phrase_cat WHERE svy_phrase_cat.category_fi = svy_category.category_id AND svy_phrase_cat.phrase_fi = %s ORDER BY svy_phrase_cat.sequence",
89 if ((
$row[
"defaultvalue"] == 1) and (
$row[
"owner_fi"] == 0))
91 $categories[
$row[
"category_id"]] = $this->lng->txt($row[
"title"]);
95 $categories[
$row[
"category_id"]] = $row[
"title"];
112 $result = $ilDB->queryF(
"SELECT svy_category.* FROM svy_category, svy_phrase_cat WHERE svy_phrase_cat.category_fi = svy_category.category_id AND svy_phrase_cat.phrase_fi = %s AND (svy_category.owner_fi = 0 OR svy_category.owner_fi = %s) ORDER BY svy_phrase_cat.sequence",
113 array(
'integer',
'integer'),
114 array($phrase_id, $ilUser->getId())
118 $neutral =
$row[
"neutral"];
119 if ((
$row[
"defaultvalue"] == 1) and (
$row[
"owner_fi"] == 0))
121 $this->categories->addCategory($this->lng->txt(
$row[
"title"]), 0, $neutral);
125 $this->categories->addCategory(
$row[
"title"], 0, $neutral);
147 return $ilDB->fetchAssoc(
$result);
174 $this->label =
$data[
'label'];
179 include_once(
"./Services/RTE/classes/class.ilRTE.php");
186 $this->categories->flushCategories();
187 $result = $ilDB->queryF(
"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",
195 $this->categories->addCategory(
$data[
"title"],
$data[
"other"],
$data[
"neutral"], null, (
$data[
'scale']) ?
$data[
'scale'] : (
$data[
'sequence'] + 1));
199 parent::loadFromDb(
$id);
214 $this->categories->getCategoryCount()
234 $affectedRows = parent::saveToDb($original_id);
235 if ($affectedRows == 1)
237 $affectedRows = $ilDB->manipulateF(
"DELETE FROM " . $this->
getAdditionalTableName() .
" WHERE question_fi = %s",
239 array($this->
getId())
241 $affectedRows = $ilDB->manipulateF(
"INSERT INTO " . $this->
getAdditionalTableName() .
" (question_fi, orientation) VALUES (%s, %s)",
242 array(
'integer',
'text'),
258 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_variable WHERE question_fi = %s",
260 array($this->
getId())
263 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
265 $cat = $this->categories->getCategory($i);
267 $next_id = $ilDB->nextId(
'svy_variable');
268 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_variable (variable_id, category_fi, question_fi, value1, other, sequence, scale, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
269 array(
'integer',
'integer',
'integer',
'float',
'integer',
'integer',
'integer',
'integer'),
270 array($next_id, $category_id, $this->
getId(), ($i + 1), $cat->other, $i, ($cat->scale > 0) ? $cat->scale : null, time())
282 function toXML($a_include_header = TRUE, $obligatory_state =
"")
284 include_once(
"./Services/Xml/classes/class.ilXmlWriter.php");
287 $this->
insertXML($a_xml_writer, $a_include_header, $obligatory_state);
288 $xml = $a_xml_writer->xmlDumpMem(FALSE);
289 if (!$a_include_header)
291 $pos = strpos($xml,
"?>");
292 $xml = substr($xml, $pos + 2);
305 function insertXML(&$a_xml_writer, $a_include_header = TRUE, $obligatory_state =
"")
308 "id" => $this->
getId(),
310 "type" => $this->getQuestiontype(),
313 $a_xml_writer->xmlStartTag(
"question", $attrs);
315 $a_xml_writer->xmlElement(
"description", NULL, $this->
getDescription());
316 $a_xml_writer->xmlElement(
"author", NULL, $this->
getAuthor());
317 if (strlen($this->label))
320 "label" => $this->label,
327 $a_xml_writer->xmlStartTag(
"questiontext", $attrs);
329 $a_xml_writer->xmlEndTag(
"questiontext");
331 $a_xml_writer->xmlStartTag(
"responses");
333 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
338 if (strlen($this->categories->getCategory($i)->other)) $attrs[
'other'] = $this->categories->getCategory($i)->other;
339 if (strlen($this->categories->getCategory($i)->neutral)) $attrs[
'neutral'] = $this->categories->getCategory($i)->neutral;
340 if (strlen($this->categories->getCategory($i)->label)) $attrs[
'label'] = $this->categories->getCategory($i)->label;
341 if (strlen($this->categories->getCategory($i)->scale)) $attrs[
'scale'] = $this->categories->getCategory($i)->scale;
342 $a_xml_writer->xmlStartTag(
"response_single", $attrs);
343 $this->
addMaterialTag($a_xml_writer, $this->categories->getCategory($i)->title);
344 $a_xml_writer->xmlEndTag(
"response_single");
347 $a_xml_writer->xmlEndTag(
"responses");
349 if (count($this->material))
351 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $this->material[
"internal_link"], $matches))
354 "label" => $this->material[
"title"]
356 $a_xml_writer->xmlStartTag(
"material", $attrs);
357 $intlink =
"il_" . IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
358 if (strcmp($matches[1],
"") != 0)
360 $intlink = $this->material[
"internal_link"];
362 $a_xml_writer->xmlElement(
"mattext", NULL, $intlink);
363 $a_xml_writer->xmlEndTag(
"material");
367 $a_xml_writer->xmlStartTag(
"metadata");
368 $a_xml_writer->xmlStartTag(
"metadatafield");
369 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"orientation");
370 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->
getOrientation());
371 $a_xml_writer->xmlEndTag(
"metadatafield");
372 $a_xml_writer->xmlEndTag(
"metadata");
374 $a_xml_writer->xmlEndTag(
"question");
387 foreach ($a_meta as $key => $value)
389 switch ($value[
"label"])
407 for ($i = $lower_limit; $i <= $upper_limit; $i++)
409 $this->categories->addCategory($i);
425 $next_id = $ilDB->nextId(
'svy_phrase');
426 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_phrase (phrase_id, title, defaultvalue, owner_fi, tstamp) VALUES (%s, %s, %s, %s, %s)",
427 array(
'integer',
'text',
'text',
'integer',
'integer'),
428 array($next_id,
$title, 1, $ilUser->getId(), time())
430 $phrase_id = $next_id;
435 $next_id = $ilDB->nextId(
'svy_category');
436 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_category (category_id, title, defaultvalue, owner_fi, tstamp, neutral) VALUES (%s, %s, %s, %s, %s, %s)",
437 array(
'integer',
'text',
'text',
'integer',
'integer',
'text'),
438 array($next_id, $data[
'answer'], 1, $ilUser->getId(), time(), $data[
'neutral'])
440 $category_id = $next_id;
441 $next_id = $ilDB->nextId(
'svy_phrase_cat');
442 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_phrase_cat (phrase_category_id, phrase_fi, category_fi, sequence, other, scale) VALUES (%s, %s, %s, %s, %s, %s)",
443 array(
'integer',
'integer',
'integer',
'integer',
'integer',
'integer'),
444 array($next_id, $phrase_id, $category_id, $counter, ($data[
'other']) ? 1 : 0, $data[
'scale'])
458 return "SurveySingleChoiceQuestion";
480 $entered_value = $post_data[$this->
getId() .
"_value"];
482 if (strlen($entered_value))
484 array_push(
$data, array(
"value" => $entered_value,
"textanswer" => $post_data[$this->
getId() .
'_' . $entered_value .
'_other']));
486 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
488 $cat = $this->categories->getCategory($i);
491 if ($i != $entered_value)
493 if (strlen($post_data[$this->
getId() .
"_" . $i .
"_other"]))
495 array_push(
$data, array(
"value" => $i,
"textanswer" => $post_data[$this->
getId() .
'_' . $i .
'_other'],
"uncheck" =>
true));
514 $entered_value = $post_data[$this->
getId() .
"_value"];
518 if (strlen($entered_value) == 0)
return $this->lng->txt(
"question_not_checked");
520 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
522 $cat = $this->categories->getCategory($i);
525 if ($i == $entered_value)
527 if (array_key_exists($this->
getId() .
"_" . $entered_value .
"_other", $post_data) && !strlen($post_data[$this->
getId() .
"_" . $entered_value .
"_other"]))
529 return $this->lng->txt(
"question_mr_no_other_answer");
534 if (strlen($post_data[$this->
getId() .
"_" . $i .
"_other"]))
536 return $this->lng->txt(
"question_sr_no_other_answer_checked");
554 $category = rand(0, $this->categories->getCategoryCount()-1);
555 $cat = $this->categories->getCategory($category);
556 $next_id = $ilDB->nextId(
'svy_answer');
557 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
558 array(
'integer',
'integer',
'integer',
'float',
'text',
'integer'),
559 array($next_id, $this->
getId(), $active_id, $category, ($cat->other) ?
"Random Data" : null, time())
567 $entered_value = $post_data[$this->
getId() .
"_value"];
571 return array(array(
"value"=>$entered_value,
572 "textanswer"=>$post_data[$this->
getId() .
"_" . $entered_value .
"_other"]));
574 if (strlen($entered_value) == 0)
return;
576 $next_id = $ilDB->nextId(
'svy_answer');
577 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
578 array(
'integer',
'integer',
'integer',
'float',
'text',
'integer'),
579 array($next_id, $this->
getId(), $active_id, (strlen($entered_value)) ? $entered_value : NULL, ($post_data[$this->
getId() .
"_" . $entered_value .
"_other"]) ? $post_data[$this->
getId() .
"_" . $entered_value .
"_other"] : null, time())
587 $question_id = $this->
getId();
589 $result_array = array();
592 $sql =
"SELECT svy_answer.* FROM svy_answer".
593 " JOIN svy_finished ON (svy_finished.finished_id = svy_answer.active_fi)".
594 " WHERE svy_answer.question_fi = ".$ilDB->quote($question_id,
"integer").
595 " AND svy_finished.survey_fi = ".$ilDB->quote(
$survey_id,
"integer");
598 $sql .=
" AND ".$ilDB->in(
"svy_finished.finished_id", $finished_ids,
"",
"integer");
607 if ($row[
"textanswer"])
609 $result_array[
"textanswers"][$row[
"value"]][] = $row[
"textanswer"];
613 if (is_array($result_array[
"textanswers"]))
615 ksort($result_array[
"textanswers"], SORT_NUMERIC);
620 $result_array[
"USERS_ANSWERED"] =
$result->numRows();
621 $result_array[
"USERS_SKIPPED"] = $nr_of_users -
$result->numRows();
630 $category = $this->categories->getCategoryForScale(key(
$cumulated)+1);
631 $result_array[
"MODE"] = $prefix . $category->title;
632 $result_array[
"MODE_VALUE"] = key(
$cumulated)+1;
635 for ($key = 0; $key < $this->categories->getCategoryCount(); $key++)
637 $cat = $this->categories->getCategory($key);
641 $percentage = (float)((
int)
$cumulated[$cat->scale-1]/$numrows);
645 $result_array[
"variables"][$key] = array(
"title" => (strlen($cat->title)) ? $cat->title : $this->lng->txt(
'other_answer'),
"selected" => (int)
$cumulated[$cat->scale-1],
"percentage" => $percentage);
649 $result_array[
"variables"][$key] = array(
"title" => $cat->title,
"selected" => (
int)
$cumulated[$cat->scale-1],
"percentage" => $percentage);
658 for ($i = 0; $i < $key; $i++)
660 array_push($median, $value+1);
667 $median_value = 0.5 * ($median[(
$total/2)-1] + $median[(
$total/2)]);
668 if (round($median_value) != $median_value)
670 $median_value = $median_value .
"<br />" .
"(" . $this->lng->txt(
"median_between") .
" " . (floor($median_value)) .
"-" . $this->categories->getCategory((
int)floor($median_value)-1)->title .
" " . $this->lng->txt(
"and") .
" " . (ceil($median_value)) .
"-" . $this->categories->getCategory((
int)ceil($median_value)-1)->title .
")";
675 $median_value = $median[((
$total+1)/2)-1];
682 $result_array[
"ARITHMETIC_MEAN"] =
"";
683 $result_array[
"MEDIAN"] = $median_value;
684 $result_array[
"QUESTION_TYPE"] =
"SurveySingleChoiceQuestion";
685 return $result_array;
699 include_once (
"./Services/Excel/classes/class.ilExcelUtils.php");
700 $worksheet =& $workbook->addWorksheet();
702 switch ($export_label)
728 $worksheet->write($rowcounter, 1, $eval_data[
"USERS_ANSWERED"]);
731 $worksheet->write($rowcounter, 1, $eval_data[
"USERS_SKIPPED"]);
734 preg_match(
"/(.*?)\s+-\s+(.*)/", $eval_data[
"MODE"], $matches);
749 foreach ($eval_data[
"variables"] as $key => $value)
752 $category = $this->categories->getCategory($key);
753 $worksheet->write($rowcounter, 2, $category->scale);
759 if (is_array($eval_data[
"textanswers"]))
765 foreach ($eval_data[
"textanswers"] as $key => $answers)
767 $title = $eval_data[
"variables"][$key][
"title"];
768 foreach ($answers as $answer)
787 $title = parent::addUserSpecificResultsExportTitles($a_array, $a_use_label, $a_substitute);
790 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
792 $cat = $this->categories->getCategory($i);
795 if(!$a_use_label || $a_substitute)
797 array_push($a_array,
$title.
' - '. $this->lng->txt(
'other'));
801 array_push($a_array,
"");
819 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
821 $cat = $this->categories->getCategory($i);
829 if (count($resultset[
"answers"][$this->
getId()]))
831 foreach ($resultset[
"answers"][$this->
getId()] as $key => $answer)
833 array_push($a_array, $answer[
"value"]+1);
838 array_push($a_array, $answer[
"textanswer"]);
848 array_push($a_array,
"");
866 $sql =
"SELECT svy_answer.* FROM svy_answer".
867 " JOIN svy_finished ON (svy_finished.finished_id = svy_answer.active_fi)".
868 " WHERE svy_answer.question_fi = ".$ilDB->quote($this->
getId(),
"integer").
869 " AND svy_finished.survey_fi = ".$ilDB->quote(
$survey_id,
"integer");
872 $sql .=
" AND ".$ilDB->in(
"svy_finished.finished_id", $finished_ids,
"",
"integer");
878 $category = $this->categories->getCategoryForScale(
$row[
"value"]+1);
879 $title =
$row[
"value"] + 1 .
" - " . $category->title;
880 if ($category->other)
$title .=
": " .
$row[
"textanswer"];
899 $categorytext .= $material[
"text"];
901 $this->categories->addCategory(
904 strlen($data[
'neutral']) ? $data[
'neutral'] : 0,
905 strlen($data[
'label']) ? $data[
'label'] : null,
906 strlen($data[
'scale']) ? $data[
'scale'] : null
930 return array(
"<",
"<=",
"=",
"<>",
">=",
">");
943 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
945 $category = $this->categories->getCategory($i);
946 $options[$category->scale-1] = $category->scale .
" - " . $category->title;
959 include_once
"./Services/Form/classes/class.ilSelectInputGUI.php";
963 $step3->setValue($default);
977 $category = $this->categories->getCategoryForScale($value+1);
980 return $category->scale .
982 ((strlen($category->title)) ? $category->title : $this->lng->txt(
'other_answer'));
& getWorkingDataFromUserInput($post_data)
Creates the user data of the svy_answer table from the POST data.
saveUserInput($post_data, $active_id, $a_return=false)
saveCategoryToDb($categorytext, $neutral=0)
Saves a category to the database.
saveCompletionStatus($original_id="")
Saves the complete flag to the database.
getPreconditionValueOutput($value)
Returns the output for a precondition value.
getAuthor()
Gets the authors name of the SurveyQuestion object.
$cumulated
An array containing the cumulated results of the question for a given survey.
SingleChoice survey question.
getTitle()
Gets the title string of the SurveyQuestion object.
& getCumulatedResults($survey_id, $nr_of_users, $finished_ids)
usableForPrecondition()
Returns if the question is usable for preconditions.
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.
_convert_text($a_text, $a_target="has been removed")
importAdditionalMetadata($a_meta)
Import additional meta data from the question import file.
getAdditionalTableName()
Returns the name of the additional question data table in the database.
setId($id=-1)
Sets the id of the SurveyQuestion object.
isComplete()
Returns true if the question is complete for use.
savePhrase($title)
Saves a set of categories to a default phrase.
getQuestiontext()
Gets the questiontext of the SurveyQuestion object.
getOrientation()
Gets the orientation of the question output.
addStandardNumbers($lower_limit, $upper_limit)
Adds standard numbers as categories.
importResponses($a_data)
Import response data from the question import file.
saveToDb($original_id="")
Saves a SurveySingleChoiceQuestion object to a database.
setOwner($owner="")
Sets the creator/owner ID of the SurveyQuestion object.
setComplete($a_complete)
Sets the complete state of the question.
insertXML(&$a_xml_writer, $a_include_header=TRUE, $obligatory_state="")
Adds the question XML to a given XMLWriter object.
setOriginalId($original_id)
fetchAssoc($a_set)
Fetch row as associative array from result set.
SurveyQuestion( $title="", $description="", $author="", $questiontext="", $owner=-1)
SurveyQuestion constructor The constructor takes possible arguments an creates an instance of the Sur...
setQuestiontext($questiontext="")
Sets the questiontext of the SurveyQuestion object.
getPreconditionOptions()
Returns the options for preconditions.
_getQuestionDataArray($id)
Returns the question data fields from the database.
addUserSpecificResultsExportTitles(&$a_array, $a_use_label=false, $a_substitute=true)
overwritten addUserSpecificResultsExportTitles
if(!is_array($argv)) $options
getId()
Gets the id of the SurveyQuestion object.
& getUserAnswers($survey_id, $finished_ids)
Returns an array containing all answers to this question in a given survey.
Basic class for all survey question types.
addUserSpecificResultsData(&$a_array, &$resultset)
Adds the values for the user specific results export for a given user.
saveMaterial()
save material to db
xmlHeader()
Writes xml header public.
& getCategoriesForPhrase($phrase_id)
Gets the available categories for a given phrase.
toXML($a_include_header=TRUE, $obligatory_state="")
Returns an xml representation of the question.
saveRandomData($active_id)
Saves random answers for a given active user in the database.
static _replaceMediaObjectImageSrc($a_text, $a_direction=0)
replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
setAuthor($author="")
Sets the authors name of the SurveyQuestion object.
loadFromDb($id)
Loads a SurveySingleChoiceQuestion object from the 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.
setDescription($description="")
Sets the description string of the SurveyQuestion object.
checkUserInput($post_data, $survey_id)
Checks the input of the active user for obligatory status and entered values.
addPhrase($phrase_id)
Adds a phrase to the question.
setExportDetailsXLS(&$workbook, &$format_title, &$format_bold, &$eval_data, $export_label)
Creates an Excel worksheet for the detailed cumulated results of this question.
getQuestionType()
Returns the question type of the question.
getDescription()
Gets the description string of the SurveyQuestion object.
SurveySingleChoiceQuestion( $title="", $description="", $author="", $questiontext="", $owner=-1, $orientation=1)
SurveySingleChoiceQuestion constructor.
setObjId($obj_id=0)
Set the reference id of the container object.
getPreconditionSelectValue($default="", $title, $variable)
Creates a form property for the precondition value.
getAvailableRelations()
Returns the available relations for the question.
setTitle($title="")
Sets the title string of the SurveyQuestion object.