ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
SurveyTextQuestion Class Reference

Text survey question. More...

+ Inheritance diagram for SurveyTextQuestion:
+ Collaboration diagram for SurveyTextQuestion:

Public Member Functions

 SurveyTextQuestion ( $title="", $description="", $author="", $questiontext="", $owner=-1)
 The constructor takes possible arguments an creates an instance of the SurveyTextQuestion object. More...
 
 _getQuestionDataArray ($id)
 Returns the question data fields from the database. More...
 
 loadFromDb ($id)
 Loads a SurveyTextQuestion object from the database. More...
 
 isComplete ()
 Returns true if the question is complete for use. More...
 
 setMaxChars ($maxchars=0)
 Sets the maximum number of allowed characters for the text answer. More...
 
 getMaxChars ()
 Returns the maximum number of allowed characters for the text answer. More...
 
 saveToDb ($original_id="")
 Saves a SurveyTextQuestion object to a database. More...
 
 toXML ($a_include_header=TRUE, $obligatory_state="")
 Returns an xml representation of the question. More...
 
 insertXML (&$a_xml_writer, $a_include_header=TRUE, $obligatory_state="")
 Adds the question XML to a given XMLWriter object. More...
 
 _getMaxChars ($question_id)
 Returns the maxium number of allowed characters for the text answer. More...
 
 getQuestionType ()
 Returns the question type of the question. More...
 
 getAdditionalTableName ()
 Returns the name of the additional question data table in the database. More...
 
getWorkingDataFromUserInput ($post_data)
 Creates the user data of the svy_answer table from the POST data. More...
 
 checkUserInput ($post_data, $survey_id)
 Checks the input of the active user for obligatory status and entered values. More...
 
 randomText ($length)
 
 saveRandomData ($active_id)
 Saves random answers for a given active user in the database. More...
 
 saveUserInput ($post_data, $active_id, $a_return=false)
 
getCumulatedResults ($survey_id, $nr_of_users, $finished_ids)
 
 setExportDetailsXLS (&$workbook, &$format_title, &$format_bold, &$eval_data, $export_label)
 Creates an Excel worksheet for the detailed cumulated results of this question. More...
 
 addUserSpecificResultsData (&$a_array, &$resultset)
 Adds the values for the user specific results export for a given user. More...
 
getUserAnswers ($survey_id, $finished_ids)
 Returns an array containing all answers to this question in a given survey. More...
 
 importResponses ($a_data)
 Import response data from the question import file. More...
 
 usableForPrecondition ()
 Returns if the question is usable for preconditions. More...
 
 getTextWidth ()
 Returns the width of the answer field. More...
 
 getTextHeight ()
 Returns the height of the answer field. More...
 
 setTextWidth ($a_textwidth)
 Sets the width of the answer field. More...
 
 setTextHeight ($a_textheight)
 Sets the height of the answer field. More...
 
