ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.SurveyConstraintsTableGUI.php
Go to the documentation of this file.
1 <?php
2 
24 {
25  protected bool $read_only;
26  protected array $structure;
27 
28  public function __construct(
29  object $a_parent_obj,
30  string $a_parent_cmd,
31  ilObjSurvey $a_survey,
32  bool $a_read_only
33  ) {
34  global $DIC;
35 
36  $this->ctrl = $DIC->ctrl();
37  $this->lng = $DIC->language();
38  $ilCtrl = $DIC->ctrl();
39  $lng = $DIC->language();
40 
41  $this->read_only = $a_read_only;
42 
43  parent::__construct($a_parent_obj, $a_parent_cmd);
44 
45  $this->setLimit(9999);
46  $this->disable("numinfo");
47 
48  $this->setDescription($lng->txt("constraints_introduction"));
49 
50  if (!$this->read_only) {
51  $this->addColumn("", "", 1);
52  }
53 
54  $this->addColumn("", "", 1);
55  $this->addColumn($lng->txt("constraints_list_of_entities"), "");
56  $this->addColumn($lng->txt("existing_constraints"), "");
57 
58  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
59  $this->setRowTemplate("tpl.svy_constraints_row.html", "Modules/Survey");
60 
61  if (!$this->read_only) {
62  $this->addMultiCommand("createConstraints", $lng->txt("constraint_add"));
63  $this->setSelectAllCheckbox("includeElements");
64  }
65 
66  $this->initItems($a_survey);
67  }
68 
69  protected function initItems(ilObjSurvey $a_survey): void
70  {
71  $lng = $this->lng;
72 
73  $this->structure = array();
74  $tbl_data = array();
75 
76  $survey_questions = $a_survey->getSurveyQuestions();
77 
78  $last_questionblock_id = 0;
79  $counter = 1;
80  foreach ($survey_questions as $data) {
81  $title = $data["title"];
82  $show = true;
83  if ($data["questionblock_id"] > 0) {
84  $title = $data["questionblock_title"];
85  $type = $lng->txt("questionblock");
86  if ($data["questionblock_id"] != $last_questionblock_id) {
87  $last_questionblock_id = $data["questionblock_id"];
88  $this->structure[$counter] = array();
89  $this->structure[$counter][] = $data["question_id"];
90  } else {
91  $this->structure[$counter - 1][] = $data["question_id"];
92  $show = false;
93  }
94  } else {
95  $this->structure[$counter] = array($data["question_id"]);
96  $type = $lng->txt("question");
97  }
98  if ($show) {
99  $id = $content = $parsed = $conjunction = null;
100 
101  if ($counter === 1) {
102  $content = $lng->txt("constraints_first_question_description");
103  } else {
104  $constraints = $a_survey->getConstraints($data["question_id"]);
105  if (count($constraints)) {
106  $parsed = array();
107 
108  foreach ($constraints as $constraint) {
109  $parsed[] = array(
110  "id" => $constraint["id"],
111  "title" => $survey_questions[$constraint["question"]]["title"] . " " .
112  $constraint["short"] . " " .
113  $constraint["valueoutput"]
114  );
115  }
116 
117  if (count($constraints) > 1) {
118  $conjunction = ($constraints[0]['conjunction'])
119  ? $lng->txt('conjunction_or_title')
120  : $lng->txt('conjunction_and_title');
121  }
122  }
123  }
124  if ($counter !== 1) {
125  $id = $counter;
126  }
127 
128  $icontype = "question.png";
129  if ($data["questionblock_id"] > 0) {
130  $icontype = "questionblock.png";
131  }
132 
133  $tbl_data[] = array(
134  "counter" => $counter,
135  "id" => $id,
136  "title" => $title,
137  "type" => $type,
138  "icon" => ilUtil::getImagePath($icontype, "Modules/Survey"),
139  "content" => $content,
140  "constraints" => $parsed,
141  "conjunction" => $conjunction
142  );
143 
144  $counter++;
145  }
146  }
147 
148  $this->setData($tbl_data);
149  }
150 
151  public function getStructure(): array
152  {
153  return $this->structure;
154  }
155 
156  protected function fillRow(array $a_set): void
157  {
158  $ilCtrl = $this->ctrl;
159  $lng = $this->lng;
160 
161  // $ilCtrl->setParameterByClass("ilObjSurveyAdministrationGUI", "item_id", $a_set["usr_id"]);
162 
163  if (!$this->read_only) {
164  if ($a_set["id"]) {
165  $this->tpl->setVariable("ID", $a_set["id"]);
166  } else {
167  $this->tpl->touchBlock("checkbox");
168  }
169  }
170 
171  $this->tpl->setVariable("COUNTER", $a_set["counter"]);
172  $this->tpl->setVariable("TITLE", $a_set["title"]);
173  $this->tpl->setVariable("TYPE", $a_set["type"]);
174  $this->tpl->setVariable("ICON_HREF", $a_set["icon"]);
175  $this->tpl->setVariable("ICON_ALT", $a_set["type"]);
176  $this->tpl->setVariable("CONTENT", $a_set["content"]);
177 
178  if (is_array($a_set["constraints"])) {
179  foreach ($a_set["constraints"] as $constraint) {
180  if (!$this->read_only) {
181  $ilCtrl->setParameter($this->getParentObject(), "precondition", $constraint["id"]);
182  $ilCtrl->setParameter($this->getParentObject(), "start", $a_set["counter"]);
183  $url = $ilCtrl->getLinkTarget($this->getParentObject(), "editPrecondition");
184  $ilCtrl->setParameter($this->getParentObject(), "precondition", "");
185  $ilCtrl->setParameter($this->getParentObject(), "start", "");
186  $this->tpl->setVariable("TEXT_EDIT_PRECONDITION", $lng->txt("edit"));
187  $this->tpl->setVariable("EDIT_PRECONDITION", $url);
188 
189  $ilCtrl->setParameter($this->getParentObject(), "precondition", $constraint["id"]);
190  $url = $ilCtrl->getLinkTarget($this->getParentObject(), "confirmDeleteConstraints");
191  $ilCtrl->setParameter($this->getParentObject(), "precondition", "");
192  $this->tpl->setVariable("TEXT_DELETE_PRECONDITION", $lng->txt("delete"));
193  $this->tpl->setVariable("DELETE_PRECONDITION", $url);
194  }
195 
196  $this->tpl->setCurrentBlock("constraint");
197  $this->tpl->setVariable("CONSTRAINT_TEXT", $constraint["title"]);
198  $this->tpl->parseCurrentBlock();
199  }
200 
201  if ($a_set["conjunction"]) {
202  $this->tpl->setCurrentBlock("conjunction");
203  $this->tpl->setVariable("TEXT_CONJUNCTION", $a_set["conjunction"]);
204  $this->tpl->parseCurrentBlock();
205  }
206  }
207  }
208 }
setData(array $a_data)
getSurveyQuestions(bool $with_answers=false)
Returns the survey questions and questionblocks in an array.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
setFormAction(string $a_form_action, bool $a_multipart=false)
$type
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
setDescription(string $a_val)
ilLanguage $lng
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
getConstraints(int $question_id)
Returns the constraints to a given question or questionblock.
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
__construct(object $a_parent_obj, string $a_parent_cmd, ilObjSurvey $a_survey, bool $a_read_only)
__construct(Container $dic, ilPlugin $plugin)
setLimit(int $a_limit=0, int $a_default_limit=0)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
disable(string $a_module_name)
$url
addMultiCommand(string $a_cmd, string $a_text)