ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilPDSelectedItemsBlockMembershipsProvider.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 protected readonly ilTree $tree;
24 protected readonly ilAccessHandler $access;
25 protected readonly ilSetting $settings;
27
28 public function __construct(protected readonly ilObjUser $actor)
29 {
30 global $DIC;
31
32 $this->tree = $DIC->repositoryTree();
33 $this->access = $DIC->access();
34 $this->settings = $DIC->settings();
36 $DIC->database(),
38 );
39 }
40
41 protected function getObjectsByMembership(array $objTypes = []): array
42 {
43 $short_desc = $this->settings->get('rep_shorten_description');
44 $short_desc_max_length = (int) $this->settings->get('rep_shorten_description_length');
45
46 if (!is_array($objTypes) || $objTypes === []) {
47 $objTypes = $this->repository->getValidObjectTypes();
48 }
49
50 $references = [];
51 foreach ($this->repository->getForUser($this->actor, $objTypes, $this->actor->getLanguage()) as $item) {
52 $refId = $item->getRefId();
53 $objId = $item->getObjId();
54 $parentRefId = $item->getParentRefId();
55 $title = $item->getTitle();
56 $parentTreeLftValue = $item->getParentLftTree();
57 $parentTreeLftValue = sprintf('%010d', $parentTreeLftValue);
58
59 if (!$this->access->checkAccess('visible', '', $refId)) {
60 continue;
61 }
62
63 $periodStart = $periodEnd = null;
64 if ($item->getPeriodStart() !== null && $item->getPeriodEnd() !== null) {
65 if ($item->objectPeriodHasTime()) {
66 $periodStart = new ilDateTime($item->getPeriodStart()->getTimestamp(), IL_CAL_UNIX);
67 $periodEnd = new ilDateTime($item->getPeriodEnd()->getTimestamp(), IL_CAL_UNIX);
68 } else {
69 $periodStart = new ilDate($item->getPeriodStart()->format('Y-m-d'), IL_CAL_DATE);
70 $periodEnd = new ilDate($item->getPeriodEnd()->format('Y-m-d'), IL_CAL_DATE);
71 }
72 }
73
74 $description = $item->getDescription();
75 if ($short_desc && $short_desc_max_length !== 0) {
76 $description = ilStr::shortenTextExtended($description, $short_desc_max_length, true);
77 }
78
79 $references[$parentTreeLftValue . $title . $refId] = [
80 'ref_id' => $refId,
81 'obj_id' => $objId,
82 'type' => $item->getType(),
83 'title' => $title,
84 'description' => $description,
85 'parent_ref' => $parentRefId,
86 'start' => $periodStart,
87 'end' => $periodEnd
88 ];
89 }
90
91 return $references;
92 }
93
94 public function getItems(array $object_type_white_list = []): array
95 {
96 return $this->getObjectsByMembership($object_type_white_list);
97 }
98}
const IL_CAL_DATE
const IL_CAL_UNIX
@classDescription Date and time handling
Class for single dates.
User class.
readonly ilPDSelectedItemsBlockMembershipsObjectRepository $repository
ILIAS Setting Class.
static shortenTextExtended(string $a_str, int $a_len, bool $a_dots=false, bool $a_next_blank=false, bool $a_keep_extension=false)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
const RECOVERY_FOLDER_ID
Definition: constants.php:37
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
global $DIC
Definition: shib_login.php:26
$objId
Definition: xapitoken.php:55
$refId
Definition: xapitoken.php:56