- Public Member Functions inherited from SurveyQuestion
 SurveyQuestion ( $title="", $description="", $author="", $questiontext="", $owner=-1)
 SurveyQuestion constructor The constructor takes possible arguments an creates an instance of the SurveyQuestion object. More...
 
 _SurveyQuestion ()
 
 setComplete ($a_complete)
 Sets the complete state of the question. More...
 
 isComplete ()
 Returns 1, if a question is complete for use. More...
 
 questionTitleExists ($title, $questionpool_object="")
 Returns TRUE if the question title exists in the database. More...
 
 setTitle ($title="")
 Sets the title string of the SurveyQuestion object. More...
 
 setObligatory ($obligatory=1)
 Sets the obligatory state of the question. More...
 
 setOrientation ($orientation=0)
 Sets the orientation of the question output. More...
 
 setId ($id=-1)
 Sets the id of the SurveyQuestion object. More...
 
 setSurveyId ($id=-1)
 Sets the survey id of the SurveyQuestion object. More...
 
 setDescription ($description="")
 Sets the description string of the SurveyQuestion object. More...
 
 addMaterials ($materials_file, $materials_name="")
 Sets the materials uri. More...
 
 setMaterialsfile ($materials_filename, $materials_tempfilename="", $materials_name="")
 Sets and uploads the materials uri. More...
 
 deleteMaterial ($materials_name="")
 Deletes a materials uri with a given name. More...
 
 flushMaterials ()
 Deletes all materials uris. More...
 
 setAuthor ($author="")
 Sets the authors name of the SurveyQuestion object. More...
 
 setQuestiontext ($questiontext="")
 Sets the questiontext of the SurveyQuestion object. More...
 
 setOwner ($owner="")
 Sets the creator/owner ID of the SurveyQuestion object. More...
 
 getTitle ()
 Gets the title string of the SurveyQuestion object. More...
 
 getId ()
 Gets the id of the SurveyQuestion object. More...
 
 getObligatory ($survey_id="")
 Gets the obligatory state of the question. More...
 
 getSurveyId ()
 Gets the survey id of the SurveyQuestion object. More...
 
 getOrientation ()
 Gets the orientation of the question output. More...
 
 getDescription ()
 Gets the description string of the SurveyQuestion object. More...
 
 getAuthor ()
 Gets the authors name of the SurveyQuestion object. More...
 
 getOwner ()
 Gets the creator/owner ID of the SurveyQuestion object. More...
 
 getQuestiontext ()
 Gets the questiontext of the SurveyQuestion object. More...
 
 getObjId ()
 Get the reference id of the container object. More...
 
 setObjId ($obj_id=0)
 Set the reference id of the container object. More...
 
 duplicate ($for_survey=true, $title="", $author="", $owner="")
 Duplicates a survey question. More...
 
 copyObject ($target_questionpool, $title="")
 Copies an assOrderingQuestion object. More...
 
 copyXHTMLMediaObjectsOfQuestion ($a_q_id)
 Increases the media object usage counter when a question is duplicated. More...
 
 loadFromDb ($question_id)
 Loads a SurveyQuestion object from the database. More...
 
 _isComplete ($question_id)
 Checks whether the question is complete or not. More...
 
 saveCompletionStatus ($original_id="")
 Saves the complete flag to the database. More...
 
 saveToDb ($original_id="")
 Saves a SurveyQuestion object to a database. More...
 
 saveMaterial ()
 save material to db More...
 
 createNewQuestion ()
 Creates a new question with a 0 timestamp when a new question is created This assures that an ID is given to the question if a file upload or something else occurs. More...
 
 saveWorkingData ($limit_to=LIMIT_NO_LIMIT)
 Saves the learners input of the question to the database. More...
 
 getImagePath ()
 Returns the image path for web accessable images of a question. More...
 
 getMaterialsPath ()
 Returns the materials path for web accessable materials of a question. More...
 
 getImagePathWeb ()
 Returns the web image path for web accessable images of a question. More...
 
 getMaterialsPathWeb ()
 Returns the web image path for web accessable images of a question. More...
 
 saveCategoryToDb ($categorytext, $neutral=0)
 Saves a category to the database. More...
 
 deleteAdditionalTableData ($question_id)
 Deletes datasets from the additional question table in the database. More...
 
 delete ($question_id)
 Deletes a question and all materials from the database. More...
 
 _getQuestionType ($question_id)
 Returns the question type of a question with a given id. More...
 
 _getTitle ($question_id)
 Returns the question title of a question with a given id. More...
 
 _getOriginalId ($question_id, $a_return_question_id_if_no_original=true)
 Returns the original id of a question. More...
 
 syncWithOriginal ()
 
 getPhrase ($phrase_id)
 Returns a phrase for a given database id. More...
 
 phraseExists ($title)
 Returns true if the phrase title already exists for the current user. More...
 
 _questionExists ($question_id)
 Returns true if the question already exists in the database. More...
 
 addInternalLink ($material_id, $title="")
 
 deleteMaterials ($a_array)
 Deletes materials. More...
 
 duplicateMaterials ($question_id)
 Duplicates the materials of a question. More...
 
 addMaterial ($obj_material)
 
 setMaterial ($material_id="", $is_import=false, $material_title="")
 Sets a material link for the question. More...
 
 _resolveInternalLink ($internal_link)
 
 _resolveIntLinks ($question_id)
 
 _getInternalLinkHref ($target="", $a_parent_ref_id=null)
 
 _isWriteable ($question_id, $user_id)
 Returns true if the question is writeable by a certain user. More...
 
 getQuestionTypeID ()
 Returns the question type ID of the question. More...
 
 getQuestionType ()
 Returns the question type of the question. More...
 
_instanciateQuestion ($question_id)
 Creates an instance of a question with a given question id. More...
 
_instanciateQuestionGUI ($question_id)
 Creates an instance of a question GUI with a given question id. More...
 
 isHTML ($a_text)
 Checks if a given string contains HTML or not. More...
 
 QTIMaterialToString ($a_material)
 Reads an QTI material tag an creates a text string. More...
 
 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. More...
 
 prepareTextareaOutput ($txt_output, $prepare_for_latex_output=FALSE)
 Prepares a string for a text area output in surveys. More...
 
 _getQuestionDataArray ($id)
 Returns the question data fields from the database. More...
 
 addUserSpecificResultsExportTitles (&$a_array, $a_use_label=false, $a_substitute=true)
 Adds the entries for the title row of the user specific results. More...
 
 addUserSpecificResultsData (&$a_array, &$resultset)
 Adds the values for the user specific results export for a given user. More...
 
getUserAnswers ($survey_id)
 Returns an array containing all answers to this question in a given survey. More...
 
getWorkingDataFromUserInput ($post_data)
 Creates the user data of the svy_answer table from the POST data. More...
 
 importAdditionalMetadata ($a_meta)
 Import additional meta data from the question import file. More...
 
 importResponses ($a_data)
 Import response data from the question import file. More...
 
 importAdjectives ($a_data)
 Import bipolar adjectives from the question import file. More...
 
 importMatrix ($a_data)
 Import matrix rows from the question import file. More...
 
 setExportCumulatedXLS (&$worksheet, &$format_title, &$format_bold, &$eval_data, $row, $export_label)
 Creates the Excel output for the cumulated results of this question. More...
 
