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