3 declare(strict_types=1);
76 Psr\Http\Message\ServerRequestInterface $request,
78 ILIAS\
HTTP\Wrapper\RequestWrapper $request_wrapper,
82 $this->
ctrl = $ilCtrl;
97 $cmd = $this->
ctrl->getCmd();
98 $next_class = $this->
ctrl->getNextClass($this);
100 switch ($next_class) {
101 case "ilpropertyformgui":
103 $this->
ctrl->forwardCommand($form);
108 case self::CMD_DELETE:
109 case self::CMD_DELETE_CONFIRMATION:
110 case self::CMD_GET_ASYNC_MODAL:
115 $this->
ctrl->redirect($this,
'view');
117 case self::CMD_PROFILE_NOT_PUBLIC:
121 throw new ilException(
"ilObjStudyProgrammeAutoCategoriesGUI: Command not supported: $cmd");
129 protected function view(
bool $profile_not_public =
false): void
131 if ($profile_not_public) {
132 $this->tpl->setOnScreenMessage(
"info", $this->
lng->txt(
'prg_profile_not_public'));
135 $collected_modals = [];
139 $collected_modals[] = $modal;
142 foreach ($this->
getObject()->getAutomaticContentCategories() as $ac) {
143 $ref_id = $ac->getCategoryRefId();
150 $collected_modals[] = $modal;
152 $ac->getCategoryRefId(),
153 $modal->getShowSignal()
158 $this->ui_renderer->render($link),
159 $this->ui_renderer->render($usr),
160 $this->ui_renderer->render($actions),
164 usort(
$data,
static function (array
$a, array
$b):
int {
165 return strnatcasecmp($a[4], $b[4]);
169 $table->setData(
$data);
171 $this->tpl->setContent(
172 $this->ui_renderer->render($collected_modals)
180 protected function save(): void
183 $form->setValuesByPost();
186 $cat_ref_id = $form->getInput(self::F_CATEGORY_REF);
187 $current_ref_id = $form->getInput(self::F_CATEGORY_ORIGINAL_REF);
190 $this->tpl->setOnScreenMessage(
192 sprintf($this->
lng->txt(
'not_a_valid_cat_id'), $cat_ref_id),
198 if (!is_null($current_ref_id) && $current_ref_id !== $cat_ref_id) {
199 $ids = [(
int) $current_ref_id];
200 $this->
getObject()->deleteAutomaticContentCategories($ids);
203 $this->
getObject()->storeAutomaticContentCategory((
int) $cat_ref_id);
208 $get = $this->request->getQueryParams();
209 $post = $this->request->getParsedBody();
210 $field = self::CHECKBOX_CATEGORY_REF_IDS;
212 $field_ids_in_get = array_key_exists($field, $get);
213 $field_ids_in_post = array_key_exists($field,
$post);
217 if ($field_ids_in_get) {
218 $cat_ids = $get[$field];
219 $msg = $this->
lng->txt(
'prg_delete_single_confirmation');
220 } elseif ($field_ids_in_post) {
221 $cat_ids = implode(
' ',
$post[$field]);
222 $msg = $this->
lng->txt(
'prg_delete_confirmation');
224 $this->tpl->setOnScreenMessage(
"info", $this->
lng->txt(
'prg_delete_nothing_selected'),
true);
225 $this->
ctrl->redirect($this, self::CMD_VIEW);
228 $cat_ids = base64_encode($cat_ids);
230 $this->
ctrl->setParameterByClass(self::class, $field, $cat_ids);
231 $delete = $this->
ctrl->getFormActionByClass(self::class, self::CMD_DELETE);
232 $cancel = $this->
ctrl->getFormActionByClass(self::class, self::CMD_VIEW);
233 $this->
ctrl->clearParameterByClass(self::class, $field);
236 $this->button_factory->standard($this->
lng->txt(
'prg_confirm_delete'), $delete),
237 $this->button_factory->standard($this->lng->txt(
'prg_cancel'), $cancel)
240 $message_box = $this->message_box_factory->confirmation($msg)->withButtons($buttons);
242 $this->tpl->setContent($this->ui_renderer->render($message_box));
245 protected function delete():
void 247 $field = self::CHECKBOX_CATEGORY_REF_IDS;
248 $get = $this->request->getQueryParams();
250 if (!array_key_exists($field, $get)) {
251 $this->tpl->setOnScreenMessage(
"failure", $this->
lng->txt(
'prg_delete_failure'),
true);
252 $this->
ctrl->redirect($this, self::CMD_VIEW);
255 $cat_ids = base64_decode($get[$field]);
256 $cat_ids = explode(
' ', trim($cat_ids));
257 $cat_ids = array_map(
'intval', $cat_ids);
259 $this->
getObject()->deleteAutomaticContentCategories($cat_ids);
261 $msg = $this->
lng->txt(
'prg_delete_single_success');
262 if (count($cat_ids) > 1) {
263 $msg = $this->
lng->txt(
'prg_delete_success');
266 $this->tpl->setOnScreenMessage(
"success", $msg,
true);
267 $this->
ctrl->redirect($this, self::CMD_VIEW);
283 if ($this->
object === null ||
293 if (!is_null($current_ref_id)) {
294 $this->
ctrl->setParameter($this, self::CHECKBOX_CATEGORY_REF_IDS, (
string) $current_ref_id);
296 $link = $this->
ctrl->getLinkTarget($this,
"getAsyncModalOutput",
"",
true);
297 $this->
ctrl->setParameter($this, self::CHECKBOX_CATEGORY_REF_IDS, null);
298 return $this->ui_factory->modal()->roundtrip(
301 )->withAsyncRenderUrl(
308 $current_ref_id = null;
309 if ($this->request_wrapper->has(self::CHECKBOX_CATEGORY_REF_IDS)) {
310 $current_ref_id = $this->request_wrapper->retrieve(
311 self::CHECKBOX_CATEGORY_REF_IDS,
315 $form = $this->
getForm($current_ref_id);
316 $form_id =
"form_" . $form->getId();
317 $submit = $this->ui_factory->button()->primary($this->
lng->txt(
'add'),
"#")->
withOnLoadCode(
318 function (
$id) use ($form_id) {
319 return "$('#$id').click(function() { document.getElementById('$form_id').submit(); return false; });";
322 $modal = $this->ui_factory->modal()
324 $this->
lng->txt(
'modal_categories_title'),
325 $this->ui_factory->legacy($form->getHtml())
327 ->withActionButtons([$submit])
328 ->withAdditionalOnLoadCode(
329 function (
$id) use ($form) {
330 $selector_post_var = self::F_CATEGORY_REF;
331 $js = $form->getItemByPostVar($selector_post_var)->getOnloadCode();
332 return implode(
';', $js);
337 echo $this->ui_renderer->renderAsync($modal);
345 $form->setId(uniqid((
string) $current_ref_id,
true));
347 $form->setFormAction($this->
ctrl->getFormAction($this,
"save"));
349 $this->
lng->txt(
"category"),
350 self::F_CATEGORY_REF,
354 $cat->getExplorerGUI()->setTypeWhiteList([
"root",
"cat"]);
355 if ($current_ref_id !== null) {
356 $cat->getExplorerGUI()->setPathOpen($current_ref_id);
357 $cat->setValue($current_ref_id);
360 $cat->getExplorerGUI()->setAjax(
false);
361 $form->addItem($cat);
364 $hi->setValue((
string)$current_ref_id ??
"");
375 $btn = $this->ui_factory->button()->primary($this->
lng->txt(
'add_category'),
'')
376 ->withOnClick($add_cat_signal);
377 $this->
toolbar->addComponent($btn);
385 $items[] = $this->ui_factory
387 ->shy($this->
lng->txt(
'edit'),
'')
388 ->withOnClick($signal)
391 $this->
ctrl->setParameterByClass(self::class, self::CHECKBOX_CATEGORY_REF_IDS, $cat_ref_id);
392 $link = $this->
ctrl->getLinkTarget($this, self::CMD_DELETE_CONFIRMATION);
393 $this->
ctrl->clearParameterByClass(self::class, self::CHECKBOX_CATEGORY_REF_IDS);
395 $items[] = $this->ui_factory
397 ->shy($this->
lng->txt(
'delete'), $link)
400 return $this->ui_factory->dropdown()->standard($items);
406 $editor = implode(
' ', [
407 $username[
'firstname'],
408 $username[
'lastname'],
409 '(' . $username[
'login'] .
')' 413 if (!$usr->hasPublicProfile()) {
414 $url = $this->
ctrl->getLinkTarget($this, self::CMD_PROFILE_NOT_PUBLIC);
416 return $this->ui_factory->link()->standard($editor,
$url);
424 static function (array
$c):
string {
427 $this->tree->getPathFull($cat_ref_id)
429 $path = implode(
' > ', $hops);
430 return [
$path, $this->ui_factory->link()->standard($path,
$url)];
An entity that renders components to a string output.
setRefId(int $prg_ref_id)
Set ref-id of StudyProgramme before using this GUI.
ilGlobalTemplateInterface $tpl
ILIAS HTTP Wrapper RequestWrapper $request_wrapper
getForm(?int $current_ref_id=null)
Class ChatMainBarProvider .
const CHECKBOX_CATEGORY_REF_IDS
getModal(int $current_ref_id=null)
Class ilObjStudyProgrammeAutoCategoriesGUI.
view(bool $profile_not_public=false)
Render.
ilObjStudyProgramme $object
static getInstanceByRefId($ref_id)
static _lookupName(int $a_user_id)
lookup user name
Psr Http Message ServerRequestInterface $request
const CMD_GET_ASYNC_MODAL
getToolbar(Signal $add_cat_signal)
Setup toolbar.
MessageBox Factory $message_box_factory
withOnLoadCode(Closure $binder)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const CMD_PROFILE_NOT_PUBLIC
const CMD_DELETE_CONFIRMATION
__construct(ilGlobalTemplateInterface $tpl, ilCtrl $ilCtrl, ilToolbarGUI $ilToolbar, ilLanguage $lng, Factory $ui_factory, MessageBox\Factory $message_box_factory, Button\Factory $button_factory, Renderer $ui_renderer, Psr\Http\Message\ServerRequestInterface $request, ilTree $tree, ILIAS\HTTP\Wrapper\RequestWrapper $request_wrapper, ILIAS\Refinery\Factory $refinery)
const F_CATEGORY_ORIGINAL_REF
static _lookupTitle(int $obj_id)
ILIAS Refinery Factory $refinery
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getStaticLink(?int $a_ref_id, string $a_type='', bool $a_fallback_goto=true, string $append="")
Get static link.
Button Factory $button_factory
save()
Store data from (modal-)form.
ILIAS UI Factory $ui_factory
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
ILIAS UI Renderer $ui_renderer
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
getItemPath(int $cat_ref_id)
static _lookupType(int $id, bool $reference=false)
getUserRepresentation(int $usr_id)
getItemAction(int $cat_ref_id, Signal $signal)
getObject()
Get current StudyProgramme-object.