setExportCumulatedCVS (&$eval_data, $export_label)
 Creates the CSV output for the cumulated results of this question. More...
 
 setExportDetailsXLS (&$workbook, &$format_title, &$format_bold, &$eval_data, $export_label)
 Creates an Excel worksheet for the detailed cumulated results of this question. More...
 
 usableForPrecondition ()
 Returns if the question is usable for preconditions. More...
 
 getAvailableRelations ()
 Returns the available relations for the question. More...
 
 getPreconditionOptions ()
 Returns the options for preconditions. More...
 
 getPreconditionValueOutput ($value)
 Returns the output for a precondition value. More...
 
 getPreconditionSelectValue ($default="", $title, $variable)
 Creates a form property for the precondition value. More...
 
 outChart ($survey_id, $type="")
 Creates an image visualising the results of the question. More...
 
 setOriginalId ($original_id)
 
 getOriginalId ()
 
 saveRandomData ($active_id)
 Saves random answers for a given active user in the database. More...
 
 getMaterial ()
 
 setSubtype ($a_subtype)
 
 getSubtype ()
 
 getCumulatedResultData ($survey_id, $counter, $finished_ids)
 Creates a the cumulated results data for the question. More...
 
 __get ($value)
 Object getter. More...
 
 __set ($key, $value)
 Object setter. More...
 
 getCopyIds ($a_group_by_survey=false)
 
 hasCopies ()
 
 getSkippedValue ()
 

Data Fields

 $maxchars
 
 $textwidth
 
 $textheight
 
- Data Fields inherited from SurveyQuestion
 $id
 
 $title
 
 $description
 
 $owner
 
 $author
 
 $materials
 
 $survey_id
 
 $obj_id
 
 $questiontext
 
 $obligatory
 
 $ilias
 
 $tpl
 
 $lng
 
 $orientation
 
 $material
 
 $complete
 

Additional Inherited Members

- Static Public Member Functions inherited from SurveyQuestion
static _includeClass ($question_type, $gui=0)
 Include the php class file for a given question type. More...
 
static _getQuestionTypeName ($type_tag)
 Return the translation for a given question type tag. More...
 
static _changeOriginalId ($a_question_id, $a_original_id, $a_object_id)
 Change original id of existing question in db. More...
 
- Protected Member Functions inherited from SurveyQuestion
calculateCumulatedResults ($survey_id, $finished_ids)
 
- Protected Attributes inherited from SurveyQuestion
 $cumulated
 An array containing the cumulated results of the question for a given survey. More...
 

Detailed Description

Text survey question.

The SurveyTextQuestion class defines and encapsulates basic methods and attributes for text survey question types.

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Version
$Id$

Definition at line 37 of file class.SurveyTextQuestion.php.

Member Function Documentation

◆ _getMaxChars()

SurveyTextQuestion::_getMaxChars (   $question_id)

Returns the maxium number of allowed characters for the text answer.

Returns
integer The maximum number of characters public

Definition at line 290 of file class.SurveyTextQuestion.php.

References $result, and $row.

291  {
292  global $ilDB;
293  $result = $ilDB->queryF("SELECT maxchars FROM svy_question WHERE question_id = %s",
294  array('integer'),
295  array($question_id)
296  );
297  if ($result->numRows())
298  {
299  $row = $ilDB->fetchAssoc($result);
300  return $row["maxchars"];
301  }
302  return 0;
303  }
$result

◆ _getQuestionDataArray()

SurveyTextQuestion::_getQuestionDataArray (   $id)

Returns the question data fields from the database.

Parameters
integer$idThe question ID from the database
Returns
array Array containing the question fields and data from the database public

Definition at line 73 of file class.SurveyTextQuestion.php.

References SurveyQuestion\$id, $result, and getAdditionalTableName().

74  {
75  global $ilDB;
76  $result = $ilDB->queryF("SELECT svy_question.*, " . $this->getAdditionalTableName() . ".* FROM svy_question, " . $this->getAdditionalTableName() . " WHERE svy_question.question_id = %s AND svy_question.question_id = " . $this->getAdditionalTableName() . ".question_fi",
77  array('integer'),
78  array($id)
79  );
80  if ($result->numRows() == 1)
81  {
82  return $ilDB->fetchAssoc($result);
83  }
84  else
85  {
86  return array();
87  }
88  }
$result
getAdditionalTableName()
Returns the name of the additional question data table in the database.
+ Here is the call graph for this function:

◆ addUserSpecificResultsData()

SurveyTextQuestion::addUserSpecificResultsData ( $a_array,
$resultset 
)

Adds the values for the user specific results export for a given user.

Parameters
array$a_arrayAn array which is used to append the values
array$resultsetThe evaluation data for a given user public

Definition at line 519 of file class.SurveyTextQuestion.php.

References SurveyQuestion\getId(), and SurveyQuestion\getSkippedValue().

520  {
521  if (count($resultset["answers"][$this->getId()]))
522  {
523  foreach ($resultset["answers"][$this->getId()] as $key => $answer)
524  {
525  array_push($a_array, $answer["textanswer"]);
526  }
527  }
528  else
529  {
530  array_push($a_array, $this->getSkippedValue());
531  }
532  }
getId()
Gets the id of the SurveyQuestion object.
+ Here is the call graph for this function:

◆ checkUserInput()

