ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilPortfolioRepositoryGUI.php
Go to the documentation of this file.
1 <?php
2 
20 
28 {
29  protected \ILIAS\Portfolio\InternalGUIService $gui;
31  protected ilLanguage $lng;
32  protected ilObjUser $user;
33  protected ilCtrl $ctrl;
35  protected ilTabsGUI $tabs;
36  protected ilHelpGUI $help;
39  protected ilSetting $settings;
40  protected int $user_id;
42  protected \ILIAS\DI\UIServices $ui;
43 
44  public function __construct()
45  {
46  global $DIC;
47 
48  $this->lng = $DIC->language();
49  $this->user = $DIC->user();
50  $this->ctrl = $DIC->ctrl();
51  $this->tpl = $DIC["tpl"];
52  $this->tabs = $DIC->tabs();
53  $this->help = $DIC["ilHelp"];
54  $this->locator = $DIC["ilLocator"];
55  $this->toolbar = $DIC->toolbar();
56  $this->settings = $DIC->settings();
57  $this->ui = $DIC->ui();
58  $lng = $DIC->language();
59  $ilUser = $DIC->user();
60 
61  $lng->loadLanguageModule("prtf");
62  $lng->loadLanguageModule("user");
63 
64  $this->access_handler = new ilPortfolioAccessHandler();
65 
66  $this->port_request = $DIC->portfolio()
67  ->internal()
68  ->gui()
69  ->standardRequest();
70 
71  $this->user_id = $ilUser->getId();
72  $this->gui = $DIC->portfolio()->internal()->gui();
73  }
74 
75  public function executeCommand(): void
76  {
77  $ilCtrl = $this->ctrl;
78  $lng = $this->lng;
79  $tpl = $this->tpl;
80  $ilTabs = $this->tabs;
81 
82  if (!$this->access_handler->editPortfolios()) {
83  throw new ilException($this->lng->txt("no_permission"));
84  }
85 
86  $next_class = $ilCtrl->getNextClass($this);
87  $cmd = $ilCtrl->getCmd("show");
88 
89  $tpl->setTitle($lng->txt("portfolio"));
90  $tpl->setTitleIcon(
91  ilUtil::getImagePath("standard/icon_prtf.svg"),
92  $lng->txt("portfolio")
93  );
94 
95  switch ($next_class) {
96  case "ilobjportfoliogui":
97 
98  $gui = new ilObjPortfolioGUI($this->port_request->getPortfolioId());
99 
100  if ($cmd !== "preview") {
101  $this->setLocator();
102 
103  $exercise_back_ref_id = $this->port_request->getExcBackRefId();
104  if ($exercise_back_ref_id > 0) {
105  $ilTabs->setBack2Target($lng->txt("obj_exc"), ilLink::_getLink($exercise_back_ref_id));
106  } else {
107  $ilTabs->setBack2Target($lng->txt("prtf_tab_portfolios"), $ilCtrl->getLinkTarget($this, "show"));
108  }
109  }
110 
111  $ilCtrl->forwardCommand($gui);
112  break;
113 
114  default:
115  $this->setLocator();
116  $this->setTabs();
117  $this->$cmd();
118  break;
119  }
120  }
121 
122  public function setTabs(): void
123  {
124  $ilTabs = $this->tabs;
125  $lng = $this->lng;
126  $ilCtrl = $this->ctrl;
127  $ilHelp = $this->help;
128 
129  $ilHelp->setScreenIdComponent("prtf");
130 
131  $ilTabs->addTab(
132  "mypf",
133  $lng->txt("prtf_tab_portfolios"),
134  $ilCtrl->getLinkTarget($this)
135  );
136 
137  $ilTabs->addTab(
138  "otpf",
139  $lng->txt("prtf_tab_other_users"),
140  $ilCtrl->getLinkTarget($this, "showotherFilter")
141  );
142 
143  $ilTabs->activateTab("mypf");
144  }
145 
146  protected function setLocator(): void
147  {
148  $ilLocator = $this->locator;
149  $lng = $this->lng;
150  $ilCtrl = $this->ctrl;
151  $tpl = $this->tpl;
152 
153  $ilLocator->addItem(
154  $lng->txt("portfolio"),
155  $ilCtrl->getLinkTarget($this, "show")
156  );
157 
158  $tpl->setLocator();
159  }
160 
161  protected function checkAccess(
162  string $a_permission,
163  ?int $a_portfolio_id = null
164  ): bool {
165  if ($a_portfolio_id) {
166  return $this->access_handler->checkAccess($a_permission, "", $a_portfolio_id);
167  }
168  // currently only object-based permissions
169  return true;
170  }
171 
172 
173  //
174  // LIST INCL. ACTIONS
175  //
176 
177  protected function show(): void
178  {
179  $tpl = $this->tpl;
180  $ilToolbar = $this->toolbar;
181  $ilCtrl = $this->ctrl;
182 
183  $this->gui->button(
184  $this->lng->txt("prtf_add_portfolio"),
185  $ilCtrl->getLinkTargetByClass("ilObjPortfolioGUI", "create")
186  )->toToolbar(true);
187 
189  if (count($templates) > 0) {
190  $this->gui->button(
191  $this->lng->txt("prtf_add_portfolio_from_template"),
192  $ilCtrl->getLinkTargetByClass("ilObjPortfolioGUI", "createFromTemplate")
193  )->toToolbar(true);
194  }
195 
196  $portfolio_list = $this->getPortfolioList();
197 
198  $tpl->setContent($portfolio_list);
199  }
200 
201  protected function getPortfolioList(): string
202  {
203  $ui = $this->ui;
204  $f = $ui->factory();
205  $renderer = $ui->renderer();
206  $lng = $this->lng;
207  $ctrl = $this->ctrl;
208 
209  $access_handler = new ilPortfolioAccessHandler();
210 
211  $shared_objects = $access_handler->getObjectsIShare(false);
212 
213  $items = [];
214 
215  foreach (ilObjPortfolio::getPortfoliosOfUser($this->user_id) as $port) {
216  // icon
217  $icon = $f->symbol()->icon()->custom(
218  ilUtil::getImagePath("standard/icon_prtf.svg"),
219  $lng->txt("obj_portfolio"),
220  "medium"
221  );
222  if (!$port["is_online"] || !in_array($port["id"], $shared_objects)) {
223  $icon = $icon->withDisabled(true);
224  }
225 
226  // actions
227  $prtf_path = array(get_class($this), "ilobjportfoliogui");
228  $action = [];
229  // ... preview
230  $ctrl->setParameterByClass("ilobjportfoliogui", "prt_id", $port["id"]);
231  $preview_action = $ctrl->getLinkTargetByClass($prtf_path, "preview");
232  $action[] = $f->button()->shy($lng->txt("preview"), $preview_action);
233  // ... edit content
234  $action[] = $f->button()->shy(
235  $lng->txt("prtf_edit_content"),
236  $ctrl->getLinkTargetByClass($prtf_path, "view")
237  );
238  $ctrl->setParameter($this, "prt_id", $port["id"]);
239  if ($port["is_online"]) {
240  // ... set offline
241  $action[] = $f->button()->shy(
242  $lng->txt("prtf_set_offline"),
243  $ctrl->getLinkTarget($this, "setOffline")
244  );
245  } else {
246  // ... set online
247  $action[] = $f->button()->shy(
248  $lng->txt("prtf_set_online"),
249  $ctrl->getLinkTarget($this, "setOnline")
250  );
251  }
252  $ctrl->setParameter($this, "prt_id", "");
253  // ... settings
254  $action[] = $f->button()->shy(
255  $lng->txt("settings"),
256  $ctrl->getLinkTargetByClass($prtf_path, "edit")
257  );
258  // ... sharing
259  $action[] = $f->button()->shy(
260  $lng->txt("wsp_permissions"),
261  $ctrl->getLinkTargetByClass(array(get_class($this), "ilobjportfoliogui", "ilWorkspaceAccessGUI"), "share")
262  );
263  $ctrl->setParameterByClass("ilobjportfoliogui", "prt_id", "");
264 
265  // ... delete
266  $ctrl->setParameter($this, "prtf", $port["id"]);
267  $action[] = $f->button()->shy(
268  $lng->txt("delete"),
269  $ctrl->getLinkTarget($this, "confirmPortfolioDeletion")
270  );
271  $ctrl->setParameter($this, "prtf", "");
272  $actions = $f->dropdown()->standard($action);
273 
274 
275  // properties
276  $props = [];
277  // ... online
278  $props[$lng->txt("online")] = ($port["is_online"])
279  ? $lng->txt("yes")
280  : $lng->txt("no");
281  //: "<span class='il_ItemAlertProperty'>" . $lng->txt("no") . "</span>";
282  // ... shared
283  $props[$lng->txt("wsp_status_shared")] = (in_array($port["id"], $shared_objects))
284  ? $lng->txt("yes")
285  : $lng->txt("no");
286  //: "<span class='il_ItemAlertProperty'>" . $lng->txt("no") . "</span>";
287  // ... default (my profile)
288  if ($port["is_default"]) {
289  $props[$lng->txt("prtf_default_portfolio")] = $lng->txt("yes");
290  }
291  // ... handed in
292  // exercise portfolio?
293  $exercises = ilPortfolioExerciseGUI::checkExercise($this->user_id, $port["id"], false, true);
294  $visible_to_tutor = false;
295  foreach ($exercises as $exinfo) {
296  if ($exinfo["submitted"]) {
297  $visible_to_tutor = true;
298  $props[$exinfo["ass_title"]] =
299  str_replace("$1", $exinfo["submitted_date"], $lng->txt("prtf_submission_on"));
300  } else {
301  $props[$exinfo["ass_title"]] = $lng->txt("prtf_no_submission");
302  //$props[$exinfo["ass_title"]] = "<span class='il_ItemAlertProperty'>" . $lng->txt("prtf_no_submission") . "</span>";
303  }
304  }
305  if ($visible_to_tutor) {
306  $props[$lng->txt("prtf_visible_for_tutor")] = $lng->txt("yes");
307  }
308 
309 
310  $items[] = $f->item()->standard($f->button()->shy($port["title"], $preview_action))
311  ->withActions($actions)
312  ->withProperties($props)
313  ->withLeadIcon($icon);
314  }
315 
316 
317  $std_list = $f->panel()->listing()->standard($lng->txt("prtf_portfolios"), array(
318  $f->item()->group("", $items)
319  ));
320 
321  return $renderer->render($std_list);
322  }
323 
324 
325  protected function setOnline(): void
326  {
327  $ilCtrl = $this->ctrl;
328  $lng = $this->lng;
329 
330  $prt_id = $this->port_request->getPortfolioId();
331  if (ilObjPortfolio::_lookupOwner($prt_id) === $this->user_id) {
332  $portfolio = new ilObjPortfolio($prt_id, false);
333  $portfolio->setOnline(true);
334  $portfolio->update();
335  $this->tpl->setOnScreenMessage('success', $lng->txt("saved_successfully"), true);
336  $ilCtrl->redirect($this, "show");
337  }
338  $ilCtrl->redirect($this, "show");
339  }
340 
341  protected function setOffline(): void
342  {
343  $ilCtrl = $this->ctrl;
344  $lng = $this->lng;
345 
346  $prt_id = $this->port_request->getPortfolioId();
347  if (ilObjPortfolio::_lookupOwner($prt_id) === $this->user_id) {
348  $portfolio = new ilObjPortfolio($prt_id, false);
349  $portfolio->setOnline(false);
350  $portfolio->update();
351  $this->tpl->setOnScreenMessage('success', $lng->txt("saved_successfully"), true);
352  $ilCtrl->redirect($this, "show");
353  }
354  $ilCtrl->redirect($this, "show");
355  }
356 
357 
358  protected function saveTitles(): void
359  {
360  $ilCtrl = $this->ctrl;
361  $lng = $this->lng;
362 
363  $titles = $this->port_request->getTitles();
364  $online = $this->port_request->getOnline();
365  foreach ($titles as $id => $title) {
366  if (trim($title) && $this->checkAccess("write", $id)) {
367  $portfolio = new ilObjPortfolio($id, false);
368  $portfolio->setTitle(ilUtil::stripSlashes($title));
369 
370  if (in_array($id, $online)) {
371  $portfolio->setOnline(true);
372  } else {
373  $portfolio->setOnline(false);
374  }
375 
376  $portfolio->update();
377  }
378  }
379 
380  $this->tpl->setOnScreenMessage('success', $lng->txt("saved_successfully"), true);
381  $ilCtrl->redirect($this, "show");
382  }
383 
384  protected function confirmPortfolioDeletion(): void
385  {
386  $ilCtrl = $this->ctrl;
387  $tpl = $this->tpl;
388  $lng = $this->lng;
389 
390  $prtfs = $this->port_request->getPortfolioIds();
391 
392  if (count($prtfs) === 0) {
393  $this->tpl->setOnScreenMessage('info', $lng->txt("no_checkbox"), true);
394  $ilCtrl->redirect($this, "show");
395  } else {
396  $cgui = new ilConfirmationGUI();
397  $cgui->setFormAction($ilCtrl->getFormAction($this));
398  $cgui->setHeaderText($lng->txt("prtf_sure_delete_portfolios"));
399  $cgui->setCancel($lng->txt("cancel"), "show");
400  $cgui->setConfirm($lng->txt("delete"), "deletePortfolios");
401 
402  foreach ($prtfs as $id) {
403  $cgui->addItem("prtfs[]", $id, ilObjPortfolio::_lookupTitle($id));
404  }
405 
406  $tpl->setContent($cgui->getHTML());
407  }
408  }
409 
410  protected function deletePortfolios(): void
411  {
412  $lng = $this->lng;
413  $ilCtrl = $this->ctrl;
414 
415  $port_ids = $this->port_request->getPortfolioIds();
416  foreach ($port_ids as $id) {
417  if ($this->checkAccess("write", $id)) {
418  $portfolio = new ilObjPortfolio($id, false);
419  if ($portfolio->getOwner() === $this->user_id) {
420  $this->access_handler->removePermission($id);
421  $portfolio->delete();
422  }
423  }
424  }
425  $this->tpl->setOnScreenMessage('success', $lng->txt("prtf_portfolio_deleted"), true);
426  $ilCtrl->redirect($this, "show");
427  }
428 
429 
430  //
431  // DEFAULT PORTFOLIO (aka profile)
432  //
433 
434 
435  protected function getWorkspaceAccess(): ilPortfolioAccessHandler
436  {
438  $wsp_access = $this->access_handler;
439  return $wsp_access;
440  }
441 
442 
443 
444  //
445  // SHARE
446  //
447 
448  protected function showOtherFilter(): void
449  {
450  $this->showOther(false);
451  }
452 
453  protected function showOther(
454  bool $a_load_data = true
455  ): void {
456  $tpl = $this->tpl;
457  $ilTabs = $this->tabs;
458  $ilTabs->activateTab("otpf");
459  $tbl = new ilWorkspaceShareTableGUI($this, "showOther", $this->getWorkspaceAccess(), null, $a_load_data);
460  $tpl->setContent($tbl->getHTML());
461  }
462 
463  protected function applyShareFilter(): void
464  {
465  $tbl = new ilWorkspaceShareTableGUI($this, "showOther", $this->getWorkspaceAccess());
466  $tbl->resetOffset();
467  $tbl->writeFilterToSession();
468 
469  $this->showOther();
470  }
471 
472  protected function resetShareFilter(): void
473  {
474  $tbl = new ilWorkspaceShareTableGUI($this, "showOther", $this->getWorkspaceAccess());
475  $tbl->resetOffset();
476  $tbl->resetFilter();
477 
478  $this->showOther(false);
479  }
480 
481  public function redirectSendMailToSharer(): void
482  {
483  $owner_id = $this->port_request->getOwnerId();
484  $prt_id = $this->port_request->getPortfolioId();
485 
486  if ($owner_id > 0) {
487  $login = ilObjUser::_lookupLogin($owner_id);
488 
489  // #16530 - see ilObjCourseGUI::createMailSignature
490  $sig = chr(13) . chr(10) . chr(13) . chr(10);
491  $sig .= $this->lng->txt('prtf_permanent_link');
492  $sig .= chr(13) . chr(10) . chr(13) . chr(10);
493  $sig .= ilLink::_getStaticLink($prt_id, "prtf", true);
494  $sig = rawurlencode(base64_encode($sig));
495 
497  $this,
498  "showotherFilter",
499  array(),
500  array(
501  'type' => 'new',
502  'rcp_to' => $login,
504  )
505  ));
506  }
507  }
508 
509 }
$renderer
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)
Help GUI class.
getLinkTarget(object $a_gui_obj, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
setContent(string $a_html)
Sets content for standard template.
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.
setTitle(string $a_title, bool $hidden=false)
Sets title in standard template.
loadLanguageModule(string $a_module)
Load language module.
Portfolio repository gui class.
setLocator()
Insert locator.
static getAvailablePortfolioTemplates(string $a_permission="read")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
ilPortfolioAccessHandler $access_handler
Workspace share handler table GUI class.
ilObjPortfolioGUI: ilPortfolioPageGUI, ilPageObjectGUI ilObjPortfolioGUI: ilWorkspaceAccessGUI, ilCommentGUI, ilCommonActionDispatcherGUI ilObjPortfolioGUI: ilObjectContentStyleSettingsGUI, ilPortfolioExerciseGUI ilObjPortfolioGUI: ILIAS
static _lookupTitle(int $obj_id)
setScreenIdComponent(string $a_comp)
static getPortfoliosOfUser(int $a_user_id)
Get portfolios of user.
global $DIC
Definition: shib_login.php:26
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
final const string SIGNATURE_KEY
getObjectsIShare(bool $a_online_only=true)
setTitleIcon(string $a_icon_path, string $a_icon_desc="")
set title icon
static redirect(string $a_script)
activateTab(string $a_id)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
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.
static getRedirectTarget( $gui, string $cmd, array $gui_params=[], array $mail_params=[], array $context_params=[])
ILIAS Portfolio InternalGUIService $gui
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
getLinkTargetByClass( $a_class, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
static _lookupLogin(int $a_user_id)