ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilBulkEditQuestionsGUI Class Reference

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 44 of file class.ilBulkEditQuestionsGUI.php.

54  {
55  }

Member Function Documentation

◆ executeCommand()

ilBulkEditQuestionsGUI::executeCommand ( )

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

References $out, ILIAS\Repository\ctrl(), getAuthorUpdater(), getFormAuthor(), getFormLifecycle(), getFormTaxonomies(), getLifecycleUpdater(), getQuestionIds(), ILIAS\Repository\lng(), store(), and storeTaxonomies().

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

◆ getAuthorUpdater()

ilBulkEditQuestionsGUI::getAuthorUpdater ( )
protected

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

References $q.

Referenced by executeCommand().

166  : \Closure
167  {
168  return function (array $questions, string $author) {
169  foreach ($questions as $q) {
170  $q->setAuthor($author);
171  $q->saveQuestionDataToDb();
172  }
173  return true;
174  };
175  }
$q
Definition: shib_logout.php:21
+ Here is the caller graph for this function:

◆ getFormAuthor()

ilBulkEditQuestionsGUI::getFormAuthor ( )
protected

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

References ILIAS\Repository\ctrl(), getShiftTrafo(), ILIAS\Repository\lng(), and ILIAS\UI\Implementation\Component\Input\ViewControl\withAdditionalTransformation().

Referenced by executeCommand().