SurveyTextQuestion::checkUserInput (   $post_data,
  $survey_id 
)

Checks the input of the active user for obligatory status and entered values.

Parameters
array$post_dataThe contents of the $_POST array
integer$survey_idThe database ID of the active survey
Returns
string Empty string if the input is ok, an error message otherwise public

Definition at line 353 of file class.SurveyTextQuestion.php.

References SurveyQuestion\$survey_id, SurveyQuestion\getId(), and SurveyQuestion\getObligatory().

354  {
355  $entered_value = $post_data[$this->getId() . "_text_question"];
356 
357  if ((!$this->getObligatory($survey_id)) && (strlen($entered_value) == 0)) return "";
358 
359  if (strlen($entered_value) == 0) return $this->lng->txt("text_question_not_filled_out");
360 
361  return "";
362  }
getObligatory($survey_id="")
Gets the obligatory state of the question.
getId()
Gets the id of the SurveyQuestion object.
+ Here is the call graph for this function:

◆ getAdditionalTableName()

SurveyTextQuestion::getAdditionalTableName ( )

Returns the name of the additional question data table in the database.

Returns
string The additional table name public

Definition at line 322 of file class.SurveyTextQuestion.php.

Referenced by _getQuestionDataArray(), loadFromDb(), and saveToDb().

323  {
324  return "svy_qst_text";
325  }
+ Here is the caller graph for this function:

◆ getCumulatedResults()

& SurveyTextQuestion::getCumulatedResults (   $survey_id,
  $nr_of_users,
  $finished_ids 
)

Definition at line 420 of file class.SurveyTextQuestion.php.

References SurveyQuestion\$cumulated, $result, $row, SurveyQuestion\$survey_id, and SurveyQuestion\getId().

421  {
422  global $ilDB;
423 
424  $question_id = $this->getId();
425 
426  $result_array = array();
427  $cumulated = array();
428  $textvalues = array();
429 
430  $sql = "SELECT svy_answer.* FROM svy_answer".
431  " JOIN svy_finished ON (svy_finished.finished_id = svy_answer.active_fi)".
432  " WHERE svy_answer.question_fi = ".$ilDB->quote($question_id, "integer").
433  " AND svy_finished.survey_fi = ".$ilDB->quote($survey_id, "integer");
434  if($finished_ids)
435  {
436  $sql .= " AND ".$ilDB->in("svy_finished.finished_id", $finished_ids, "", "integer");
437  }
438 
439  $result = $ilDB->query($sql);
440  while ($row = $ilDB->fetchAssoc($result))
441  {
442  $cumulated[$row["value"]]++;
443  array_push($textvalues, $row["textanswer"]);
444  }
445  asort($cumulated, SORT_NUMERIC);
446  end($cumulated);
447  $numrows = $result->numRows();
448  $result_array["USERS_ANSWERED"] = $result->numRows();
449  $result_array["USERS_SKIPPED"] = $nr_of_users - $result->numRows();
450  $result_array["QUESTION_TYPE"] = "SurveyTextQuestion";
451  $result_array["textvalues"] = $textvalues;
452  return $result_array;
453  }
$cumulated
An array containing the cumulated results of the question for a given survey.
$result
getId()
Gets the id of the SurveyQuestion object.
+ Here is the call graph for this function:

◆ getMaxChars()

SurveyTextQuestion::getMaxChars ( )

Returns the maximum number of allowed characters for the text answer.

public

Definition at line 165 of file class.SurveyTextQuestion.php.

Referenced by insertXML(), saveToDb(), and saveUserInput().

166  {
167  return ($this->maxchars) ? $this->maxchars : NULL;
168  }
+ Here is the caller graph for this function:

◆ getQuestionType()

SurveyTextQuestion::getQuestionType ( )

Returns the question type of the question.

Returns
integer The question type of the question public

Definition at line 311 of file class.SurveyTextQuestion.php.

312  {
313  return "SurveyTextQuestion";
314  }

◆ getTextHeight()

SurveyTextQuestion::getTextHeight ( )

Returns the height of the answer field.

Returns
integer The height of the answer field in characters public

Definition at line 616 of file class.SurveyTextQuestion.php.

Referenced by insertXML(), and saveToDb().

617  {
618  return ($this->textheight) ? $this->textheight : NULL;
619  }
+ Here is the caller graph for this function:

◆ getTextWidth()

SurveyTextQuestion::getTextWidth ( )

Returns the width of the answer field.

Returns
integer The width of the answer field in characters public

Definition at line 605 of file class.SurveyTextQuestion.php.

Referenced by insertXML(), and saveToDb().

606  {
607  return ($this->textwidth) ? $this->textwidth : NULL;
608  }
+ Here is the caller graph for this function:

◆ getUserAnswers()

& SurveyTextQuestion::getUserAnswers (   $survey_id,
  $finished_ids 
)

Returns an array containing all answers to this question in a given survey.

Parameters
integer$survey_idThe database ID of the survey
Returns
array An array containing the answers to the question. The keys are either the user id or the anonymous id public

Definition at line 541 of file class.SurveyTextQuestion.php.

References $result, $row, SurveyQuestion\$survey_id, and SurveyQuestion\getId().

