ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
ilBulkEditQuestionsGUI Class Reference

@ilCtrl_Calls ilBulkEditQuestionsGUI: ilFormPropertyDispatchGUI More...

+ Collaboration diagram for ilBulkEditQuestionsGUI:

Public Member Functions

 __construct (protected ilGlobalTemplateInterface $tpl, protected ilCtrl $ctrl, protected ilLanguage $lng, protected UIFactory $ui_factory, protected UIRenderer $ui_renderer, protected Refinery $refinery, protected ServerRequestInterface $request, protected RequestWrapper $request_wrapper, protected int $qpl_obj_id,)
 
 executeCommand ()
 

Data Fields

const PARAM_IDS = 'qids'
 
const CMD_EDITTAUTHOR = 'bulkedit_author'
 
const CMD_SAVEAUTHOR = 'bulksave_author'
 
const CMD_EDITLIFECYCLE = 'bulkedit_lifecycle'
 
const CMD_SAVELIFECYCLE = 'bulksave_lifecycle'
 
const CMD_EDITTAXONOMIES = 'bulkedit_taxonomies'
 
const CMD_SAVETAXONOMIES = 'bulksave_taxonomies'
 
const CMD_SAVETAXONOMIESADD = 'bulksave_taxonomies_add'
 

Protected Member Functions

 getQuestionIds ()
 
 store (Form\Standard $form, Closure $update)
 
 getQuestions ()
 
 getShiftTrafo ()
 
 getFormAuthor ()
 
 getAuthorUpdater ()
 
 getFormLifecycle ()
 
 getLifecycleUpdater ()
 
 getFormTaxonomies ()
 
 storeTaxonomies (ilPropertyFormGUI $form)
 

Protected Attributes

array $question_ids = []
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilBulkEditQuestionsGUI::__construct ( protected ilGlobalTemplateInterface  $tpl,
protected ilCtrl  $ctrl,
protected ilLanguage  $lng,
protected UIFactory  $ui_factory,
protected UIRenderer  $ui_renderer,
protected Refinery  $refinery,
protected ServerRequestInterface  $request,
protected RequestWrapper  $request_wrapper,
protected int  $qpl_obj_id 
)

Definition at line 43 of file class.ilBulkEditQuestionsGUI.php.

53 {
54 }

Member Function Documentation

◆ executeCommand()

ilBulkEditQuestionsGUI::executeCommand ( )

Definition at line 58 of file class.ilBulkEditQuestionsGUI.php.

58 : void
59 {
60 $cmd = $this->ctrl->getCmd();
61 $this->ctrl->saveParameter($this, self::PARAM_IDS);
62
63 $this->question_ids = $this->getQuestionIds();
64
65 $out = [];
66
67 if ($this->question_ids === []) {
68 $out[] = $this->ui_factory->messageBox()->failure(
69 $this->lng->txt('qpl_bulkedit_no_ids')
70 );
71
72 } else {
73
74 switch ($cmd) {
76 $out[] = $this->getFormAuthor();
77 break;
79 $out = array_merge($out, $this->store(
80 $this->getFormAuthor(),
81 $this->getAuthorUpdater()
82 ));
83 break;
84
86 $out[] = $this->getFormLifecycle();
87 break;
89 $out = array_merge($out, $this->store(
90 $this->getFormLifecycle(),
91 $this->getLifecycleUpdater()
92 ));
93 break;
94
96 $out[] = $this->ui_factory->legacy()->content($this->getFormTaxonomies()->getHTML());
97 break;
100 $out = array_merge($out, $this->storeTaxonomies($this->getFormTaxonomies()));
101 break;
102
103 default:
104 throw new \Exception("'$cmd'" . " not implemented");
105 }
106 }
107
108 $this->tpl->setContent($this->ui_renderer->render($out));
109 }
$out
Definition: buildRTE.php:24
store(Form\Standard $form, Closure $update)
storeTaxonomies(ilPropertyFormGUI $form)

References $out, CMD_EDITLIFECYCLE, CMD_EDITTAUTHOR, CMD_EDITTAXONOMIES, CMD_SAVEAUTHOR, CMD_SAVELIFECYCLE, CMD_SAVETAXONOMIES, CMD_SAVETAXONOMIESADD, ILIAS\Repository\ctrl(), getAuthorUpdater(), getFormAuthor(), getFormLifecycle(), getFormTaxonomies(), getLifecycleUpdater(), getQuestionIds(), ILIAS\Repository\lng(), store(), and storeTaxonomies().

+ Here is the call graph for this function:

◆ getAuthorUpdater()

ilBulkEditQuestionsGUI::getAuthorUpdater ( )
protected

Definition at line 165 of file class.ilBulkEditQuestionsGUI.php.

165 : \Closure
166 {
167 return function (array $questions, string $author) {
168 foreach ($questions as $q) {
169 $q->setAuthor($author);
170 $q->saveQuestionDataToDb();
171 }
172 return true;
173 };
174 }
$q
Definition: shib_logout.php:25

References $q.

Referenced by executeCommand().

+ Here is the caller graph for this function:

◆ getFormAuthor()

ilBulkEditQuestionsGUI::getFormAuthor ( )
protected

Definition at line 152 of file class.ilBulkEditQuestionsGUI.php.

152 : Form\Standard
153 {
154 return $this->ui_factory->input()->container()->form()->standard(
155 $this->ctrl->getFormAction($this, self::CMD_SAVEAUTHOR),
156 [
157 $this->ui_factory->input()->field()
158 ->text($this->lng->txt('author'))
159 ->withRequired(true)
160 ]
161 )
162 ->withAdditionalTransformation($this->getShiftTrafo());
163 }

References ILIAS\Repository\ctrl(), getShiftTrafo(), and ILIAS\UI\Component\Input\Container\Container\withAdditionalTransformation().

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFormLifecycle()

ilBulkEditQuestionsGUI::getFormLifecycle ( )
protected

Definition at line 176 of file class.ilBulkEditQuestionsGUI.php.

176 : Form\Standard
177 {
179 $options = $lifecycle->getSelectOptions($this->lng);
180 return $this->ui_factory->input()->container()->form()->standard(
181 $this->ctrl->getFormAction($this, self::CMD_SAVELIFECYCLE),
182 [
183 $this->ui_factory->input()->field()
184 ->select($this->lng->txt('qst_lifecycle'), $options)
185 ->withRequired(true)
186 ]
187 )
188 ->withAdditionalTransformation($this->getShiftTrafo());
189 }
$lifecycle

References $lifecycle, ILIAS\UI\Implementation\Component\Input\Field\$options, ILIAS\Repository\ctrl(), ilAssQuestionLifecycle\getDraftInstance(), getShiftTrafo(), and ILIAS\Repository\lng().

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFormTaxonomies()

ilBulkEditQuestionsGUI::getFormTaxonomies ( )
protected

Definition at line 203 of file class.ilBulkEditQuestionsGUI.php.

