19declare(strict_types=1);
62 protected Psr\Http\Message\ServerRequestInterface
$request;
77 Psr\Http\Message\ServerRequestInterface
$request,
83 $this->
ctrl = $ilCtrl;
98 $cmd = $this->
ctrl->getCmd();
99 $next_class = $this->
ctrl->getNextClass($this);
101 switch ($next_class) {
102 case "ilpropertyformgui":
104 $this->
ctrl->forwardCommand($form);
116 $this->
ctrl->redirect($this,
'view');
122 throw new ilException(
"ilObjStudyProgrammeAutoCategoriesGUI: Command not supported: $cmd");
130 protected function view(
bool $profile_not_public =
false): void
132 if ($profile_not_public) {
133 $this->tpl->setOnScreenMessage(
"info", $this->
lng->txt(
'prg_profile_not_public'));
136 $collected_modals = [];
140 $collected_modals[] = $modal;
143 foreach ($this->
getObject()->getAutomaticContentCategories() as $ac) {
144 $ref_id = $ac->getCategoryRefId();
149 $usr = $this->
getUserRepresentation($ac->getLastEditorId()) ?? $this->ui_factory->legacy()->content(
'-');
151 $collected_modals[] = $modal;
153 $ac->getCategoryRefId(),
154 $modal->getShowSignal()
159 $this->ui_renderer->render($link),
160 $this->ui_renderer->render($usr),
161 $this->ui_renderer->render($actions),
165 usort(
$data,
static function (array
$a, array
$b):
int {
166 return strnatcasecmp(
$a[4],
$b[4]);
170 $table->setData(
$data);
172 $this->tpl->setContent(
173 $this->ui_renderer->render($collected_modals)
181 protected function save(): void
184 $form->setValuesByPost();
187 $cat_ref_id = $form->getInput(self::F_CATEGORY_REF);
188 $current_ref_id = $form->getInput(self::F_CATEGORY_ORIGINAL_REF);
191 $this->tpl->setOnScreenMessage(
193 sprintf($this->
lng->txt(
'not_a_valid_cat_id'), $cat_ref_id),
199 if (!is_null($current_ref_id) && $current_ref_id !== $cat_ref_id) {
200 $ids = [(
int) $current_ref_id];
201 $this->
getObject()->deleteAutomaticContentCategories($ids);
204 $this->
getObject()->storeAutomaticContentCategory((
int) $cat_ref_id);
209 $get = $this->request->getQueryParams();
210 $post = $this->request->getParsedBody();
213 $field_ids_in_get = array_key_exists($field, $get);
214 $field_ids_in_post = array_key_exists($field,
$post);
218 if ($field_ids_in_get) {
219 $cat_ids = $get[$field];
220 $msg = $this->
lng->txt(
'prg_delete_single_confirmation');
221 } elseif ($field_ids_in_post) {
222 $cat_ids = implode(
' ',
$post[$field]);
223 $msg = $this->
lng->txt(
'prg_delete_confirmation');
225 $this->tpl->setOnScreenMessage(
"info", $this->
lng->txt(
'prg_delete_nothing_selected'),
true);
226 $this->
ctrl->redirect($this, self::CMD_VIEW);
229 $cat_ids = base64_encode($cat_ids);
231 $this->
ctrl->setParameterByClass(self::class, $field, $cat_ids);
232 $delete = $this->
ctrl->getFormActionByClass(self::class, self::CMD_DELETE);
233 $cancel = $this->
ctrl->getFormActionByClass(self::class, self::CMD_VIEW);
234 $this->
ctrl->clearParameterByClass(self::class, $field);
237 $this->button_factory->standard($this->
lng->txt(
'prg_confirm_delete'), $delete),
238 $this->button_factory->standard($this->
lng->txt(
'prg_cancel'), $cancel)
241 $message_box = $this->message_box_factory->confirmation($msg)->withButtons($buttons);
243 $this->tpl->setContent($this->ui_renderer->render($message_box));
246 protected function delete():
void
249 $get = $this->request->getQueryParams();
251 if (!array_key_exists($field, $get)) {
252 $this->tpl->setOnScreenMessage(
"failure", $this->
lng->txt(
'prg_delete_failure'),
true);
253 $this->
ctrl->redirect($this, self::CMD_VIEW);
256 $cat_ids = base64_decode($get[$field]);
257 $cat_ids = explode(
' ', trim($cat_ids));
258 $cat_ids = array_map(
'intval', $cat_ids);
260 $this->
getObject()->deleteAutomaticContentCategories($cat_ids);
262 $msg = $this->
lng->txt(
'prg_delete_single_success');
263 if (count($cat_ids) > 1) {
264 $msg = $this->
lng->txt(
'prg_delete_success');
267 $this->tpl->setOnScreenMessage(
"success", $msg,
true);
268 $this->
ctrl->redirect($this, self::CMD_VIEW);
284 if ($this->
object ===
null ||
285 $this->
object->getRefId() !== $this->prg_ref_id
294 if (!is_null($current_ref_id)) {
295 $this->
ctrl->setParameter($this, self::CHECKBOX_CATEGORY_REF_IDS, (
string) $current_ref_id);
297 $link = $this->
ctrl->getLinkTarget($this, self::CMD_GET_ASYNC_MODAL,
"",
true);
298 $this->
ctrl->setParameter($this, self::CHECKBOX_CATEGORY_REF_IDS,
null);
299 return $this->ui_factory->modal()->roundtrip(
302 )->withAsyncRenderUrl(
309 $current_ref_id =
null;
310 if ($this->request_wrapper->has(self::CHECKBOX_CATEGORY_REF_IDS)) {
311 $current_ref_id = $this->request_wrapper->retrieve(
312 self::CHECKBOX_CATEGORY_REF_IDS,
316 $form = $this->
getForm($current_ref_id);
317 $form_id =
"form_" . $form->getId();
318 $submit = $this->ui_factory->button()->primary($this->
lng->txt(
'add'),
"#")->withOnLoadCode(
319 function (
$id) use ($form_id) {
320 return "$('#$id').click(function() { document.getElementById('$form_id').submit(); return false; });";
323 $modal = $this->ui_factory->modal()
325 $this->
lng->txt(
'modal_categories_title'),
326 $this->ui_factory->legacy()->content($form->getHtml())
328 ->withActionButtons([$submit])
329 ->withAdditionalOnLoadCode(
330 function (
$id) use ($form) {
332 $js = $form->getItemByPostVar($selector_post_var)->getOnloadCode();
334 document.getElementById('$id').onclose = ()=> {
335 let smodal = document.querySelectorAll('body dialog')
336 .item(document.querySelectorAll('body dialog').length-1);
340 return implode(
';', $js);
344 echo $this->ui_renderer->renderAsync($modal);
352 $form->setId(uniqid((
string) $current_ref_id,
true));
354 $form->setFormAction($this->
ctrl->getFormAction($this,
"save"));
356 $this->
lng->txt(
"category"),
357 self::F_CATEGORY_REF,
360 $cat->getExplorerGUI()->setSelectableTypes([
"cat"]);
361 $cat->getExplorerGUI()->setTypeWhiteList([
"root",
"cat"]);
362 if ($current_ref_id !==
null) {
363 $cat->getExplorerGUI()->setPathOpen($current_ref_id);
364 $cat->setValue($current_ref_id);
367 $cat->getExplorerGUI()->setAjax(
true);
368 $form->addItem($cat);
371 $hi->setValue((
string) $current_ref_id ??
"");
382 $btn = $this->ui_factory->button()->primary($this->
lng->txt(
'add_category'),
'')
383 ->withOnClick($add_cat_signal);
384 $this->
toolbar->addComponent($btn);
392 $items[] = $this->ui_factory
394 ->shy($this->
lng->txt(
'edit'),
'')
398 $this->
ctrl->setParameterByClass(self::class, self::CHECKBOX_CATEGORY_REF_IDS, $cat_ref_id);
399 $link = $this->
ctrl->getLinkTarget($this, self::CMD_DELETE_CONFIRMATION);
400 $this->
ctrl->clearParameterByClass(self::class, self::CHECKBOX_CATEGORY_REF_IDS);
402 $items[] = $this->ui_factory
404 ->shy($this->
lng->txt(
'delete'), $link)
407 return $this->ui_factory->dropdown()->standard($items);
413 if (array_filter($username) === []) {
417 $editor = implode(
' ', [
418 $username[
'firstname'],
419 $username[
'lastname'],
420 '(' . $username[
'login'] .
')'
423 $back_url = $this->
ctrl->getLinkTarget($this, self::CMD_VIEW);
424 $this->
ctrl->setParameterByClass(PublicProfileGUI::class,
'back_url', urlencode($back_url));
425 $this->
ctrl->setParameterByClass(PublicProfileGUI::class,
'user_id', $usr_id);
426 $url = $this->
ctrl->getLinkTargetByClass(PublicProfileGUI::class,
'view');
429 if (!$usr->hasPublicProfile()) {
430 $url = $this->
ctrl->getLinkTarget($this, self::CMD_PROFILE_NOT_PUBLIC);
432 return $this->ui_factory->link()->standard($editor,
$url);
440 static function (array
$c):
string {
443 $this->tree->getPathFull($cat_ref_id)
445 $path = implode(
' > ', $hops);
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Builds a Color from either hex- or rgb values.
GUI class for public user profile presentation.
Class ilCtrl provides processing control methods.
Base class for ILIAS Exception handling.
static _getStaticLink(?int $a_ref_id, string $a_type='', bool $a_fallback_goto=true, string $append="")
Class ilObjStudyProgrammeAutoCategoriesGUI.
ILIAS UI Factory $ui_factory
getToolbar(Signal $add_cat_signal)
Setup toolbar.
getModal(?int $current_ref_id=null)
getItemPath(int $cat_ref_id)
ILIAS UI Renderer $ui_renderer
save()
Store data from (modal-)form.
Psr Http Message ServerRequestInterface $request
getItemAction(int $cat_ref_id, Signal $signal)
getObject()
Get current StudyProgramme-object.
ilObjStudyProgramme $object
ilGlobalTemplateInterface $tpl
view(bool $profile_not_public=false)
Render.
const CHECKBOX_CATEGORY_REF_IDS
Button Factory $button_factory
MessageBox Factory $message_box_factory
__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
setRefId(int $prg_ref_id)
Set ref-id of StudyProgramme before using this GUI.
ILIAS HTTP Wrapper RequestWrapper $request_wrapper
getUserRepresentation(int $usr_id)
const CMD_GET_ASYNC_MODAL
const CMD_DELETE_CONFIRMATION
const CMD_PROFILE_NOT_PUBLIC
getForm(?int $current_ref_id=null)
ILIAS Refinery Factory $refinery
static getInstanceByRefId($ref_id)
static _lookupName(int $a_user_id)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupType(int $id, bool $reference=false)
static _lookupTitle(int $obj_id)
Class ilObjStudyProgrammeAutoCategoriesGUI.
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
Interface RequestWrapper.
withOnClick(Signal $signal)
Get a component like this, triggering a signal of another component on click.
This describes a Standard Dropdown.
This is how a factory for Message Boxes looks like.
An entity that renders components to a string output.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples