ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilObjDataCollection.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4
16{
17 public function initType()
18 {
19 $this->type = "dcl";
20 }
21
22
23 public function doRead()
24 {
25 global $DIC;
26 $ilDB = $DIC['ilDB'];
27
28 $result = $ilDB->query("SELECT * FROM il_dcl_data WHERE id = " . $ilDB->quote($this->getId(), "integer"));
29
30 $data = $ilDB->fetchObject($result);
31 $this->setOnline($data->is_online);
32 $this->setRating($data->rating);
33 $this->setApproval($data->approval);
34 $this->setPublicNotes($data->public_notes);
35 $this->setNotification($data->notification);
36 }
37
38
39 protected function doCreate($clone_mode = false)
40 {
41 global $DIC;
42 $ilDB = $DIC['ilDB'];
43 $ilLog = $DIC['ilLog'];
44
45 $ilLog->write('doCreate');
46
47 if (!$clone_mode) {
48 //Create Main Table - The title of the table is per default the title of the data collection object
49 $main_table = ilDclCache::getTableCache();
50 $main_table->setObjId($this->getId());
51 $main_table->setTitle($this->getTitle());
52 $main_table->setAddPerm(1);
53 $main_table->setEditPerm(1);
54 $main_table->setDeletePerm(0);
55 $main_table->setDeleteByOwner(1);
56 $main_table->setEditByOwner(1);
57 $main_table->setLimited(0);
58 $main_table->setIsVisible(true);
59 $main_table->doCreate();
60 }
61
62 $ilDB->insert(
63 "il_dcl_data",
64 array(
65 "id" => array("integer", $this->getId()),
66 "is_online" => array("integer", (int) $this->getOnline()),
67 "rating" => array("integer", (int) $this->getRating()),
68 "public_notes" => array("integer", (int) $this->getPublicNotes()),
69 "approval" => array("integer", (int) $this->getApproval()),
70 "notification" => array("integer", (int) $this->getNotification()),
71 )
72 );
73 }
74
75
79 public function doClone()
80 {
81 return false;
82 }
83
84
85 protected function doDelete()
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
99 public function doUpdate()
100 {
101 global $DIC;
102 $ilDB = $DIC['ilDB'];
103
104 $ilDB->update(
105 "il_dcl_data",
106 array(
107 "id" => array("integer", $this->getId()),
108 "is_online" => array("integer", (int) $this->getOnline()),
109 "rating" => array("integer", (int) $this->getRating()),
110 "public_notes" => array("integer", (int) $this->getPublicNotes()),
111 "approval" => array("integer", (int) $this->getApproval()),
112 "notification" => array("integer", (int) $this->getNotification()),
113 ),
114 array(
115 "id" => array("integer", $this->getId()),
116 )
117 );
118 }
119
120
126 public static function sendNotification($a_action, $a_table_id, $a_record_id = null)
127 {
128 global $DIC;
129 $ilUser = $DIC['ilUser'];
130 $ilAccess = $DIC['ilAccess'];
131
132 // If coming from trash, never send notifications and don't load dcl Object
133 if ($_GET['ref_id'] == SYSTEM_FOLDER_ID) {
134 return;
135 }
136
137 $dclObj = new ilObjDataCollection($_GET['ref_id']);
138
139 if ($dclObj->getNotification() != 1) {
140 return;
141 }
142 $obj_table = ilDclCache::getTableCache($a_table_id);
143 $obj_dcl = $obj_table->getCollectionObject();
144
145 // recipients
147 if (!sizeof($users)) {
148 return;
149 }
150
152
153 //FIXME $_GET['ref_id]
154 $link = ilLink::_getLink($_GET['ref_id']);
155
156 // prepare mail content
157 // use language of recipient to compose message
158
159 // send mails
160 foreach (array_unique($users) as $idx => $user_id) {
161 // the user responsible for the action should not be notified
162 // FIXME $_GET['ref_id]
163 $record = ilDclCache::getRecordCache($a_record_id);
164 $ilDclTable = new ilDclTable($record->getTableId());
165 if ($user_id != $ilUser->getId() && $ilDclTable->hasPermissionToViewRecord(filter_input(INPUT_GET, 'ref_id'), $record, $user_id)) {
166 // use language of recipient to compose message
168 $ulng->loadLanguageModule('dcl');
169
170 $subject = sprintf($ulng->txt('dcl_change_notification_subject'), $obj_dcl->getTitle());
171 // update/delete
172 $message = $ulng->txt("dcl_hello") . " " . ilObjUser::_lookupFullname($user_id) . ",\n\n";
173 $message .= $ulng->txt('dcl_change_notification_dcl_' . $a_action) . ":\n\n";
174 $message .= $ulng->txt('obj_dcl') . ": " . $obj_dcl->getTitle() . "\n\n";
175 $message .= $ulng->txt('dcl_table') . ": " . $obj_table->getTitle() . "\n\n";
176 $message .= $ulng->txt('dcl_record') . ":\n";
177 $message .= "------------------------------------\n";
178 if ($a_record_id) {
179 if (!$record->getTableId()) {
180 $record->setTableId($a_table_id);
181 }
182 // $message .= $ulng->txt('dcl_record_id').": ".$a_record_id.":\n";
183 $t = "";
184 if ($tableview_id = $record->getTable()->getFirstTableViewId($_GET['ref_id'], $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 .= $t;
203 }
204 $message .= "------------------------------------\n";
205 $message .= $ulng->txt('dcl_changed_by') . ": " . $ilUser->getFullname() . " " . 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
220
227 public function getFirstVisibleTableId()
228 {
229 global $DIC;
231 $ilDB = $DIC['ilDB'];
232 $ilDB->setLimit(1);
233 $only_visible = ilObjDataCollectionAccess::hasWriteAccess($this->ref_id) ? '' : ' AND is_visible = 1 ';
234 $result = $ilDB->query(
235 'SELECT id
236 FROM il_dcl_table
237 WHERE obj_id = ' . $ilDB->quote($this->getId(), 'integer') .
238 $only_visible . '
239 ORDER BY -table_order DESC '
240 ); //"-table_order DESC" is ASC with NULL last
241
242 // if there's no visible table, fetch first one not visible
243 // this is to avoid confusion, since the default of a table after creation is not visible
244 if (!$result->numRows() && $only_visible) {
245 $ilDB->setLimit(1);
246 $result = $ilDB->query(
247 'SELECT id
248 FROM il_dcl_table
249 WHERE obj_id = ' . $ilDB->quote($this->getId(), 'integer') . '
250 ORDER BY -table_order DESC '
251 );
252 }
253
254 return $ilDB->fetchObject($result)->id;
255 }
256
257
261 public function reorderTables($table_order)
262 {
263 if ($table_order) {
264 $order = 10;
265 foreach ($table_order as $title) {
266 $table_id = ilDclTable::_getTableIdByTitle($title, $this->getId());
267 $table = ilDclCache::getTableCache($table_id);
268 $table->setOrder($order);
269 $table->doUpdate();
270 $order += 10;
271 }
272 }
273 }
274
275
285 public function doCloneObject($new_obj, $a_target_id, $a_copy_id = null, $a_omit_tree = false)
286 {
287
288 //copy online status if object is not the root copy object
289 $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
290
291 if (!$cp_options->isRootNode($this->getRefId())) {
292 $new_obj->setOnline($this->getOnline());
293 }
294
295 $new_obj->cloneStructure($this->getRefId());
296
297 return $new_obj;
298 }
299
300 //TODO: Find better way to copy data (including references)
301 /*public function doCloneObject(ilObjDataCollection $new_obj, $a_target_id, $a_copy_id = 0) {
302 //$new_obj->delete();
303 $created_new_id = $new_obj->getId();
304 $obj_id = $this->getId();
305
306 $exp = new ilExport();
307 $exp->exportObject($this->getType(), $obj_id, "5.0.0");
308
309 $file_name = substr(strrchr($exp->export_run_dir, DIRECTORY_SEPARATOR), 1);
310
311 $import = new ilImport((int)$a_target_id);
312 $new_id = $import->importObject(null, $exp->export_run_dir.".zip", $file_name.".zip", $this->getType(), "", true);
313
314 $new_obj->delete();
315
316 if ($new_id > 0)
317 {
318 $obj = ilObjectFactory::getInstanceByObjId($new_id);
319 $obj->setId($created_new_id);
320
321 $obj->createReference();
322 $obj->putInTree($a_target_id);
323 $obj->setPermissions($a_target_id);
324
325
326 }
327
328 return $obj;
329 }*/
330
336 public function cloneStructure($original_id)
337 {
338 $original = new ilObjDataCollection($original_id);
339
340 $this->setApproval($original->getApproval());
341 $this->setNotification($original->getNotification());
342 $this->setPublicNotes($original->getPublicNotes());
343 $this->setRating($original->getRating());
344
345 // delete old tables.
346 foreach ($this->getTables() as $table) {
347 $table->doDelete();
348 }
349
350 // add new tables.
351 foreach ($original->getTables() as $table) {
352 $new_table = new ilDclTable();
353 $new_table->setObjId($this->getId());
354 $new_table->cloneStructure($table);
355 }
356
357 // mandatory for all cloning functions
359
360 foreach ($this->getTables() as $table) {
361 $table->afterClone();
362 }
363 }
364
365
369 public function setOnline($a_val)
370 {
371 $this->is_online = $a_val;
372 }
373
374
378 public function getOnline()
379 {
380 return $this->is_online;
381 }
382
383
387 public function setRating($a_val)
388 {
389 $this->rating = $a_val;
390 }
391
392
396 public function getRating()
397 {
398 return $this->rating;
399 }
400
401
405 public function setPublicNotes($a_val)
406 {
407 $this->public_notes = $a_val;
408 }
409
410
414 public function getPublicNotes()
415 {
416 return $this->public_notes;
417 }
418
419
423 public function setApproval($a_val)
424 {
425 $this->approval = $a_val;
426 }
427
428
432 public function getApproval()
433 {
434 return $this->approval;
435 }
436
437
441 public function setNotification($a_val)
442 {
443 $this->notification = $a_val;
444 }
445
446
450 public function getNotification()
451 {
452 return $this->notification;
453 }
454
455
462 public static function _hasWriteAccess($ref)
463 {
465 }
466
467
474 public static function _hasReadAccess($ref)
475 {
477 }
478
479
483 public function getTables()
484 {
485 global $DIC;
486 $ilDB = $DIC['ilDB'];
487
488 $query = "SELECT id FROM il_dcl_table WHERE obj_id = " . $ilDB->quote($this->getId(), "integer") .
489 " ORDER BY -table_order DESC";
490 $set = $ilDB->query($query);
491 $tables = array();
492
493 while ($rec = $ilDB->fetchAssoc($set)) {
494 $tables[$rec['id']] = ilDclCache::getTableCache($rec['id']);
495 }
496
497 return $tables;
498 }
499
500
501 public function getTableById($table_id)
502 {
503 return ilDclCache::getTableCache($table_id);
504 }
505
506
510 public function getVisibleTables()
511 {
512 $tables = array();
513 foreach ($this->getTables() as $table) {
514 if ($table->getIsVisible() && $table->getVisibleTableViews($this->ref_id)) {
515 $tables[$table->getId()] = $table;
516 }
517 }
518
519 return $tables;
520 }
521
522
531 public static function _hasTableByTitle($title, $obj_id)
532 {
533 global $DIC;
534 $ilDB = $DIC['ilDB'];
535 $result = $ilDB->query(
536 'SELECT * FROM il_dcl_table WHERE obj_id = ' . $ilDB->quote($obj_id, 'integer') . ' AND title = '
537 . $ilDB->quote($title, 'text')
538 );
539
540 return ($ilDB->numRows($result)) ? true : false;
541 }
542
543
544 public function getStyleSheetId()
545 {
546 }
547}
$result
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
static _getInstance($a_copy_id)
Get instance of copy wizard options.
static getTableCache($table_id=0)
static getRecordCache($record_id=0)
const TYPE_DATACOLLECTION
static setCloneOf($old, $new, $type)
Class ilDclBaseFieldModel.
static _getTableIdByTitle($title, $obj_id)
static _getLanguageOfUser($a_usr_id)
Get language object of user.
static getNotificationsForObject($type, $id, $page_id=null, $ignore_threshold=false)
Get all users for given object.
static updateNotificationTime($type, $id, array $user_ids, $page_id=false)
Update the last mail timestamp for given object and users.
Class ilObjDataCollection.
doCloneObject($new_obj, $a_target_id, $a_copy_id=null, $a_omit_tree=false)
Clone DCL.
static _hasTableByTitle($title, $obj_id)
Checks if a DataCollection has a table with a given title.
setPublicNotes($a_val)
setPublicNotes
setNotification($a_val)
setNotification
cloneStructure($original_id)
Attention only use this for objects who have not yet been created (use like: $x = new ilObjDataCollec...
static _lookupLogin($a_user_id)
lookup login
static _lookupFullname($a_user_id)
Lookup Full Name.
Class ilObject2 This is an intermediate progress of ilObject class.
getRefId()
get reference id @access public
getTitle()
get object title @access public
getId()
get object id @access public
static getNamePresentation( $a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
notification()
Definition: notification.php:2
$query
global $ilDB
$data
Definition: storeScorm.php:23
$ilUser
Definition: imgupload.php:18
$message
Definition: xapiexit.php:14
$DIC
Definition: xapitoken.php:46