153  : Form\Standard
154  {
155  return $this->ui_factory->input()->container()->form()->standard(
156  $this->ctrl->getFormAction($this, self::CMD_SAVEAUTHOR),
157  [
158  $this->ui_factory->input()->field()
159  ->text($this->lng->txt('author'))
160  ->withRequired(true)
161  ]
162  )
164  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFormLifecycle()

ilBulkEditQuestionsGUI::getFormLifecycle ( )
protected

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

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

Referenced by executeCommand().

177  : Form\Standard
178  {
180  $options = $lifecycle->getSelectOptions($this->lng);
181  return $this->ui_factory->input()->container()->form()->standard(
182  $this->ctrl->getFormAction($this, self::CMD_SAVELIFECYCLE),
183  [
184  $this->ui_factory->input()->field()
185  ->select($this->lng->txt('qst_lifecycle'), $options)
186  ->withRequired(true)
187  ]
188  )
190  }
$lifecycle
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFormTaxonomies()

ilBulkEditQuestionsGUI::getFormTaxonomies ( )
protected

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

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

Referenced by executeCommand().

205  {
206  $form = new ilPropertyFormGUI();
207  $form->setFormAction($this->ctrl->getFormAction($this, self::CMD_SAVETAXONOMIES));
208  $taxonomy_ids = \ilObjTaxonomy::getUsageOfObject($this->qpl_obj_id);
209 
210  //taken from assQuestionGUI::populateTaxonomyFormSection
211  foreach ($taxonomy_ids as $taxonomy_id) {
212  $taxonomy = new ilObjTaxonomy($taxonomy_id);
213  $label = sprintf($this->lng->txt('qpl_qst_edit_form_taxonomy'), $taxonomy->getTitle());
214  $postvar = "tax_node_assign_$taxonomy_id";
215  // selector not working due to failing modals, actually:
216  // $taxSelect = new ilTaxSelectInputGUI($taxonomy->getId(), $postvar, true);
217  $taxSelect = new ilTaxAssignInputGUI($taxonomy->getId(), true, $label, $postvar, true);
218  $taxSelect->setTitle($label);
219  $form->addItem($taxSelect);
220  }
221  $form->addCommandButton(self::CMD_SAVETAXONOMIES, $this->lng->txt("qpl_bulk_save_overwrite"));
222  $form->addCommandButton(self::CMD_SAVETAXONOMIESADD, $this->lng->txt("qpl_bulk_save_add"));
223  return $form;
224  }
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 file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLifecycleUpdater()

ilBulkEditQuestionsGUI::getLifecycleUpdater ( )
protected

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

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

Referenced by executeCommand().

192  : \Closure
193  {
194  return function (array $questions, string $lifecycle) {
196  foreach ($questions as $q) {
197  $q->setLifecycle($lc);
198  $q->saveToDb();
199  }
200  return true;
201  };
202  }
$lifecycle
$q
Definition: shib_logout.php:21
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getQuestionIds()

ilBulkEditQuestionsGUI::getQuestionIds ( )
protected

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

References ILIAS\Repository\refinery().

Referenced by executeCommand().

112  : array
113  {
114  if (!$this->request_wrapper->has(self::PARAM_IDS)) {
115  return [];
116  }
117  $trafo = $this->refinery->custom()->transformation(
118  fn($v) => array_map('intval', explode(',', $v))
119  );
120  return $this->request_wrapper->retrieve(self::PARAM_IDS, $trafo);
121  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getQuestions()

ilBulkEditQuestionsGUI::getQuestions ( )
protected

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

References assQuestion\instantiateQuestion().

Referenced by store(), and storeTaxonomies().

137  : array
138  {
139  $questions = [];
140  foreach ($this->question_ids as $qid) {
141  $questions[] = \assQuestion::instantiateQuestion($qid);
142  }
143  return $questions;
144  }
static instantiateQuestion(int $question_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getShiftTrafo()

ilBulkEditQuestionsGUI::getShiftTrafo ( )
protected

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

References ILIAS\Repository\refinery().

Referenced by getFormAuthor(), and getFormLifecycle().

147  {
148  return $this->refinery->custom()->transformation(
149  fn(array $v) => array_shift($v)
150  );
151  }
Transform values according to custom configuration.
+ 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 123 of file class.ilBulkEditQuestionsGUI.php.

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

Referenced by executeCommand().

123  : array
124  {
125  $out = [];
126  $form = $form->withRequest($this->request);
127  $data = $form->getData();
128  $questions = $this->getQuestions();
129  if ($data !== null && $update($questions, $data)) {
130  $this->tpl->setOnScreenMessage('success', $this->lng->txt('qpl_bulkedit_success'), true);
131  $this->ctrl->redirectByClass(ilObjQuestionPoolGUI::class, ilObjQuestionPoolGUI::DEFAULT_CMD);
132  }
133  $out[] = $form;
134  return $out;
135  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$out
Definition: buildRTE.php:24
+ 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 226 of file class.ilBulkEditQuestionsGUI.php.

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

Referenced by executeCommand().

226  : void
227  {
228  $questions = $this->getQuestions();
229  $post = $this->request->getParsedBody();
230  $form_cmd = array_shift($post['cmd']);
231  $overwrite = ($form_cmd === $this->lng->txt('qpl_bulk_save_overwrite'));
232 
233  $taxonomy_ids = \ilObjTaxonomy::getUsageOfObject($this->qpl_obj_id);
234  foreach ($taxonomy_ids as $taxonomy_id) {
235  $postvar = "tax_node_assign_$taxonomy_id";
236  foreach ($questions as $q) {
237  $assignments = new ilTaxNodeAssignment(ilObject::_lookupType($q->getObjId()), $q->getObjId(), 'quest', $taxonomy_id);
238  $assigned_nodes = $assignments->getAssignmentsOfItem($q->getId());
239 
240  $skip = [];
241  foreach ($assigned_nodes as $existing) {
242  if ($overwrite && !in_array($existing["node_id"], $post[$postvar])
243  ) {
244  $assignments->deleteAssignment((int) $existing["node_id"], $q->getId());
245  } else {
246  $skip[] = (int) $existing["node_id"];
247  }
248  }
249 
250  $values = $post[$postvar];
251  foreach ($values as $value) {
252  if (!in_array((int) $value, $skip)) {
253  $assignments->addAssignment((int) $value, $q->getId());
254  }
255  }
256  }
257  }
258  $this->tpl->setOnScreenMessage('success', $this->lng->txt('qpl_bulkedit_success'), true);
259  $this->ctrl->redirectByClass(ilObjQuestionPoolGUI::class, ilObjQuestionPoolGUI::DEFAULT_CMD);
260  }
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)
getAssignmentsOfItem(int $a_item_id)
Get assignments for item.
$q
Definition: shib_logout.php:21
static _lookupType(int $id, bool $reference=false)
$post
Definition: ltitoken.php:46
+ 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 57 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 37 of file class.ilBulkEditQuestionsGUI.php.

◆ CMD_SAVELIFECYCLE

const ilBulkEditQuestionsGUI::CMD_SAVELIFECYCLE = 'bulksave_lifecycle'

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

◆ CMD_SAVETAXONOMIES

const ilBulkEditQuestionsGUI::CMD_SAVETAXONOMIES = 'bulksave_taxonomies'

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

◆ CMD_SAVETAXONOMIESADD

const ilBulkEditQuestionsGUI::CMD_SAVETAXONOMIESADD = 'bulksave_taxonomies_add'

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

◆ PARAM_IDS

const ilBulkEditQuestionsGUI::PARAM_IDS = 'qids'

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


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