ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 require_once('./Services/Object/classes/class.ilObject2.php');
5 require_once('./Modules/DataCollection/classes/Table/class.ilDclTable.php');
6 require_once('./Modules/DataCollection/classes/Helpers/class.ilDclCache.php');
7 require_once('./Modules/DataCollection/classes/class.ilObjDataCollectionAccess.php');
8 
20 
21  public function initType() {
22  $this->type = "dcl";
23  }
24 
25 
26  public function doRead() {
27  global $DIC;
28  $ilDB = $DIC['ilDB'];
29 
30  $result = $ilDB->query("SELECT * FROM il_dcl_data WHERE id = " . $ilDB->quote($this->getId(), "integer"));
31 
32  $data = $ilDB->fetchObject($result);
33  $this->setOnline($data->is_online);
34  $this->setRating($data->rating);
35  $this->setApproval($data->approval);
36  $this->setPublicNotes($data->public_notes);
37  $this->setNotification($data->notification);
38  }
39 
40 
41  protected function doCreate($clone_mode = false) {
42  global $DIC;
43  $ilDB = $DIC['ilDB'];
44  $ilLog = $DIC['ilLog'];
45 
46  $ilLog->write('doCreate');
47 
48  if (!$clone_mode) {
49  //Create Main Table - The title of the table is per default the title of the data collection object
50  $main_table = ilDclCache::getTableCache();
51  $main_table->setObjId($this->getId());
52  $main_table->setTitle($this->getTitle());
53  $main_table->setAddPerm(1);
54  $main_table->setEditPerm(1);
55  $main_table->setDeletePerm(0);
56  $main_table->setDeleteByOwner(1);
57  $main_table->setEditByOwner(1);
58  $main_table->setLimited(0);
59  $main_table->setIsVisible(true);
60  $main_table->doCreate();
61  }
62 
63 
64  $ilDB->insert("il_dcl_data", 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 
78  public function doClone() {
79  return false;
80  }
81 
82 
83  protected function doDelete() {
84  global $DIC;
85  $ilDB = $DIC['ilDB'];
86 
87  foreach ($this->getTables() as $table) {
88  $table->doDelete(false, true);
89  }
90 
91  $query = "DELETE FROM il_dcl_data WHERE id = " . $ilDB->quote($this->getId(), "integer");
92  $ilDB->manipulate($query);
93  }
94 
95 
96  public function doUpdate() {
97  global $DIC;
98  $ilDB = $DIC['ilDB'];
99 
100  $ilDB->update("il_dcl_data", array(
101  "id" => array( "integer", $this->getId() ),
102  "is_online" => array( "integer", (int)$this->getOnline() ),
103  "rating" => array( "integer", (int)$this->getRating() ),
104  "public_notes" => array( "integer", (int)$this->getPublicNotes() ),
105  "approval" => array( "integer", (int)$this->getApproval() ),
106  "notification" => array( "integer", (int)$this->getNotification() ),
107  ), array(
108  "id" => array( "integer", $this->getId() )
109  ));
110  }
111 
112 
118  public static function sendNotification($a_action, $a_table_id, $a_record_id = NULL) {
119  global $DIC;
120  $ilUser = $DIC['ilUser'];
121  $ilAccess = $DIC['ilAccess'];
122 
123  // If coming from trash, never send notifications and don't load dcl Object
124  if ($_GET['ref_id'] == SYSTEM_FOLDER_ID) {
125  return;
126  }
127 
128  $dclObj = new ilObjDataCollection($_GET['ref_id']);
129 
130  if ($dclObj->getNotification() != 1) {
131  return;
132  }
133  $obj_table = ilDclCache::getTableCache($a_table_id);
134  $obj_dcl = $obj_table->getCollectionObject();
135 
136  // recipients
137  require_once('./Services/Notification/classes/class.ilNotification.php');
139  if (! sizeof($users)) {
140  return;
141  }
142 
144 
145  //FIXME $_GET['ref_id]
146  require_once('./Services/Link/classes/class.ilLink.php');
147  $link = ilLink::_getLink($_GET['ref_id']);
148 
149  // prepare mail content
150  // use language of recipient to compose message
151  require_once('./Services/Language/classes/class.ilLanguageFactory.php');
152 
153  // send mails
154  require_once('./Services/Mail/classes/class.ilMail.php');
155  require_once('./Services/User/classes/class.ilObjUser.php');
156  require_once('./Services/Language/classes/class.ilLanguageFactory.php');
157  require_once('./Services/User/classes/class.ilUserUtil.php');
158  foreach (array_unique($users) as $idx => $user_id) {
159  // the user responsible for the action should not be notified
160  // FIXME $_GET['ref_id]
161  $record = ilDclCache::getRecordCache($a_record_id);
162  $ilDclTable = new ilDclTable($record->getTableId());
163  if ($user_id != $ilUser->getId() && $ilDclTable->hasPermissionToViewRecord(filter_input(INPUT_GET, 'ref_id'), $record, $user_id)) {
164  // use language of recipient to compose message
165  $ulng = ilLanguageFactory::_getLanguageOfUser($user_id);
166  $ulng->loadLanguageModule('dcl');
167 
168  $subject = sprintf($ulng->txt('dcl_change_notification_subject'), $obj_dcl->getTitle());
169  // update/delete
170  $message = $ulng->txt("dcl_hello") . " " . ilObjUser::_lookupFullname($user_id) . ",\n\n";
171  $message .= $ulng->txt('dcl_change_notification_dcl_' . $a_action) . ":\n\n";
172  $message .= $ulng->txt('obj_dcl') . ": " . $obj_dcl->getTitle() . "\n\n";
173  $message .= $ulng->txt('dcl_table') . ": " . $obj_table->getTitle() . "\n\n";
174  $message .= $ulng->txt('dcl_record') . ":\n";
175  $message .= "------------------------------------\n";
176  if ($a_record_id) {
177  if (!$record->getTableId()) {
178  $record->setTableId($a_table_id);
179  }
180  // $message .= $ulng->txt('dcl_record_id').": ".$a_record_id.":\n";
181  $t = "";
182  if ($tableview_id = $record->getTable()->getFirstTableViewId($_GET['ref_id'], $user_id)) {
183  $visible_fields = ilDclTableView::find($tableview_id)->getVisibleFields();
184  if (empty($visible_fields)) {
185  continue;
186  }
188  foreach ($visible_fields as $field) {
189  if ($field->isStandardField()) {
190  $value = $record->getStandardFieldPlainText($field->getId());
191  } elseif ($record_field = $record->getRecordField($field->getId())) {
192  $value = $record_field->getPlainText();
193  }
194 
195  if ($value) {
196  $t .= $field->getTitle() . ": " . $value . "\n";
197  }
198  }
199  }
200  $message .= $t;
201  }
202  $message .= "------------------------------------\n";
203  $message .= $ulng->txt('dcl_changed_by') . ": " . $ilUser->getFullname() . " " . ilUserUtil::getNamePresentation($ilUser->getId())
204  . "\n\n";
205  $message .= $ulng->txt('dcl_change_notification_link') . ": " . $link . "\n\n";
206 
207  $message .= $ulng->txt('dcl_change_why_you_receive_this_email');
208 
209  $mail_obj = new ilMail(ANONYMOUS_USER_ID);
210  $mail_obj->appendInstallationSignature(true);
211  $mail_obj->sendMail(ilObjUser::_lookupLogin($user_id), "", "", $subject, $message, array(), array( "system" ));
212  } else {
213  unset($users[$idx]);
214  }
215  }
216  }
217 
224  public function getFirstVisibleTableId() {
225  global $DIC;
227  $ilDB = $DIC['ilDB'];
228  $ilDB->setLimit(1);
229  $only_visible = ilObjDataCollectionAccess::hasWriteAccess($this->ref_id) ? '' : ' AND is_visible = 1 ';
230  $result = $ilDB->query('SELECT id
231  FROM il_dcl_table
232  WHERE obj_id = ' . $ilDB->quote($this->getId(), 'integer') .
233  $only_visible . '
234  ORDER BY -table_order DESC '); //"-table_order DESC" is ASC with NULL last
235 
236  // if there's no visible table, fetch first one not visible
237  // this is to avoid confusion, since the default of a table after creation is not visible
238  if (!$result->numRows() && $only_visible) {
239  $ilDB->setLimit(1);
240  $result = $ilDB->query('SELECT id
241  FROM il_dcl_table
242  WHERE obj_id = ' . $ilDB->quote($this->getId(), 'integer') . '
243  ORDER BY -table_order DESC ');
244  }
245  return $ilDB->fetchObject($result)->id;
246  }
247 
251  public function reorderTables($table_order) {
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  }
264 
265 
275  public function doCloneObject($new_obj, $a_target_id, $a_copy_id = NULL, $a_omit_tree = false) {
276 
277  //copy online status if object is not the root copy object
278  $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
279 
280  if(!$cp_options->isRootNode($this->getRefId()))
281  {
282  $new_obj->setOnline($this->getOnline());
283  }
284 
285  $new_obj->cloneStructure($this->getRefId());
286 
287  return $new_obj;
288  }
289 
290  //TODO: Find better way to copy data (including references)
291  /*public function doCloneObject(ilObjDataCollection $new_obj, $a_target_id, $a_copy_id = 0) {
292  //$new_obj->delete();
293  $created_new_id = $new_obj->getId();
294  $obj_id = $this->getId();
295 
296  $exp = new ilExport();
297  $exp->exportObject($this->getType(), $obj_id, "5.0.0");
298 
299  $file_name = substr(strrchr($exp->export_run_dir, DIRECTORY_SEPARATOR), 1);
300 
301  $import = new ilImport((int)$a_target_id);
302  $new_id = $import->importObject(null, $exp->export_run_dir.".zip", $file_name.".zip", $this->getType(), "", true);
303 
304  $new_obj->delete();
305 
306  if ($new_id > 0)
307  {
308  $obj = ilObjectFactory::getInstanceByObjId($new_id);
309  $obj->setId($created_new_id);
310 
311  $obj->createReference();
312  $obj->putInTree($a_target_id);
313  $obj->setPermissions($a_target_id);
314 
315 
316  }
317 
318  return $obj;
319  }*/
320 
326  public function cloneStructure($original_id) {
327  $original = new ilObjDataCollection($original_id);
328 
329  $this->setApproval($original->getApproval());
330  $this->setNotification($original->getNotification());
331  $this->setPublicNotes($original->getPublicNotes());
332  $this->setRating($original->getRating());
333 
334  // delete old tables.
335  foreach ($this->getTables() as $table) {
336  $table->doDelete();
337  }
338 
339  // add new tables.
340  foreach ($original->getTables() as $table) {
341  $new_table = new ilDclTable();
342  $new_table->setObjId($this->getId());
343  $new_table->cloneStructure($table);
344  }
345 
346  // mandatory for all cloning functions
348 
349  foreach ($this->getTables() as $table) {
350  $table->afterClone();
351  }
352  }
353 
354 
358  public function setOnline($a_val) {
359  $this->is_online = $a_val;
360  }
361 
362 
366  public function getOnline() {
367  return $this->is_online;
368  }
369 
370 
374  public function setRating($a_val) {
375  $this->rating = $a_val;
376  }
377 
378 
382  public function getRating() {
383  return $this->rating;
384  }
385 
386 
390  public function setPublicNotes($a_val) {
391  $this->public_notes = $a_val;
392  }
393 
394 
398  public function getPublicNotes() {
399  return $this->public_notes;
400  }
401 
402 
406  public function setApproval($a_val) {
407  $this->approval = $a_val;
408  }
409 
410 
414  public function getApproval() {
415  return $this->approval;
416  }
417 
418 
422  public function setNotification($a_val) {
423  $this->notification = $a_val;
424  }
425 
426 
430  public function getNotification() {
431  return $this->notification;
432  }
433 
434 
441  public static function _hasWriteAccess($ref) {
443  }
444 
445 
452  public static function _hasReadAccess($ref) {
454  }
455 
456 
460  public function getTables() {
461  global $DIC;
462  $ilDB = $DIC['ilDB'];
463 
464  $query = "SELECT id FROM il_dcl_table WHERE obj_id = " . $ilDB->quote($this->getId(), "integer") .
465  " ORDER BY -table_order DESC";
466  $set = $ilDB->query($query);
467  $tables = array();
468 
469  while ($rec = $ilDB->fetchAssoc($set)) {
470  $tables[$rec['id']] = ilDclCache::getTableCache($rec['id']);
471  }
472 
473  return $tables;
474  }
475 
476  public function getTableById($table_id) {
477  return ilDclCache::getTableCache($table_id);
478  }
479 
483  public function getVisibleTables() {
484  $tables = array();
485  foreach ($this->getTables() as $table) {
486  if ($table->getIsVisible() && $table->getVisibleTableViews($this->ref_id)) {
487  $tables[$table->getId()] = $table;
488  }
489  }
490 
491  return $tables;
492  }
493 
494 
503  public static function _hasTableByTitle($title, $obj_id) {
504  global $DIC;
505  $ilDB = $DIC['ilDB'];
506  $result = $ilDB->query('SELECT * FROM il_dcl_table WHERE obj_id = ' . $ilDB->quote($obj_id, 'integer') . ' AND title = '
507  . $ilDB->quote($title, 'text'));
508 
509  return ($ilDB->numRows($result)) ? true : false;
510  }
511 
512 
513  public function getStyleSheetId() { }
514 }
515 
516 ?>
static _lookupLogin($a_user_id)
lookup login
const TYPE_DATACOLLECTION
static setCloneOf($old, $new, $type)
static _getTableIdByTitle($title, $obj_id)
$result
setPublicNotes($a_val)
setPublicNotes
$_GET["client_id"]
static _lookupFullname($a_user_id)
Lookup Full Name.
static updateNotificationTime($type, $id, array $user_ids, $page_id=false)
Update the last mail timestamp for given object and users.
static getTableCache($table_id=0)
Class ilDclBaseFieldModel.
static getNotificationsForObject($type, $id, $page_id=null, $ignore_threshold=false)
Get all users for given object.
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)
Default behaviour is:
static _getInstance($a_copy_id)
Get instance of copy wizard options.
This class handles base functions for mail handling.
static getRecordCache($record_id=0)
notification()
Definition: notification.php:2
$ilUser
Definition: imgupload.php:18
static _hasTableByTitle($title, $obj_id)
Checks if a DataCollection has a table with a given title.
Create styles array
The data for the language used.
static _getLanguageOfUser($a_usr_id)
Get language object of user.
cloneStructure($original_id)
Attention only use this for objects who have not yet been created (use like: $x = new ilObjDataCollec...
setApproval($a_val)
setApproval
global $ilDB
Class ilObject2 This is an intermediate progress of ilObject class.
global $DIC
Class ilObjDataCollection.
doCloneObject($new_obj, $a_target_id, $a_copy_id=NULL, $a_omit_tree=false)
Clone DCL.
setNotification($a_val)
setNotification