542  {
543  global $ilDB;
544 
545  $answers = array();
546 
547  $sql = "SELECT svy_answer.* FROM svy_answer, svy_finished".
548  " WHERE svy_finished.survey_fi = ".$ilDB->quote($survey_id, "integer").
549  " AND svy_answer.question_fi = ".$ilDB->quote($this->getId(), "integer").
550  " AND svy_finished.finished_id = svy_answer.active_fi";
551  if($finished_ids)
552  {
553  $sql .= " AND ".$ilDB->in("svy_finished.finished_id", $finished_ids, "", "integer");
554  }
555  $result = $ilDB->query($sql);
556  while ($row = $ilDB->fetchAssoc($result))
557  {
558  $answers[$row["active_fi"]] = $row["textanswer"];
559  }
560  return $answers;
561  }
$result
getId()
Gets the id of the SurveyQuestion object.
+ Here is the call graph for this function:

◆ getWorkingDataFromUserInput()

& SurveyTextQuestion::getWorkingDataFromUserInput (   $post_data)

Creates the user data of the svy_answer table from the POST data.

Returns
array User data according to the svy_answer table public

Definition at line 333 of file class.SurveyTextQuestion.php.

References $data, and SurveyQuestion\getId().

334  {
335  $entered_value = $post_data[$this->getId() . "_text_question"];
336  $data = array();
337  if (strlen($entered_value))
338  {
339  array_push($data, array("textanswer" => $entered_value));
340  }
341  return $data;
342  }
getId()
Gets the id of the SurveyQuestion object.
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
+ Here is the call graph for this function:

◆ importResponses()

SurveyTextQuestion::importResponses (   $a_data)

Import response data from the question import file.

Returns
array $a_data Array containing the response data public

Definition at line 569 of file class.SurveyTextQuestion.php.

References $data, SurveyQuestion\$id, setMaxChars(), setTextHeight(), and setTextWidth().

570  {
571  foreach ($a_data as $id => $data)
572  {
573  if ($data["maxlength"] > 0)
574  {
575  $this->setMaxChars($data["maxlength"]);
576  }
577  if ($data["rows"] > 0)
578  {
579  $this->setTextHeight($data["rows"]);
580  }
581  if ($data["columns"] > 0)
582  {
583  $this->setTextWidth($data["columns"]);
584  }
585  }
586  }
setTextHeight($a_textheight)
Sets the height of the answer field.
setMaxChars($maxchars=0)
Sets the maximum number of allowed characters for the text answer.
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
setTextWidth($a_textwidth)
Sets the width of the answer field.
+ Here is the call graph for this function:

◆ insertXML()

SurveyTextQuestion::insertXML ( $a_xml_writer,
  $a_include_header = TRUE,
  $obligatory_state = "" 
)

Adds the question XML to a given XMLWriter object.

Parameters
object$a_xml_writerThe XMLWriter object
boolean$a_include_headerDetermines wheather or not the XML should be used
string$obligatory_stateThe value of the obligatory state public

Definition at line 224 of file class.SurveyTextQuestion.php.

References SurveyQuestion\addMaterialTag(), SurveyQuestion\getAuthor(), SurveyQuestion\getDescription(), SurveyQuestion\getId(), getMaxChars(), SurveyQuestion\getObligatory(), SurveyQuestion\getQuestiontext(), getTextHeight(), getTextWidth(), and SurveyQuestion\getTitle().

Referenced by toXML().

225  {
226  $attrs = array(
227  "id" => $this->getId(),
228  "title" => $this->getTitle(),
229  "type" => $this->getQuestiontype(),
230  "obligatory" => $this->getObligatory()
231  );
232  $a_xml_writer->xmlStartTag("question", $attrs);
233 
234  $a_xml_writer->xmlElement("description", NULL, $this->getDescription());
235  $a_xml_writer->xmlElement("author", NULL, $this->getAuthor());
236  if (strlen($this->label))
237  {
238  $attrs = array(
239  "label" => $this->label,
240  );
241  }
242  else
243  {
244  $attrs = array();
245  }
246  $a_xml_writer->xmlStartTag("questiontext", $attrs);
247  $this->addMaterialTag($a_xml_writer, $this->getQuestiontext());
248  $a_xml_writer->xmlEndTag("questiontext");
249 
250  $a_xml_writer->xmlStartTag("responses");
251  $attrs = array(
252  "id" => "0",
253  "rows" => $this->getTextHeight(),
254  "columns" => $this->getTextWidth()
255  );
256  if ($this->getMaxChars() > 0)
257  {
258  $attrs["maxlength"] = $this->getMaxChars();
259  }
260  $a_xml_writer->xmlElement("response_text", $attrs);
261  $a_xml_writer->xmlEndTag("responses");
262 
263  if (count($this->material))
264  {
265  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches))
266  {
267  $attrs = array(
268  "label" => $this->material["title"]
269  );
270  $a_xml_writer->xmlStartTag("material", $attrs);
271  $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
272  if (strcmp($matches[1], "") != 0)
273  {
274  $intlink = $this->material["internal_link"];
275  }
276  $a_xml_writer->xmlElement("mattext", NULL, $intlink);
277  $a_xml_writer->xmlEndTag("material");
278  }
279  }
280 
281  $a_xml_writer->xmlEndTag("question");
282  }
getTextWidth()
Returns the width of the answer field.
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.
getQuestiontext()
Gets the questiontext of the SurveyQuestion object.
getId()
Gets the id of the SurveyQuestion object.
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.
getDescription()
Gets the description string of the SurveyQuestion object.
getMaxChars()
Returns the maximum number of allowed characters for the text answer.
getTextHeight()
Returns the height of the answer field.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isComplete()

