24include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
67 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
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))
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);
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)
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'),
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'),
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');
584 $fields[
'answer_id'] = array(
"integer", $next_id);
585 $fields[
'question_fi'] = array(
"integer", $this->
getId());
586 $fields[
'active_fi'] = array(
"integer", $active_id);
587 $fields[
'value'] = array(
"float", (strlen($entered_value)) ? $entered_value : NULL);
588 $fields[
'textanswer'] = array(
"clob", ($post_data[$this->
getId() .
"_" . $entered_value .
"_other"]) ? $post_data[$this->
getId() .
"_" . $entered_value .
"_other"] :
null);
589 $fields[
'tstamp'] = array(
"integer", time());
591 $affectedRows =
$ilDB->insert(
"svy_answer", $fields);
598 $question_id = $this->
getId();
600 $result_array = array();
603 $sql =
"SELECT svy_answer.* FROM svy_answer".
604 " JOIN svy_finished ON (svy_finished.finished_id = svy_answer.active_fi)".
605 " WHERE svy_answer.question_fi = ".$ilDB->quote($question_id,
"integer").
606 " AND svy_finished.survey_fi = ".$ilDB->quote(
$survey_id,
"integer");
609 $sql .=
" AND ".$ilDB->in(
"svy_finished.finished_id", $finished_ids,
"",
"integer");
618 if (
$row[
"textanswer"])
620 $result_array[
"textanswers"][
$row[
"value"]][] =
$row[
"textanswer"];
624 if (is_array($result_array[
"textanswers"]))
626 ksort($result_array[
"textanswers"], SORT_NUMERIC);
631 $result_array[
"USERS_ANSWERED"] =
$result->numRows();
632 $result_array[
"USERS_SKIPPED"] = $nr_of_users -
$result->numRows();
641 $category = $this->categories->getCategoryForScale(key(
$cumulated)+1);
642 $result_array[
"MODE"] = $prefix . $category->title;
643 $result_array[
"MODE_VALUE"] = key(
$cumulated)+1;
646 for ($key = 0; $key < $this->categories->getCategoryCount(); $key++)
648 $cat = $this->categories->getCategory($key);
652 $percentage = (float)((
int)
$cumulated[$cat->scale-1]/$numrows);
656 $result_array[
"variables"][$key] = array(
"title" => (strlen($cat->title)) ? $cat->title : $this->lng->txt(
'other_answer'),
"selected" => (
int)
$cumulated[$cat->scale-1],
"percentage" => $percentage);
660 $result_array[
"variables"][$key] = array(
"title" => $cat->title,
"selected" => (
int)
$cumulated[$cat->scale-1],
"percentage" => $percentage);
669 for ($i = 0; $i < $key; $i++)
671 array_push($median, $value+1);
678 $median_value = 0.5 * ($median[(
$total/2)-1] + $median[(
$total/2)]);
679 if (round($median_value) != $median_value)
681 $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 .
")";
686 $median_value = $median[((
$total+1)/2)-1];
693 $result_array[
"ARITHMETIC_MEAN"] =
"";
694 $result_array[
"MEDIAN"] = $median_value;
695 $result_array[
"QUESTION_TYPE"] =
"SurveySingleChoiceQuestion";
696 return $result_array;
710 include_once (
"./Services/Excel/classes/class.ilExcelUtils.php");
711 $worksheet =& $workbook->addWorksheet();
713 switch ($export_label)
739 $worksheet->write($rowcounter, 1, $eval_data[
"USERS_ANSWERED"]);
742 $worksheet->write($rowcounter, 1, $eval_data[
"USERS_SKIPPED"]);
745 preg_match(
"/(.*?)\s+-\s+(.*)/", $eval_data[
"MODE"], $matches);
760 foreach ($eval_data[
"variables"] as $key => $value)
763 $category = $this->categories->getCategory($key);
764 $worksheet->write($rowcounter, 2, $category->scale);
770 if (is_array($eval_data[
"textanswers"]))
776 foreach ($eval_data[
"textanswers"] as $key => $answers)
778 $title = $eval_data[
"variables"][$key][
"title"];
779 foreach ($answers as $answer)
798 $title = parent::addUserSpecificResultsExportTitles($a_array, $a_use_label, $a_substitute);
801 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
803 $cat = $this->categories->getCategory($i);
806 if(!$a_use_label || $a_substitute)
808 array_push($a_array,
$title.
' - '. $this->lng->txt(
'other'));
812 array_push($a_array,
"");
830 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
832 $cat = $this->categories->getCategory($i);
840 if (count($resultset[
"answers"][$this->
getId()]))
842 foreach ($resultset[
"answers"][$this->
getId()] as $key => $answer)
844 array_push($a_array, $answer[
"value"]+1);
849 array_push($a_array, $answer[
"textanswer"]);
859 array_push($a_array,
"");
877 $sql =
"SELECT svy_answer.* FROM svy_answer".
878 " JOIN svy_finished ON (svy_finished.finished_id = svy_answer.active_fi)".
879 " WHERE svy_answer.question_fi = ".$ilDB->quote($this->
getId(),
"integer").
880 " AND svy_finished.survey_fi = ".$ilDB->quote(
$survey_id,
"integer");
883 $sql .=
" AND ".$ilDB->in(
"svy_finished.finished_id", $finished_ids,
"",
"integer");
889 $category = $this->categories->getCategoryForScale(
$row[
"value"]+1);
890 $title =
$row[
"value"] + 1 .
" - " . $category->title;
891 if ($category->other)
$title .=
": " .
$row[
"textanswer"];
912 $this->categories->addCategory(
915 strlen(
$data[
'neutral']) ?
$data[
'neutral'] : 0,
916 strlen(
$data[
'label']) ?
$data[
'label'] :
null,
917 strlen(
$data[
'scale']) ?
$data[
'scale'] :
null
941 return array(
"<",
"<=",
"=",
"<>",
">=",
">");
954 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
956 $category = $this->categories->getCategory($i);
957 $options[$category->scale-1] = $category->scale .
" - " . $category->title;
970 include_once
"./Services/Form/classes/class.ilSelectInputGUI.php";
974 $step3->setValue($default);
988 $category = $this->categories->getCategoryForScale($value+1);
991 return $category->scale .
993 ((strlen($category->title)) ? $category->title : $this->lng->txt(
'other_answer'));
Basic class for all survey question types.
setQuestiontext($questiontext="")
Sets the questiontext of the SurveyQuestion object.
setId($id=-1)
Sets the id of the SurveyQuestion object.
setAuthor($author="")
Sets the authors name of the SurveyQuestion object.
SurveyQuestion( $title="", $description="", $author="", $questiontext="", $owner=-1)
SurveyQuestion constructor The constructor takes possible arguments an creates an instance of the Sur...
getDescription()
Gets the description string of the SurveyQuestion object.
getId()
Gets the id of the SurveyQuestion object.
setDescription($description="")
Sets the description string of the SurveyQuestion object.
setObjId($obj_id=0)
Set the reference id of the container object.
getAuthor()
Gets the authors name of the SurveyQuestion object.
setOriginalId($original_id)
getQuestiontext()
Gets the questiontext of the SurveyQuestion object.
getObligatory($survey_id="")
Gets the obligatory state of the question.
setOrientation($orientation=0)
Sets the orientation of the question output.
saveCategoryToDb($categorytext, $neutral=0)
Saves a category to the database.
getTitle()
Gets the title string of the SurveyQuestion object.
setComplete($a_complete)
Sets the complete state of the question.
saveMaterial()
save material to db
setOwner($owner="")
Sets the creator/owner ID of the SurveyQuestion object.
setTitle($title="")
Sets the title string of the SurveyQuestion object.
saveCompletionStatus($original_id="")
Saves the complete flag to the database.
$cumulated
An array containing the cumulated results of the question for a given survey.
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.
getOrientation()
Gets the orientation of the question output.
setObligatory($obligatory=1)
Sets the obligatory state of the question.
SingleChoice survey question.
insertXML(&$a_xml_writer, $a_include_header=TRUE, $obligatory_state="")
Adds the question XML to a given XMLWriter object.
& getCumulatedResults($survey_id, $nr_of_users, $finished_ids)
getPreconditionOptions()
Returns the options for preconditions.
getQuestionType()
Returns the question type of the question.
addUserSpecificResultsData(&$a_array, &$resultset)
Adds the values for the user specific results export for a given user.
addPhrase($phrase_id)
Adds a phrase to the question.
isComplete()
Returns true if the question is complete for use.
savePhrase($title)
Saves a set of categories to a default phrase.
importAdditionalMetadata($a_meta)
Import additional meta data from the question import file.
checkUserInput($post_data, $survey_id)
Checks the input of the active user for obligatory status and entered values.
saveUserInput($post_data, $active_id, $a_return=false)
importResponses($a_data)
Import response data from the question import file.
saveToDb($original_id="")
Saves a SurveySingleChoiceQuestion object to a database.
usableForPrecondition()
Returns if the question is usable for preconditions.
_getQuestionDataArray($id)
Returns the question data fields from the database.
toXML($a_include_header=TRUE, $obligatory_state="")
Returns an xml representation of the question.
getAdditionalTableName()
Returns the name of the additional question data table in the database.
addUserSpecificResultsExportTitles(&$a_array, $a_use_label=false, $a_substitute=true)
overwritten addUserSpecificResultsExportTitles
getPreconditionSelectValue($default="", $title, $variable)
Creates a form property for the precondition value.
& getWorkingDataFromUserInput($post_data)
Creates the user data of the svy_answer table from the POST data.
setExportDetailsXLS(&$workbook, &$format_title, &$format_bold, &$eval_data, $export_label)
Creates an Excel worksheet for the detailed cumulated results of this question.
SurveySingleChoiceQuestion( $title="", $description="", $author="", $questiontext="", $owner=-1, $orientation=1)
SurveySingleChoiceQuestion constructor.
getAvailableRelations()
Returns the available relations for the question.
saveRandomData($active_id)
Saves random answers for a given active user in the database.
addStandardNumbers($lower_limit, $upper_limit)
Adds standard numbers as categories.
& getCategoriesForPhrase($phrase_id)
Gets the available categories for a given phrase.
& getUserAnswers($survey_id, $finished_ids)
Returns an array containing all answers to this question in a given survey.
loadFromDb($id)
Loads a SurveySingleChoiceQuestion object from the database.
getPreconditionValueOutput($value)
Returns the output for a precondition value.
_convert_text($a_text, $a_target="has been removed")
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...
xmlHeader()
Writes xml header @access public.
if(!is_array($argv)) $options