ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
4 require_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(),
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 }
getItems($object_type_white_list=array())
An optional array of object_types used for filter purposes array An array of repository items...
settings()
Definition: settings.php:2
static shortenText( $a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$objId
Definition: xapitoken.php:39
$refId
Definition: xapitoken.php:40
const IL_CAL_UNIX
repository()
Definition: repository.php:5
Class for single dates.
global $DIC
Definition: goto.php:24
getObjectsByMembership(array $objTypes=[])
Gets all objects the current user is member of.
const IL_CAL_DATE
Interface ilPDSelectedItemsBlockProvider.
__construct(ilObjUser $actor)
ilPDSelectedItemsBlockSelectedItemsProvider constructor.
const RECOVERY_FOLDER_ID
Definition: constants.php:35