ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilPortfolioRepositoryGUI.php
Go to the documentation of this file.
1 <?php
2 
20 
28 {
30  protected ilLanguage $lng;
31  protected ilObjUser $user;
32  protected ilCtrl $ctrl;
34  protected ilTabsGUI $tabs;
35  protected ilHelpGUI $help;
38  protected ilSetting $settings;
39  protected int $user_id;
41  protected \ILIAS\DI\UIServices $ui;
42 
43  public function __construct()
44  {
45  global $DIC;
46 
47  $this->lng = $DIC->language();
48  $this->user = $DIC->user();
49  $this->ctrl = $DIC->ctrl();
50  $this->tpl = $DIC["tpl"];
51  $this->tabs = $DIC->tabs();
52  $this->help = $DIC["ilHelp"];
53  $this->locator = $DIC["ilLocator"];
54  $this->toolbar = $DIC->toolbar();
55  $this->settings = $DIC->settings();
56  $this->ui = $DIC->ui();
57  $lng = $DIC->language();
58  $ilUser = $DIC->user();
59 
60  $lng->loadLanguageModule("prtf");
61  $lng->loadLanguageModule("user");
62 
63  $this->access_handler = new ilPortfolioAccessHandler();
64 
65  $this->port_request = $DIC->portfolio()
66  ->internal()
67  ->gui()
68  ->standardRequest();
69 
70  $this->user_id = $ilUser->getId();
71  }
72 
73  public function executeCommand(): void
74  {
75  $ilCtrl = $this->ctrl;
76  $lng = $this->lng;
77  $tpl = $this->tpl;
78  $ilTabs = $this->tabs;
79 
80  if (!$this->access_handler->editPortfolios()) {
81  throw new ilException($this->lng->txt("no_permission"));
82  }
83 
84  $next_class = $ilCtrl->getNextClass($this);
85  $cmd = $ilCtrl->getCmd("show");
86 
87  $tpl->setTitle($lng->txt("portfolio"));
88  $tpl->setTitleIcon(
89  ilUtil::getImagePath("icon_prtf.svg"),
90  $lng->txt("portfolio")
91  );
92 
93  switch ($next_class) {
94  case "ilobjportfoliogui":
95 
96  $gui = new ilObjPortfolioGUI($this->port_request->getPortfolioId());
97 
98  if ($cmd !== "preview") {
99  $this->setLocator();
100 
101  $exercise_back_ref_id = $this->port_request->getExcBackRefId();
102  if ($exercise_back_ref_id > 0) {
103  $ilTabs->setBack2Target($lng->txt("obj_exc"), ilLink::_getLink($exercise_back_ref_id));
104  } else {
105  $ilTabs->setBack2Target($lng->txt("prtf_tab_portfolios"), $ilCtrl->getLinkTarget($this, "show"));
106  }
107  }
108 
109  $ilCtrl->forwardCommand($gui);
110  break;
111 
112  default:
113  $this->setLocator();
114  $this->setTabs();
115  $this->$cmd();
116  break;
117  }
118  }
119 
120  public function setTabs(): void
121  {
122  $ilTabs = $this->tabs;
123  $lng = $this->lng;
124  $ilCtrl = $this->ctrl;
125  $ilHelp = $this->help;
126 
127  $ilHelp->setScreenIdComponent("prtf");
128 
129  $ilTabs->addTab(
130  "mypf",
131  $lng->txt("prtf_tab_portfolios"),
132  $ilCtrl->getLinkTarget($this)
133  );
134 
135  $ilTabs->addTab(
136  "otpf",
137  $lng->txt("prtf_tab_other_users"),
138  $ilCtrl->getLinkTarget($this, "showotherFilter")
139  );
140 
141  $ilTabs->activateTab("mypf");
142  }
143 
144  protected function setLocator(): void
145  {
146  $ilLocator = $this->locator;
147  $lng = $this->lng;
148  $ilCtrl = $this->ctrl;
149  $tpl = $this->tpl;
150 
151  $ilLocator->addItem(
152  $lng->txt("portfolio"),
153  $ilCtrl->getLinkTarget($this, "show")
154  );
155 
156  $tpl->setLocator();
157  }
158 
159  protected function checkAccess(
160  string $a_permission,
161  ?int $a_portfolio_id = null
162  ): bool {
163  if ($a_portfolio_id) {
164  return $this->access_handler->checkAccess($a_permission, "", $a_portfolio_id);
165  }
166  // currently only object-based permissions
167  return true;
168  }
169 
170 
171  //
172  // LIST INCL. ACTIONS
173  //
174 
175  protected function show(): void
176  {
177  $tpl = $this->tpl;
178  $ilToolbar = $this->toolbar;
179  $ilCtrl = $this->ctrl;
180 
181  $button = ilLinkButton::getInstance();
182  $button->setCaption("prtf_add_portfolio");
183  $button->setUrl($ilCtrl->getLinkTargetByClass("ilObjPortfolioGUI", "create"));
184  $ilToolbar->addButtonInstance($button);
185  $portfolio_list = $this->getPortfolioList();
186 
187  $tpl->setContent($portfolio_list);
188  }
189 
190  protected function getPortfolioList(): string
191  {
192  $ui = $this->ui;
193  $f = $ui->factory();
194  $renderer = $ui->renderer();
195  $lng = $this->lng;
196  $ctrl = $this->ctrl;
197 
198  $access_handler = new ilPortfolioAccessHandler();
199 
200  $shared_objects = $access_handler->getObjectsIShare(false);
201 
202  $items = [];
203 
204  foreach (ilObjPortfolio::getPortfoliosOfUser($this->user_id) as $port) {
205  // icon
206  $icon = $f->symbol()->icon()->custom(
207  ilUtil::getImagePath("icon_prtf.svg"),
208  $lng->txt("obj_portfolio"),
209  "medium"
210  );
211  if (!$port["is_online"] || !in_array($port["id"], $shared_objects)) {
212  $icon = $icon->withDisabled(true);
213  }
214 
215  // actions
216  $prtf_path = array(get_class($this), "ilobjportfoliogui");
217  $action = [];
218  // ... preview
219  $ctrl->setParameterByClass("ilobjportfoliogui", "prt_id", $port["id"]);
220  $preview_action = $ctrl->getLinkTargetByClass($prtf_path, "preview");
221  $action[] = $f->button()->shy($lng->txt("preview"), $preview_action);
222  // ... edit content
223  $action[] = $f->button()->shy(
224  $lng->txt("prtf_edit_content"),
225  $ctrl->getLinkTargetByClass($prtf_path, "view")
226  );
227  $ctrl->setParameter($this, "prt_id", $port["id"]);
228  if ($port["is_online"]) {
229  // ... set offline
230  $action[] = $f->button()->shy(
231  $lng->txt("prtf_set_offline"),
232  $ctrl->getLinkTarget($this, "setOffline")
233  );
234  } else {
235  // ... set online
236  $action[] = $f->button()->shy(
237  $lng->txt("prtf_set_online"),
238  $ctrl->getLinkTarget($this, "setOnline")
239  );
240  }
241  $ctrl->setParameter($this, "prt_id", "");
242  // ... settings
243  $action[] = $f->button()->shy(
244  $lng->txt("settings"),
245  $ctrl->getLinkTargetByClass($prtf_path, "edit")
246  );
247  // ... sharing
248  $action[] = $f->button()->shy(
249  $lng->txt("wsp_permissions"),
250  $ctrl->getLinkTargetByClass(array(get_class($this), "ilobjportfoliogui", "ilWorkspaceAccessGUI"), "share")
251  );
252  $ctrl->setParameterByClass("ilobjportfoliogui", "prt_id", "");
253 
254  if ($port["is_online"]) {
255  if (!$port["is_default"]) {
256  // ... set as default
257  $ctrl->setParameter($this, "prt_id", $port["id"]);
258 
259  $action[] = $f->button()->shy(
260  $lng->txt("prtf_set_as_default"),
261  $ctrl->getLinkTarget($this, "setDefaultConfirmation")
262  );
263 
264  $ctrl->setParameter($this, "prt_id", "");
265  } else {
266  // ... unset as default
267  $action[] = $f->button()->shy(
268  $lng->txt("prtf_unset_as_default"),
269  $ctrl->getLinkTarget($this, "unsetDefault")
270  );
271  }
272  }
273  // ... delete
274  $ctrl->setParameter($this, "prtf", $port["id"]);
275  $action[] = $f->button()->shy(
276  $lng->txt("delete"),
277  $ctrl->getLinkTarget($this, "confirmPortfolioDeletion")
278  );
279  $ctrl->setParameter($this, "prtf", "");
280  $actions = $f->dropdown()->standard($action);
281 
282 
283  // properties
284  $props = [];
285  // ... online
286  $props[$lng->txt("online")] = ($port["is_online"])
287  ? $lng->txt("yes")
288  : $lng->txt("no");
289  //: "<span class='il_ItemAlertProperty'>" . $lng->txt("no") . "</span>";
290  // ... shared
291  $props[$lng->txt("wsp_status_shared")] = (in_array($port["id"], $shared_objects))
292  ? $lng->txt("yes")
293  : $lng->txt("no");
294  //: "<span class='il_ItemAlertProperty'>" . $lng->txt("no") . "</span>";
295  // ... default (my profile)
296  if ($port["is_default"]) {
297  $props[$lng->txt("prtf_default_portfolio")] = $lng->txt("yes");
298  }
299  // ... handed in
300  // exercise portfolio?
301  $exercises = ilPortfolioExerciseGUI::checkExercise($this->user_id, $port["id"], false, true);
302  foreach ($exercises as $exinfo) {
303  if ($exinfo["submitted"]) {
304  $props[$exinfo["ass_title"]] =
305  str_replace("$1", $exinfo["submitted_date"], $lng->txt("prtf_submission_on"));
306  } else {
307  $props[$exinfo["ass_title"]] = $lng->txt("prtf_no_submission");
308  //$props[$exinfo["ass_title"]] = "<span class='il_ItemAlertProperty'>" . $lng->txt("prtf_no_submission") . "</span>";
309  }
310  }
311 
312 
313  $items[] = $f->item()->standard($f->button()->shy($port["title"], $preview_action))
314  ->withActions($actions)
315  ->withProperties($props)
316  ->withLeadIcon($icon);
317  }
318 
319 
320  $std_list = $f->panel()->listing()->standard($lng->txt("prtf_portfolios"), array(
321  $f->item()->group("", $items)
322  ));
323 
324  return $renderer->render($std_list);
325  }
326 
327 
328  protected function setOnline(): void
329  {
330  $ilCtrl = $this->ctrl;
331  $lng = $this->lng;
332 
333  $prt_id = $this->port_request->getPortfolioId();
334  if (ilObjPortfolio::_lookupOwner($prt_id) === $this->user_id) {
335  $portfolio = new ilObjPortfolio($prt_id, false);
336  $portfolio->setOnline(true);
337  $portfolio->update();
338  $this->tpl->setOnScreenMessage('success', $lng->txt("saved_successfully"), true);
339  $ilCtrl->redirect($this, "show");
340  }
341  $ilCtrl->redirect($this, "show");
342  }
343 
344  protected function setOffline(): void
345  {
346  $ilCtrl = $this->ctrl;
347  $lng = $this->lng;
348 
349  $prt_id = $this->port_request->getPortfolioId();
350  if (ilObjPortfolio::_lookupOwner($prt_id) === $this->user_id) {
351  $portfolio = new ilObjPortfolio($prt_id, false);
352  $portfolio->setOnline(false);
353  $portfolio->update();
354  $this->tpl->setOnScreenMessage('success', $lng->txt("saved_successfully"), true);
355  $ilCtrl->redirect($this, "show");
356  }
357  $ilCtrl->redirect($this, "show");
358  }
359 
360 
361  protected function saveTitles(): void
362  {
363  $ilCtrl = $this->ctrl;
364  $lng = $this->lng;
365 
366  $titles = $this->port_request->getTitles();
367  $online = $this->port_request->getOnline();
368  foreach ($titles as $id => $title) {
369  if (trim($title) && $this->checkAccess("write", $id)) {
370  $portfolio = new ilObjPortfolio($id, false);
371  $portfolio->setTitle(ilUtil::stripSlashes($title));
372 
373  if (in_array($id, $online)) {
374  $portfolio->setOnline(true);
375  } else {
376  $portfolio->setOnline(false);
377  }
378 
379  $portfolio->update();
380  }
381  }
382 
383  $this->tpl->setOnScreenMessage('success', $lng->txt("saved_successfully"), true);
384  $ilCtrl->redirect($this, "show");
385  }
386 
387  protected function confirmPortfolioDeletion(): void
388  {
389  $ilCtrl = $this->ctrl;
390  $tpl = $this->tpl;
391  $lng = $this->lng;
392 
393  $prtfs = $this->port_request->getPortfolioIds();
394 
395  if (count($prtfs) === 0) {
396  $this->tpl->setOnScreenMessage('info', $lng->txt("no_checkbox"), true);
397  $ilCtrl->redirect($this, "show");
398  } else {
399  $cgui = new ilConfirmationGUI();
400  $cgui->setFormAction($ilCtrl->getFormAction($this));
401  $cgui->setHeaderText($lng->txt("prtf_sure_delete_portfolios"));
402  $cgui->setCancel($lng->txt("cancel"), "show");
403  $cgui->setConfirm($lng->txt("delete"), "deletePortfolios");
404 
405  foreach ($prtfs as $id) {
406  $cgui->addItem("prtfs[]", $id, ilObjPortfolio::_lookupTitle($id));
407  }
408 
409  $tpl->setContent($cgui->getHTML());
410  }
411  }
412 
413  protected function deletePortfolios(): void
414  {
415  $lng = $this->lng;
416  $ilCtrl = $this->ctrl;
417 
418  $port_ids = $this->port_request->getPortfolioIds();
419  foreach ($port_ids as $id) {
420  if ($this->checkAccess("write", $id)) {
421  $portfolio = new ilObjPortfolio($id, false);
422  if ($portfolio->getOwner() === $this->user_id) {
423  $this->access_handler->removePermission($id);
424  $portfolio->delete();
425  }
426  }
427  }
428  $this->tpl->setOnScreenMessage('success', $lng->txt("prtf_portfolio_deleted"), true);
429  $ilCtrl->redirect($this, "show");
430  }
431 
432 
433  //
434  // DEFAULT PORTFOLIO (aka profile)
435  //
436 
437  protected function unsetDefault(): void
438  {
439  $ilCtrl = $this->ctrl;
440  $lng = $this->lng;
442 
443  if ($this->checkAccess("write")) {
444  // #12845
445  $ilUser->setPref("public_profile", "n");
446  $ilUser->writePrefs();
447 
448  ilObjPortfolio::setUserDefault($this->user_id);
449  $this->tpl->setOnScreenMessage('success', $lng->txt("prtf_unset_default_share_info"), true);
450  }
451  $ilCtrl->redirect($this, "show");
452  }
453 
457  protected function setDefaultConfirmation(): void
458  {
459  $ilCtrl = $this->ctrl;
460  $lng = $this->lng;
461  $tpl = $this->tpl;
462  $ilTabs = $this->tabs;
464 
465  $prtf_id = $this->port_request->getPortfolioId();
466 
467  if ($prtf_id && $this->checkAccess("write")) {
468  // if already shared, no need to ask again
469  if ($this->access_handler->hasRegisteredPermission($prtf_id) ||
470  $this->access_handler->hasGlobalPermission($prtf_id)) {
471  $this->setDefault($prtf_id);
472  return;
473  }
474 
475  $ilTabs->clearTargets();
476  $ilTabs->setBackTarget(
477  $lng->txt("cancel"),
478  $ilCtrl->getLinkTarget($this, "show")
479  );
480 
481  $ilCtrl->setParameter($this, "prt_id", $prtf_id);
482 
483  // #20310
484  if (!$ilSetting->get("enable_global_profiles")) {
485  $ilCtrl->redirect($this, "setDefaultRegistered");
486  }
487 
488  $cgui = new ilConfirmationGUI();
489  $cgui->setFormAction($ilCtrl->getFormAction($this));
490  $cgui->setHeaderText($lng->txt("prtf_set_default_publish_confirmation"));
491  $cgui->setCancel($lng->txt("prtf_set_default_publish_global"), "setDefaultGlobal");
492  $cgui->setConfirm($lng->txt("prtf_set_default_publish_registered"), "setDefaultRegistered");
493  $tpl->setContent($cgui->getHTML());
494 
495  return;
496  }
497 
498  $ilCtrl->redirect($this, "show");
499  }
500 
501  protected function setDefaultGlobal(): void
502  {
503  $ilCtrl = $this->ctrl;
504 
505  $prtf_id = $this->port_request->getPortfolioId();
506  if ($prtf_id && $this->checkAccess("write")) {
507  $this->access_handler->addPermission($prtf_id, ilWorkspaceAccessGUI::PERMISSION_ALL);
508  $this->setDefault($prtf_id);
509  }
510  $ilCtrl->redirect($this, "show");
511  }
512 
513  protected function setDefaultRegistered(): void
514  {
515  $ilCtrl = $this->ctrl;
516 
517  $prtf_id = $this->port_request->getPortfolioId();
518  if ($prtf_id && $this->checkAccess("write")) {
519  $this->access_handler->addPermission($prtf_id, ilWorkspaceAccessGUI::PERMISSION_REGISTERED);
520  $this->setDefault($prtf_id);
521  }
522  $ilCtrl->redirect($this, "show");
523  }
524 
525  protected function setDefault(int $a_prtf_id): void
526  {
527  $ilCtrl = $this->ctrl;
528  $lng = $this->lng;
530 
531  if ($a_prtf_id && $this->checkAccess("write")) {
532  // #12845
533  if ($this->access_handler->hasGlobalPermission($a_prtf_id)) {
534  $ilUser->setPref("public_profile", "g");
535  $ilUser->writePrefs();
536  } elseif ($this->access_handler->hasRegisteredPermission($a_prtf_id)) {
537  $ilUser->setPref("public_profile", "y");
538  $ilUser->writePrefs();
539  } else {
540  return;
541  }
542  ilObjPortfolio::setUserDefault($this->user_id, $a_prtf_id);
543  $this->tpl->setOnScreenMessage('success', $lng->txt("settings_saved"), true);
544  }
545  $ilCtrl->redirect($this, "show");
546  }
547 
548  protected function getWorkspaceAccess(): ilPortfolioAccessHandler
549  {
551  $wsp_access = $this->access_handler;
552  return $wsp_access;
553  }
554 
555 
556 
557  //
558  // SHARE
559  //
560 
561  protected function showOtherFilter(): void
562  {
563  $this->showOther(false);
564  }
565 
566  protected function showOther(
567  bool $a_load_data = true
568  ): void {
569  $tpl = $this->tpl;
570  $ilTabs = $this->tabs;
571 
572  $ilTabs->activateTab("otpf");
573 
574  $tbl = new ilWorkspaceShareTableGUI($this, "showOther", $this->getWorkspaceAccess(), null, $a_load_data);
575  $tpl->setContent($tbl->getHTML());
576  }
577 
578  protected function applyShareFilter(): void
579  {
580  $tbl = new ilWorkspaceShareTableGUI($this, "showOther", $this->getWorkspaceAccess());
581  $tbl->resetOffset();
582  $tbl->writeFilterToSession();
583 
584  $this->showOther();
585  }
586 
587  protected function resetShareFilter(): void
588  {
589  $tbl = new ilWorkspaceShareTableGUI($this, "showOther", $this->getWorkspaceAccess());
590  $tbl->resetOffset();
591  $tbl->resetFilter();
592 
593  $this->showOther();
594  }
595 }
setLocator()
Insert locator.
getLinkTargetByClass( $a_class, string $a_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
static checkExercise(int $a_user_id, int $a_obj_id, bool $a_add_submit=false, bool $as_array=false)
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
Help GUI class.
setParameterByClass(string $a_class, string $a_parameter, $a_value)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupOwner(int $obj_id)
Lookup owner user ID for object ID.
loadLanguageModule(string $a_module)
Load language module.
setTitleIcon(string $a_icon_path, string $a_icon_desc="")
set title icon
Portfolio repository gui class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
ilPortfolioAccessHandler $access_handler
Workspace share handler table GUI class.
Portfolio view gui class.
static _lookupTitle(int $obj_id)
setContent(string $a_html)
Sets content for standard template.
setScreenIdComponent(string $a_comp)
static getPortfoliosOfUser(int $a_user_id)
Get portfolios of user.
static setUserDefault(int $a_user_id, ?int $a_portfolio_id=null)
Set the user default portfolio.
setTitle(string $a_title, bool $hidden=false)
Sets title in standard template.
getObjectsIShare(bool $a_online_only=true)
activateTab(string $a_id)
getLinkTarget(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
global $ilSetting
Definition: privfeed.php:17
checkAccess(string $a_permission, ?int $a_portfolio_id=null)
Access handler for portfolio NOTE: This file needs to stay in the classes directory, WAC will be confused otherwise.
$ilUser
Definition: imgupload.php:34
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setDefaultConfirmation()
Confirm sharing when setting default.