ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.SurveyConstraintsTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/Table/classes/class.ilTable2GUI.php");
5 
15 {
16  protected $read_only; // [bool]
17  protected $structure; // [array]
18 
19  public function __construct($a_parent_obj, $a_parent_cmd = "", ilObjSurvey $a_survey, $a_read_only)
20  {
21  global $DIC;
22 
23  $this->ctrl = $DIC->ctrl();
24  $this->lng = $DIC->language();
25  $ilCtrl = $DIC->ctrl();
26  $lng = $DIC->language();
27 
28  $this->read_only = (bool) $a_read_only;
29 
30  parent::__construct($a_parent_obj, $a_parent_cmd);
31 
32  $this->setLimit(9999);
33  $this->disable("numinfo");
34 
35  $this->setDescription($lng->txt("constraints_introduction"));
36 
37  if (!$this->read_only) {
38  $this->addColumn("", "", 1);
39  }
40 
41  $this->addColumn("", "", 1);
42  $this->addColumn($lng->txt("constraints_list_of_entities"), "");
43  $this->addColumn($lng->txt("existing_constraints"), "");
44 
45  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
46  $this->setRowTemplate("tpl.svy_constraints_row.html", "Modules/Survey");
47 
48  if (!$this->read_only) {
49  $this->addMultiCommand("createConstraints", $lng->txt("constraint_add"));
50  $this->setSelectAllCheckbox("includeElements");
51  }
52 
53  $this->initItems($a_survey);
54  }
55 
56  protected function initItems(ilObjSurvey $a_survey)
57  {
58  $lng = $this->lng;
59 
60  $this->structure = array();
61  $tbl_data = array();
62 
63  $survey_questions = $a_survey->getSurveyQuestions();
64 
65  $last_questionblock_id = 0;
66  $counter = 1;
67  foreach ($survey_questions as $data) {
68  $title = $data["title"];
69  $show = true;
70  if ($data["questionblock_id"] > 0) {
71  $title = $data["questionblock_title"];
72  $type = $lng->txt("questionblock");
73  if ($data["questionblock_id"] != $last_questionblock_id) {
74  $last_questionblock_id = $data["questionblock_id"];
75  $this->structure[$counter] = array();
76  array_push($this->structure[$counter], $data["question_id"]);
77  } else {
78  array_push($this->structure[$counter - 1], $data["question_id"]);
79  $show = false;
80  }
81  } else {
82  $this->structure[$counter] = array($data["question_id"]);
83  $type = $lng->txt("question");
84  }
85  if ($show) {
86  $id = $content = $parsed = $conjunction = null;
87 
88  if ($counter == 1) {
89  $content = $lng->txt("constraints_first_question_description");
90  } else {
91  $constraints = $a_survey->getConstraints($data["question_id"]);
92  if (count($constraints)) {
93  $parsed = array();
94 
95  foreach ($constraints as $constraint) {
96  $parsed[] = array(
97  "id" => $constraint["id"],
98  "title" => $survey_questions[$constraint["question"]]["title"] . " " .
99  $constraint["short"] . " " .
100  $constraint["valueoutput"]
101  );
102  }
103 
104  if (count($constraints) > 1) {
105  $conjunction = ($constraints[0]['conjunction'])
106  ? $lng->txt('conjunction_or_title')
107  : $lng->txt('conjunction_and_title');
108  }
109  }
110  }
111  if ($counter != 1) {
112  $id = $counter;
113  }
114 
115  $icontype = "question.png";
116  if ($data["questionblock_id"] > 0) {
117  $icontype = "questionblock.png";
118  }
119 
120  $tbl_data[] = array(
121  "counter" => $counter,
122  "id" => $id,
123  "title" => $title,
124  "type" => $type,
125  "icon" => ilUtil::getImagePath($icontype, "Modules/Survey"),
126  "content" => $content,
127  "constraints" => $parsed,
128  "conjunction" => $conjunction
129  );
130 
131  $counter++;
132  }
133  }
134 
135  $this->setData($tbl_data);
136  }
137 
138  public function getStructure()
139  {
140  return $this->structure;
141  }
142 
143  protected function fillRow($a_set)
144  {
146  $lng = $this->lng;
147 
148  // $ilCtrl->setParameterByClass("ilObjSurveyAdministrationGUI", "item_id", $a_set["usr_id"]);
149 
150  if (!$this->read_only) {
151  if ($a_set["id"]) {
152  $this->tpl->setVariable("ID", $a_set["id"]);
153  } else {
154  $this->tpl->touchBlock("checkbox");
155  }
156  }
157 
158  $this->tpl->setVariable("COUNTER", $a_set["counter"]);
159  $this->tpl->setVariable("TITLE", $a_set["title"]);
160  $this->tpl->setVariable("TYPE", $a_set["type"]);
161  $this->tpl->setVariable("ICON_HREF", $a_set["icon"]);
162  $this->tpl->setVariable("ICON_ALT", $a_set["type"]);
163  $this->tpl->setVariable("CONTENT", $a_set["content"]);
164 
165  if (is_array($a_set["constraints"])) {
166  foreach ($a_set["constraints"] as $constraint) {
167  if (!$this->read_only) {
168  $ilCtrl->setParameter($this->getParentObject(), "precondition", $constraint["id"]);
169  $ilCtrl->setParameter($this->getParentObject(), "start", $a_set["counter"]);
170  $url = $ilCtrl->getLinkTarget($this->getParentObject(), "editPrecondition");
171  $ilCtrl->setParameter($this->getParentObject(), "precondition", "");
172  $ilCtrl->setParameter($this->getParentObject(), "start", "");
173  $this->tpl->setVariable("TEXT_EDIT_PRECONDITION", $lng->txt("edit"));
174  $this->tpl->setVariable("EDIT_PRECONDITION", $url);
175 
176  $ilCtrl->setParameter($this->getParentObject(), "precondition", $constraint["id"]);
177  $url = $ilCtrl->getLinkTarget($this->getParentObject(), "confirmDeleteConstraints");
178  $ilCtrl->setParameter($this->getParentObject(), "precondition", "");
179  $this->tpl->setVariable("TEXT_DELETE_PRECONDITION", $lng->txt("delete"));
180  $this->tpl->setVariable("DELETE_PRECONDITION", $url);
181  }
182 
183  $this->tpl->setCurrentBlock("constraint");
184  $this->tpl->setVariable("CONSTRAINT_TEXT", $constraint["title"]);
185  $this->tpl->parseCurrentBlock();
186  }
187 
188  if ($a_set["conjunction"]) {
189  $this->tpl->setCurrentBlock("conjunction");
190  $this->tpl->setVariable("TEXT_CONJUNCTION", $a_set["conjunction"]);
191  $this->tpl->parseCurrentBlock();
192  }
193  }
194  }
195 }
setDescription($a_val)
Set description.
$type
global $DIC
Definition: saml.php:7
getConstraints($question_id)
Returns the constraints to a given question or questionblock.
if(!array_key_exists('StateId', $_REQUEST)) $id
getParentObject()
Get parent object.
TableGUI class for survey constraints.
global $ilCtrl
Definition: ilias.php:18
Class ilTable2GUI.
& getSurveyQuestions($with_answers=false)
Returns the survey questions and questionblocks in an array.
setSelectAllCheckbox($a_select_all_checkbox, $a_select_all_on_top=false)
Set the name of the checkbox that should be toggled with a select all button.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
addMultiCommand($a_cmd, $a_text)
Add Command button.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
disable($a_module_name)
diesables particular modules of table
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
$url
setLimit($a_limit=0, $a_default_limit=0)
__construct($a_parent_obj, $a_parent_cmd="", ilObjSurvey $a_survey, $a_read_only)