ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
class.SurveyMatrixQuestion.php
Go to the documentation of this file.
1 <?php
2  /*
3  +----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +----------------------------------------------------------------------------+
22 */
23 
24 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
25 
36 {
42  var $columns;
43 
49  var $rows;
50 
57 
64 
72 
80 
88 
89  /*
90  * Layout of the matrix question
91  *
92  * @var array
93  */
94  var $layout;
95 
96  /*
97  * Use placeholders for the column titles
98  *
99  * @var boolean
100  */
102 
103  /*
104  * Show a legend
105  *
106  * @var boolean
107  */
108  var $legend;
109 
111 
113 
115 
116  /*
117  * Use random order for rows
118  *
119  * @var boolean
120  */
122 
124 
126 
128 
130 
131 
146  var $subtype;
147 
159  $title = "",
160  $description = "",
161  $author = "",
162  $questiontext = "",
163  $owner = -1
164  )
165  {
167  $this->subtype = 0;
168  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
169  $this->columns = new SurveyCategories();
170  $this->rows = new SurveyCategories();
171  $this->bipolar_adjective1 = "";
172  $this->bipolar_adjective2 = "";
173  $this->rowSeparators = 0;
174  $this->columnSeparators = 0;
175  $this->neutralColumnSeparator = 1;
176  }
177 
185  function getColumnCount()
186  {
187  return $this->columns->getCategoryCount();
188  }
189 
197  function removeColumn($index)
198  {
199  $this->columns->removeCategory($index);
200  }
201 
209  function removeColumns($array)
210  {
211  $this->columns->removeCategories($array);
212  }
213 
221  function removeColumnWithName($name)
222  {
223  $this->columns->removeCategoryWithName($name);
224  }
225 
229  public function getColumns()
230  {
231  return $this->columns;
232  }
233 
242  function getColumn($index)
243  {
244  return $this->columns->getCategory($index);
245  }
246 
247  function getColumnForScale($scale)
248  {
249  return $this->columns->getCategoryForScale($scale);
250  }
251 
259  function getColumnIndex($name)
260  {
261  return $this->columns->getCategoryIndex($name);
262  }
263 
264 
271  function flushColumns()
272  {
273  $this->columns->flushCategories();
274  }
275 
282  function getRowCount()
283  {
284  return $this->rows->getCategoryCount();
285  }
286 
292  function addRow($a_text, $a_other, $a_label)
293  {
294  $this->rows->addCategory($a_text, $a_other, 0, $a_label);
295  }
296 
303  function addRowAtPosition($a_text, $a_other, $a_position)
304  {
305  $this->rows->addCategoryAtPosition($a_text, $a_position, $a_other);
306  }
307 
314  function flushRows()
315  {
316  $this->rows = new SurveyCategories();
317  }
318 
325  function getRow($a_index)
326  {
327  return $this->rows->getCategory($a_index);
328  }
329 
330  function moveRowUp($index)
331  {
332  $this->rows->moveCategoryUp($index);
333  }
334 
335  function moveRowDown($index)
336  {
337  $this->rows->moveCategoryDown($index);
338  }
339 
347  function removeRows($array)
348  {
349  $this->rows->removeCategories($array);
350  }
351 
357  public function removeRow($index)
358  {
359  $this->rows->removeCategory($index);
360  }
361 
369  function getBipolarAdjective($a_index)
370  {
371  switch ($a_index)
372  {
373  case 1:
374  return (strlen($this->bipolar_adjective2)) ? $this->bipolar_adjective2 : NULL;
375  break;
376  case 0:
377  default:
378  return (strlen($this->bipolar_adjective1)) ? $this->bipolar_adjective1 : NULL;
379  break;
380  }
381  return NULL;
382  }
383 
391  function setBipolarAdjective($a_index, $a_value)
392  {
393  switch ($a_index)
394  {
395  case 1:
396  $this->bipolar_adjective2 = $a_value;
397  break;
398  case 0:
399  default:
400  $this->bipolar_adjective1 = $a_value;
401  break;
402  }
403  }
404 
411  function addPhrase($phrase_id)
412  {
413  global $ilUser;
414  global $ilDB;
415 
416  $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 = %s OR svy_category.owner_fi = %s) ORDER BY svy_phrase_cat.sequence",
417  array('integer', 'integer', 'integer'),
418  array($phrase_id, 0, $ilUser->getId())
419  );
420  while ($row = $ilDB->fetchAssoc($result))
421  {
422  $neutral = $row["neutral"];
423  if (($row["defaultvalue"] == 1) && ($row["owner_fi"] == 0))
424  {
425  $this->columns->addCategory($this->lng->txt($row["title"]), 0, $neutral);
426  }
427  else
428  {
429  $this->columns->addCategory($row["title"], 0, $neutral);
430  }
431  }
432  }
433 
442  {
443  global $ilDB;
444 
445  $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",
446  array('integer'),
447  array($id)
448  );
449  if ($result->numRows() == 1)
450  {
451  return $ilDB->fetchAssoc($result);
452  }
453  else
454  {
455  return array();
456  }
457  }
458 
465  function loadFromDb($id)
466  {
467  global $ilDB;
468  $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",
469  array('integer'),
470  array($id)
471  );
472  if ($result->numRows() == 1)
473  {
474  $data = $ilDB->fetchAssoc($result);
475  $this->setId($data["question_id"]);
476  $this->setTitle($data["title"]);
477  $this->label = $data['label'];
478  $this->setDescription($data["description"]);
479  $this->setObjId($data["obj_fi"]);
480  $this->setAuthor($data["author"]);
481  $this->setOwner($data["owner_fi"]);
482  include_once("./Services/RTE/classes/class.ilRTE.php");
483  $this->setQuestiontext(ilRTE::_replaceMediaObjectImageSrc($data["questiontext"], 1));
484  $this->setObligatory($data["obligatory"]);
485  $this->setComplete($data["complete"]);
486  $this->setOriginalId($data["original_id"]);
487  $this->setSubtype($data["subtype"]);
488  $this->setRowSeparators($data["row_separators"]);
489  $this->setNeutralColumnSeparator($data["neutral_column_separator"]);
490  $this->setColumnSeparators($data["column_separators"]);
491  $this->setColumnPlaceholders($data["column_placeholders"]);
492  $this->setLegend($data["legend"]);
493  $this->setSingleLineRowCaption($data["singleline_row_caption"]);
494  $this->setRepeatColumnHeader($data["repeat_column_header"]);
495  $this->setColumnHeaderPosition($data["column_header_position"]);
496  $this->setRandomRows($data["random_rows"]);
497  $this->setColumnOrder($data["column_order"]);
498  $this->setColumnImages($data["column_images"]);
499  $this->setRowImages($data["row_images"]);
500  $this->setBipolarAdjective(0, $data["bipolar_adjective1"]);
501  $this->setBipolarAdjective(1, $data["bipolar_adjective2"]);
502  $this->setLayout($data["layout"]);
503  $this->flushColumns();
504 
505  $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",
506  array('integer'),
507  array($id)
508  );
509  if ($result->numRows() > 0)
510  {
511  while ($data = $ilDB->fetchAssoc($result))
512  {
513  $this->columns->addCategory($data["title"], $data["other"], $data["neutral"], null, ($data['scale']) ? $data['scale'] : ($data['sequence'] + 1));
514  }
515  }
516 
517  $result = $ilDB->queryF("SELECT * FROM svy_qst_matrixrows WHERE question_fi = %s ORDER BY sequence",
518  array('integer'),
519  array($id)
520  );
521  while ($row = $ilDB->fetchAssoc($result))
522  {
523  $this->addRow($row["title"], $row['other'], $row['label']);
524  }
525  }
526  parent::loadFromDb($id);
527  }
528 
535  function isComplete()
536  {
537  if (
538  strlen($this->getTitle()) &&
539  strlen($this->getAuthor()) &&
540  strlen($this->getQuestiontext()) &&
541  $this->getColumnCount() &&
542  $this->getRowCount()
543  )
544  {
545  return 1;
546  }
547  else
548  {
549  return 0;
550  }
551  }
552 
558  function saveToDb($original_id = NULL, $withanswers = true)
559  {
560  global $ilDB;
561 
562  $affectedRows = parent::saveToDb($original_id);
563 
564  if ($affectedRows == 1)
565  {
566  $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
567  array('integer'),
568  array($this->getId())
569  );
570  $affectedRows = $ilDB->manipulateF("INSERT INTO " . $this->getAdditionalTableName() . " (
571  question_fi, subtype, column_separators, row_separators, neutral_column_separator,column_placeholders,
572  legend, singleline_row_caption, repeat_column_header, column_header_position, random_rows,
573  column_order, column_images, row_images, bipolar_adjective1, bipolar_adjective2, layout, tstamp)
574  VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
575  array(
576  'integer', 'integer', 'text', 'text', 'text', 'integer', 'text', 'text', 'text',
577  'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer'
578  ),
579  array(
580  $this->getId(),
581  $this->getSubtype(),
582  $this->getColumnSeparators(),
583  $this->getRowSeparators(),
584  $this->getNeutralColumnSeparator(),
585  $this->getColumnPlaceholders(),
586  $this->getLegend(),
587  $this->getSingleLineRowCaption(),
588  $this->getRepeatColumnHeader(),
589  $this->getColumnHeaderPosition(),
590  $this->getRandomRows(),
591  $this->getColumnOrder(),
592  $this->getColumnImages(),
593  $this->getRowImages(),
594  $this->getBipolarAdjective(0),
595  $this->getBipolarAdjective(1),
596  serialize($this->getLayout()),
597  time()
598  )
599  );
600 
601  // saving material uris in the database
602  $this->saveMaterial();
603 
604  $this->saveColumnsToDb();
605  $this->saveRowsToDb();
606  }
607  }
608 
609  function saveBipolarAdjectives($adjective1, $adjective2)
610  {
611  global $ilDB;
612 
613  $affectedRows = $ilDB->manipulateF("UPDATE " . $this->getAdditionalTableName() . " SET bipolar_adjective1 = %s, bipolar_adjective2 = %s WHERE question_fi = %s",
614  array('text', 'text', 'integer'),
615  array((strlen($adjective1)) ? $adjective1 : NULL, (strlen($adjective2)) ? $adjective2 : NULL, $this->getId())
616  );
617  }
618 
627  function saveColumnToDb($columntext, $neutral = 0)
628  {
629  global $ilUser, $ilDB;
630 
631  $result = $ilDB->queryF("SELECT title, category_id FROM svy_category WHERE title = %s AND neutral = %s AND owner_fi = %s",
632  array('text', 'text', 'integer'),
633  array($columntext, $neutral, $ilUser->getId())
634  );
635  $insert = FALSE;
636  $returnvalue = "";
637  if ($result->numRows())
638  {
639  $insert = TRUE;
640  while ($row = $ilDB->fetchAssoc($result))
641  {
642  if (strcmp($row["title"], $columntext) == 0)
643  {
644  $returnvalue = $row["category_id"];
645  $insert = FALSE;
646  }
647  }
648  }
649  else
650  {
651  $insert = TRUE;
652  }
653  if ($insert)
654  {
655  $next_id = $ilDB->nextId('svy_category');
656  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_category (category_id, title, defaultvalue, owner_fi, neutral, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
657  array('integer', 'text', 'text', 'integer', 'text', 'integer'),
658  array($next_id, $columntext, 0, $ilUser->getId(), $neutral, time())
659  );
660  $returnvalue = $next_id;
661  }
662  return $returnvalue;
663  }
664 
665  function saveColumnsToDb($original_id = "")
666  {
667  global $ilDB;
668 
669  // save columns
670  $question_id = $this->getId();
671  if (strlen($original_id))
672  {
673  $question_id = $original_id;
674  }
675 
676  // delete existing column relations
677  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_variable WHERE question_fi = %s",
678  array('integer'),
679  array($question_id)
680  );
681  // create new column relations
682  for ($i = 0; $i < $this->getColumnCount(); $i++)
683  {
684  $cat = $this->getColumn($i);
685  $column_id = $this->saveColumnToDb($cat->title, $cat->neutral);
686  $next_id = $ilDB->nextId('svy_variable');
687  $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)",
688  array('integer','integer','integer','float','integer','integer', 'integer','integer'),
689  array($next_id, $column_id, $question_id, ($i + 1), $cat->other, $i, ($cat->scale > 0) ? $cat->scale : null, time())
690  );
691  }
692  $this->saveCompletionStatus($original_id);
693  }
694 
695  function saveRowsToDb($original_id = "")
696  {
697  global $ilDB;
698 
699  // save rows
700  $question_id = $this->getId();
701  if (strlen($original_id))
702  {
703  $question_id = $original_id;
704  }
705 
706  // delete existing rows
707  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_qst_matrixrows WHERE question_fi = %s",
708  array('integer'),
709  array($question_id)
710  );
711  // create new rows
712  for ($i = 0; $i < $this->getRowCount(); $i++)
713  {
714  $row = $this->getRow($i);
715  $next_id = $ilDB->nextId('svy_qst_matrixrows');
716  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_qst_matrixrows (id_svy_qst_matrixrows, title, label, other, sequence, question_fi) VALUES (%s, %s, %s, %s, %s, %s)",
717  array('integer','text','text','integer','integer','integer'),
718  array($next_id, $row->title, $row->label, ($row->other) ? 1 : 0, $i, $question_id)
719  );
720  }
721  $this->saveCompletionStatus($original_id);
722  }
723 
730  function toXML($a_include_header = TRUE, $obligatory_state = "")
731  {
732  include_once("./Services/Xml/classes/class.ilXmlWriter.php");
733  $a_xml_writer = new ilXmlWriter;
734  $a_xml_writer->xmlHeader();
735  $this->insertXML($a_xml_writer, $a_include_header, $obligatory_state);
736  $xml = $a_xml_writer->xmlDumpMem(FALSE);
737  if (!$a_include_header)
738  {
739  $pos = strpos($xml, "?>");
740  $xml = substr($xml, $pos + 2);
741  }
742  return $xml;
743  }
744 
753  function insertXML(&$a_xml_writer, $a_include_header = TRUE, $obligatory_state = "")
754  {
755  $attrs = array(
756  "id" => $this->getId(),
757  "title" => $this->getTitle(),
758  "type" => $this->getQuestiontype(),
759  "subtype" => $this->getSubtype(),
760  "obligatory" => $this->getObligatory()
761  );
762  $a_xml_writer->xmlStartTag("question", $attrs);
763 
764  $a_xml_writer->xmlElement("description", NULL, $this->getDescription());
765  $a_xml_writer->xmlElement("author", NULL, $this->getAuthor());
766  $a_xml_writer->xmlStartTag("questiontext");
767  $this->addMaterialTag($a_xml_writer, $this->getQuestiontext());
768  $a_xml_writer->xmlEndTag("questiontext");
769 
770  $a_xml_writer->xmlStartTag("matrix");
771  $a_xml_writer->xmlStartTag("matrixrows");
772  for ($i = 0; $i < $this->getRowCount(); $i++)
773  {
774  $attrs = array(
775  "id" => $i
776  );
777  if (strlen($this->getRow($i)->label))
778  {
779  $attrs['label'] = $this->getRow($i)->label;
780  }
781  if ($this->getRow($i)->other)
782  {
783  $attrs['other'] = 1;
784  }
785  $a_xml_writer->xmlStartTag("matrixrow", $attrs);
786  $this->addMaterialTag($a_xml_writer, $this->getRow($i)->title);
787  $a_xml_writer->xmlEndTag("matrixrow");
788  }
789  $a_xml_writer->xmlEndTag("matrixrows");
790 
791  $a_xml_writer->xmlStartTag("responses");
792  if (strlen($this->getBipolarAdjective(0)) && (strlen($this->getBipolarAdjective(1))))
793  {
794  $a_xml_writer->xmlStartTag("bipolar_adjectives");
795  $attribs = array(
796  "label" => "0"
797  );
798  $a_xml_writer->xmlElement("adjective", $attribs, $this->getBipolarAdjective(0));
799  $attribs = array(
800  "label" => "1"
801  );
802  $a_xml_writer->xmlElement("adjective", $attribs, $this->getBipolarAdjective(1));
803  $a_xml_writer->xmlEndTag("bipolar_adjectives");
804  }
805  for ($i = 0; $i < $this->getColumnCount(); $i++)
806  {
807  $attrs = array(
808  "id" => $i
809  );
810  if ($this->getColumn($i)->neutral)
811  {
812  $attrs['label'] = 'neutral';
813  }
814  switch ($this->getSubtype())
815  {
816  case 0:
817  $a_xml_writer->xmlStartTag("response_single", $attrs);
818  break;
819  case 1:
820  $a_xml_writer->xmlStartTag("response_multiple", $attrs);
821  break;
822  }
823  $this->addMaterialTag($a_xml_writer, $this->getColumn($i)->title);
824  switch ($this->getSubtype())
825  {
826  case 0:
827  $a_xml_writer->xmlEndTag("response_single");
828  break;
829  case 1:
830  $a_xml_writer->xmlEndTag("response_multiple");
831  break;
832  }
833  }
834 
835  $a_xml_writer->xmlEndTag("responses");
836  $a_xml_writer->xmlEndTag("matrix");
837 
838  if (count($this->material))
839  {
840  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches))
841  {
842  $attrs = array(
843  "label" => $this->material["title"]
844  );
845  $a_xml_writer->xmlStartTag("material", $attrs);
846  $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
847  if (strcmp($matches[1], "") != 0)
848  {
849  $intlink = $this->material["internal_link"];
850  }
851  $a_xml_writer->xmlElement("mattext", NULL, $intlink);
852  $a_xml_writer->xmlEndTag("material");
853  }
854  }
855 
856  $a_xml_writer->xmlStartTag("metadata");
857  $a_xml_writer->xmlStartTag("metadatafield");
858  $a_xml_writer->xmlElement("fieldlabel", NULL, "column_separators");
859  $a_xml_writer->xmlElement("fieldentry", NULL, $this->getColumnSeparators());
860  $a_xml_writer->xmlEndTag("metadatafield");
861 
862  $a_xml_writer->xmlStartTag("metadatafield");
863  $a_xml_writer->xmlElement("fieldlabel", NULL, "row_separators");
864  $a_xml_writer->xmlElement("fieldentry", NULL, $this->getRowSeparators());
865  $a_xml_writer->xmlEndTag("metadatafield");
866 
867  $a_xml_writer->xmlStartTag("metadatafield");
868  $a_xml_writer->xmlElement("fieldlabel", NULL, "neutral_column_separator");
869  $a_xml_writer->xmlElement("fieldentry", NULL, $this->getNeutralColumnSeparator());
870  $a_xml_writer->xmlEndTag("metadatafield");
871 
872  $a_xml_writer->xmlStartTag("metadatafield");
873  $a_xml_writer->xmlElement("fieldlabel", NULL, "layout");
874  $a_xml_writer->xmlElement("fieldentry", NULL, serialize($this->getLayout()));
875  $a_xml_writer->xmlEndTag("metadatafield");
876 
877  $a_xml_writer->xmlEndTag("metadata");
878 
879  $a_xml_writer->xmlEndTag("question");
880  }
881 
882  function syncWithOriginal()
883  {
884  if ($this->getOriginalId())
885  {
886  parent::syncWithOriginal();
887  $this->saveColumnsToDb($this->getOriginalId());
888  $this->saveRowsToDb($this->getOriginalId());
889  }
890  }
891 
892 
900  function addStandardNumbers($lower_limit, $upper_limit)
901  {
902  for ($i = $lower_limit; $i <= $upper_limit; $i++)
903  {
904  $this->columns->addCategory($i);
905  }
906  }
907 
915  function savePhrase($title)
916  {
917  global $ilUser;
918  global $ilDB;
919 
920  $next_id = $ilDB->nextId('svy_phrase');
921  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_phrase (phrase_id, title, defaultvalue, owner_fi, tstamp) VALUES (%s, %s, %s, %s, %s)",
922  array('integer','text','text','integer','integer'),
923  array($next_id, $title, 1, $ilUser->getId(), time())
924  );
925  $phrase_id = $next_id;
926 
927  $counter = 1;
928  foreach ($_SESSION['save_phrase_data'] as $data)
929  {
930  $next_id = $ilDB->nextId('svy_category');
931  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_category (category_id, title, defaultvalue, owner_fi, tstamp, neutral) VALUES (%s, %s, %s, %s, %s, %s)",
932  array('integer','text','text','integer','integer','text'),
933  array($next_id, $data['answer'], 1, $ilUser->getId(), time(), $data['neutral'])
934  );
935  $category_id = $next_id;
936  $next_id = $ilDB->nextId('svy_phrase_cat');
937  $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)",
938  array('integer', 'integer', 'integer','integer', 'integer', 'integer'),
939  array($next_id, $phrase_id, $category_id, $counter, ($data['other']) ? 1 : 0, $data['scale'])
940  );
941  $counter++;
942  }
943  }
944 
951  function getQuestionType()
952  {
953  return "SurveyMatrixQuestion";
954  }
955 
963  {
964  return "svy_qst_matrix";
965  }
966 
973  function &getWorkingDataFromUserInput($post_data)
974  {
975  $data = array();
976  foreach ($post_data as $key => $value)
977  {
978  switch ($this->getSubtype())
979  {
980  case 0:
981  if (preg_match("/matrix_" . $this->getId() . "_(\d+)/", $key, $matches))
982  {
983  if (is_array($value))
984  {
985  foreach ($value as $val)
986  {
987  array_push($data, array("value" => $val, "rowvalue" => $matches[1], "textanswer" => $post_data['matrix_other_' . $this->getId() . '_' . $matches[1]]));
988  }
989  }
990  else
991  {
992  array_push($data, array("value" => $value, "rowvalue" => $matches[1], "textanswer" => $post_data['matrix_other_' . $this->getId() . '_' . $matches[1]]));
993  }
994  }
995  break;
996  case 1:
997  if (preg_match("/matrix_" . $this->getId() . "_(\d+)/", $key, $matches))
998  {
999  if (is_array($value))
1000  {
1001  foreach ($value as $val)
1002  {
1003  array_push($data, array("value" => $val, "rowvalue" => $matches[1], "textanswer" => $post_data['matrix_other_' . $this->getId() . '_' . $matches[1]]));
1004  }
1005  }
1006  else
1007  {
1008  array_push($data, array("value" => $value, "rowvalue" => $matches[1], "textanswer" => $post_data['matrix_other_' . $this->getId() . '_' . $matches[1]]));
1009  }
1010  }
1011  break;
1012  }
1013  }
1014  return $data;
1015  }
1016 
1026  function checkUserInput($post_data, $survey_id)
1027  {
1028  if (!$this->getObligatory($survey_id)) return "";
1029  switch ($this->getSubtype())
1030  {
1031  case 0:
1032  $counter = 0;
1033  foreach ($post_data as $key => $value)
1034  {
1035  if (preg_match("/matrix_" . $this->getId() . "_(\d+)/", $key, $matches))
1036  {
1037  if (array_key_exists('matrix_other_' . $this->getId() . "_" . $matches[1], $post_data) && strlen($post_data['matrix_other_' . $this->getId() . "_" . $matches[1]]) == 0)
1038  {
1039  return $this->lng->txt("question_mr_no_other_answer");
1040  }
1041  $counter++;
1042  }
1043  }
1044  if ($counter != $this->getRowCount()) return $this->lng->txt("matrix_question_radio_button_not_checked");
1045  break;
1046  case 1:
1047  $counter = 0;
1048  foreach ($post_data as $key => $value)
1049  {
1050  if (preg_match("/matrix_" . $this->getId() . "_(\d+)/", $key, $matches))
1051  {
1052  if (array_key_exists('matrix_other_' . $this->getId() . "_" . $matches[1], $post_data) && strlen($post_data['matrix_other_' . $this->getId() . "_" . $matches[1]]) == 0)
1053  {
1054  return $this->lng->txt("question_mr_no_other_answer");
1055  }
1056  $counter++;
1057  if ((!is_array($value)) || (count($value) < 1))
1058  {
1059  return $this->lng->txt("matrix_question_checkbox_not_checked");
1060  }
1061  }
1062  }
1063  if ($counter != $this->getRowCount()) return $this->lng->txt("matrix_question_checkbox_not_checked");
1064  break;
1065  }
1066  return "";
1067  }
1068 
1074  public function saveRandomData($active_id)
1075  {
1076  global $ilDB;
1077  $columncount = $this->getColumnCount();
1078  for ($row = 0; $row < $this->getRowCount(); $row++)
1079  {
1080  if ($this->getSubType() == 1)
1081  {
1082  // multiple responses
1083  for ($i = 0; $i < $columncount; $i++)
1084  {
1085  if (rand(0,1))
1086  {
1087  $next_id = $ilDB->nextId('svy_answer');
1088  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, rowvalue, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s)",
1089  array('integer','integer','integer','float','text','integer','integer'),
1090  array($next_id, $this->getId(), $active_id, $i, NULL, $row, time())
1091  );
1092  }
1093  }
1094  }
1095  else
1096  {
1097  // single responses
1098  $category = rand(0, $columncount-1);
1099  $next_id = $ilDB->nextId('svy_answer');
1100  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, rowvalue, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s)",
1101  array('integer','integer','integer','float','text','integer','integer'),
1102  array($next_id, $this->getId(), $active_id, $category, NULL, $row, time())
1103  );
1104  }
1105  }
1106  }
1107 
1108  function saveUserInput($post_data, $active_id, $a_return = false)
1109  {
1110  global $ilDB;
1111 
1112  if($a_return)
1113  {
1114  $return_data = array();
1115  }
1116  switch ($this->getSubtype())
1117  {
1118  case 0:
1119  foreach ($post_data as $key => $value)
1120  {
1121  if (preg_match("/matrix_" . $this->getId() . "_(\d+)/", $key, $matches))
1122  {
1123  $other_value = (array_key_exists('matrix_other_' . $this->getId() . '_' . $matches[1], $post_data)) ? ($post_data['matrix_other_' . $this->getId() . '_' . $matches[1]]) : null;
1124  if(!$a_return)
1125  {
1126  $next_id = $ilDB->nextId('svy_answer');
1127  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, rowvalue, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s)",
1128  array('integer','integer','integer','float','text','integer','integer'),
1129  array($next_id, $this->getId(), $active_id, $value, $other_value, $matches[1], time())
1130  );
1131  }
1132  else
1133  {
1134  $return_data[] = array("value"=>$value,
1135  "textanswer"=>$other_value,
1136  "rowvalue"=>$matches[1]);
1137  }
1138  }
1139  }
1140  break;
1141  case 1:
1142  foreach ($post_data as $key => $value)
1143  {
1144  if (preg_match("/matrix_" . $this->getId() . "_(\d+)/", $key, $matches))
1145  {
1146  $other_value = (array_key_exists('matrix_other_' . $this->getId() . '_' . $matches[1], $post_data)) ? ($post_data['matrix_other_' . $this->getId() . '_' . $matches[1]]) : null;
1147  foreach ($value as $checked)
1148  {
1149  if (strlen($checked))
1150  {
1151  if(!$a_return)
1152  {
1153  $next_id = $ilDB->nextId('svy_answer');
1154  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, rowvalue, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s)",
1155  array('integer','integer','integer','float','text','integer','integer'),
1156  array($next_id, $this->getId(), $active_id, $checked, $other_value, $matches[1], time())
1157  );
1158  }
1159  else
1160  {
1161  $return_data[] = array("value"=>$checked,
1162  "textanswer"=>$other_value,
1163  "rowvalue"=>$matches[1]);
1164  }
1165  }
1166  }
1167  }
1168  }
1169  break;
1170  }
1171  if($a_return)
1172  {
1173  return $return_data;
1174  }
1175  }
1176 
1183  function deleteAdditionalTableData($question_id)
1184  {
1185  parent::deleteAdditionalTableData($question_id);
1186 
1187  global $ilDB;
1188  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_qst_matrixrows WHERE question_fi = %s",
1189  array('integer'),
1190  array($question_id)
1191  );
1192  }
1193 
1201  function getNrOfUsersAnswered($survey_id, $finished_ids = null)
1202  {
1203  global $ilDB;
1204 
1205  $sql = "SELECT svy_answer.active_fi, svy_answer.question_fi".
1206  " FROM svy_answer".
1207  " JOIN svy_finished ON (svy_finished.finished_id = svy_answer.active_fi)".
1208  " WHERE svy_answer.question_fi = ".$ilDB->quote($this->getId(), "integer").
1209  " AND svy_finished.survey_fi = ".$ilDB->quote($survey_id, "integer");
1210  if($finished_ids)
1211  {
1212  $sql .= " AND ".$ilDB->in("svy_finished.finished_id", $finished_ids, "", "integer");
1213  }
1214 
1215  $result = $ilDB->query($sql);
1216  $found = array();
1217  while ($row = $ilDB->fetchAssoc($result))
1218  {
1219  $found[$row["active_fi"].$row["question_fi"]] = 1;
1220  }
1221  return count($found);
1222  }
1223 
1232  function &getCumulatedResultsForRow($rowindex, $survey_id, $nr_of_users, $finished_ids)
1233  {
1234  global $ilDB;
1235 
1236  $question_id = $this->getId();
1237 
1238  $result_array = array();
1239  $cumulated = array();
1240 
1241  $sql = "SELECT svy_answer.* FROM svy_answer".
1242  " JOIN svy_finished ON (svy_finished.finished_id = svy_answer.active_fi)".
1243  " WHERE svy_answer.question_fi = ".$ilDB->quote($question_id, "integer").
1244  " AND svy_answer.rowvalue = ".$ilDB->quote($rowindex, "integer").
1245  " AND svy_finished.survey_fi = ".$ilDB->quote($survey_id, "integer");
1246  if($finished_ids)
1247  {
1248  $sql .= " AND ".$ilDB->in("svy_finished.finished_id", $finished_ids, "", "integer");
1249  }
1250  $result = $ilDB->query($sql);
1251 
1252  switch ($this->getSubtype())
1253  {
1254  case 0:
1255  case 1:
1256  while ($row = $ilDB->fetchAssoc($result))
1257  {
1258  $cumulated[$row["value"]]++;
1259 
1260  // add text value to result array
1261  if ($row["textanswer"])
1262  {
1263  $result_array["textanswers"][$row["value"]][] = $row["textanswer"];
1264  }
1265  }
1266  // sort textanswers by value
1267  if (is_array($result_array["textanswers"]))
1268  {
1269  ksort($result_array["textanswers"], SORT_NUMERIC);
1270  }
1271  asort($cumulated, SORT_NUMERIC);
1272  end($cumulated);
1273  break;
1274  }
1275  $numrows = $result->numRows();
1276  $result_array["USERS_ANSWERED"] = $this->getNrOfUsersAnswered($survey_id, $finished_ids);
1277  $result_array["USERS_SKIPPED"] = $nr_of_users - $this->getNrOfUsersAnswered($survey_id, $finished_ids);
1278 
1279  if(sizeof($cumulated))
1280  {
1281  $prefix = "";
1282  if (strcmp(key($cumulated), "") != 0)
1283  {
1284  $prefix = (key($cumulated)+1) . " - ";
1285  }
1286  $cat = $this->getColumnForScale(key($cumulated)+1);
1287  $result_array["MODE"] = $prefix . $cat->title;
1288  $result_array["MODE_VALUE"] = key($cumulated)+1;
1289  $result_array["MODE_NR_OF_SELECTIONS"] = $cumulated[key($cumulated)];
1290  }
1291  for ($key = 0; $key < $this->getColumnCount(); $key++)
1292  {
1293  $cat = $this->getColumn($key);
1294  $scale = $cat->scale-1;
1295 
1296  $percentage = 0;
1297  if ($numrows > 0)
1298  {
1299  $percentage = (float)((int)$cumulated[$scale]/$numrows);
1300  }
1301 
1302  $result_array["variables"][$key] = array("title" => $cat->title, "selected" => (int)$cumulated[$scale], "percentage" => $percentage);
1303  }
1304  ksort($cumulated, SORT_NUMERIC);
1305  $median = array();
1306  $total = 0;
1307  foreach ($cumulated as $value => $key)
1308  {
1309  $total += $key;
1310  for ($i = 0; $i < $key; $i++)
1311  {
1312  array_push($median, $value+1);
1313  }
1314  }
1315  if ($total > 0)
1316  {
1317  if (($total % 2) == 0)
1318  {
1319  $median_value = 0.5 * ($median[($total/2)-1] + $median[($total/2)]);
1320  if (round($median_value) != $median_value)
1321  {
1322  $cat = $this->getColumnForScale((int)floor($median_value));
1323  $cat2 = $this->getColumnForScale((int)ceil($median_value));
1324  $median_value = $median_value . "<br />" . "(" . $this->lng->txt("median_between") . " " . (floor($median_value)) . "-" . $cat->title . " " . $this->lng->txt("and") . " " . (ceil($median_value)) . "-" . $cat2->title . ")";
1325  }
1326  }
1327  else
1328  {
1329  $median_value = $median[(($total+1)/2)-1];
1330  }
1331  }
1332  else
1333  {
1334  $median_value = "";
1335  }
1336  $result_array["ARITHMETIC_MEAN"] = "";
1337  $result_array["MEDIAN"] = $median_value;
1338  $result_array["QUESTION_TYPE"] = "SurveyMatrixQuestion";
1339  $result_array["ROW"] = $this->getRow($rowindex)->title;
1340  return $result_array;
1341  }
1342 
1350  function &getCumulatedResults($survey_id, $nr_of_users, $finished_ids)
1351  {
1352  global $ilDB;
1353 
1354  $question_id = $this->getId();
1355 
1356  $result_array = array();
1357  $cumulated = array();
1358 
1359  $sql = "SELECT svy_answer.* FROM svy_answer".
1360  " JOIN svy_finished ON (svy_finished.finished_id = svy_answer.active_fi)".
1361  " WHERE svy_answer.question_fi = ".$ilDB->quote($question_id, "integer").
1362  " AND svy_finished.survey_fi = ".$ilDB->quote($survey_id, "integer");
1363  if($finished_ids)
1364  {
1365  $sql .= " AND ".$ilDB->in("svy_finished.finished_id", $finished_ids, "", "integer");
1366  }
1367  $result = $ilDB->query($sql);
1368 
1369  switch ($this->getSubtype())
1370  {
1371  case 0:
1372  case 1:
1373  while ($row = $ilDB->fetchAssoc($result))
1374  {
1375  $cumulated[$row["value"]]++;
1376  }
1377  asort($cumulated, SORT_NUMERIC);
1378  end($cumulated);
1379  break;
1380  }
1381  $numrows = $result->numRows();
1382  $result_array["USERS_ANSWERED"] = $this->getNrOfUsersAnswered($survey_id, $finished_ids);
1383  $result_array["USERS_SKIPPED"] = $nr_of_users - $this->getNrOfUsersAnswered($survey_id, $finished_ids);
1384 
1385  if(sizeof($cumulated))
1386  {
1387  $prefix = "";
1388  if (strcmp(key($cumulated), "") != 0)
1389  {
1390  $prefix = (key($cumulated)+1) . " - ";
1391  }
1392  $cat = $this->getColumnForScale(key($cumulated)+1);
1393  $result_array["MODE"] = $prefix . $cat->title;
1394  $result_array["MODE_VALUE"] = key($cumulated)+1;
1395  $result_array["MODE_NR_OF_SELECTIONS"] = $cumulated[key($cumulated)];
1396  }
1397  for ($key = 0; $key < $this->getColumnCount(); $key++)
1398  {
1399  $cat = $this->getColumn($key);
1400  $scale = $cat->scale-1;
1401 
1402  $percentage = 0;
1403  if ($numrows > 0)
1404  {
1405  $percentage = (float)((int)$cumulated[$scale]/$numrows);
1406  }
1407 
1408  $result_array["variables"][$key] = array("title" => $cat->title, "selected" => (int)$cumulated[$scale], "percentage" => $percentage);
1409  }
1410  ksort($cumulated, SORT_NUMERIC);
1411  $median = array();
1412  $total = 0;
1413  foreach ($cumulated as $value => $key)
1414  {
1415  $total += $key;
1416  for ($i = 0; $i < $key; $i++)
1417  {
1418  array_push($median, $value+1);
1419  }
1420  }
1421  if ($total > 0)
1422  {
1423  if (($total % 2) == 0)
1424  {
1425  $median_value = 0.5 * ($median[($total/2)-1] + $median[($total/2)]);
1426  if (round($median_value) != $median_value)
1427  {
1428  $cat = $this->getColumnForScale((int)floor($median_value));
1429  $cat2 = $this->getColumnForScale((int)ceil($median_value));
1430  $median_value = $median_value . "<br />" . "(" . $this->lng->txt("median_between") . " " . (floor($median_value)) . "-" . $cat->title . " " . $this->lng->txt("and") . " " . (ceil($median_value)) . "-" . $cat2->title . ")";
1431  }
1432  }
1433  else
1434  {
1435  $median_value = $median[(($total+1)/2)-1];
1436  }
1437  }
1438  else
1439  {
1440  $median_value = "";
1441  }
1442  $result_array["ARITHMETIC_MEAN"] = "";
1443  $result_array["MEDIAN"] = $median_value;
1444  $result_array["QUESTION_TYPE"] = "SurveyMatrixQuestion";
1445 
1446  $cumulated_results = array();
1447  $cumulated_results["TOTAL"] = $result_array;
1448  for ($i = 0; $i < $this->getRowCount(); $i++)
1449  {
1450  $rowresult =& $this->getCumulatedResultsForRow($i, $survey_id, $nr_of_users, $finished_ids);
1451  $cumulated_results[$i] = $rowresult;
1452  }
1453  return $cumulated_results;
1454  }
1455 
1467  function setExportCumulatedXLS(&$worksheet, &$format_title, &$format_bold, &$eval_data, $row, $export_label)
1468  {
1469  include_once ("./Services/Excel/classes/class.ilExcelUtils.php");
1470  $column = 0;
1471  switch ($export_label)
1472  {
1473  case 'label_only':
1474  $worksheet->writeString($row, $column, ilExcelUtils::_convert_text($this->label));
1475  break;
1476  case 'title_only':
1477  $worksheet->writeString($row, $column, ilExcelUtils::_convert_text($this->getTitle()));
1478  break;
1479  default:
1480  $worksheet->writeString($row, $column, ilExcelUtils::_convert_text($this->getTitle()));
1481  $column++;
1482  $worksheet->writeString($row, $column, ilExcelUtils::_convert_text($this->label));
1483  break;
1484  }
1485  $column++;
1486  $worksheet->writeString($row, $column, ilExcelUtils::_convert_text(strip_tags($this->getQuestiontext())));
1487  $column++;
1488  $worksheet->writeString($row, $column, ilExcelUtils::_convert_text($this->lng->txt($eval_data["TOTAL"]["QUESTION_TYPE"])));
1489  $column++;
1490  $worksheet->write($row, $column, $eval_data["TOTAL"]["USERS_ANSWERED"]);
1491  $column++;
1492  $worksheet->write($row, $column, $eval_data["TOTAL"]["USERS_SKIPPED"]);
1493  $column++;
1494  $worksheet->write($row, $column, ilExcelUtils::_convert_text($eval_data["TOTAL"]["MODE_VALUE"]));
1495  $column++;
1496  $worksheet->write($row, $column, ilExcelUtils::_convert_text($eval_data["TOTAL"]["MODE"]));
1497  $column++;
1498  $worksheet->write($row, $column, $eval_data["TOTAL"]["MODE_NR_OF_SELECTIONS"]);
1499  $column++;
1500  $worksheet->write($row, $column, ilExcelUtils::_convert_text(str_replace("<br />", " ", $eval_data["TOTAL"]["MEDIAN"])));
1501  $column++;
1502  $worksheet->write($row, $column, $eval_data["TOTAL"]["ARITHMETIC_MEAN"]);
1503  $row++;
1504  $add = 0;
1505  switch ($export_label)
1506  {
1507  case 'label_only':
1508  case 'title_only':
1509  break;
1510  default:
1511  $add = 1;
1512  break;
1513  }
1514  foreach ($eval_data as $evalkey => $evalvalue)
1515  {
1516  if (is_numeric($evalkey))
1517  {
1518  $worksheet->writeString($row, 1+$add, ilExcelUtils::_convert_text($evalvalue["ROW"]));
1519  $worksheet->write($row, 3+$add, $evalvalue["USERS_ANSWERED"]);
1520  $worksheet->write($row, 4+$add, $evalvalue["USERS_SKIPPED"]);
1521  $worksheet->write($row, 5+$add, ilExcelUtils::_convert_text($evalvalue["MODE_VALUE"]));
1522  $worksheet->write($row, 6+$add, ilExcelUtils::_convert_text($evalvalue["MODE"]));
1523  $worksheet->write($row, 7+$add, $evalvalue["MODE_NR_OF_SELECTIONS"]);
1524  $worksheet->write($row, 8+$add, ilExcelUtils::_convert_text(str_replace("<br />", " ", $evalvalue["MEDIAN"])));
1525  $worksheet->write($row, 9+$add, $evalvalue["ARITHMETIC_MEAN"]);
1526  $row++;
1527  }
1528  }
1529  return $row;
1530  }
1531 
1543  function &setExportCumulatedCVS(&$eval_data, $export_label)
1544  {
1545  $result = array();
1546  foreach ($eval_data as $evalkey => $evalvalue)
1547  {
1548  $csvrow = array();
1549  if (is_numeric($evalkey))
1550  {
1551  array_push($csvrow, "");
1552  array_push($csvrow, $evalvalue["ROW"]);
1553  array_push($csvrow, "");
1554  }
1555  else
1556  {
1557  switch ($export_label)
1558  {
1559  case 'label_only':
1560  array_push($csvrow, $this->label);
1561  break;
1562  case 'title_only':
1563  array_push($csvrow, $this->getTitle());
1564  break;
1565  default:
1566  array_push($csvrow, $this->getTitle());
1567  array_push($csvrow, $this->label);
1568  break;
1569  }
1570  array_push($csvrow, strip_tags($this->getQuestiontext()));
1571  array_push($csvrow, $this->lng->txt($evalvalue["QUESTION_TYPE"]));
1572  }
1573  array_push($csvrow, $evalvalue["USERS_ANSWERED"]);
1574  array_push($csvrow, $evalvalue["USERS_SKIPPED"]);
1575  array_push($csvrow, $evalvalue["MODE"]);
1576  array_push($csvrow, $evalvalue["MODE_NR_OF_SELECTIONS"]);
1577  array_push($csvrow, $evalvalue["MEDIAN"]);
1578  array_push($csvrow, $evalvalue["ARITHMETIC_MEAN"]);
1579  array_push($result, $csvrow);
1580  }
1581  return $result;
1582  }
1583 
1593  function setExportDetailsXLS(&$workbook, &$format_title, &$format_bold, &$eval_data, $export_label)
1594  {
1595  include_once ("./Services/Excel/classes/class.ilExcelUtils.php");
1596  $worksheet =& $workbook->addWorksheet();
1597  $rowcounter = 0;
1598  switch ($export_label)
1599  {
1600  case 'label_only':
1601  $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("label")), $format_bold);
1602  $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->label));
1603  break;
1604  case 'title_only':
1605  $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_bold);
1606  $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->getTitle()));
1607  break;
1608  default:
1609  $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_bold);
1610  $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->getTitle()));
1611  $rowcounter++;
1612  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("label")), $format_bold);
1613  $worksheet->writeString($rowcounter, 1, ilExcelUtils::_convert_text($this->label));
1614  break;
1615  }
1616  $rowcounter++;
1617  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("question")), $format_bold);
1618  $worksheet->writeString($rowcounter, 1, ilExcelUtils::_convert_text($this->getQuestiontext()));
1619  $rowcounter++;
1620  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("question_type")), $format_bold);
1621  $worksheet->writeString($rowcounter, 1, ilExcelUtils::_convert_text($this->lng->txt($this->getQuestionType())));
1622  $rowcounter++;
1623  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("users_answered")), $format_bold);
1624  $worksheet->write($rowcounter, 1, $eval_data["TOTAL"]["USERS_ANSWERED"]);
1625  $rowcounter++;
1626  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("users_skipped")), $format_bold);
1627  $worksheet->write($rowcounter, 1, $eval_data["TOTAL"]["USERS_SKIPPED"]);
1628  $rowcounter++;
1629 
1630  preg_match("/(.*?)\s+-\s+(.*)/", $eval_data["TOTAL"]["MODE"], $matches);
1631  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode")), $format_bold);
1632  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($matches[1]));
1633  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode_text")), $format_bold);
1634  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($matches[2]));
1635  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode_nr_of_selections")), $format_bold);
1636  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($eval_data["TOTAL"]["MODE_NR_OF_SELECTIONS"]));
1637  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("median")), $format_bold);
1638  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text(str_replace("<br />", " ", $eval_data["TOTAL"]["MEDIAN"])));
1639  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("categories")), $format_bold);
1640  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_title);
1641  $worksheet->write($rowcounter, 2, ilExcelUtils::_convert_text($this->lng->txt("value")), $format_title);
1642  $worksheet->write($rowcounter, 3, ilExcelUtils::_convert_text($this->lng->txt("category_nr_selected")), $format_title);
1643  $worksheet->write($rowcounter++, 4, ilExcelUtils::_convert_text($this->lng->txt("percentage_of_selections")), $format_title);
1644 
1645  foreach ($eval_data["TOTAL"]["variables"] as $key => $value)
1646  {
1647  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($value["title"]));
1648  $worksheet->write($rowcounter, 2, $key+1);
1649  $worksheet->write($rowcounter, 3, ilExcelUtils::_convert_text($value["selected"]));
1650  $worksheet->write($rowcounter++, 4, ilExcelUtils::_convert_text($value["percentage"]), $format_percent);
1651  }
1652 
1653  foreach ($eval_data as $evalkey => $evalvalue)
1654  {
1655  if (is_numeric($evalkey))
1656  {
1657  $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("row")), $format_bold);
1658  $worksheet->writeString($rowcounter, 1, ilExcelUtils::_convert_text($evalvalue["ROW"]));
1659  $worksheet->writeString($rowcounter + 1, 0, ilExcelUtils::_convert_text($this->lng->txt("users_answered")), $format_bold);
1660  $worksheet->write($rowcounter + 1, 1, $evalvalue["USERS_ANSWERED"]);
1661  $worksheet->writeString($rowcounter + 2, 0, ilExcelUtils::_convert_text($this->lng->txt("users_skipped")), $format_bold);
1662  $worksheet->write($rowcounter + 2, 1, $evalvalue["USERS_SKIPPED"]);
1663  $rowcounter = $rowcounter + 3;
1664 
1665  preg_match("/(.*?)\s+-\s+(.*)/", $evalvalue["MODE"], $matches);
1666  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode")), $format_bold);
1667  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($matches[1]));
1668  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode_text")), $format_bold);
1669  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($matches[2]));
1670  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode_nr_of_selections")), $format_bold);
1671  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($evalvalue["MODE_NR_OF_SELECTIONS"]));
1672  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("median")), $format_bold);
1673  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text(str_replace("<br />", " ", $evalvalue["MEDIAN"])));
1674  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("categories")), $format_bold);
1675  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_title);
1676  $worksheet->write($rowcounter, 2, ilExcelUtils::_convert_text($this->lng->txt("value")), $format_title);
1677  $worksheet->write($rowcounter, 3, ilExcelUtils::_convert_text($this->lng->txt("category_nr_selected")), $format_title);
1678  $worksheet->write($rowcounter++, 4, ilExcelUtils::_convert_text($this->lng->txt("percentage_of_selections")), $format_title);
1679 
1680  foreach ($evalvalue["variables"] as $key => $value)
1681  {
1682  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($value["title"]));
1683  $worksheet->write($rowcounter, 2, $key+1);
1684  $worksheet->write($rowcounter, 3, ilExcelUtils::_convert_text($value["selected"]));
1685  $worksheet->write($rowcounter++, 4, ilExcelUtils::_convert_text($value["percentage"]), $format_percent);
1686  }
1687 
1688  // add text answers to detailed results
1689  if (is_array($evalvalue["textanswers"]))
1690  {
1691  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("freetext_answers")), $format_bold);
1692  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_title);
1693  $worksheet->write($rowcounter++, 2, ilExcelUtils::_convert_text($this->lng->txt("answer")), $format_title);
1694 
1695  foreach ($evalvalue["textanswers"] as $key => $answers)
1696  {
1697  $title = $evalvalue["variables"][$key]["title"];
1698  foreach ($answers as $answer)
1699  {
1700  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($title));
1701  $worksheet->write($rowcounter++, 2, ilExcelUtils::_convert_text($answer));
1702  }
1703  }
1704  }
1705  }
1706  }
1707  // out compressed 2D-Matrix
1708  $format_center =& $workbook->addFormat();
1709  $format_center->setColor('black');
1710  $format_center->setAlign('center');
1711 
1712  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("overview")), $format_bold);
1713  // title row with variables
1714  $rowcounter++;
1715  $counter = 0;
1716  $worksheet->write($rowcounter, $counter, "", $format_title);
1717  foreach ($eval_data["TOTAL"]["variables"] as $variable)
1718  {
1719  $worksheet->write($rowcounter, 1+$counter, ilExcelUtils::_convert_text($variable["title"]), $format_title);
1720  $counter++;
1721  }
1722  $rowcounter++;
1723  // rows with variable values
1724  foreach ($eval_data as $index => $data)
1725  {
1726  if (is_numeric($index))
1727  {
1728  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($data["ROW"]), $format_title);
1729  $counter = 1;
1730  foreach ($data["variables"] as $vardata)
1731  {
1732  $worksheet->write($rowcounter, $counter, $vardata["selected"], $format_center);
1733  $counter++;
1734  }
1735  $rowcounter++;
1736  }
1737  }
1738  }
1739 
1746  function addUserSpecificResultsExportTitles(&$a_array, $a_use_label = false, $a_substitute = true)
1747  {
1748  parent::addUserSpecificResultsExportTitles($a_array, $a_use_label, $a_substitute);
1749 
1750  for ($i = 0; $i < $this->getRowCount(); $i++)
1751  {
1752  // create row title according label, add 'other column'
1753  $row = $this->getRow($i);
1754 
1755  if(!$a_use_label)
1756  {
1757  $title = $row->title;
1758  }
1759  else
1760  {
1761  if($a_substitute)
1762  {
1763  $title = $row->label ? $row->label : $row->title;
1764  }
1765  else
1766  {
1767  $title = $row->label;
1768  }
1769  }
1770  array_push($a_array, $title);
1771 
1772  if ($row->other)
1773  {
1774  if(!$a_use_label || $a_substitute)
1775  {
1776  array_push($a_array, $title. ' - '. $this->lng->txt('other'));
1777  }
1778  else
1779  {
1780  array_push($a_array, "");
1781  }
1782  }
1783 
1784  switch ($this->getSubtype())
1785  {
1786  case 0:
1787  break;
1788  case 1:
1789  for ($index = 0; $index < $this->getColumnCount(); $index++)
1790  {
1791  $col = $this->getColumn($index);
1792  if(!$a_use_label || $a_substitute)
1793  {
1794  array_push($a_array, ($index+1) . " - " . $col->title);
1795  }
1796  else
1797  {
1798  array_push($a_array, "");
1799  }
1800  }
1801  break;
1802  }
1803  }
1804  }
1805 
1813  function addUserSpecificResultsData(&$a_array, &$resultset)
1814  {
1815  if (count($resultset["answers"][$this->getId()]))
1816  {
1817  array_push($a_array, "");
1818  switch ($this->getSubtype())
1819  {
1820  case 0:
1821  for ($i = 0; $i < $this->getRowCount(); $i++)
1822  {
1823  // add textanswer column for single choice mode
1824  $row = $this->getRow($i);
1825  $textanswer = "";
1826  $checked = FALSE;
1827  foreach ($resultset["answers"][$this->getId()] as $result)
1828  {
1829  if ($result["rowvalue"] == $i)
1830  {
1831  $checked = TRUE;
1832  array_push($a_array, $result["value"] + 1);
1833 
1834  if ($result["textanswer"])
1835  {
1836  $textanswer = $result["textanswer"];
1837  }
1838  }
1839  }
1840  if (!$checked)
1841  {
1842  array_push($a_array, $this->getSkippedValue());
1843  }
1844  if ($row->other)
1845  {
1846  array_push($a_array, $textanswer);
1847  }
1848  }
1849  break;
1850  case 1:
1851  for ($i = 0; $i < $this->getRowCount(); $i++)
1852  {
1853  // add textanswer column for multiple choice mode
1854  $row = $this->getRow($i);
1855  $textanswer = "";
1856  $checked = FALSE;
1857  $checked_values = array();
1858  foreach ($resultset["answers"][$this->getId()] as $result)
1859  {
1860  if ($result["rowvalue"] == $i)
1861  {
1862  $checked = TRUE;
1863  array_push($checked_values, $result["value"] + 1);
1864 
1865  if ($result["textanswer"])
1866  {
1867  $textanswer = $result["textanswer"];
1868  }
1869  }
1870  }
1871  if (!$checked)
1872  {
1873  array_push($a_array, $this->getSkippedValue());
1874  }
1875  else
1876  {
1877  array_push($a_array, "");
1878  }
1879  if ($row->other)
1880  {
1881  array_push($a_array, $textanswer);
1882  }
1883  for ($index = 0; $index < $this->getColumnCount(); $index++)
1884  {
1885  if (!$checked)
1886  {
1887  array_push($a_array, "");
1888  }
1889  else
1890  {
1891  $cat = $this->getColumn($index);
1892  $scale = $cat->scale;
1893  if (in_array($scale, $checked_values))
1894  {
1895  array_push($a_array, $scale);
1896  }
1897  else
1898  {
1899  array_push($a_array, 0);
1900  }
1901  }
1902  }
1903  }
1904  break;
1905  }
1906  }
1907  else
1908  {
1909  array_push($a_array, $this->getSkippedValue());
1910  for ($i = 0; $i < $this->getRowCount(); $i++)
1911  {
1912  array_push($a_array, "");
1913 
1914  // add empty "other" column if not answered
1915  $row = $this->getRow($i);
1916  if ($row->other)
1917  {
1918  array_push($a_array, "");
1919  }
1920 
1921  switch ($this->getSubtype())
1922  {
1923  case 0:
1924  break;
1925  case 1:
1926  for ($index = 0; $index < $this->getColumnCount(); $index++)
1927  {
1928  array_push($a_array, "");
1929  }
1930  break;
1931  }
1932  }
1933  }
1934  }
1935 
1943  function &getUserAnswers($survey_id, $finished_ids)
1944  {
1945  global $ilDB;
1946 
1947  $answers = array();
1948 
1949  $sql = "SELECT svy_answer.* FROM svy_answer".
1950  " JOIN svy_finished ON (svy_finished.finished_id = svy_answer.active_fi)".
1951  " WHERE svy_answer.question_fi = ".$ilDB->quote($this->getId(), "integer").
1952  " AND svy_finished.survey_fi = ".$ilDB->quote($survey_id, "integer");
1953  if($finished_ids)
1954  {
1955  $sql .= " AND ".$ilDB->in("svy_finished.finished_id", $finished_ids, "", "integer");
1956  }
1957  $sql .= " ORDER BY rowvalue, value";
1958  $result = $ilDB->query($sql);
1959 
1960  while ($row = $ilDB->fetchAssoc($result))
1961  {
1962  $column = $this->getColumnForScale($row["value"]+1);
1963  if (!is_array($answers[$row["active_fi"]])) $answers[$row["active_fi"]] = array();
1964  $rowobj = $this->getRow($row["rowvalue"]);
1965  array_push($answers[$row["active_fi"]], $rowobj->title . (($rowobj->other) ? (" " . $row["textanswer"]) : "") . ": " . ($row["value"] + 1) . " - " . $column->title);
1966  }
1967  foreach ($answers as $key => $value)
1968  {
1969  $answers[$key] = implode("<br />", $value);
1970  }
1971  return $answers;
1972  }
1973 
1980  function getSubtype()
1981  {
1982  return $this->subtype;
1983  }
1984 
1991  function setSubtype($a_subtype = 0)
1992  {
1993  switch ($a_subtype)
1994  {
1995  case 1:
1996  case 2:
1997  case 3:
1998  case 4:
1999  case 5:
2000  case 6:
2001  $this->subtype = $a_subtype;
2002  break;
2003  case 0:
2004  default:
2005  $this->subtype = 0;
2006  break;
2007  }
2008  }
2009 
2016  function setColumnSeparators($enable = 0)
2017  {
2018  switch ($enable)
2019  {
2020  case 1:
2021  $this->columnSeparators = 1;
2022  break;
2023  case 0:
2024  default:
2025  $this->columnSeparators = 0;
2026  break;
2027  }
2028  }
2029 
2037  {
2038  return ($this->columnSeparators) ? 1 : 0;
2039  }
2040 
2047  function setRowSeparators($enable = 0)
2048  {
2049  switch ($enable)
2050  {
2051  case 1:
2052  $this->rowSeparators = 1;
2053  break;
2054  case 0:
2055  default:
2056  $this->rowSeparators = 0;
2057  break;
2058  }
2059  }
2060 
2067  function getRowSeparators()
2068  {
2069  return ($this->rowSeparators) ? 1 : 0;
2070  }
2071 
2078  function setNeutralColumnSeparator($enable = 0)
2079  {
2080  switch ($enable)
2081  {
2082  case 1:
2083  $this->neutralColumnSeparator = 1;
2084  break;
2085  case 0:
2086  default:
2087  $this->neutralColumnSeparator = 0;
2088  break;
2089  }
2090  }
2091 
2099  {
2100  return ($this->neutralColumnSeparator) ? 1 : 0;
2101  }
2102 
2111  function importAdditionalMetadata($a_meta)
2112  {
2113  foreach ($a_meta as $key => $value)
2114  {
2115  switch ($value["label"])
2116  {
2117  case "column_separators":
2118  $this->setColumnSeparators($value["entry"]);
2119  break;
2120  case "row_separators":
2121  $this->setRowSeparators($value["entry"]);
2122  break;
2123  case "layout":
2124  $this->setLayout($value["entry"]);
2125  break;
2126  case "neutral_column_separator":
2127  $this->setNeutralColumnSeparator($value["entry"]);
2128  break;
2129  }
2130  }
2131  }
2132 
2139  function importAdjectives($a_data)
2140  {
2141  $i = 0;
2142  foreach ($a_data as $adjective)
2143  {
2144  if (is_numeric($adjective["label"]))
2145  {
2146  $this->setBipolarAdjective($adjective["label"], $adjective["text"]);
2147  }
2148  else
2149  {
2150  $this->setBipolarAdjective($i, $adjective["text"]);
2151  }
2152  $i++;
2153  }
2154  }
2155 
2162  function importMatrix($a_data)
2163  {
2164  foreach ($a_data as $row)
2165  {
2166  $this->addRow($row['title'], $row['other'], $row['label']);
2167  }
2168  }
2169 
2176  function importResponses($a_data)
2177  {
2178  foreach ($a_data as $id => $data)
2179  {
2180  $column = "";
2181  foreach ($data["material"] as $material)
2182  {
2183  $column .= $material["text"];
2184  }
2185  $this->columns->addCategory($column, null, (strcmp($data["label"], "neutral") == 0) ? true : false);
2186  }
2187  }
2188 
2196  {
2197  return FALSE;
2198  }
2199 
2208  {
2209  return $value;
2210  }
2211 
2218  public function getPreconditionSelectValue($default = "", $title, $variable)
2219  {
2220  include_once "./Services/Form/classes/class.ilSelectInputGUI.php";
2221  $step3 = new ilSelectInputGUI($title, $variable);
2222  $options = $this->getPreconditionOptions();
2223  $step3->setOptions($options);
2224  $step3->setValue($default);
2225  return $step3;
2226  }
2227 
2237  function saveLayout($percent_row, $percent_columns, $percent_bipolar_adjective1 = "", $percent_bipolar_adjective2 = "", $percent_neutral)
2238  {
2239  global $ilDB;
2240 
2241  $layout = array(
2242  "percent_row" => $percent_row,
2243  "percent_columns" => $percent_columns,
2244  "percent_bipolar_adjective1" => $percent_bipolar_adjective1,
2245  "percent_bipolar_adjective2" => $percent_bipolar_adjective2,
2246  "percent_neutral" => $percent_neutral
2247  );
2248  $affectedRows = $ilDB->manipulateF("UPDATE " . $this->getAdditionalTableName() . " SET layout = %s WHERE question_fi = %s",
2249  array('text', 'integer'),
2250  array(serialize($layout), $this->getId())
2251  );
2252  }
2253 
2254  function getLayout()
2255  {
2256  if (!is_array($this->layout) || count($this->layout) == 0)
2257  {
2258  if ($this->hasBipolarAdjectives() && $this->hasNeutralColumn())
2259  {
2260  $this->layout = array(
2261  "percent_row" => 30,
2262  "percent_columns" => 40,
2263  "percent_bipolar_adjective1" => 10,
2264  "percent_bipolar_adjective2" => 10,
2265  "percent_neutral" => 10
2266  );
2267  }
2268  elseif ($this->hasBipolarAdjectives())
2269  {
2270  $this->layout = array(
2271  "percent_row" => 30,
2272  "percent_columns" => 50,
2273  "percent_bipolar_adjective1" => 10,
2274  "percent_bipolar_adjective2" => 10,
2275  "percent_neutral" => 0
2276  );
2277  }
2278  elseif ($this->hasNeutralColumn())
2279  {
2280  $this->layout = array(
2281  "percent_row" => 30,
2282  "percent_columns" => 50,
2283  "percent_bipolar_adjective1" => 0,
2284  "percent_bipolar_adjective2" => 0,
2285  "percent_neutral" => 20
2286  );
2287  }
2288  else
2289  {
2290  $this->layout = array(
2291  "percent_row" => 30,
2292  "percent_columns" => 70,
2293  "percent_bipolar_adjective1" => 0,
2294  "percent_bipolar_adjective2" => 0,
2295  "percent_neutral" => 0
2296  );
2297  }
2298  }
2299  return $this->layout;
2300  }
2301 
2302  function setLayout($layout)
2303  {
2304  if (is_array($layout))
2305  {
2306  $this->layout = $layout;
2307  }
2308  else
2309  {
2310  $this->layout = unserialize($layout);
2311  }
2312  }
2313 
2320  {
2321  if ((strlen($this->getBipolarAdjective(0))) && (strlen($this->getBipolarAdjective(1))))
2322  {
2323  return TRUE;
2324  }
2325  else
2326  {
2327  return FALSE;
2328  }
2329  }
2330 
2336  function hasNeutralColumn()
2337  {
2338  for ($i = 0; $i < $this->getColumnCount(); $i++)
2339  {
2340  $column = $this->getColumn($i);
2341  if ($column->neutral && strlen($column->title)) return true;
2342  }
2343  return FALSE;
2344  }
2345 
2351  function setColumnPlaceholders($a_value = 0)
2352  {
2353  $this->columnPlaceholders = ($a_value) ? 1 : 0;
2354  }
2355 
2362  {
2363  return ($this->columnPlaceholders) ? 1 : 0;
2364  }
2365 
2371  function setLegend($a_value = 0)
2372  {
2373  $this->legend = ($a_value) ? 1 : 0;
2374  }
2375 
2381  function getLegend()
2382  {
2383  return ($this->legend) ? 1 : 0;
2384  }
2385 
2386  function setSingleLineRowCaption($a_value = 0)
2387  {
2388  $this->singleLineRowCaption = ($a_value) ? 1 : 0;
2389  }
2390 
2392  {
2393  return ($this->singleLineRowCaption) ? 1 : 0;
2394  }
2395 
2396  function setRepeatColumnHeader($a_value = 0)
2397  {
2398  $this->repeatColumnHeader = ($a_value) ? 1 : 0;
2399  }
2400 
2402  {
2403  return ($this->repeatColumnHeader) ? 1 : 0;
2404  }
2405 
2406  function setColumnHeaderPosition($a_value)
2407  {
2408  $this->columnHeaderPosition = $a_value;
2409  }
2410 
2412  {
2413  return ($this->columnHeaderPosition) ? $this->columnHeaderPosition : 0;
2414  }
2415 
2416  function setRandomRows($a_value = 0)
2417  {
2418  $this->randomRows = ($a_value) ? 1 : 0;
2419  }
2420 
2421  function getRandomRows()
2422  {
2423  return ($this->randomRows) ? 1 : 0;
2424  }
2425 
2426  function setColumnOrder($a_value)
2427  {
2428  $this->columnOrder = $a_value;
2429  }
2430 
2431  function getColumnOrder()
2432  {
2433  return ($this->columnOrder) ? $this->columnOrder : 0;
2434  }
2435 
2436  function setColumnImages($a_value = 0)
2437  {
2438  $this->columnImages = ($a_value) ? 1 : 0;
2439  }
2440 
2441  function getColumnImages()
2442  {
2443  return ($this->columnImages) ? 1 : 0;
2444  }
2445 
2446  function setRowImages($a_value = 0)
2447  {
2448  $this->rowImages = ($a_value) ? 1 : 0;
2449  }
2450 
2451  function getRowImages()
2452  {
2453  return ($this->rowImages) ? 1 : 0;
2454  }
2455 
2456  public function getRows()
2457  {
2458  return $this->rows;
2459  }
2460 
2466  public function getCumulatedResultData($survey_id, $counter, $finished_ids)
2467  {
2468  $cumulated =& $this->calculateCumulatedResults($survey_id, $finished_ids);
2469  $questiontext = preg_replace("/<[^>]+?>/ims", "", $this->getQuestiontext());
2470 
2471  include_once "./Services/Utilities/classes/class.ilStr.php";
2472  $maxlen = 75;
2473  if (strlen($questiontext) > $maxlen + 3)
2474  {
2475  $questiontext = ilStr::substr($questiontext, 0, $maxlen) . "...";
2476  }
2477 
2478  $result = array();
2479  $row = array(
2480  'counter' => $counter,
2481  'title' => $counter.'. '.$this->getTitle(),
2482  'question' => $questiontext,
2483  'users_answered' => $cumulated['TOTAL']['USERS_ANSWERED'],
2484  'users_skipped' => $cumulated['TOTAL']['USERS_SKIPPED'],
2485  'question_type' => $this->lng->txt($cumulated['TOTAL']['QUESTION_TYPE']),
2486  'mode' => $cumulated['TOTAL']['MODE'],
2487  'mode_nr_of_selections' => $cumulated['TOTAL']['MODE_NR_OF_SELECTIONS'],
2488  'median' => $cumulated['TOTAL']['MEDIAN'],
2489  'arithmetic_mean' => $cumulated['TOTAL']['ARITHMETIC_MEAN']
2490  );
2491  array_push($result, $row);
2492  $maxlen -= 3;
2493  foreach ($cumulated as $key => $value)
2494  {
2495  if (is_numeric($key))
2496  {
2497  if (strlen($value['ROW']) > $maxlen + 3)
2498  {
2499  $value['ROW'] = ilStr::substr($value['ROW'], 0, $maxlen) . "...";
2500  }
2501 
2502  $row = array(
2503  'title' => '',
2504  'question' => ($key+1) . ". " . $value['ROW'],
2505  'users_answered' => $value['USERS_ANSWERED'],
2506  'users_skipped' => $value['USERS_SKIPPED'],
2507  'question_type' => '',
2508  'mode' => $value["MODE"],
2509  'mode_nr_of_selections' => $value["MODE_NR_OF_SELECTIONS"],
2510  'median' => $value["MEDIAN"],
2511  'arithmetic_mean' => $value["ARITHMETIC_MEAN"]
2512  );
2513  array_push($result, $row);
2514  }
2515  }
2516  return $result;
2517  }
2518 }
2519 ?>
< a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">< img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/></a >< br/>< strong > Enter Code *if($_SERVER['REQUEST_METHOD']=='POST' &&@ $_POST['do']=='contact') $_SESSION['ctform']['success']
toXML($a_include_header=TRUE, $obligatory_state="")
Returns an xml representation of the question.
addRowAtPosition($a_text, $a_other, $a_position)
Adds a row at a given position.
saveCompletionStatus($original_id="")
Saves the complete flag to the database.
getAuthor()
Gets the authors name of the SurveyQuestion object.
$cumulated
An array containing the cumulated results of the question for a given survey.
getTitle()
Gets the title string of the SurveyQuestion object.
getBipolarAdjective($a_index)
Returns one of the bipolar adjectives.
This class represents a selection list property in a property form.
$result
getCumulatedResultData($survey_id, $counter, $finished_ids)
Creates a the cumulated results data for the question.
getObligatory($survey_id="")
Gets the obligatory state of the question.
getRow($a_index)
Returns a specific row.
& getCumulatedResults($survey_id, $nr_of_users, $finished_ids)
Returns the cumulated results for the question.
setExportCumulatedXLS(&$worksheet, &$format_title, &$format_bold, &$eval_data, $row, $export_label)
Creates the Excel output for the cumulated results of this question.
_getQuestionDataArray($id)
Returns the question data fields from the database.
setObligatory($obligatory=1)
Sets the obligatory state of the question.
_convert_text($a_text, $a_target="has been removed")
saveToDb($original_id=NULL, $withanswers=true)
Saves a SurveyMatrixQuestion object to a database.
savePhrase($title)
Saves a set of columns to a default phrase.
setColumnPlaceholders($a_value=0)
Set whether placeholders should be used for the column titles or not.
setId($id=-1)
Sets the id of the SurveyQuestion object.
hasBipolarAdjectives()
Returns TRUE if bipolar adjectives exist.
XML writer class.
SurveyMatrixQuestion( $title="", $description="", $author="", $questiontext="", $owner=-1)
SurveyMatrixQuestion constructor The constructor takes possible arguments an creates an instance of t...
removeRows($array)
Removes rows from the question.
checkUserInput($post_data, $survey_id)
Checks the input of the active user for obligatory status and entered values.
saveBipolarAdjectives($adjective1, $adjective2)
getQuestiontext()
Gets the questiontext of the SurveyQuestion object.
getRowSeparators()
Gets the separators enable state for the matrix rows.
saveRandomData($active_id)
Saves random answers for a given active user in the database.
getColumns()
Return the columns.
getPreconditionValueOutput($value)
Returns the output for a precondition value.
setOwner($owner="")
Sets the creator/owner ID of the SurveyQuestion object.
getColumn($index)
Returns the name of a column for a given index.
setExportDetailsXLS(&$workbook, &$format_title, &$format_bold, &$eval_data, $export_label)
Creates an Excel worksheet for the detailed cumulated results of this question.
addUserSpecificResultsData(&$a_array, &$resultset)
Adds the values for the user specific results export for a given user.
setComplete($a_complete)
Sets the complete state of the question.
flushColumns()
Empties the columns list.
deleteAdditionalTableData($question_id)
Deletes datasets from the additional question table in the database.
getPreconditionOptions()
Returns the options for preconditions.
& getWorkingDataFromUserInput($post_data)
Creates the user data of the svy_answer table from the POST data.
saveLayout($percent_row, $percent_columns, $percent_bipolar_adjective1="", $percent_bipolar_adjective2="", $percent_neutral)
Saves the layout of a matrix question.
importAdjectives($a_data)
Import bipolar adjectives from the question import file.
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.
Class SurveyCategories.
hasNeutralColumn()
Returns TRUE if a neutral column exists.
setNeutralColumnSeparator($enable=0)
Enables/Disables a separator for the neutral column.
getLegend()
Get whether the legend should be shown or not.
& calculateCumulatedResults($survey_id, $finished_ids)
if(!is_array($argv)) $options
usableForPrecondition()
Returns if the question is usable for preconditions.
getId()
Gets the id of the SurveyQuestion object.
addStandardNumbers($lower_limit, $upper_limit)
Adds standard numbers as columns.
The SurveyMatrixQuestion class defines and encapsulates basic methods and attributes for matrix quest...
Basic class for all survey question types.
removeRow($index)
Removes a row.
importMatrix($a_data)
Import matrix rows from the question import file.
saveMaterial()
save material to db
importResponses($a_data)
Import response data from the question import file.
loadFromDb($id)
Loads a SurveyMatrixQuestion object from the database.
setLegend($a_value=0)
Set whether the legend should be shown or not.
addUserSpecificResultsExportTitles(&$a_array, $a_use_label=false, $a_substitute=true)
Adds the entries for the title row of the user specific results.
getPreconditionSelectValue($default="", $title, $variable)
Creates a form property for the precondition value.
setColumnSeparators($enable=0)
Enables/Disables separators for the matrix columns.
xmlHeader()
Writes xml header public.
saveColumnToDb($columntext, $neutral=0)
Saves a column to the database.
setSubtype($a_subtype=0)
Sets the subtype of the matrix question.
getNrOfUsersAnswered($survey_id, $finished_ids=null)
Returns the number of users that answered the question for a given survey.
getColumnIndex($name)
Returns the index of a column with a given name.
saveUserInput($post_data, $active_id, $a_return=false)
flushRows()
Empties the row list.
getSubtype()
Returns the subtype of the matrix question.
removeColumn($index)
Removes a column from the list of columns.
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
global $ilUser
Definition: imgupload.php:15
setAuthor($author="")
Sets the authors name of the SurveyQuestion object.
setRowSeparators($enable=0)
Enables/Disables separators for the matrix rows.
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.
importAdditionalMetadata($a_meta)
Import additional meta data from the question import file.
removeColumnWithName($name)
Removes a column from the list of columns.
setDescription($description="")
Sets the description string of the SurveyQuestion object.
addRow($a_text, $a_other, $a_label)
Adds a row to the question.
& getCumulatedResultsForRow($rowindex, $survey_id, $nr_of_users, $finished_ids)
Returns the cumulated results for a given row.
& getUserAnswers($survey_id, $finished_ids)
Returns an array containing all answers to this question in a given survey.
getColumnPlaceholders()
Get whether placeholders should be used for the column titles or not.
insertXML(&$a_xml_writer, $a_include_header=TRUE, $obligatory_state="")
Adds the question XML to a given XMLWriter object.
getDescription()
Gets the description string of the SurveyQuestion object.
getQuestionType()
Returns the question type of the question.
getColumnCount()
Returns the number of columns.
setObjId($obj_id=0)
Set the reference id of the container object.
getColumnSeparators()
Gets the separators enable state for the matrix columns.
getAdditionalTableName()
Returns the name of the additional question data table in the database.
setBipolarAdjective($a_index, $a_value)
Sets one of the bipolar adjectives.
& setExportCumulatedCVS(&$eval_data, $export_label)
Creates the CSV output for the cumulated results of this question.
getRowCount()
Returns the number of rows in the question.
getNeutralColumnSeparator()
Gets the separator enable state for the neutral column.
addPhrase($phrase_id)
Adds a phrase to the question.
removeColumns($array)
Removes many columns from the list of columns.
isComplete()
Returns 1 if the question is complete for use.
setTitle($title="")
Sets the title string of the SurveyQuestion object.