ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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->db->manipulateF('DELETE FROM il_dcl_data WHERE id = %s', [ilDBConstants::T_INTEGER], [$this->getId()]);
82  }
83 
84  protected function doUpdate(): void
85  {
86  $this->db->update(
87  'il_dcl_data',
88  [
89  'id' => [ilDBConstants::T_INTEGER, $this->getId()],
90  'is_online' => [ilDBConstants::T_INTEGER, $this->getOnline() ? 1 : 0],
91  'rating' => [ilDBConstants::T_INTEGER, $this->getRating() ? 1 : 0],
92  'public_notes' => [ilDBConstants::T_INTEGER, $this->getPublicNotes() ? 1 : 0],
93  'approval' => [ilDBConstants::T_INTEGER, $this->getApproval() ? 1 : 0],
94  'notification' => [ilDBConstants::T_INTEGER, $this->getNotification() ? 1 : 0],
95  ],
96  [
97  'id' => [ilDBConstants::T_INTEGER, $this->getId()],
98  ]
99  );
100  }
101 
102  public function sendRecordNotification(int $action, ilDclBaseRecordModel $record): void
103  {
104  if (!$this->getNotification()) {
105  return;
106  }
107 
110  $this->getId(),
111  1
112  );
113 
115 
116  $mail = new ilDataCollectionMailNotification();
117  $mail->setType($action);
118  $mail->setActor($this->user->getId());
119  $mail->setObjId($this->getId());
120  $mail->setRefId($this->getRefId());
121  $mail->setRecord($record);
122  $mail->setSender(ANONYMOUS_USER_ID);
123 
124  foreach ($users as $user_id) {
125  if (
126  $user_id !== $this->user->getId() &&
127  $record->getTable()->hasPermissionToViewRecord($this->getRefId(), $record, $user_id) &&
128  [] !== $record->getTable()->getVisibleTableViews($user_id)
129  ) {
130  $mail->addRecipient($user_id);
131  }
132  }
133 
134  $mail->send();
135  }
136 
137  protected function doCloneObject(ilObject2 $new_obj, int $a_target_id, ?int $a_copy_id = null): void
138  {
139  $new_obj->setNotification($this->getNotification());
140  if (!(ilCopyWizardOptions::_getInstance($a_copy_id))->isRootNode($this->getRefId())) {
141  $new_obj->setOnline($this->getOnline());
142  $new_obj->update();
143  }
144  $new_obj->cloneStructure($this->getRefId());
145  }
146 
147  public function cloneStructure(int $original_id): void
148  {
149  $original = new ilObjDataCollection($original_id);
150  $this->setApproval($original->getApproval());
151  $this->setNotification($original->getNotification());
152  $this->setPublicNotes($original->getPublicNotes());
153  $this->setRating($original->getRating());
154  foreach ($this->getTables() as $table) {
155  $table->doDelete();
156  }
157  foreach ($original->getTables() as $table) {
158  $new_table = new ilDclTable();
159  $new_table->setObjId($this->getId());
160  $new_table->cloneStructure($table);
161  }
163  foreach ($this->getTables() as $table) {
164  $table->afterClone();
165  }
166  }
167 
168  public function setOnline(bool $a_val): void
169  {
170  $this->is_online = $a_val;
171  }
172 
173  public function getOnline(): bool
174  {
175  return $this->is_online;
176  }
177 
178  public function setRating(bool $a_val): void
179  {
180  $this->rating = $a_val;
181  }
182 
183  public function getRating(): bool
184  {
185  return $this->rating;
186  }
187 
188  public function setPublicNotes(bool $a_val): void
189  {
190  $this->public_notes = $a_val;
191  }
192 
193  public function getPublicNotes(): bool
194  {
195  return $this->public_notes;
196  }
197 
198  public function setApproval(bool $a_val): void
199  {
200  $this->approval = $a_val;
201  }
202 
203  public function getApproval(): bool
204  {
205  return $this->approval;
206  }
207 
208  public function setNotification(bool $a_val): void
209  {
210  $this->notification = $a_val;
211  }
212 
213  public function getNotification(): bool
214  {
215  return $this->notification;
216  }
217 
221  public function getTables(): array
222  {
223  $stmt = $this->db->queryF(
224  'SELECT id FROM il_dcl_table WHERE obj_id = %s ORDER BY table_order',
226  [$this->getId()]
227  );
228  $tables = [];
229  while ($rec = $this->db->fetchAssoc($stmt)) {
230  $tables[$rec['id']] = $this->getTableById($rec['id']);
231  }
232  return $tables;
233  }
234 
235  public function getTableById(int $table_id): ilDclTable
236  {
237  return ilDclCache::getTableCache($table_id);
238  }
239 
243  public function getVisibleTables(): array
244  {
245  $tables = [];
246  foreach ($this->getTables() as $table) {
247  if ($table->getIsVisible() && $table->getVisibleTableViews()) {
248  $tables[$table->getId()] = $table;
249  }
250  }
251  return $tables;
252  }
253 
254  public function getStyleSheetId(): int
255  {
256  return 0;
257  }
258 }
const TYPE_DATACOLLECTION
sendRecordNotification(int $action, ilDclBaseRecordModel $record)
const ANONYMOUS_USER_ID
Definition: constants.php:27
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.
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)