ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjDataCollection.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 public const TYPE = 'dcl';
24 private bool $is_online = false;
25 private bool $rating = false;
26 private bool $approval = false;
27 private bool $public_notes = false;
28 private bool $notification = false;
30
31 public function __construct(int $a_id = 0, bool $a_reference = true)
32 {
33 parent::__construct($a_id, $a_reference);
34 $this->notification_settings = new ilDclNotification($this->db);
35 }
36
37 protected function initType(): void
38 {
39 $this->type = $this::TYPE;
40 }
41
42 protected function doRead(): void
43 {
44 $stmt = $this->db->queryF('SELECT * FROM il_dcl_data WHERE id = %s', [ilDBConstants::T_INTEGER], [$this->getId()]);
45 if ($data = $this->db->fetchObject($stmt)) {
46 $this->setOnline((bool) $data->is_online);
47 $this->setRating((bool) $data->rating);
48 $this->setApproval((bool) $data->approval);
49 $this->setPublicNotes((bool) $data->public_notes);
50 $this->setNotification((bool) $data->notification);
51 }
52 }
53
54 protected function doCreate(bool $clone_mode = false): void
55 {
56 if (!$clone_mode) {
57 $main_table = ilDclCache::getTableCache();
58 $main_table->setObjId($this->getId());
59 $main_table->setTitle($this->getTitle());
60 $main_table->setAddPerm(true);
61 $main_table->setEditPerm(true);
62 $main_table->setDeletePerm(false);
63 $main_table->setDeleteByOwner(true);
64 $main_table->setEditByOwner(true);
65 $main_table->setLimited(false);
66 $main_table->setIsVisible(true);
67 $main_table->doCreate();
68 }
69 $this->createMetaData();
70 $this->db->insert(
71 'il_dcl_data',
72 [
73 'id' => [ilDBConstants::T_INTEGER, $this->getId()],
74 'is_online' => [ilDBConstants::T_INTEGER, $this->getOnline() ? 1 : 0],
75 'rating' => [ilDBConstants::T_INTEGER, $this->getRating() ? 1 : 0],
76 'public_notes' => [ilDBConstants::T_INTEGER, $this->getPublicNotes() ? 1 : 0],
77 'approval' => [ilDBConstants::T_INTEGER, $this->getApproval() ? 1 : 0],
78 'notification' => [ilDBConstants::T_INTEGER, $this->getNotification() ? 1 : 0],
79 ]
80 );
81 }
82
83 protected function doDelete(): void
84 {
85 foreach ($this->getTables() as $table) {
86 $table->doDelete(false, true);
87 }
88 $this->deleteMetaData();
89 $this->notification_settings->deleteForObject($this);
90 $this->db->manipulateF('DELETE FROM il_dcl_data WHERE id = %s', [ilDBConstants::T_INTEGER], [$this->getId()]);
91 }
92
93 protected function doUpdate(): void
94 {
95 $this->updateMetaData();
96 $this->db->update(
97 'il_dcl_data',
98 [
99 'id' => [ilDBConstants::T_INTEGER, $this->getId()],
100 'is_online' => [ilDBConstants::T_INTEGER, $this->getOnline() ? 1 : 0],
101 'rating' => [ilDBConstants::T_INTEGER, $this->getRating() ? 1 : 0],
102 'public_notes' => [ilDBConstants::T_INTEGER, $this->getPublicNotes() ? 1 : 0],
103 'approval' => [ilDBConstants::T_INTEGER, $this->getApproval() ? 1 : 0],
104 'notification' => [ilDBConstants::T_INTEGER, $this->getNotification() ? 1 : 0],
105 ],
106 [
107 'id' => [ilDBConstants::T_INTEGER, $this->getId()],
108 ]
109 );
110 }
111
113 {
114 if (!$this->getNotification()) {
115 return;
116 }
117
120 $this->getId(),
121 1
122 );
123
125
127 $mail->setType($action->value);
128 $mail->setActor($this->user->getId());
129 $mail->setObjId($this->getId());
130 $mail->setRefId($this->getRefId());
131 $mail->setRecord($record);
132 $mail->setSender(ANONYMOUS_USER_ID);
133
134 foreach ($users as $user_id) {
135 if (
136 $user_id !== $this->user->getId() &&
137 $record->getTable()->hasPermissionToViewRecord($this->getRefId(), $record, $user_id) &&
138 [] !== $record->getTable()->getVisibleTableViews($user_id) &&
139 $this->notification_settings->has($this, $user_id, $action)
140 ) {
141 $mail->addRecipient($user_id);
142 }
143 }
144
145 $mail->send();
146 }
147
148 protected function doCloneObject(ilObject2 $new_obj, int $a_target_id, ?int $a_copy_id = null): void
149 {
150 $new_obj->setNotification($this->getNotification());
151 if (!(ilCopyWizardOptions::_getInstance($a_copy_id))->isRootNode($this->getRefId())) {
152 $new_obj->setOnline($this->getOnline());
153 $new_obj->update();
154 }
155 $new_obj->cloneStructure($this->getRefId());
156 $this->cloneMetaData($new_obj);
157 }
158
159 public function cloneStructure(int $original_id): void
160 {
161 $original = new ilObjDataCollection($original_id);
162 $this->setApproval($original->getApproval());
163 $this->setNotification($original->getNotification());
164 $this->setPublicNotes($original->getPublicNotes());
165 $this->setRating($original->getRating());
166 foreach ($this->getTables() as $table) {
167 $table->doDelete();
168 }
169 foreach ($original->getTables() as $table) {
170 $new_table = new ilDclTable();
171 $new_table->setObjId($this->getId());
172 $new_table->cloneStructure($table);
173 }
175 foreach ($this->getTables() as $table) {
176 $table->afterClone();
177 }
178 }
179
180 public function setOnline(bool $a_val): void
181 {
182 $this->is_online = $a_val;
183 }
184
185 public function getOnline(): bool
186 {
187 return $this->is_online;
188 }
189
190 public function setRating(bool $a_val): void
191 {
192 $this->rating = $a_val;
193 }
194
195 public function getRating(): bool
196 {
197 return $this->rating;
198 }
199
200 public function setPublicNotes(bool $a_val): void
201 {
202 $this->public_notes = $a_val;
203 }
204
205 public function getPublicNotes(): bool
206 {
207 return $this->public_notes;
208 }
209
210 public function setApproval(bool $a_val): void
211 {
212 $this->approval = $a_val;
213 }
214
215 public function getApproval(): bool
216 {
217 return $this->approval;
218 }
219
220 public function setNotification(bool $a_val): void
221 {
222 $this->notification = $a_val;
223 }
224
225 public function getNotification(): bool
226 {
227 return $this->notification;
228 }
229
233 public function getTables(): array
234 {
235 $stmt = $this->db->queryF(
236 'SELECT id FROM il_dcl_table WHERE obj_id = %s ORDER BY table_order',
238 [$this->getId()]
239 );
240 $tables = [];
241 while ($rec = $this->db->fetchAssoc($stmt)) {
242 $tables[$rec['id']] = $this->getTableById($rec['id']);
243 }
244 return $tables;
245 }
246
247 public function getTableById(int $table_id): ilDclTable
248 {
249 return ilDclCache::getTableCache($table_id);
250 }
251
255 public function getVisibleTables(): array
256 {
257 $tables = [];
258 foreach ($this->getTables() as $table) {
259 if ($table->getIsVisible() && $table->getVisibleTableViews()) {
260 $tables[$table->getId()] = $table;
261 }
262 }
263 return $tables;
264 }
265
266 public function getStyleSheetId(): int
267 {
268 return 0;
269 }
270}
static _getInstance(int $a_copy_id)
static getTableCache(?int $table_id=null)
const TYPE_DATACOLLECTION
static setCloneOf(int $old, int $new, string $type)
static updateNotificationTime(int $type, int $id, array $user_ids, ?int $page_id=null, bool $activate_new_entries=true)
Update the last mail timestamp for given object and users.
static getNotificationsForObject(int $type, int $id, ?int $page_id=null, bool $ignore_threshold=false)
Get all users/recipients for given object.
__construct(int $a_id=0, bool $a_reference=true)
Constructor.
ilDclNotification $notification_settings
sendRecordNotification(ilDclNotificationType $action, ilDclBaseRecordModel $record)
doCreate(bool $clone_mode=false)
doCloneObject(ilObject2 $new_obj, int $a_target_id, ?int $a_copy_id=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
cloneMetaData(ilObject $target_obj)
Copy meta data.
const ANONYMOUS_USER_ID
Definition: constants.php:27
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc