ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilQuestionEditGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24use ILIAS\Style\Content\Service as ContentStyle;
25
38{
39 private \ilGlobalTemplateInterface $main_tpl;
40 private \ilTabsGUI $tabs;
41 private readonly \ilHelpGUI $help;
42 private readonly \ilCtrlInterface $ctrl;
43 private readonly \ilAccessHandler $access;
44 private readonly \ilLanguage $lng;
45 private readonly \ilRbacSystem $rbac_system;
46 private readonly ContentStyle $content_style;
47
50
51 private ?int $questionid = null;
52 private ?int $poolrefid = null;
53 private ?int $poolobjid = null;
54 private ?string $questiontype = null;
56 private array $new_id_listeners;
58 private bool $selfassessmenteditingmode = false;
59 private ?int $defaultnroftries = null;
60 private ?ilPageConfig $page_config = null;
61
62 public function __construct()
63 {
65 global $DIC;
66
67 $this->main_tpl = $DIC['tpl'];
68 $this->tabs = $DIC['ilTabs'];
69 $this->help = $DIC['ilHelp'];
70 $this->ctrl = $DIC['ilCtrl'];
71 $this->access = $DIC['ilAccess'];
72 $this->lng = $DIC['lng'];
73 $this->rbac_system = $DIC['rbacsystem'];
74 $this->content_style = $DIC->contentStyle();
75
76 $local_dic = QuestionPoolDIC::dic();
77 $this->request = $local_dic['request_data_collector'];
78 $this->questionrepository = $local_dic['question.general_properties.repository'];
79
80 if ($this->request->raw('qpool_ref_id')) {
81 $this->setPoolRefId($this->request->raw('qpool_ref_id'));
82 } elseif ($this->request->raw('qpool_obj_id')) {
83 $this->setPoolObjId($this->request->raw('qpool_obj_id'));
84 }
85 $this->setQuestionId($this->request->getQuestionId());
86 $this->setQuestionType($this->request->raw('q_type'));
87 $this->lng->loadLanguageModule('assessment');
88
89 $this->ctrl->saveParameter($this, ['qpool_ref_id', 'qpool_obj_id', 'q_id', 'q_type']);
90
91
92 $this->new_id_listeners = [];
93 $this->new_id_listener_cnt = 0;
94 }
95
96 public function setSelfAssessmentEditingMode(bool $a_selfassessmenteditingmode): void
97 {
98 $this->selfassessmenteditingmode = $a_selfassessmenteditingmode;
99 }
100
101 public function getSelfAssessmentEditingMode(): bool
102 {
104 }
105
106 public function setDefaultNrOfTries(?int $a_defaultnroftries): void
107 {
108 $this->defaultnroftries = $a_defaultnroftries;
109 }
110
111 public function getDefaultNrOfTries(): ?int
112 {
114 }
115
116 public function setPageConfig(ilPageConfig $a_val): void
117 {
118 $this->page_config = $a_val;
119 }
120
121 public function getPageConfig(): ?ilPageConfig
122 {
123 return $this->page_config;
124 }
125
126 public function executeCommand(): string
127 {
128 $cmd = $this->ctrl->getCmd();
129 $next_class = $this->ctrl->getNextClass();
130
131 switch ($next_class) {
132 default:
133 $question_gui = assQuestionGUI::_getQuestionGUI(
134 $this->getQuestionType() ?? '',
135 $this->getQuestionId()
136 );
137 $question = $question_gui->getObject();
138 $question->setSelfAssessmentEditingMode(
140 );
141 if ($this->getDefaultNrOfTries() > 0) {
142 $question->setDefaultNrOfTries(
143 $this->getDefaultNrOfTries()
144 );
145 }
146
147 if (is_object($this->page_config)) {
148 $question->setPreventRteUsage($this->getPageConfig()->getPreventRteUsage());
149 $question_gui->setInLearningModuleContext(get_class($this->page_config) === ilLMPageConfig::class);
150 }
151 $question->setObjId((int) $this->getPoolObjId());
152 $question_gui->setObject($question);
153
154 $count = $this->questionrepository->usageCount($question_gui->getObject()->getId());
155 if ($count > 0) {
156 if ($this->rbac_system->checkAccess('write', $this->getPoolRefId())) {
157 $this->main_tpl->setOnScreenMessage('info', sprintf($this->lng->txt('qpl_question_is_in_use'), $count));
158 }
159 }
160
161 $this->tabs->activateTab('question');
162 if ($cmd !== 'save') {
163 return (string) $this->ctrl->forwardCommand($question_gui);
164 }
165 if ($question_gui->saveQuestion()) {
166 $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
167 }
168
169 return (string) $question_gui->editQuestion();
170 }
171 }
172
173 public function forwardToFeedbackEditGUI(assQuestionGUI $question_gui): void
174 {
175 $this->ctrl->forwardCommand(
177 $question_gui,
178 $this->ctrl,
179 $this->access,
180 $this->main_tpl,
181 $this->tabs,
182 $this->lng,
183 $this->help,
184 $this->request,
185 $this->content_style
186 )
187 );
188 }
189
190 public function setQuestionId(?int $a_questionid): void
191 {
192 $this->questionid = $a_questionid;
193 $this->ctrl->setParameter($this, 'q_id', $this->questionid);
194 }
195
196 public function getQuestionId(): ?int
197 {
198 return $this->questionid;
199 }
200
201 public function setPoolRefId(?int $a_poolrefid): void
202 {
203 $this->poolrefid = $a_poolrefid;
204 $this->ctrl->setParameter($this, 'qpool_ref_id', $this->poolrefid);
205
206 if ($this->getPoolRefId() > 0) {
208 } else {
209 $this->setPoolObjId(null);
210 }
211 }
212
213 public function getPoolRefId(): ?int
214 {
215 return $this->poolrefid;
216 }
217
218 public function setPoolObjId(?int $a_poolobjid): void
219 {
220 $this->poolobjid = $a_poolobjid;
221 $this->ctrl->setParameter($this, 'qpool_obj_id', $this->poolobjid);
222 }
223
224 public function getPoolObjId(): ?int
225 {
226 return $this->poolobjid;
227 }
228
229 public function setQuestionType(?string $a_questiontype): void
230 {
231 $this->questiontype = $a_questiontype;
232 $this->ctrl->setParameter($this, 'q_type', $this->questiontype);
233 }
234
235 public function getQuestionType(): ?string
236 {
237 return $this->questiontype;
238 }
239}
static _getQuestionGUI(string $question_type='', int $question_id=-1)
Creates a question gui representation and returns the alias to the question gui.
static _lookupObjId(int $ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilQuestionEditGUI.
setSelfAssessmentEditingMode(bool $a_selfassessmenteditingmode)
setPoolRefId(?int $a_poolrefid)
setQuestionType(?string $a_questiontype)
readonly ContentStyle $content_style
readonly RequestDataCollector $request
forwardToFeedbackEditGUI(assQuestionGUI $question_gui)
readonly ilHelpGUI $help
setQuestionId(?int $a_questionid)
setPageConfig(ilPageConfig $a_val)
readonly ilRbacSystem $rbac_system
setPoolObjId(?int $a_poolobjid)
readonly ilLanguage $lng
readonly GeneralQuestionPropertiesRepository $questionrepository
readonly ilCtrlInterface $ctrl
readonly ilAccessHandler $access
setDefaultNrOfTries(?int $a_defaultnroftries)
ilGlobalTemplateInterface $main_tpl
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26