ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilPDSelectedItemsBlockMembershipsObjectDatabaseRepository.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
23  private const VALID_OBJECT_TYPES = [
24  'crs',
25  'grp',
26  ];
27 
28  private ilDBInterface $db;
29  private int $recoveryFolderId;
30 
31  public function __construct(ilDBInterface $db, int $recoveryFolderId)
32  {
33  $this->db = $db;
34  $this->recoveryFolderId = $recoveryFolderId;
35  }
36 
40  public function getValidObjectTypes(): array
41  {
42  return self::VALID_OBJECT_TYPES;
43  }
44 
45  public function getForUser(ilObjUser $user, array $objTypes, string $actorLanguageCode): Generator
46  {
47  $objTypes = array_intersect($objTypes, self::VALID_OBJECT_TYPES);
48  if ($objTypes === []) {
49  return;
50  }
51 
52  $odObjTypes = ' AND ' . $this->db->in(
53  'od.type',
54  $objTypes,
55  false,
57  );
58 
59  $res = $this->db->queryF(
60  "
61  SELECT DISTINCT
62  od.obj_id,
63  objr.ref_id,
64  (
65  CASE
66  WHEN (trans.title IS NOT NULL AND trans.title != '')
67  THEN trans.title
68  ELSE od.title
69  END
70  ) title,
71  (
72  CASE
73  WHEN (trans.description IS NOT NULL AND trans.description != '')
74  THEN trans.description
75  ELSE od.description
76  END
77  ) description,
78  od.type,
79  t.parent,
80  tp.lft parent_lft,
81  (
82  CASE
83  WHEN od.type = 'crs' THEN crs_settings.period_start
84  ELSE grp_settings.period_start
85  END
86  ) period_start,
87  (
88  CASE
89  WHEN od.type = 'crs' THEN crs_settings.period_end
90  ELSE grp_settings.period_end
91  END
92  ) period_end,
93  (
94  CASE
95  WHEN od.type = 'crs' THEN crs_settings.period_time_indication
96  ELSE grp_settings.period_time_indication
97  END
98  ) period_has_time
99  FROM rbac_ua ua
100  INNER JOIN rbac_fa fa ON fa.rol_id = ua.rol_id AND fa.assign = %s
101  INNER JOIN object_reference objr ON objr.ref_id = fa.parent
102  INNER JOIN object_data od ON od.obj_id = objr.obj_id $odObjTypes
103  INNER JOIN tree t ON t.child = objr.ref_id AND t.tree = %s AND t.parent != %s
104  INNER JOIN tree tp ON tp.child = t.parent
105  LEFT JOIN grp_settings ON grp_settings.obj_id = od.obj_id
106  LEFT JOIN crs_settings ON crs_settings.obj_id = od.obj_id
107  LEFT JOIN object_translation trans ON trans.obj_id = od.obj_id AND trans.lang_code = %s
108  WHERE ua.usr_id = %s
109  ",
111  ['y', 1, $this->recoveryFolderId, $actorLanguageCode, $user->getId()]
112  );
113 
114  while ($row = $this->db->fetchAssoc($res)) {
115  $periodStart = null;
116  if (!is_null($row['period_start'])) {
117  $periodStart = new DateTimeImmutable($row['period_start'], new DateTimeZone('UTC'));
118  }
119  $periodEnd = null;
120  if (!is_null($row['period_end'])) {
121  $periodEnd = new DateTimeImmutable($row['period_end'], new DateTimeZone('UTC'));
122  }
123 
125  (int) $row['ref_id'],
126  (int) $row['obj_id'],
127  (string) $row['type'],
128  (string) $row['title'],
129  (string) $row['description'],
130  (int) $row['parent'],
131  (int) $row['parent_lft'],
132  (bool) $row['period_has_time'],
133  $periodStart,
134  $periodEnd
135  );
136  }
137  }
138 }
$res
Definition: ltiservices.php:66
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null