SurveyTextQuestion::isComplete ( )

Returns true if the question is complete for use.

Returns
boolean True if the question is complete for use, otherwise false public

Definition at line 134 of file class.SurveyTextQuestion.php.

References SurveyQuestion\getAuthor(), SurveyQuestion\getQuestiontext(), and SurveyQuestion\getTitle().

135  {
136  if (
137  strlen($this->getTitle()) &&
138  strlen($this->getAuthor()) &&
139  strlen($this->getQuestiontext())
140  )
141  {
142  return 1;
143  }
144  else
145  {
146  return 0;
147  }
148  }
getAuthor()
Gets the authors name of the SurveyQuestion object.
getTitle()
Gets the title string of the SurveyQuestion object.
getQuestiontext()
Gets the questiontext of the SurveyQuestion object.
+ Here is the call graph for this function:

◆ loadFromDb()

SurveyTextQuestion::loadFromDb (   $id)

Loads a SurveyTextQuestion object from the database.

Parameters
integer$idThe database id of the text survey question public

Definition at line 96 of file class.SurveyTextQuestion.php.

References $data, SurveyQuestion\$id, $result, ilRTE\_replaceMediaObjectImageSrc(), ilDB\fetchAssoc(), getAdditionalTableName(), SurveyQuestion\setAuthor(), SurveyQuestion\setComplete(), SurveyQuestion\setDescription(), SurveyQuestion\setId(), setMaxChars(), SurveyQuestion\setObjId(), SurveyQuestion\setObligatory(), SurveyQuestion\setOriginalId(), SurveyQuestion\setOwner(), SurveyQuestion\setQuestiontext(), setTextHeight(), setTextWidth(), and SurveyQuestion\setTitle().

97  {
98  global $ilDB;
99 
100  $result = $ilDB->queryF("SELECT svy_question.*, " . $this->getAdditionalTableName() . ".* FROM svy_question LEFT JOIN " . $this->getAdditionalTableName() . " ON " . $this->getAdditionalTableName() . ".question_fi = svy_question.question_id WHERE svy_question.question_id = %s",
101  array('integer'),
102  array($id)
103  );
104  if ($result->numRows() == 1)
105  {
106  $data = $ilDB->fetchAssoc($result);
107  $this->setId($data["question_id"]);
108  $this->setTitle($data["title"]);
109  $this->label = $data['label'];
110  $this->setDescription($data["description"]);
111  $this->setObjId($data["obj_fi"]);
112  $this->setAuthor($data["author"]);
113  $this->setOwner($data["owner_fi"]);
114  include_once("./Services/RTE/classes/class.ilRTE.php");
115  $this->setQuestiontext(ilRTE::_replaceMediaObjectImageSrc($data["questiontext"], 1));
116  $this->setObligatory($data["obligatory"]);
117  $this->setComplete($data["complete"]);
118  $this->setOriginalId($data["original_id"]);
119 
120  $this->setMaxChars($data["maxchars"]);
121  $this->setTextWidth($data["width"]);
122  $this->setTextHeight($data["height"]);
123 
124  }
125  parent::loadFromDb($id);
126  }
setTextHeight($a_textheight)
Sets the height of the answer field.
$result
setObligatory($obligatory=1)
Sets the obligatory state of the question.
setId($id=-1)
Sets the id of the SurveyQuestion object.
setOwner($owner="")
Sets the creator/owner ID of the SurveyQuestion object.
setComplete($a_complete)
Sets the complete state of the question.
setMaxChars($maxchars=0)
Sets the maximum number of allowed characters for the text answer.
setOriginalId($original_id)
fetchAssoc($a_set)
Fetch row as associative array from result set.
setQuestiontext($questiontext="")
Sets the questiontext of the SurveyQuestion object.
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.
setDescription($description="")
Sets the description string of the SurveyQuestion object.
getAdditionalTableName()
Returns the name of the additional question data table in the database.
setObjId($obj_id=0)
Set the reference id of the container object.
setTextWidth($a_textwidth)
Sets the width of the answer field.
setTitle($title="")
Sets the title string of the SurveyQuestion object.
+ Here is the call graph for this function:

◆ randomText()

SurveyTextQuestion::randomText (   $length)

Definition at line 364 of file class.SurveyTextQuestion.php.

Referenced by saveRandomData().

365  {
366  $random= "";
367  $char_list = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
368  $char_list .= "abcdefghijklmnopqrstuvwxyz";
369  $char_list .= "1234567890";
370  for($i = 0; $i < $length; $i++)
371  {
372  $random .= substr($char_list,(rand()%(strlen($char_list))), 1);
373  if (!rand(0,5)) $random .= ' ';
374  }
375  return $random;
376  }
+ Here is the caller graph for this function:

