ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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", "components/ILIAS/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 {
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 $tbl_data[] = array(
129 "counter" => $counter,
130 "id" => $id,
131 "title" => $title,
132 "type" => $type,
133 "content" => $content,
134 "constraints" => $parsed,
135 "conjunction" => $conjunction
136 );
137
138 $counter++;
139 }
140 }
141
142 $this->setData($tbl_data);
143 }
144
145 public function getStructure(): array
146 {
147 return $this->structure;
148 }
149
150 protected function fillRow(array $a_set): void
151 {
152 $ilCtrl = $this->ctrl;
154
155 // $ilCtrl->setParameterByClass("ilObjSurveyAdministrationGUI", "item_id", $a_set["usr_id"]);
156
157 if (!$this->read_only) {
158 if ($a_set["id"]) {
159 $this->tpl->setVariable("ID", $a_set["id"]);
160 } else {
161 $this->tpl->touchBlock("checkbox");
162 }
163 }
164
165 $this->tpl->setVariable("COUNTER", $a_set["counter"]);
166 $this->tpl->setVariable("TITLE", $a_set["title"]);
167 $this->tpl->setVariable("TYPE", $a_set["type"]);
168 $this->tpl->setVariable("ICON_ALT", $a_set["type"]);
169 $this->tpl->setVariable("CONTENT", $a_set["content"]);
170
171 if (is_array($a_set["constraints"])) {
172 foreach ($a_set["constraints"] as $constraint) {
173 if (!$this->read_only) {
174 $ilCtrl->setParameter($this->getParentObject(), "precondition", $constraint["id"]);
175 $ilCtrl->setParameter($this->getParentObject(), "start", $a_set["counter"]);
176 $url = $ilCtrl->getLinkTarget($this->getParentObject(), "editPrecondition");
177 $ilCtrl->setParameter($this->getParentObject(), "precondition", "");
178 $ilCtrl->setParameter($this->getParentObject(), "start", "");
179 $this->tpl->setVariable("TEXT_EDIT_PRECONDITION", $lng->txt("edit"));
180 $this->tpl->setVariable("EDIT_PRECONDITION", $url);
181
182 $ilCtrl->setParameter($this->getParentObject(), "precondition", $constraint["id"]);
183 $url = $ilCtrl->getLinkTarget($this->getParentObject(), "confirmDeleteConstraints");
184 $ilCtrl->setParameter($this->getParentObject(), "precondition", "");
185 $this->tpl->setVariable("TEXT_DELETE_PRECONDITION", $lng->txt("delete"));
186 $this->tpl->setVariable("DELETE_PRECONDITION", $url);
187 }
188
189 $this->tpl->setCurrentBlock("constraint");
190 $this->tpl->setVariable("CONSTRAINT_TEXT", $constraint["title"]);
191 $this->tpl->parseCurrentBlock();
192 }
193
194 if ($a_set["conjunction"]) {
195 $this->tpl->setCurrentBlock("conjunction");
196 $this->tpl->setVariable("TEXT_CONJUNCTION", $a_set["conjunction"]);
197 $this->tpl->parseCurrentBlock();
198 }
199 }
200 }
201}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(object $a_parent_obj, string $a_parent_cmd, ilObjSurvey $a_survey, bool $a_read_only)
fillRow(array $a_set)
Standard Version of Fill Row.
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...
getSurveyQuestions(bool $with_answers=false)
Returns the survey questions and questionblocks in an array.
getConstraints(int $question_id)
Returns the constraints to a given question or questionblock.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setLimit(int $a_limit=0, int $a_default_limit=0)
set max.
setDescription(string $a_val)
addMultiCommand(string $a_cmd, string $a_text)
setFormAction(string $a_form_action, bool $a_multipart=false)
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)
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setData(array $a_data)
Set table data.
ilLanguage $lng
disable(string $a_module_name)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26
$url
Definition: shib_logout.php:68
$counter