ILIAS  release_8 Revision v8.24
class.ilObjDataCollection.php
Go to the documentation of this file.
1<?php
2
20{
21 private bool $is_online = false;
22 private string $rating = "";
23 private string $approval = "";
24 private string $public_notes = "";
25 private string $notification = "";
26
27 protected function initType(): void
28 {
29 $this->type = "dcl";
30 }
31
32 protected function doRead(): void
33 {
34 global $DIC;
35 $ilDB = $DIC['ilDB'];
36
37 $result = $ilDB->query("SELECT * FROM il_dcl_data WHERE id = " . $ilDB->quote($this->getId(), "integer"));
38
39 $data = $ilDB->fetchObject($result);
40 if ($data) {
41 $this->setOnline($data->is_online);
42 $this->setRating($data->rating);
43 $this->setApproval($data->approval);
44 $this->setPublicNotes($data->public_notes);
45 $this->setNotification($data->notification);
46 }
47 }
48
49 protected function doCreate(bool $clone_mode = false): void
50 {
51 global $DIC;
52 $ilDB = $DIC['ilDB'];
53 $ilLog = $DIC['ilLog'];
54
55 $ilLog->write('doCreate');
56
57 if (!$clone_mode) {
58 //Create Main Table - The title of the table is per default the title of the data collection object
59 $main_table = ilDclCache::getTableCache();
60 $main_table->setObjId($this->getId());
61 $main_table->setTitle($this->getTitle());
62 $main_table->setAddPerm(1);
63 $main_table->setEditPerm(1);
64 $main_table->setDeletePerm(0);
65 $main_table->setDeleteByOwner(1);
66 $main_table->setEditByOwner(1);
67 $main_table->setLimited(0);
68 $main_table->setIsVisible(true);
69 $main_table->doCreate();
70 }
71
72 $ilDB->insert(
73 "il_dcl_data",
74 array(
75 "id" => array("integer", $this->getId()),
76 "is_online" => array("integer", (int) $this->getOnline()),
77 "rating" => array("integer", (int) $this->getRating()),
78 "public_notes" => array("integer", (int) $this->getPublicNotes()),
79 "approval" => array("integer", (int) $this->getApproval()),
80 "notification" => array("integer", (int) $this->getNotification()),
81 )
82 );
83 }
84
85 protected function doDelete(): void
86 {
87 global $DIC;
88 $ilDB = $DIC['ilDB'];
89
90 foreach ($this->getTables() as $table) {
91 $table->doDelete(false, true);
92 }
93
94 $query = "DELETE FROM il_dcl_data WHERE id = " . $ilDB->quote($this->getId(), "integer");
95 $ilDB->manipulate($query);
96 }
97
98 protected function doUpdate(): void
99 {
100 global $DIC;
101 $ilDB = $DIC['ilDB'];
102
103 $ilDB->update(
104 "il_dcl_data",
105 array(
106 "id" => array("integer", $this->getId()),
107 "is_online" => array("integer", (int) $this->getOnline()),
108 "rating" => array("integer", (int) $this->getRating()),
109 "public_notes" => array("integer", (int) $this->getPublicNotes()),
110 "approval" => array("integer", (int) $this->getApproval()),
111 "notification" => array("integer", (int) $this->getNotification()),
112 ),
113 array(
114 "id" => array("integer", $this->getId()),
115 )
116 );
117 }
118
124 public function sendNotification($a_action, $a_table_id, $a_record_id = null)
125 {
126 global $DIC;
127 $ilUser = $DIC->user();
128
129 // If coming from trash, never send notifications and don't load dcl Object
130 if ($this->getRefId() === SYSTEM_FOLDER_ID) {
131 return;
132 }
133
134 if ($this->getNotification() != 1) {
135 return;
136 }
137 $obj_table = ilDclCache::getTableCache($a_table_id);
138
139 // recipients
142 $this->getId(),
143 true
144 );
145 if (!count($users)) {
146 return;
147 }
148
150
151 $link = ilLink::_getLink($this->getRefId());
152
153 // prepare mail content
154 // use language of recipient to compose message
155
156 // send mails
157 foreach (array_unique($users) as $idx => $user_id) {
158 // the user responsible for the action should not be notified
159 $record = ilDclCache::getRecordCache($a_record_id);
160 $ilDclTable = new ilDclTable($record->getTableId());
161 if ($user_id != $ilUser->getId() && $ilDclTable->hasPermissionToViewRecord(filter_input(
162 INPUT_GET,
163 'ref_id'
164 ), $record, $user_id)) {
165 // use language of recipient to compose message
167 $ulng->loadLanguageModule('dcl');
168
169 $subject = sprintf($ulng->txt('dcl_change_notification_subject'), $this->getTitle());
170 // update/delete
171 $message = $ulng->txt("dcl_hello") . " " . ilObjUser::_lookupFullname($user_id) . ",\n\n";
172 $message .= $ulng->txt('dcl_change_notification_dcl_' . $a_action) . ":\n\n";
173 $message .= $ulng->txt('obj_dcl') . ": " . $this->getTitle() . "\n\n";
174 $message .= $ulng->txt('dcl_table') . ": " . $obj_table->getTitle() . "\n\n";
175 $message .= $ulng->txt('dcl_record') . ":\n";
176 $message .= "------------------------------------\n";
177 if ($a_record_id) {
178 if (!$record->getTableId()) {
179 $record->setTableId($a_table_id);
180 }
181 // $message .= $ulng->txt('dcl_record_id').": ".$a_record_id.":\n";
182 $t = "";
183
184 if ($tableview_id = $record->getTable()->getFirstTableViewId($this->getRefId(), $user_id)) {
185 $visible_fields = ilDclTableView::find($tableview_id)->getVisibleFields();
186 if (empty($visible_fields)) {
187 continue;
188 }
190 foreach ($visible_fields as $field) {
191 if ($field->isStandardField()) {
192 $value = $record->getStandardFieldPlainText($field->getId());
193 } elseif ($record_field = $record->getRecordField($field->getId())) {
194 $value = $record_field->getPlainText();
195 }
196
197 if ($value) {
198 $t .= $field->getTitle() . ": " . $value . "\n";
199 }
200 }
201 }
202 $message .= $this->prepareMessageText($t);
203 }
204 $message .= "------------------------------------\n";
205 $message .= $ulng->txt('dcl_changed_by') . ": " . ilUserUtil::getNamePresentation($ilUser->getId())
206 . "\n\n";
207 $message .= $ulng->txt('dcl_change_notification_link') . ": " . $link . "\n\n";
208
209 $message .= $ulng->txt('dcl_change_why_you_receive_this_email');
210
211 $mail_obj = new ilMail(ANONYMOUS_USER_ID);
212 $mail_obj->appendInstallationSignature(true);
213 $mail_obj->enqueue(ilObjUser::_lookupLogin($user_id), "", "", $subject, $message, array());
214 } else {
215 unset($users[$idx]);
216 }
217 }
218 }
219
224 public function getFirstVisibleTableId(): int
225 {
226 global $DIC;
228 $ilDB = $DIC['ilDB'];
229 $ilDB->setLimit(1);
230 $only_visible = ilObjDataCollectionAccess::hasWriteAccess($this->ref_id) ? '' : ' AND is_visible = 1 ';
231 $result = $ilDB->query(
232 'SELECT id FROM il_dcl_table
233 WHERE obj_id = ' . $ilDB->quote($this->getId(), 'integer') .
234 $only_visible . ' ORDER BY -table_order DESC'
235 ); //"-table_order DESC" is ASC with NULL last
236
237 // if there's no visible table, fetch first one not visible
238 // this is to avoid confusion, since the default of a table after creation is not visible
239 if (!$result->numRows() && $only_visible) {
240 $ilDB->setLimit(1);
241 $result = $ilDB->query(
242 'SELECT id FROM il_dcl_table
243 WHERE obj_id = ' . $ilDB->quote($this->getId(), 'integer') . ' ORDER BY -table_order DESC '
244 );
245 }
246
247 return $ilDB->fetchObject($result)->id;
248 }
249
250 public function reorderTables(array $table_order): void
251 {
252 if ($table_order) {
253 $order = 10;
254 foreach ($table_order as $title) {
255 $table_id = ilDclTable::_getTableIdByTitle($title, $this->getId());
256 $table = ilDclCache::getTableCache($table_id);
257 $table->setOrder($order);
258 $table->doUpdate();
259 $order += 10;
260 }
261 }
262 }
263
271 protected function doCloneObject(ilObject2 $new_obj, int $a_target_id, ?int $a_copy_id = null): void
272 {
273 assert($new_obj instanceof ilObjDataCollection);
274 //copy online status if object is not the root copy object
275 $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
276
277 if (!$cp_options->isRootNode($this->getRefId())) {
278 $new_obj->setOnline(true);
279 }
280
281 $new_obj->cloneStructure($this->getRefId());
282 }
283
288 public function cloneStructure(int $original_id): void
289 {
290 $original = new ilObjDataCollection($original_id);
291
292 $this->setApproval($original->getApproval());
293 $this->setNotification($original->getNotification());
294 $this->setPublicNotes($original->getPublicNotes());
295 $this->setRating($original->getRating());
296
297 // delete old tables.
298 foreach ($this->getTables() as $table) {
299 $table->doDelete();
300 }
301
302 // add new tables.
303 foreach ($original->getTables() as $table) {
304 $new_table = new ilDclTable();
305 $new_table->setObjId($this->getId());
306 $new_table->cloneStructure($table);
307 }
308
309 // mandatory for all cloning functions
311
312 foreach ($this->getTables() as $table) {
313 $table->afterClone();
314 }
315 }
316
320 public function setOnline($a_val): void
321 {
322 $this->is_online = $a_val;
323 }
324
328 public function getOnline(): bool
329 {
330 return $this->is_online;
331 }
332
333 public function setRating(string $a_val): void
334 {
335 $this->rating = $a_val;
336 }
337
338 public function getRating(): string
339 {
340 return $this->rating;
341 }
342
343 public function setPublicNotes(string $a_val)
344 {
345 $this->public_notes = $a_val;
346 }
347
348 public function getPublicNotes(): string
349 {
350 return $this->public_notes;
351 }
352
353 public function setApproval(string $a_val): void
354 {
355 $this->approval = $a_val;
356 }
357
358 public function getApproval(): string
359 {
360 return $this->approval;
361 }
362
363 public function setNotification(string $a_val): void
364 {
365 $this->notification = $a_val;
366 }
367
368 public function getNotification(): string
369 {
370 return $this->notification;
371 }
372
378 public static function _hasWriteAccess(int $ref): bool
379 {
381 }
382
388 public static function _hasReadAccess(int $ref): bool
389 {
391 }
392
396 public function getTables(): array
397 {
398 global $DIC;
399 $ilDB = $DIC['ilDB'];
400
401 $query = "SELECT id FROM il_dcl_table WHERE obj_id = " . $ilDB->quote($this->getId(), "integer") .
402 " ORDER BY -table_order DESC";
403 $set = $ilDB->query($query);
404 $tables = array();
405
406 while ($rec = $ilDB->fetchAssoc($set)) {
407 $tables[$rec['id']] = ilDclCache::getTableCache($rec['id']);
408 }
409
410 return $tables;
411 }
412
413 public function getTableById(int $table_id): ilDclTable
414 {
415 return ilDclCache::getTableCache($table_id);
416 }
417
418 public function getVisibleTables(): array
419 {
420 $tables = array();
421 foreach ($this->getTables() as $table) {
422 if ($table->getIsVisible() && $table->getVisibleTableViews($this->ref_id)) {
423 $tables[$table->getId()] = $table;
424 }
425 }
426
427 return $tables;
428 }
429
436 public static function _hasTableByTitle(string $title, int $obj_id): bool
437 {
438 global $DIC;
439 $ilDB = $DIC['ilDB'];
440 $result = $ilDB->query(
441 'SELECT * FROM il_dcl_table WHERE obj_id = ' . $ilDB->quote($obj_id, 'integer') . ' AND title = '
442 . $ilDB->quote($title, 'text')
443 );
444
445 return ($ilDB->numRows($result)) ? true : false;
446 }
447
448 public function getStyleSheetId(): int
449 {
450 return 0;
451 }
452
453 public function prepareMessageText(string $body): string
454 {
455 if (preg_match_all('/<.*?br.*?>/', $body, $matches)) {
456 $matches = array_unique($matches[0]);
457 $brNewLineMatches = array_map(static function ($match): string {
458 return $match . "\n";
459 }, $matches);
460
461 //Remove carriage return to guarantee all new line can be properly found
462 $body = str_replace("\r", '', $body);
463 //Replace occurrence of <br> + \n with a single \n
464 $body = str_replace($brNewLineMatches, "\n", $body);
465 //Replace additional <br> with a \”
466 $body = str_replace($matches, "\n", $body);
467 //Revert removal of carriage return
468 return str_replace("\n", "\r\n", $body);
469 }
470 return $body;
471 }
472}
return true
static _getInstance(int $a_copy_id)
static getRecordCache(?int $record_id)
const TYPE_DATACOLLECTION
static getTableCache(int $table_id=null)
static setCloneOf(int $old, int $new, string $type)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getTableIdByTitle(string $title, int $obj_id)
static _getLanguageOfUser(int $a_usr_id)
Get language object of user.
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.
static hasWriteAccess(int $ref, ?int $user_id=0)
static hasReadAccess(int $ref, ?int $user_id=0)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _hasTableByTitle(string $title, int $obj_id)
Checks if a DataCollection has a table with a given title.
doCreate(bool $clone_mode=false)
reorderTables(array $table_order)
cloneStructure(int $original_id)
Attention only use this for objects who have not yet been created (use like: $x = new ilObjDataCollec...
doCloneObject(ilObject2 $new_obj, int $a_target_id, ?int $a_copy_id=null)
Clone DCL.
static _lookupFullname(int $a_user_id)
static _lookupLogin(int $a_user_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
string $title
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link="", bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
const ANONYMOUS_USER_ID
Definition: constants.php:27
const SYSTEM_FOLDER_ID
Definition: constants.php:35
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
$query
$message
Definition: xapiexit.php:32