ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
5 
17 {
18  public function initType()
19  {
20  $this->type = "dcl";
21  }
22 
23 
24  public function doRead()
25  {
26  global $DIC;
27  $ilDB = $DIC['ilDB'];
28 
29  $result = $ilDB->query("SELECT * FROM il_dcl_data WHERE id = " . $ilDB->quote($this->getId(), "integer"));
30 
31  $data = $ilDB->fetchObject($result);
32  $this->setOnline($data->is_online);
33  $this->setRating($data->rating);
34  $this->setApproval($data->approval);
35  $this->setPublicNotes($data->public_notes);
36  $this->setNotification($data->notification);
37  }
38 
39 
40  protected function doCreate($clone_mode = false)
41  {
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  {
80  return false;
81  }
82 
83 
84  protected function doDelete()
85  {
86  global $DIC;
87  $ilDB = $DIC['ilDB'];
88 
89  foreach ($this->getTables() as $table) {
90  $table->doDelete(false, true);
91  }
92 
93  $query = "DELETE FROM il_dcl_data WHERE id = " . $ilDB->quote($this->getId(), "integer");
94  $ilDB->manipulate($query);
95  }
96 
97 
98  public function doUpdate()
99  {
100  global $DIC;
101  $ilDB = $DIC['ilDB'];
102 
103  $ilDB->update("il_dcl_data", array(
104  "id" => array( "integer", $this->getId() ),
105  "is_online" => array( "integer", (int) $this->getOnline() ),
106  "rating" => array( "integer", (int) $this->getRating() ),
107  "public_notes" => array( "integer", (int) $this->getPublicNotes() ),
108  "approval" => array( "integer", (int) $this->getApproval() ),
109  "notification" => array( "integer", (int) $this->getNotification() ),
110  ), array(
111  "id" => array( "integer", $this->getId() )
112  ));
113  }
114 
115 
121  public static function sendNotification($a_action, $a_table_id, $a_record_id = null)
122  {
123  global $DIC;
124  $ilUser = $DIC['ilUser'];
125  $ilAccess = $DIC['ilAccess'];
126 
127  // If coming from trash, never send notifications and don't load dcl Object
128  if ($_GET['ref_id'] == SYSTEM_FOLDER_ID) {
129  return;
130  }
131 
132  $dclObj = new ilObjDataCollection($_GET['ref_id']);
133 
134  if ($dclObj->getNotification() != 1) {
135  return;
136  }
137  $obj_table = ilDclCache::getTableCache($a_table_id);
138  $obj_dcl = $obj_table->getCollectionObject();
139 
140  // recipients
142  if (!sizeof($users)) {
143  return;
144  }
145 
147 
148  //FIXME $_GET['ref_id]
149  $link = ilLink::_getLink($_GET['ref_id']);
150 
151  // prepare mail content
152  // use language of recipient to compose message
153 
154  // send mails
155  foreach (array_unique($users) as $idx => $user_id) {
156  // the user responsible for the action should not be notified
157  // FIXME $_GET['ref_id]
158  $record = ilDclCache::getRecordCache($a_record_id);
159  $ilDclTable = new ilDclTable($record->getTableId());
160  if ($user_id != $ilUser->getId() && $ilDclTable->hasPermissionToViewRecord(filter_input(INPUT_GET, 'ref_id'), $record, $user_id)) {
161  // use language of recipient to compose message
162  $ulng = ilLanguageFactory::_getLanguageOfUser($user_id);
163  $ulng->loadLanguageModule('dcl');
164 
165  $subject = sprintf($ulng->txt('dcl_change_notification_subject'), $obj_dcl->getTitle());
166  // update/delete
167  $message = $ulng->txt("dcl_hello") . " " . ilObjUser::_lookupFullname($user_id) . ",\n\n";
168  $message .= $ulng->txt('dcl_change_notification_dcl_' . $a_action) . ":\n\n";
169  $message .= $ulng->txt('obj_dcl') . ": " . $obj_dcl->getTitle() . "\n\n";
170  $message .= $ulng->txt('dcl_table') . ": " . $obj_table->getTitle() . "\n\n";
171  $message .= $ulng->txt('dcl_record') . ":\n";
172  $message .= "------------------------------------\n";
173  if ($a_record_id) {
174  if (!$record->getTableId()) {
175  $record->setTableId($a_table_id);
176  }
177  // $message .= $ulng->txt('dcl_record_id').": ".$a_record_id.":\n";
178  $t = "";
179  if ($tableview_id = $record->getTable()->getFirstTableViewId($_GET['ref_id'], $user_id)) {
180  $visible_fields = ilDclTableView::find($tableview_id)->getVisibleFields();
181  if (empty($visible_fields)) {
182  continue;
183  }
185  foreach ($visible_fields as $field) {
186  if ($field->isStandardField()) {
187  $value = $record->getStandardFieldPlainText($field->getId());
188  } elseif ($record_field = $record->getRecordField($field->getId())) {
189  $value = $record_field->getPlainText();
190  }
191 
192  if ($value) {
193  $t .= $field->getTitle() . ": " . $value . "\n";
194  }
195  }
196  }
197  $message .= $t;
198  }
199  $message .= "------------------------------------\n";
200  $message .= $ulng->txt('dcl_changed_by') . ": " . $ilUser->getFullname() . " " . ilUserUtil::getNamePresentation($ilUser->getId())
201  . "\n\n";
202  $message .= $ulng->txt('dcl_change_notification_link') . ": " . $link . "\n\n";
203 
204  $message .= $ulng->txt('dcl_change_why_you_receive_this_email');
205 
206  $mail_obj = new ilMail(ANONYMOUS_USER_ID);
207  $mail_obj->appendInstallationSignature(true);
208  $mail_obj->sendMail(ilObjUser::_lookupLogin($user_id), "", "", $subject, $message, array(), array( "system" ));
209  } else {
210  unset($users[$idx]);
211  }
212  }
213  }
214 
221  public function getFirstVisibleTableId()
222  {
223  global $DIC;
225  $ilDB = $DIC['ilDB'];
226  $ilDB->setLimit(1);
227  $only_visible = ilObjDataCollectionAccess::hasWriteAccess($this->ref_id) ? '' : ' AND is_visible = 1 ';
228  $result = $ilDB->query('SELECT id
229  FROM il_dcl_table
230  WHERE obj_id = ' . $ilDB->quote($this->getId(), 'integer') .
231  $only_visible . '
232  ORDER BY -table_order DESC '); //"-table_order DESC" is ASC with NULL last
233 
234  // if there's no visible table, fetch first one not visible
235  // this is to avoid confusion, since the default of a table after creation is not visible
236  if (!$result->numRows() && $only_visible) {
237  $ilDB->setLimit(1);
238  $result = $ilDB->query('SELECT id
239  FROM il_dcl_table
240  WHERE obj_id = ' . $ilDB->quote($this->getId(), 'integer') . '
241  ORDER BY -table_order DESC ');
242  }
243  return $ilDB->fetchObject($result)->id;
244  }
245 
249  public function reorderTables($table_order)
250  {
251  if ($table_order) {
252  $order = 10;
253  foreach ($table_order as $title) {
254  $table_id = ilDclTable::_getTableIdByTitle($title, $this->getId());
255  $table = ilDclCache::getTableCache($table_id);
256  $table->setOrder($order);
257  $table->doUpdate();
258  $order += 10;
259  }
260  }
261  }
262 
263 
273  public function doCloneObject($new_obj, $a_target_id, $a_copy_id = null, $a_omit_tree = false)
274  {
275 
276  //copy online status if object is not the root copy object
277  $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
278 
279  if (!$cp_options->isRootNode($this->getRefId())) {
280  $new_obj->setOnline($this->getOnline());
281  }
282 
283  $new_obj->cloneStructure($this->getRefId());
284 
285  return $new_obj;
286  }
287 
288  //TODO: Find better way to copy data (including references)
289  /*public function doCloneObject(ilObjDataCollection $new_obj, $a_target_id, $a_copy_id = 0) {
290  //$new_obj->delete();
291  $created_new_id = $new_obj->getId();
292  $obj_id = $this->getId();
293 
294  $exp = new ilExport();
295  $exp->exportObject($this->getType(), $obj_id, "5.0.0");
296 
297  $file_name = substr(strrchr($exp->export_run_dir, DIRECTORY_SEPARATOR), 1);
298 
299  $import = new ilImport((int)$a_target_id);
300  $new_id = $import->importObject(null, $exp->export_run_dir.".zip", $file_name.".zip", $this->getType(), "", true);
301 
302  $new_obj->delete();
303 
304  if ($new_id > 0)
305  {
306  $obj = ilObjectFactory::getInstanceByObjId($new_id);
307  $obj->setId($created_new_id);
308 
309  $obj->createReference();
310  $obj->putInTree($a_target_id);
311  $obj->setPermissions($a_target_id);
312 
313 
314  }
315 
316  return $obj;
317  }*/
318 
324  public function cloneStructure($original_id)
325  {
326  $original = new ilObjDataCollection($original_id);
327 
328  $this->setApproval($original->getApproval());
329  $this->setNotification($original->getNotification());
330  $this->setPublicNotes($original->getPublicNotes());
331  $this->setRating($original->getRating());
332 
333  // delete old tables.
334  foreach ($this->getTables() as $table) {
335  $table->doDelete();
336  }
337 
338  // add new tables.
339  foreach ($original->getTables() as $table) {
340  $new_table = new ilDclTable();
341  $new_table->setObjId($this->getId());
342  $new_table->cloneStructure($table);
343  }
344 
345  // mandatory for all cloning functions
347 
348  foreach ($this->getTables() as $table) {
349  $table->afterClone();
350  }
351  }
352 
353 
357  public function setOnline($a_val)
358  {
359  $this->is_online = $a_val;
360  }
361 
362 
366  public function getOnline()
367  {
368  return $this->is_online;
369  }
370 
371 
375  public function setRating($a_val)
376  {
377  $this->rating = $a_val;
378  }
379 
380 
384  public function getRating()
385  {
386  return $this->rating;
387  }
388 
389 
393  public function setPublicNotes($a_val)
394  {
395  $this->public_notes = $a_val;
396  }
397 
398 
402  public function getPublicNotes()
403  {
404  return $this->public_notes;
405  }
406 
407 
411  public function setApproval($a_val)
412  {
413  $this->approval = $a_val;
414  }
415 
416 
420  public function getApproval()
421  {
422  return $this->approval;
423  }
424 
425 
429  public function setNotification($a_val)
430  {
431  $this->notification = $a_val;
432  }
433 
434 
438  public function getNotification()
439  {
440  return $this->notification;
441  }
442 
443 
450  public static function _hasWriteAccess($ref)
451  {
453  }
454 
455 
462  public static function _hasReadAccess($ref)
463  {
465  }
466 
467 
471  public function getTables()
472  {
473  global $DIC;
474  $ilDB = $DIC['ilDB'];
475 
476  $query = "SELECT id FROM il_dcl_table WHERE obj_id = " . $ilDB->quote($this->getId(), "integer") .
477  " ORDER BY -table_order DESC";
478  $set = $ilDB->query($query);
479  $tables = array();
480 
481  while ($rec = $ilDB->fetchAssoc($set)) {
482  $tables[$rec['id']] = ilDclCache::getTableCache($rec['id']);
483  }
484 
485  return $tables;
486  }
487 
488  public function getTableById($table_id)
489  {
490  return ilDclCache::getTableCache($table_id);
491  }
492 
496  public function getVisibleTables()
497  {
498  $tables = array();
499  foreach ($this->getTables() as $table) {
500  if ($table->getIsVisible() && $table->getVisibleTableViews($this->ref_id)) {
501  $tables[$table->getId()] = $table;
502  }
503  }
504 
505  return $tables;
506  }
507 
508 
517  public static function _hasTableByTitle($title, $obj_id)
518  {
519  global $DIC;
520  $ilDB = $DIC['ilDB'];
521  $result = $ilDB->query('SELECT * FROM il_dcl_table WHERE obj_id = ' . $ilDB->quote($obj_id, 'integer') . ' AND title = '
522  . $ilDB->quote($title, 'text'));
523 
524  return ($ilDB->numRows($result)) ? true : false;
525  }
526 
527 
528  public function getStyleSheetId()
529  {
530  }
531 }
static _lookupLogin($a_user_id)
lookup login
const TYPE_DATACOLLECTION
static setCloneOf($old, $new, $type)
static _getTableIdByTitle($title, $obj_id)
$result
global $DIC
Definition: saml.php:7
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.
doCloneObject($new_obj, $a_target_id, $a_copy_id=null, $a_omit_tree=false)
Clone DCL.
static getTableCache($table_id=0)
Class ilDclBaseFieldModel.
static getNotificationsForObject($type, $id, $page_id=null, $ignore_threshold=false)
Get all users for given object.
catch(Exception $e) $message
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.
$query
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:
Create styles array
The data for the language used.
$users
Definition: authpage.php:44
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.
if(empty($password)) $table
Definition: pwgen.php:24
Class ilObjDataCollection.
setNotification($a_val)
setNotification