ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilPDSelectedItemsBlockMembershipsProvider.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2017 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/Membership/classes/class.ilParticipants.php';
5
10{
14 protected $actor;
15
19 protected $tree;
20
24 protected $access;
25
29 protected $settings;
30
32 private $repository;
33
38 public function __construct(ilObjUser $actor)
39 {
40 global $DIC;
41
42 $this->actor = $actor;
43 $this->tree = $DIC->repositoryTree();
44 $this->access = $DIC->access();
45 $this->settings = $DIC->settings();
47 $DIC->database(),
48 RECOVERY_FOLDER_ID
49 );
50 }
51
57 protected function getObjectsByMembership(array $objTypes = []) : array
58 {
59 $short_desc = $this->settings->get("rep_shorten_description");
60 $short_desc_max_length = $this->settings->get("rep_shorten_description_length");
61
62 if (!is_array($objTypes) || $objTypes === []) {
63 $objTypes = $this->repository->getValidObjectTypes();
64 }
65
66 $references = [];
67 foreach ($this->repository->getForUser($this->actor, $objTypes, $this->actor->getLanguage()) as $item) {
68 $refId = $item->getRefId();
69 $objId = $item->getObjId();
70 $parentRefId = $item->getParentRefId();
71 $title = $item->getTitle();
72 $parentTreeLftValue = $item->getParentLftTree();
73 $parentTreeLftValue = sprintf("%010d", $parentTreeLftValue);
74
75 if (!$this->access->checkAccess('visible', '', $refId)) {
76 continue;
77 }
78
79 $periodStart = $periodEnd = null;
80 if ($item->getPeriodStart() !== null && $item->getPeriodEnd() !== null) {
81 if ($item->objectPeriodHasTime()) {
82 $periodStart = new ilDateTime($item->getPeriodStart()->getTimestamp(), IL_CAL_UNIX);
83 $periodEnd = new ilDateTime($item->getPeriodEnd()->getTimestamp(), IL_CAL_UNIX);
84 } else {
85 $periodStart = new ilDate($item->getPeriodStart()->format('Y-m-d'), IL_CAL_DATE);
86 $periodEnd = new ilDate($item->getPeriodEnd()->format('Y-m-d'), IL_CAL_DATE);
87 }
88 }
89
90 $description = $item->getDescription();
91 if ($short_desc && $short_desc_max_length) {
92 $description = ilUtil::shortenText($description, $short_desc_max_length, true);
93 }
94
95 $references[$parentTreeLftValue . $title . $refId] = [
96 'ref_id' => $refId,
97 'obj_id' => $objId,
98 'type' => $item->getType(),
99 'title' => $title,
100 'description' => $description,
101 'parent_ref' => $parentRefId,
102 'start' => $periodStart,
103 'end' => $periodEnd
104 ];
105 }
106 ksort($references);
107
108 return $references;
109 }
110
114 public function getItems($object_type_white_list = array())
115 {
116 return $this->getObjectsByMembership($object_type_white_list);
117 }
118}
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATE
const IL_CAL_UNIX
@classDescription Date and time handling
Class for single dates.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilObjUser $actor)
ilPDSelectedItemsBlockSelectedItemsProvider constructor.
getItems($object_type_white_list=array())
array An array of repository items, each given as a structured array
getObjectsByMembership(array $objTypes=[])
Gets all objects the current user is member of.
static shortenText( $a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
Interface ilPDSelectedItemsBlockProvider.
repository()
Definition: repository.php:5
settings()
Definition: settings.php:2
$DIC
Definition: xapitoken.php:46
$objId
Definition: xapitoken.php:41
$refId
Definition: xapitoken.php:42