ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
OwnershipManagementRetrieval.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
28 
30 {
31  use RetrievalBase;
32 
33  protected array $data = [];
34 
35  public function __construct(
36  protected InternalDomainService $domain,
37  protected int $user_id,
38  protected array $objects,
39  protected string $selected_type
40  ) {
41  $this->setData($this->objects, $this->selected_type);
42  }
43 
44  public function setData(array $objects, string $selected_type): void
45  {
46  $access = $this->domain->access();
47  $tree = $this->domain->repositoryTree();
48  $is_admin = false;
49  $a_type = '';
50 
51  if (!$this->user_id) {
52  $is_admin = $access->checkAccess('visible', '', SYSTEM_FOLDER_ID);
53  }
54 
55  $this->data = [];
56  if (empty($objects[$selected_type])) {
57  return;
58  }
59 
60  foreach ($objects[$selected_type] as $id => $item) {
62  if ($refs) {
63  foreach ($refs as $ref_id) {
64  if (!$tree->isDeleted($ref_id)) {
65  if ($this->user_id) {
66  $readable = $access->checkAccessOfUser(
67  $this->user_id,
68  'read',
69  '',
70  $ref_id,
71  $a_type
72  );
73  } else {
74  $readable = $is_admin;
75  }
76 
77  $this->data[] = [
78  'obj_id' => $id,
79  'ref_id' => $ref_id,
80  'id' => $ref_id,
81  'type' => \ilObject::_lookupType($id),
82  'title' => $item,
83  'path' => $this->buildPath($ref_id),
84  'readable' => $readable
85  ];
86  }
87  }
88  }
89  }
90  }
91 
92  public function isFieldNumeric(string $field): bool
93  {
94  return in_array($field, ['id', 'obj_id', 'ref_id']);
95  }
96 
97 
98  protected function buildPath(int $ref_id): string
99  {
100  $tree = $this->domain->repositoryTree();
101  $path = '...';
102  $counter = 0;
103  $path_full = $tree->getPathFull($ref_id);
104  foreach ($path_full as $data) {
105  if (++$counter < (count($path_full) - 2)) {
106  continue;
107  }
108  if ($ref_id != $data['ref_id']) {
109  $path .= ' &raquo; ' . $data['title'];
110  }
111  }
112 
113  return $path;
114  }
115 
116  public function getData(
117  array $fields,
118  ?Range $range = null,
119  ?Order $order = null,
120  array $filter = [],
121  array $parameters = []
122  ): \Generator {
123  $data = $this->data;
124 
125  $data = $this->applyOrder($data, $order);
126  $data = $this->applyRange($data, $range);
127 
128  foreach ($data as $row) {
129  yield $row;
130  }
131  }
132 
133  public function count(array $filter, array $parameters): int
134  {
135  return count($this->data);
136  }
137 }
getData(array $fields, ?Range $range=null, ?Order $order=null, array $filter=[], array $parameters=[])
static _getAllReferences(int $id)
get all reference ids for object ID
const SYSTEM_FOLDER_ID
Definition: constants.php:35
__construct(protected InternalDomainService $domain, protected int $user_id, protected array $objects, protected string $selected_type)
$path
Definition: ltiservices.php:29
Both the subject and the direction need to be specified when expressing an order. ...
Definition: Order.php:28
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$ref_id
Definition: ltiauth.php:65
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static _lookupType(int $id, bool $reference=false)
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:28