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