ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilQuestionEditGUI.php
Go to the documentation of this file.
1 <?php
2 
31 {
32  private \ilGlobalTemplateInterface $main_tpl;
33  private \ILIAS\TestQuestionPool\InternalRequestService $request;
35  private ilLanguage $lng;
37  private ?int $questionid = null;
38  private ?int $poolrefid = null;
39  private ?int $poolobjid = null;
40  private ?string $questiontype = null;
42  private array $new_id_listeners;
43  private int $new_id_listener_cnt;
44  private bool $selfassessmenteditingmode = false;
45  private ?int $defaultnroftries = null;
46  private ?ilPageConfig $page_config = null;
47  private \ILIAS\TestQuestionPool\QuestionInfoService $questioninfo;
48 
49  public function __construct()
50  {
51  global $DIC;
52 
53  $this->main_tpl = $DIC->ui()->mainTemplate();
54  $this->ctrl = $DIC['ilCtrl'];
55  $this->request = $DIC->testQuestionPool()->internal()->request();
56  $this->lng = $DIC->language();
57  $this->rbac_system = $DIC->rbac()->system();
58  $this->questioninfo = $DIC->testQuestionPool()->questionInfo();
59 
60  if ($this->request->raw('qpool_ref_id')) {
61  $this->setPoolRefId($this->request->raw('qpool_ref_id'));
62  } elseif ($this->request->raw('qpool_obj_id')) {
63  $this->setPoolObjId($this->request->raw('qpool_obj_id'));
64  }
65  $this->setQuestionId($this->request->getQuestionId());
66  $this->setQuestionType($this->request->raw('q_type'));
67  $this->lng->loadLanguageModule('assessment');
68 
69  $this->ctrl->saveParameter($this, ['qpool_ref_id', 'qpool_obj_id', 'q_id', 'q_type']);
70 
71 
72  $this->new_id_listeners = [];
73  $this->new_id_listener_cnt = 0;
74  }
75 
76  public function setSelfAssessmentEditingMode(bool $a_selfassessmenteditingmode): void
77  {
78  $this->selfassessmenteditingmode = $a_selfassessmenteditingmode;
79  }
80 
81  public function getSelfAssessmentEditingMode(): bool
82  {
84  }
85 
86  public function setDefaultNrOfTries(?int $a_defaultnroftries): void
87  {
88  $this->defaultnroftries = $a_defaultnroftries;
89  }
90 
91  public function getDefaultNrOfTries(): ?int
92  {
94  }
95 
96  public function setPageConfig(ilPageConfig $a_val): void
97  {
98  $this->page_config = $a_val;
99  }
100 
101  public function getPageConfig(): ?ilPageConfig
102  {
103  return $this->page_config;
104  }
105 
106  public function addNewIdListener(object $a_object, string $a_method, string $a_parameters = ''): void
107  {
109  $this->new_id_listeners[$cnt]['object'] = $a_object;
110  $this->new_id_listeners[$cnt]['method'] = $a_method;
111  $this->new_id_listeners[$cnt]['parameters'] = $a_parameters;
112  $this->new_id_listener_cnt++;
113  }
114 
115  public function executeCommand(): string
116  {
117  $cmd = $this->ctrl->getCmd();
118  $next_class = $this->ctrl->getNextClass();
119 
120  switch ($next_class) {
121  default:
123  $this->getQuestionType() ?? '',
124  $this->getQuestionId()
125  );
126  $q_gui->object->setSelfAssessmentEditingMode(
128  );
129  if ($this->getDefaultNrOfTries() > 0) {
130  $q_gui->object->setDefaultNrOfTries(
131  $this->getDefaultNrOfTries()
132  );
133  }
134 
135  if (is_object($this->page_config)) {
136  $q_gui->object->setPreventRteUsage($this->getPageConfig()->getPreventRteUsage());
137  $q_gui->setInLearningModuleContext(get_class($this->page_config) === ilLMPageConfig::class);
138  }
139  $q_gui->object->setObjId((int) $this->getPoolObjId());
140 
141  for ($i = 0; $i < $this->new_id_listener_cnt; $i++) {
142  $object = $this->new_id_listeners[$i]['object'];
143  $method = $this->new_id_listeners[$i]['method'];
144  $parameters = $this->new_id_listeners[$i]['parameters'];
145  $q_gui->addNewIdListener(
146  $object,
147  $method,
148  $parameters
149  );
150  }
151 
152  $count = $this->questioninfo->usageNumber($q_gui->object->getId());
153  if ($count > 0) {
154  if ($this->rbac_system->checkAccess('write', $this->getPoolRefId())) {
155  $this->main_tpl->setOnScreenMessage('info', sprintf($this->lng->txt('qpl_question_is_in_use'), $count));
156  }
157  }
158  $this->ctrl->setCmdClass(get_class($q_gui));
159  $ret = (string) $this->ctrl->forwardCommand($q_gui);
160  break;
161  }
162 
163  return $ret;
164  }
165 
166  public function setQuestionId(?int $a_questionid): void
167  {
168  $this->questionid = $a_questionid;
169  $this->ctrl->setParameter($this, 'q_id', $this->questionid);
170  }
171 
172  public function getQuestionId(): ?int
173  {
174  return $this->questionid;
175  }
176 
177  public function setPoolRefId(?int $a_poolrefid): void
178  {
179  $this->poolrefid = $a_poolrefid;
180  $this->ctrl->setParameter($this, 'qpool_ref_id', $this->poolrefid);
181 
182  if ($this->getPoolRefId() > 0) {
184  } else {
185  $this->setPoolObjId(null);
186  }
187  }
188 
189  public function getPoolRefId(): ?int
190  {
191  return $this->poolrefid;
192  }
193 
194  public function setPoolObjId(?int $a_poolobjid): void
195  {
196  $this->poolobjid = $a_poolobjid;
197  $this->ctrl->setParameter($this, 'qpool_obj_id', $this->poolobjid);
198  }
199 
200  public function getPoolObjId(): ?int
201  {
202  return $this->poolobjid;
203  }
204 
205  public function setQuestionType(?string $a_questiontype): void
206  {
207  $this->questiontype = $a_questiontype;
208  $this->ctrl->setParameter($this, 'q_type', $this->questiontype);
209  }
210 
211  public function getQuestionType(): ?string
212  {
213  return $this->questiontype;
214  }
215 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilGlobalTemplateInterface $main_tpl
setDefaultNrOfTries(?int $a_defaultnroftries)
setQuestionId(?int $a_questionid)
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...
global $DIC
Definition: feed.php:28
setPoolRefId(?int $a_poolrefid)
setSelfAssessmentEditingMode(bool $a_selfassessmenteditingmode)
setPoolObjId(?int $a_poolobjid)
setPageConfig(ilPageConfig $a_val)
addNewIdListener(object $a_object, string $a_method, string $a_parameters='')
ILIAS TestQuestionPool QuestionInfoService $questioninfo
setQuestionType(?string $a_questiontype)
ILIAS TestQuestionPool InternalRequestService $request