◆ saveRandomData()

SurveyTextQuestion::saveRandomData (   $active_id)

Saves random answers for a given active user in the database.

Parameters
integer$active_idThe database ID of the active user

Definition at line 383 of file class.SurveyTextQuestion.php.

References SurveyQuestion\getId(), and randomText().

384  {
385  global $ilDB;
386  // single response
387  $randomtext = $this->randomText(rand(25,100));
388  $next_id = $ilDB->nextId('svy_answer');
389  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
390  array('integer', 'integer', 'integer', 'float', 'text', 'integer'),
391  array($next_id, $this->getId(), $active_id, NULL, $randomtext, time())
392  );
393  }
getId()
Gets the id of the SurveyQuestion object.
+ Here is the call graph for this function:

◆ saveToDb()

SurveyTextQuestion::saveToDb (   $original_id = "")

Saves a SurveyTextQuestion object to a database.

public

Definition at line 175 of file class.SurveyTextQuestion.php.

References getAdditionalTableName(), SurveyQuestion\getId(), getMaxChars(), getTextHeight(), getTextWidth(), and SurveyQuestion\saveMaterial().

176  {
177  global $ilDB;
178 
179  $affectedRows = parent::saveToDb($original_id);
180  if ($affectedRows == 1)
181  {
182  $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
183  array('integer'),
184  array($this->getId())
185  );
186  $affectedRows = $ilDB->manipulateF("INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, maxchars, width, height) VALUES (%s, %s, %s, %s)",
187  array('integer', 'integer', 'integer', 'integer'),
188  array($this->getId(), $this->getMaxChars(), $this->getTextWidth(), $this->getTextHeight())
189  );
190 
191  $this->saveMaterial();
192  }
193  }
getTextWidth()
Returns the width of the answer field.
getId()
Gets the id of the SurveyQuestion object.
saveMaterial()
save material to db
getAdditionalTableName()
Returns the name of the additional question data table in the database.
getMaxChars()
Returns the maximum number of allowed characters for the text answer.
getTextHeight()
Returns the height of the answer field.
+ Here is the call graph for this function:

◆ saveUserInput()

SurveyTextQuestion::saveUserInput (   $post_data,
  $active_id,
  $a_return = false 
)

Definition at line 395 of file class.SurveyTextQuestion.php.

References SurveyQuestion\getId(), getMaxChars(), and ilUtil\stripSlashes().

396  {
397  global $ilDB;
398 
399  include_once "./Services/Utilities/classes/class.ilUtil.php";
400  $entered_value = ilUtil::stripSlashes($post_data[$this->getId() . "_text_question"]);
401  $maxchars = $this->getMaxChars();
402  if ($maxchars > 0)
403  {
404  $entered_value = substr($entered_value, 0, $maxchars);
405  }
406 
407  if($a_return)
408  {
409  return array(array("value"=>null, "textanswer"=>$entered_value));
410  }
411  if (strlen($entered_value) == 0) return;
412 
413  $next_id = $ilDB->nextId('svy_answer');
414  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
415  array('integer', 'integer', 'integer', 'float', 'text', 'integer'),
416  array($next_id, $this->getId(), $active_id, NULL, (strlen($entered_value)) ? $entered_value : NULL, time())
417  );
418  }
getId()
Gets the id of the SurveyQuestion object.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
getMaxChars()
Returns the maximum number of allowed characters for the text answer.
+ Here is the call graph for this function:

◆ setExportDetailsXLS()

SurveyTextQuestion::setExportDetailsXLS ( $workbook,
$format_title,
$format_bold,
$eval_data,
  $export_label 
)

Creates an Excel worksheet for the detailed cumulated results of this question.

Parameters
object$workbookReference to the parent excel workbook
object$format_titleExcel title format
object$format_boldExcel bold format
array$eval_dataCumulated evaluation data public

Definition at line 464 of file class.SurveyTextQuestion.php.

References ilExcelUtils\_convert_text(), SurveyQuestion\getQuestiontext(), and SurveyQuestion\getTitle().

465  {
466  include_once ("./Services/Excel/classes/class.ilExcelUtils.php");
467  $worksheet =& $workbook->addWorksheet();
468  $rowcounter = 0;
469  switch ($export_label)
470  {
471  case 'label_only':
472  $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("label")), $format_bold);
473  $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->label));
474  break;
475  case 'title_only':
476  $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_bold);
477  $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->getTitle()));
478  break;
479  default:
480  $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_bold);
481  $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->getTitle()));
482  $rowcounter++;
483  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("label")), $format_bold);
484  $worksheet->writeString($rowcounter, 1, ilExcelUtils::_convert_text($this->label));
485  break;
486  }
487  $rowcounter++;
488  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("question")), $format_bold);
489  $worksheet->writeString($rowcounter, 1, ilExcelUtils::_convert_text($this->getQuestiontext()));
490  $rowcounter++;
491  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("question_type")), $format_bold);
492  $worksheet->writeString($rowcounter, 1, ilExcelUtils::_convert_text($this->lng->txt($this->getQuestionType())));
493  $rowcounter++;
494  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("users_answered")), $format_bold);
495  $worksheet->write($rowcounter, 1, $eval_data["USERS_ANSWERED"]);
496  $rowcounter++;
497  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("users_skipped")), $format_bold);
498  $worksheet->write($rowcounter, 1, $eval_data["USERS_SKIPPED"]);
499  $rowcounter++;
500 
501  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("given_answers")), $format_bold);
502  $textvalues = "";
503  if (is_array($eval_data["textvalues"]))
504  {
505  foreach ($eval_data["textvalues"] as $textvalue)
506  {
507  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($textvalue));
508  }
509  }
510  }
getTitle()
Gets the title string of the SurveyQuestion object.
_convert_text($a_text, $a_target="has been removed")
getQuestiontext()
Gets the questiontext of the SurveyQuestion object.
+ Here is the call graph for this function:

