ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilPortfolioRepositoryGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
12{
16 protected $lng;
17
21 protected $user;
22
26 protected $ctrl;
27
31 protected $tpl;
32
36 protected $tabs;
37
41 protected $help;
42
46 protected $locator;
47
51 protected $toolbar;
52
56 protected $settings;
57
58 protected $user_id; // [int]
59 protected $access_handler; // [ilPortfolioAccessHandler]
60
64 protected $ui;
65
66 public function __construct()
67 {
68 global $DIC;
69
70 $this->lng = $DIC->language();
71 $this->user = $DIC->user();
72 $this->ctrl = $DIC->ctrl();
73 $this->tpl = $DIC["tpl"];
74 $this->tabs = $DIC->tabs();
75 $this->help = $DIC["ilHelp"];
76 $this->locator = $DIC["ilLocator"];
77 $this->toolbar = $DIC->toolbar();
78 $this->settings = $DIC->settings();
79 $this->ui = $DIC->ui();
80 $lng = $DIC->language();
81 $ilUser = $DIC->user();
82
83 $lng->loadLanguageModule("prtf");
84 $lng->loadLanguageModule("user");
85
86 $this->access_handler = new ilPortfolioAccessHandler();
87
88 $this->user_id = $ilUser->getId();
89 }
90
91 public function executeCommand()
92 {
93 $ilCtrl = $this->ctrl;
96 $ilTabs = $this->tabs;
97
98 if (!$this->access_handler->editPortfolios()) {
99 throw new ilException($this->lng->txt("no_permission"));
100 }
101
102 $next_class = $ilCtrl->getNextClass($this);
103 $cmd = $ilCtrl->getCmd("show");
104
105 $tpl->setTitle($lng->txt("portfolio"));
106 $tpl->setTitleIcon(
107 ilUtil::getImagePath("icon_prtf.svg"),
108 $lng->txt("portfolio")
109 );
110
111 switch ($next_class) {
112 case "ilobjportfoliogui":
113
114 $gui = new ilObjPortfolioGUI((int) $_REQUEST["prt_id"]);
115
116 if ($cmd != "preview") {
117 $this->setLocator();
118
119 if ((int) $_GET["exc_back_ref_id"] > 0) {
120 $ilTabs->setBack2Target($lng->txt("obj_exc"), ilLink::_getLink((int) $_GET["exc_back_ref_id"]));
121 } else {
122 $ilTabs->setBack2Target($lng->txt("prtf_tab_portfolios"), $ilCtrl->getLinkTarget($this, "show"));
123 }
124 }
125
126 $ilCtrl->forwardCommand($gui);
127 break;
128
129 default:
130 $this->setLocator();
131 $this->setTabs();
132 $this->$cmd();
133 break;
134 }
135
136 return true;
137 }
138
139 public function setTabs()
140 {
141 $ilTabs = $this->tabs;
143 $ilCtrl = $this->ctrl;
144 $ilHelp = $this->help;
145
146 $ilHelp->setScreenIdComponent("prtf");
147
148 $ilTabs->addTab(
149 "mypf",
150 $lng->txt("prtf_tab_portfolios"),
151 $ilCtrl->getLinkTarget($this)
152 );
153
154 $ilTabs->addTab(
155 "otpf",
156 $lng->txt("prtf_tab_other_users"),
157 $ilCtrl->getLinkTarget($this, "showotherFilter")
158 );
159
160 $ilTabs->activateTab("mypf");
161 }
162
163 protected function setLocator()
164 {
165 $ilLocator = $this->locator;
167 $ilCtrl = $this->ctrl;
169
170 $ilLocator->addItem(
171 $lng->txt("portfolio"),
172 $ilCtrl->getLinkTarget($this, "show")
173 );
174
175 $tpl->setLocator();
176 }
177
178 protected function checkAccess($a_permission, $a_portfolio_id = null)
179 {
180 if ($a_portfolio_id) {
181 return $this->access_handler->checkAccess($a_permission, "", $a_portfolio_id);
182 }
183 // currently only object-based permissions
184 return true;
185 }
186
187
188 //
189 // LIST INCL. ACTIONS
190 //
191
192 protected function show()
193 {
196 $ilToolbar = $this->toolbar;
197 $ilCtrl = $this->ctrl;
198
199 $button = ilLinkButton::getInstance();
200 $button->setCaption("prtf_add_portfolio");
201 $button->setUrl($ilCtrl->getLinkTargetByClass("ilObjPortfolioGUI", "create"));
202 $ilToolbar->addButtonInstance($button);
203 $portfolio_list = $this->getPortfolioList();
204
205 $tpl->setContent($portfolio_list);
206 }
207
214 protected function getPortfolioList()
215 {
216 $ui = $this->ui;
217 $f = $ui->factory();
218 $renderer = $ui->renderer();
221
223
224 $shared_objects = $access_handler->getObjectsIShare(false);
225
226 $items = [];
227
228 foreach (ilObjPortfolio::getPortfoliosOfUser($this->user_id) as $port) {
229 // icon
230 $icon = $f->symbol()->icon()->custom(
231 ilUtil::getImagePath("icon_prtf.svg"),
232 $lng->txt("obj_portfolio"),
233 "medium"
234 );
235 if (!$port["is_online"] || !in_array($port["id"], $shared_objects)) {
236 $icon = $icon->withDisabled(true);
237 }
238
239 // actions
240 $prtf_path = array(get_class($this), "ilobjportfoliogui");
241 $action = [];
242 // ... preview
243 $ctrl->setParameterByClass("ilobjportfoliogui", "prt_id", $port["id"]);
244 $preview_action = $ctrl->getLinkTargetByClass($prtf_path, "preview");
245 $action[] = $f->button()->shy($lng->txt("preview"), $preview_action);
246 // ... edit content
247 $action[] = $f->button()->shy(
248 $lng->txt("prtf_edit_content"),
249 $ctrl->getLinkTargetByClass($prtf_path, "view")
250 );
251 $ctrl->setParameter($this, "prt_id", $port["id"]);
252 if ($port["is_online"]) {
253 // ... set offline
254 $action[] = $f->button()->shy(
255 $lng->txt("prtf_set_offline"),
256 $ctrl->getLinkTarget($this, "setOffline")
257 );
258 } else {
259 // ... set online
260 $action[] = $f->button()->shy(
261 $lng->txt("prtf_set_online"),
262 $ctrl->getLinkTarget($this, "setOnline")
263 );
264 }
265 $ctrl->setParameter($this, "prt_id", "");
266 // ... settings
267 $action[] = $f->button()->shy(
268 $lng->txt("settings"),
269 $ctrl->getLinkTargetByClass($prtf_path, "edit")
270 );
271 // ... sharing
272 $action[] = $f->button()->shy(
273 $lng->txt("wsp_permissions"),
274 $ctrl->getLinkTargetByClass(array(get_class($this), "ilobjportfoliogui", "ilWorkspaceAccessGUI"), "share")
275 );
276 $ctrl->setParameterByClass("ilobjportfoliogui", "prt_id", "");
277
278 if ($port["is_online"]) {
279 if (!$port["is_default"]) {
280 // ... set as default
281 $ctrl->setParameter($this, "prt_id", $port["id"]);
282
283 $action[] = $f->button()->shy(
284 $lng->txt("prtf_set_as_default"),
285 $ctrl->getLinkTarget($this, "setDefaultConfirmation")
286 );
287
288 $ctrl->setParameter($this, "prt_id", "");
289 } else {
290 // ... unset as default
291 $action[] = $f->button()->shy(
292 $lng->txt("prtf_unset_as_default"),
293 $ctrl->getLinkTarget($this, "unsetDefault")
294 );
295 }
296 }
297 // ... delete
298 $ctrl->setParameter($this, "prtfs[]", $port["id"]);
299 $action[] = $f->button()->shy(
300 $lng->txt("delete"),
301 $ctrl->getLinkTarget($this, "confirmPortfolioDeletion")
302 );
303 $ctrl->setParameter($this, "prtfs[]", "");
304 $actions = $f->dropdown()->standard($action);
305
306
307 // properties
308 $props = [];
309 // ... online
310 $props[$lng->txt("online")] = ($port["is_online"])
311 ? $lng->txt("yes")
312 : "<span class='il_ItemAlertProperty'>" . $lng->txt("no") . "</span>";
313 // ... shared
314 $props[$lng->txt("wsp_status_shared")] = (in_array($port["id"], $shared_objects))
315 ? $lng->txt("yes")
316 : "<span class='il_ItemAlertProperty'>" . $lng->txt("no") . "</span>";
317 // ... default (my profile)
318 if ($port["is_default"]) {
319 $props[$lng->txt("prtf_default_portfolio")] = $lng->txt("yes");
320 }
321 // ... handed in
322 // exercise portfolio?
323 $exercises = ilPortfolioExerciseGUI::checkExercise($this->user_id, $port["id"], false, true);
324 foreach ($exercises as $exinfo) {
325 if ($exinfo["submitted"]) {
326 $props[$exinfo["ass_title"]] =
327 str_replace("$1", $exinfo["submitted_date"], $lng->txt("prtf_submission_on"));
328 } else {
329 $props[$exinfo["ass_title"]] = "<span class='il_ItemAlertProperty'>" . $lng->txt("prtf_no_submission") . "</span>";
330 }
331 }
332
333
334 $items[] = $f->item()->standard($f->button()->shy($port["title"], $preview_action))
335 ->withActions($actions)
336 ->withProperties($props)
337 ->withLeadIcon($icon);
338 }
339
340
341 $std_list = $f->panel()->listing()->standard($lng->txt("prtf_portfolios"), array(
342 $f->item()->group("", $items)
343 ));
344
345 return $renderer->render($std_list);
346 }
347
348
352 protected function setOnline()
353 {
354 $ilCtrl = $this->ctrl;
356
357 $prt_id = (int) $_GET["prt_id"];
359 $portfolio = new ilObjPortfolio($prt_id, false);
360 $portfolio->setOnline(true);
361 $portfolio->update();
362 ilUtil::sendSuccess($lng->txt("saved_successfully"), true);
363 $ilCtrl->redirect($this, "show");
364 }
365 $ilCtrl->redirect($this, "show");
366 }
367
371 protected function setOffline()
372 {
373 $ilCtrl = $this->ctrl;
375
376 $prt_id = (int) $_GET["prt_id"];
378 $portfolio = new ilObjPortfolio($prt_id, false);
379 $portfolio->setOnline(false);
380 $portfolio->update();
381 ilUtil::sendSuccess($lng->txt("saved_successfully"), true);
382 $ilCtrl->redirect($this, "show");
383 }
384 $ilCtrl->redirect($this, "show");
385 }
386
387
388 protected function saveTitles()
389 {
390 $ilCtrl = $this->ctrl;
392
393 foreach ($_POST["title"] as $id => $title) {
394 if (trim($title)) {
395 if ($this->checkAccess("write", $id)) {
396 $portfolio = new ilObjPortfolio($id, false);
397 $portfolio->setTitle(ilUtil::stripSlashes($title));
398
399 if (is_array($_POST["online"]) && in_array($id, $_POST["online"])) {
400 $portfolio->setOnline(true);
401 } else {
402 $portfolio->setOnline(false);
403 }
404
405 $portfolio->update();
406 }
407 }
408 }
409
410 ilUtil::sendSuccess($lng->txt("saved_successfully"), true);
411 $ilCtrl->redirect($this, "show");
412 }
413
414 protected function confirmPortfolioDeletion()
415 {
416 $ilCtrl = $this->ctrl;
419
420 $prtfs = $_REQUEST["prtfs"];
421
422 if (!is_array($prtfs) || count($prtfs) == 0) {
423 ilUtil::sendInfo($lng->txt("no_checkbox"), true);
424 $ilCtrl->redirect($this, "show");
425 } else {
426 $cgui = new ilConfirmationGUI();
427 $cgui->setFormAction($ilCtrl->getFormAction($this));
428 $cgui->setHeaderText($lng->txt("prtf_sure_delete_portfolios"));
429 $cgui->setCancel($lng->txt("cancel"), "show");
430 $cgui->setConfirm($lng->txt("delete"), "deletePortfolios");
431
432 foreach ($prtfs as $id) {
433 $cgui->addItem("prtfs[]", $id, ilObjPortfolio::_lookupTitle($id));
434 }
435
436 $tpl->setContent($cgui->getHTML());
437 }
438 }
439
440 protected function deletePortfolios()
441 {
443 $ilCtrl = $this->ctrl;
444
445 if (is_array($_POST["prtfs"])) {
446 foreach ($_POST["prtfs"] as $id) {
447 if ($this->checkAccess("write", $id)) {
448 $portfolio = new ilObjPortfolio($id, false);
449 if ($portfolio->getOwner() == $this->user_id) {
450 $this->access_handler->removePermission($id);
451 $portfolio->delete();
452 }
453 }
454 }
455 }
456 ilUtil::sendSuccess($lng->txt("prtf_portfolio_deleted"), true);
457 $ilCtrl->redirect($this, "show");
458 }
459
460
461 //
462 // DEFAULT PORTFOLIO (aka profile)
463 //
464
465 protected function unsetDefault()
466 {
467 $ilCtrl = $this->ctrl;
470
471 if ($this->checkAccess("write")) {
472 // #12845
473 $ilUser->setPref("public_profile", "n");
474 $ilUser->writePrefs();
475
476 ilObjPortfolio::setUserDefault($this->user_id);
477 ilUtil::sendSuccess($lng->txt("prtf_unset_default_share_info"), true);
478 }
479 $ilCtrl->redirect($this, "show");
480 }
481
485 protected function setDefaultConfirmation()
486 {
487 $ilCtrl = $this->ctrl;
490 $ilTabs = $this->tabs;
492
493 $prtf_id = (int) $_REQUEST["prt_id"];
494
495 if ($prtf_id && $this->checkAccess("write")) {
496 // if already shared, no need to ask again
497 if ($this->access_handler->hasRegisteredPermission($prtf_id) ||
498 $this->access_handler->hasGlobalPermission($prtf_id)) {
499 return $this->setDefault($prtf_id);
500 }
501
502 $ilTabs->clearTargets();
503 $ilTabs->setBackTarget(
504 $lng->txt("cancel"),
505 $ilCtrl->getLinkTarget($this, "show")
506 );
507
508 $ilCtrl->setParameter($this, "prt_id", $prtf_id);
509
510 // #20310
511 if (!$ilSetting->get("enable_global_profiles")) {
512 $ilCtrl->redirect($this, "setDefaultRegistered");
513 }
514
515 $cgui = new ilConfirmationGUI();
516 $cgui->setFormAction($ilCtrl->getFormAction($this));
517 $cgui->setHeaderText($lng->txt("prtf_set_default_publish_confirmation"));
518 $cgui->setCancel($lng->txt("prtf_set_default_publish_global"), "setDefaultGlobal");
519 $cgui->setConfirm($lng->txt("prtf_set_default_publish_registered"), "setDefaultRegistered");
520 $tpl->setContent($cgui->getHTML());
521
522 return;
523 }
524
525 $ilCtrl->redirect($this, "show");
526 }
527
528 protected function setDefaultGlobal()
529 {
530 $ilCtrl = $this->ctrl;
531
532 $prtf_id = (int) $_REQUEST["prt_id"];
533 if ($prtf_id && $this->checkAccess("write")) {
534 $this->access_handler->addPermission($prtf_id, ilWorkspaceAccessGUI::PERMISSION_ALL);
535 $this->setDefault($prtf_id);
536 }
537 $ilCtrl->redirect($this, "show");
538 }
539
540 protected function setDefaultRegistered()
541 {
542 $ilCtrl = $this->ctrl;
543
544 $prtf_id = (int) $_REQUEST["prt_id"];
545 if ($prtf_id && $this->checkAccess("write")) {
546 $this->access_handler->addPermission($prtf_id, ilWorkspaceAccessGUI::PERMISSION_REGISTERED);
547 $this->setDefault($prtf_id);
548 }
549 $ilCtrl->redirect($this, "show");
550 }
551
552 protected function setDefault($a_prtf_id)
553 {
554 $ilCtrl = $this->ctrl;
557
558 if ($a_prtf_id && $this->checkAccess("write")) {
559 // #12845
560 if ($this->access_handler->hasGlobalPermission($a_prtf_id)) {
561 $ilUser->setPref("public_profile", "g");
562 $ilUser->writePrefs();
563 } elseif ($this->access_handler->hasRegisteredPermission($a_prtf_id)) {
564 $ilUser->setPref("public_profile", "y");
565 $ilUser->writePrefs();
566 } else {
567 return;
568 }
569 ilObjPortfolio::setUserDefault($this->user_id, $a_prtf_id);
570 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
571 }
572 $ilCtrl->redirect($this, "show");
573 }
574
575
576 //
577 // SHARE
578 //
579
580 protected function showOtherFilter()
581 {
582 $this->showOther(false);
583 }
584
585 protected function showOther($a_load_data = true)
586 {
588 $ilTabs = $this->tabs;
589
590 $ilTabs->activateTab("otpf");
591
592 $tbl = new ilWorkspaceShareTableGUI($this, "showOther", $this->access_handler, null, $a_load_data);
593 $tpl->setContent($tbl->getHTML());
594 }
595
596 protected function applyShareFilter()
597 {
598 $tbl = new ilWorkspaceShareTableGUI($this, "showOther", $this->access_handler);
599 $tbl->resetOffset();
600 $tbl->writeFilterToSession();
601
602 $this->showOther();
603 }
604
605 protected function resetShareFilter()
606 {
607 $tbl = new ilWorkspaceShareTableGUI($this, "showOther", $this->access_handler);
608 $tbl->resetOffset();
609 $tbl->resetFilter();
610
611 $this->showOther();
612 }
613}
user()
Definition: user.php:4
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Confirmation screen class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstance()
Factory.
Portfolio view gui class.
static setUserDefault($a_user_id, $a_portfolio_id=null)
Set the user default portfolio.
static getPortfoliosOfUser($a_user_id)
Get views of user.
static _lookupOwner($a_id)
lookup object owner
static _lookupTitle($a_id)
lookup object title
Access handler for portfolio.
static checkExercise($a_user_id, $a_obj_id, $a_add_submit=false, $as_array=false)
Portfolio repository gui class.
setDefaultConfirmation()
Confirm sharing when setting default.
checkAccess($a_permission, $a_portfolio_id=null)
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
Workspace share handler table GUI class.
global $DIC
Definition: goto.php:24
help()
Definition: help.php:2
$ilUser
Definition: imgupload.php:18
global $ilSetting
Definition: privfeed.php:17
settings()
Definition: settings.php:2
ui()
Definition: ui.php:5