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