◆ setMaxChars()

SurveyTextQuestion::setMaxChars (   $maxchars = 0)

Sets the maximum number of allowed characters for the text answer.

public

Definition at line 155 of file class.SurveyTextQuestion.php.

References $maxchars.

Referenced by importResponses(), and loadFromDb().

156  {
157  $this->maxchars = $maxchars;
158  }
+ Here is the caller graph for this function:

◆ setTextHeight()

SurveyTextQuestion::setTextHeight (   $a_textheight)

Sets the height of the answer field.

Parameters
integer$a_textheightThe height of the answer field in characters public

Definition at line 645 of file class.SurveyTextQuestion.php.

Referenced by importResponses(), and loadFromDb().

646  {
647  if ($a_textheight < 1)
648  {
649  $this->textheight = 5;
650  }
651  else
652  {
653  $this->textheight = $a_textheight;
654  }
655  }
+ Here is the caller graph for this function:

◆ setTextWidth()

SurveyTextQuestion::setTextWidth (   $a_textwidth)

Sets the width of the answer field.

Parameters
integer$a_textwidthThe width of the answer field in characters public

Definition at line 627 of file class.SurveyTextQuestion.php.

Referenced by importResponses(), and loadFromDb().

628  {
629  if ($a_textwidth < 1)
630  {
631  $this->textwidth = 50;
632  }
633  else
634  {
635  $this->textwidth = $a_textwidth;
636  }
637  }
+ Here is the caller graph for this function:

◆ SurveyTextQuestion()

SurveyTextQuestion::SurveyTextQuestion (   $title = "",
  $description = "",
  $author = "",
  $questiontext = "",
  $owner = -1 
)

The constructor takes possible arguments an creates an instance of the SurveyTextQuestion object.

Parameters
string$titleA title string to describe the question
string$descriptionA description string to describe the question
string$authorA string containing the name of the questions author
integer$ownerA numerical ID to identify the owner/creator public

Definition at line 52 of file class.SurveyTextQuestion.php.

References SurveyQuestion\$author, SurveyQuestion\$description, SurveyQuestion\$owner, SurveyQuestion\$questiontext, SurveyQuestion\$title, and SurveyQuestion\SurveyQuestion().

59  {
61  $this->maxchars = 0;
62  $this->textwidth = 50;
63  $this->textheight = 5;
64  }
SurveyQuestion( $title="", $description="", $author="", $questiontext="", $owner=-1)
SurveyQuestion constructor The constructor takes possible arguments an creates an instance of the Sur...
+ Here is the call graph for this function:

◆ toXML()

SurveyTextQuestion::toXML (   $a_include_header = TRUE,
  $obligatory_state = "" 
)

Returns an xml representation of the question.

Returns
string The xml representation of the question public

Definition at line 201 of file class.SurveyTextQuestion.php.

References insertXML(), and ilXmlWriter\xmlHeader().

202  {
203  include_once("./Services/Xml/classes/class.ilXmlWriter.php");
204  $a_xml_writer = new ilXmlWriter;
205  $a_xml_writer->xmlHeader();
206  $this->insertXML($a_xml_writer, $a_include_header, $obligatory_state);
207  $xml = $a_xml_writer->xmlDumpMem(FALSE);
208  if (!$a_include_header)
209  {
210  $pos = strpos($xml, "?>");
211  $xml = substr($xml, $pos + 2);
212  }
213  return $xml;
214  }
insertXML(&$a_xml_writer, $a_include_header=TRUE, $obligatory_state="")
Adds the question XML to a given XMLWriter object.
XML writer class.
xmlHeader()
Writes xml header public.
+ Here is the call graph for this function:

◆ usableForPrecondition()

SurveyTextQuestion::usableForPrecondition ( )

Returns if the question is usable for preconditions.

Returns
boolean TRUE if the question is usable for a precondition, FALSE otherwise public

Definition at line 594 of file class.SurveyTextQuestion.php.

595  {
596  return FALSE;
597  }

Field Documentation

◆ $maxchars

SurveyTextQuestion::$maxchars

Definition at line 39 of file class.SurveyTextQuestion.php.

Referenced by setMaxChars().

◆ $textheight

SurveyTextQuestion::$textheight

Definition at line 41 of file class.SurveyTextQuestion.php.

◆ $textwidth

SurveyTextQuestion::$textwidth

Definition at line 40 of file class.SurveyTextQuestion.php.


The documentation for this class was generated from the following file: