ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
IliasDBEmployeeTalkSeriesRepository.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ilObjUser;
27
33{
36
43 {
44 $this->currentUser = $currentUser;
45 $this->database = $database;
46 }
47
51 public function findByOwnerAndEmployee(): array
52 {
53 $userId = $this->currentUser->getId();
54
55 //TODO: Alter table talks and store series id, which makes the
56 $result = $this->database->query("
57 SELECT DISTINCT od.obj_id AS objId, oRef.ref_id AS refId
58 FROM (
59 SELECT tree.parent AS parent, talk.employee AS employee
60 FROM etal_data AS talk
61 INNER JOIN object_reference AS oRef ON oRef.obj_id = talk.object_id
62 INNER JOIN tree ON tree.child = oRef.ref_id
63 WHERE oRef.deleted IS NULL
64 ) AS talk
65 INNER JOIN object_reference AS oRef ON oRef.ref_id = talk.parent
66 INNER JOIN object_data AS od ON od.obj_id = oRef.obj_id
67 WHERE od.type = 'tals' AND (talk.employee = " . $this->database->quote($userId, 'integer') .
68 " OR od.owner = " . $this->database->quote($userId, 'integer') .
69 ") AND oRef.deleted is null");
70
71 $talkSeries = [];
72 while ($row = $result->fetchObject()) {
73 $talkSeries[] = new ilObjEmployeeTalkSeries((int) $row->refId, true);
74 }
75
76 return $talkSeries;
77 }
78
80 {
81 if ($this->hasStoredSettings($settings_dto->getObjectId())) {
82 $this->database->update(
83 'etal_serie',
84 $this->getTableColumns($settings_dto),
85 ['id' => ['integer', $settings_dto->getObjectId()]]
86 );
87 return;
88 }
89 $this->database->insert(
90 'etal_serie',
91 $this->getTableColumns($settings_dto)
92 );
93 }
94
96 {
97 $res = $this->database->query(
98 'SELECT * FROM etal_serie WHERE id = ' . $this->database->quote($obj_id, 'integer')
99 );
100
101 $editing_locked = false;
102 while ($row = $res->fetchObject()) {
103 $editing_locked = (bool) $row->editing_locked;
104 }
105
106 return new EmployeeTalkSerieSettingsDto($obj_id, $editing_locked);
107 }
108
109 public function deleteEmployeeTalkSerieSettings(int $obj_id): void
110 {
111 $this->database->manipulate(
112 'DELETE FROM etal_serie WHERE id = ' . $this->database->quote($obj_id, 'integer')
113 );
114 }
115
116 protected function hasStoredSettings(int $obj_id): bool
117 {
118 $res = $this->database->query(
119 'SELECT COUNT(*) AS count FROM etal_serie WHERE id = ' .
120 $this->database->quote($obj_id, 'integer')
121 );
122
123 return $res->fetchObject()->count > 0;
124 }
125
126 protected function getTableColumns(EmployeeTalkSerieSettingsDto $settings_dto): array
127 {
128 return [
129 'id' => ['integer', $settings_dto->getObjectId()],
130 'editing_locked' => ['integer', (int) $settings_dto->isLockedEditing()],
131 ];
132 }
133}
__construct(ilObjUser $currentUser, ilDBInterface $database)
IliasDBEmployeeTalkSeriesRepository constructor.
User class.
Interface ilDBInterface.
$res
Definition: ltiservices.php:69