204 {
205 $form = new ilPropertyFormGUI();
206 $form->setFormAction($this->ctrl->getFormAction($this, self::CMD_SAVETAXONOMIES));
207 $taxonomy_ids = \ilObjTaxonomy::getUsageOfObject($this->qpl_obj_id);
208
209 //taken from assQuestionGUI::populateTaxonomyFormSection
210 foreach ($taxonomy_ids as $taxonomy_id) {
211 $taxonomy = new ilObjTaxonomy($taxonomy_id);
212 $label = sprintf($this->lng->txt('qpl_qst_edit_form_taxonomy'), $taxonomy->getTitle());
213 $postvar = "tax_node_assign_$taxonomy_id";
214 // selector not working due to failing modals, actually:
215 // $taxSelect = new ilTaxSelectInputGUI($taxonomy->getId(), $postvar, true);
216 $taxSelect = new ilTaxAssignInputGUI($taxonomy->getId(), true, $label, $postvar, true);
217 $taxSelect->setTitle($label);
218 $form->addItem($taxSelect);
219 }
220 $form->addCommandButton(self::CMD_SAVETAXONOMIES, $this->lng->txt("qpl_bulk_save_overwrite"));
221 $form->addCommandButton(self::CMD_SAVETAXONOMIESADD, $this->lng->txt("qpl_bulk_save_add"));
222 return $form;
223 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getUsageOfObject(int $a_obj_id, bool $a_include_titles=false)
This class represents a property form user interface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References ILIAS\Repository\ctrl(), ilObjTaxonomy\getUsageOfObject(), and ILIAS\Repository\lng().

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLifecycleUpdater()

ilBulkEditQuestionsGUI::getLifecycleUpdater ( )
protected

Definition at line 191 of file class.ilBulkEditQuestionsGUI.php.

191 : \Closure
192 {
193 return function (array $questions, string $lifecycle) {
195 foreach ($questions as $q) {
196 $q->setLifecycle($lc);
197 $q->saveToDb();
198 }
199 return true;
200 };
201 }

References $lifecycle, $q, and ilAssQuestionLifecycle\getInstance().

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getQuestionIds()

ilBulkEditQuestionsGUI::getQuestionIds ( )
protected

Definition at line 111 of file class.ilBulkEditQuestionsGUI.php.

111 : array
112 {
113 if (!$this->request_wrapper->has(self::PARAM_IDS)) {
114 return [];
115 }
116 $trafo = $this->refinery->custom()->transformation(
117 fn($v) => array_map('intval', explode(',', $v))
118 );
119 return $this->request_wrapper->retrieve(self::PARAM_IDS, $trafo);
120 }

References ILIAS\Repository\refinery().

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getQuestions()

ilBulkEditQuestionsGUI::getQuestions ( )
protected

Definition at line 136 of file class.ilBulkEditQuestionsGUI.php.

136 : array
137 {
138 $questions = [];
139 foreach ($this->question_ids as $qid) {
140 $questions[] = \assQuestion::instantiateQuestion($qid);
141 }
142 return $questions;
143 }
static instantiateQuestion(int $question_id)

References assQuestion\instantiateQuestion().

Referenced by store(), and storeTaxonomies().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getShiftTrafo()

ilBulkEditQuestionsGUI::getShiftTrafo ( )
protected

Definition at line 145 of file class.ilBulkEditQuestionsGUI.php.

146 {
147 return $this->refinery->custom()->transformation(
148 fn(array $v) => array_shift($v)
149 );
150 }
Transform values according to custom configuration.

References ILIAS\Repository\refinery().

Referenced by getFormAuthor(), and getFormLifecycle().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ store()

ilBulkEditQuestionsGUI::store ( Form\Standard  $form,
Closure  $update 
)
protected

Definition at line 122 of file class.ilBulkEditQuestionsGUI.php.

122 : array
123 {
124 $out = [];
125 $form = $form->withRequest($this->request);
126 $data = $form->getData();
127 $questions = $this->getQuestions();
128 if ($data !== null && $update($questions, $data)) {
129 $this->tpl->setOnScreenMessage('success', $this->lng->txt('qpl_bulkedit_success'), true);
130 $this->ctrl->redirectByClass(ilObjQuestionPoolGUI::class, ilObjQuestionPoolGUI::DEFAULT_CMD);
131 }
132 $out[] = $form;
133 return $out;
134 }

References $data, $out, ILIAS\Repository\ctrl(), ilObjQuestionPoolGUI\DEFAULT_CMD, getQuestions(), and ILIAS\Repository\lng().

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ storeTaxonomies()

ilBulkEditQuestionsGUI::storeTaxonomies ( ilPropertyFormGUI  $form)
protected

Definition at line 225 of file class.ilBulkEditQuestionsGUI.php.

225 : void
226 {
227 $questions = $this->getQuestions();
228 $post = $this->request->getParsedBody();
229 $form_cmd = array_shift($post['cmd']);
230 $overwrite = ($form_cmd === $this->lng->txt('qpl_bulk_save_overwrite'));
231
232 $taxonomy_ids = \ilObjTaxonomy::getUsageOfObject($this->qpl_obj_id);
233 foreach ($taxonomy_ids as $taxonomy_id) {
234 $postvar = "tax_node_assign_$taxonomy_id";
235 foreach ($questions as $q) {
236 $assignments = new ilTaxNodeAssignment(ilObject::_lookupType($q->getObjId()), $q->getObjId(), 'quest', $taxonomy_id);
237 $assigned_nodes = $assignments->getAssignmentsOfItem($q->getId());
238
239 $skip = [];
240 foreach ($assigned_nodes as $existing) {
241 if ($overwrite && !in_array($existing["node_id"], $post[$postvar])
242 ) {
243 $assignments->deleteAssignment((int) $existing["node_id"], $q->getId());
244 } else {
245 $skip[] = (int) $existing["node_id"];
246 }
247 }
248
249 $values = $post[$postvar];
250 foreach ($values as $value) {
251 if (!in_array((int) $value, $skip)) {
252 $assignments->addAssignment((int) $value, $q->getId());
253 }
254 }
255 }
256 }
257 $this->tpl->setOnScreenMessage('success', $this->lng->txt('qpl_bulkedit_success'), true);
258 $this->ctrl->redirectByClass(ilObjQuestionPoolGUI::class, ilObjQuestionPoolGUI::DEFAULT_CMD);
259 }
static _lookupType(int $id, bool $reference=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$post
Definition: ltitoken.php:46

References $post, $q, ilObject\_lookupType(), ILIAS\Repository\ctrl(), ilObjQuestionPoolGUI\DEFAULT_CMD, getQuestions(), ilObjTaxonomy\getUsageOfObject(), ILIAS\Repository\int(), and ILIAS\Repository\lng().

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $question_ids

array ilBulkEditQuestionsGUI::$question_ids = []
protected

Definition at line 56 of file class.ilBulkEditQuestionsGUI.php.

◆ CMD_EDITLIFECYCLE

const ilBulkEditQuestionsGUI::CMD_EDITLIFECYCLE = 'bulkedit_lifecycle'

◆ CMD_EDITTAUTHOR

const ilBulkEditQuestionsGUI::CMD_EDITTAUTHOR = 'bulkedit_author'

◆ CMD_EDITTAXONOMIES

const ilBulkEditQuestionsGUI::CMD_EDITTAXONOMIES = 'bulkedit_taxonomies'

◆ CMD_SAVEAUTHOR

const ilBulkEditQuestionsGUI::CMD_SAVEAUTHOR = 'bulksave_author'

Definition at line 36 of file class.ilBulkEditQuestionsGUI.php.

Referenced by executeCommand().

◆ CMD_SAVELIFECYCLE

const ilBulkEditQuestionsGUI::CMD_SAVELIFECYCLE = 'bulksave_lifecycle'

Definition at line 38 of file class.ilBulkEditQuestionsGUI.php.

Referenced by executeCommand().

◆ CMD_SAVETAXONOMIES

const ilBulkEditQuestionsGUI::CMD_SAVETAXONOMIES = 'bulksave_taxonomies'

Definition at line 40 of file class.ilBulkEditQuestionsGUI.php.

Referenced by executeCommand().

◆ CMD_SAVETAXONOMIESADD

const ilBulkEditQuestionsGUI::CMD_SAVETAXONOMIESADD = 'bulksave_taxonomies_add'

Definition at line 41 of file class.ilBulkEditQuestionsGUI.php.

Referenced by executeCommand().

◆ PARAM_IDS

const ilBulkEditQuestionsGUI::PARAM_IDS = 'qids'

Definition at line 34 of file class.ilBulkEditQuestionsGUI.php.


The documentation for this class was generated from the following file: