ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 require_once('./Services/Object/classes/class.ilObject2.php');
6 require_once('class.ilDataCollectionTable.php');
7 require_once('class.ilDataCollectionCache.php');
8 
20 
24  protected $main_table_id;
25 
26 
27  public function initType() {
28  $this->type = "dcl";
29  }
30 
31 
32  public function doRead() {
33  global $ilDB;
34 
35  $result = $ilDB->query("SELECT * FROM il_dcl_data WHERE id = " . $ilDB->quote($this->getId(), "integer"));
36 
37  $data = $ilDB->fetchObject($result);
38  $this->setMainTableId($data->main_table_id);
39  $this->setOnline($data->is_online);
40  $this->setRating($data->rating);
41  $this->setApproval($data->approval);
42  $this->setPublicNotes($data->public_notes);
43  $this->setNotification($data->notification);
44  }
45 
46 
47  protected function doCreate() {
48  global $ilDB, $ilLog;
49 
50  $ilLog->write('doCreate');
51 
52  //Create Main Table - The title of the table is per default the title of the data collection object
53  require_once('./Modules/DataCollection/classes/class.ilDataCollectionTable.php');
55  $main_table->setObjId($this->getId());
56  $main_table->setTitle($this->getTitle());
57  $main_table->setAddPerm(1);
58  $main_table->setEditPerm(1);
59  $main_table->setDeletePerm(1);
60  $main_table->setEditByOwner(1);
61  $main_table->setLimited(0);
62  $main_table->doCreate();
63 
64  $ilDB->insert("il_dcl_data", array(
65  "id" => array( "integer", $this->getId() ),
66  "main_table_id" => array( "integer", (int)$main_table->getId() ),
67  "is_online" => array( "integer", (int)$this->getOnline() ),
68  "rating" => array( "integer", (int)$this->getRating() ),
69  "public_notes" => array( "integer", (int)$this->getPublicNotes() ),
70  "approval" => array( "integer", (int)$this->getApproval() ),
71  "notification" => array( "integer", (int)$this->getNotification() ),
72  ));
73  $this->setMainTableId($main_table->getId());
74  }
75 
76 
80  public function doClone() {
81  return false;
82  }
83 
84 
85  protected function doDelete() {
86  global $ilDB;
87 
88  foreach ($this->getTables() as $table) {
89  $table->doDelete(true);
90  }
91 
92  $query = "DELETE FROM il_dcl_data WHERE id = " . $ilDB->quote($this->getId(), "integer");
93  $ilDB->manipulate($query);
94  }
95 
96 
97  public function doUpdate() {
98  global $ilDB;
99 
100  $ilDB->update("il_dcl_data", array(
101  "id" => array( "integer", $this->getId() ),
102  "main_table_id" => array( "integer", (int)$this->getMainTableId() ),
103  "is_online" => array( "integer", (int)$this->getOnline() ),
104  "rating" => array( "integer", (int)$this->getRating() ),
105  "public_notes" => array( "integer", (int)$this->getPublicNotes() ),
106  "approval" => array( "integer", (int)$this->getApproval() ),
107  "notification" => array( "integer", (int)$this->getNotification() ),
108  ), array(
109  "id" => array( "integer", $this->getId() )
110  ));
111  }
112 
113 
119  public static function sendNotification($a_action, $a_table_id, $a_record_id = NULL) {
120  global $ilUser, $ilAccess;
121 
122  // If coming from trash, never send notifications and don't load dcl Object
123  if ($_GET['ref_id'] == SYSTEM_FOLDER_ID) {
124  return;
125  }
126 
127  $dclObj = new ilObjDataCollection($_GET['ref_id']);
128 
129  if ($dclObj->getNotification() != 1) {
130  return;
131  }
132  $obj_table = ilDataCollectionCache::getTableCache($a_table_id);
133  $obj_dcl = $obj_table->getCollectionObject();
134 
135  // recipients
136  require_once('./Services/Notification/classes/class.ilNotification.php');
138  if (! sizeof($users)) {
139  return;
140  }
141 
143 
144  //FIXME $_GET['ref_id]
145  require_once('./Services/Link/classes/class.ilLink.php');
146  $link = ilLink::_getLink($_GET['ref_id']);
147 
148  // prepare mail content
149  // use language of recipient to compose message
150  require_once('./Services/Language/classes/class.ilLanguageFactory.php');
151 
152  // send mails
153  require_once('./Services/Mail/classes/class.ilMail.php');
154  require_once('./Services/User/classes/class.ilObjUser.php');
155  require_once('./Services/Language/classes/class.ilLanguageFactory.php');
156  require_once('./Services/User/classes/class.ilUserUtil.php');
157  require_once('./Services/User/classes/class.ilUserUtil.php');
158  require_once('./Modules/DataCollection/classes/class.ilDataCollectionTable.php');
159 
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  if ($user_id != $ilUser->getId() && $ilAccess->checkAccessOfUser($user_id, 'read', '', $_GET['ref_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  $record = ilDataCollectionCache::getRecordCache($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  foreach ($record->getTable()->getVisibleFields() as $field) {
184  if ($record->getRecordField($field->getId())) {
185  $t .= $field->getTitle() . ": " . $record->getRecordField($field->getId())->getPlainText() . "\n";
186  }
187  }
188  $message .= $t . "\n";
189  }
190  $message .= "------------------------------------\n";
191  $message .= $ulng->txt('dcl_changed_by') . ": " . $ilUser->getFullname() . " " . ilUserUtil::getNamePresentation($ilUser->getId())
192  . "\n\n";
193  $message .= $ulng->txt('dcl_change_notification_link') . ": " . $link . "\n\n";
194 
195  $message .= $ulng->txt('dcl_change_why_you_receive_this_email');
196 
197  $mail_obj = new ilMail(ANONYMOUS_USER_ID);
198  $mail_obj->appendInstallationSignature(true);
199  $mail_obj->sendMail(ilObjUser::_lookupLogin($user_id), "", "", $subject, $message, array(), array( "system" ));
200  } else {
201  unset($users[$idx]);
202  }
203  }
204  }
205 
206 
210  public function setMainTableId($a_val) {
211  $this->main_table_id = $a_val;
212  }
213 
214 
218  public function getMainTableId() {
219  return $this->main_table_id;
220  }
221 
222 
232  public function doCloneObject(ilObjDataCollection $new_obj, $a_target_id, $a_copy_id = 0) {
233 
234  //copy online status if object is not the root copy object
235  $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
236 
237  if(!$cp_options->isRootNode($this->getRefId()))
238  {
239  $new_obj->setOnline($this->getOnline());
240  }
241 
242  $new_obj->cloneStructure($this->getRefId());
243 
244  return $new_obj;
245  }
246 
247  //TODO: Find better way to copy data (including references)
248  /*public function doCloneObject(ilObjDataCollection $new_obj, $a_target_id, $a_copy_id = 0) {
249  //$new_obj->delete();
250  $created_new_id = $new_obj->getId();
251  $obj_id = $this->getId();
252 
253  $exp = new ilExport();
254  $exp->exportObject($this->getType(), $obj_id, "5.0.0");
255 
256  $file_name = substr(strrchr($exp->export_run_dir, DIRECTORY_SEPARATOR), 1);
257 
258  $import = new ilImport((int)$a_target_id);
259  $new_id = $import->importObject(null, $exp->export_run_dir.".zip", $file_name.".zip", $this->getType(), "", true);
260 
261  $new_obj->delete();
262 
263  if ($new_id > 0)
264  {
265  $obj = ilObjectFactory::getInstanceByObjId($new_id);
266  $obj->setId($created_new_id);
267 
268  $obj->createReference();
269  $obj->putInTree($a_target_id);
270  $obj->setPermissions($a_target_id);
271 
272 
273  }
274 
275  return $obj;
276  }*/
277 
283  public function cloneStructure($original_id) {
284  $original = new ilObjDataCollection($original_id);
285 
286  $this->setApproval($original->getApproval());
287  $this->setNotification($original->getNotification());
288  $this->setPublicNotes($original->getPublicNotes());
289  $this->setRating($original->getRating());
290 
291  // delete old tables.
292  foreach ($this->getTables() as $table) {
293  $table->doDelete(true);
294  }
295 
296  // add new tables.
297  foreach ($original->getTables() as $table) {
298  $new_table = new ilDataCollectionTable();
299  $new_table->setObjId($this->getId());
300  $new_table->cloneStructure($table);
301 
302  if ($table->getId() == $original->getMainTableId()) {
303  $this->setMainTableId($new_table->getId());
304  }
305  }
306 
307  // update because maintable id is now set.
308  $this->doUpdate();
309 
310  // Set new field-ID of referenced fields
311  foreach ($original->getTables() as $origTable) {
312  foreach ($origTable->getRecordFields() as $origField) {
313  if ($origField->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_REFERENCE) {
314  $newRefId = NULL;
315  $origFieldRefObj = ilDataCollectionCache::getFieldCache($origField->getFieldRef());
316  $origRefTable = ilDataCollectionCache::getTableCache($origFieldRefObj->getTableId());
317  // Lookup the new ID of the referenced field in the actual DC
318  $tableId = ilDataCollectionTable::_getTableIdByTitle($origRefTable->getTitle(), $this->getId());
319  $fieldId = ilDataCollectionField::_getFieldIdByTitle($origFieldRefObj->getTitle(), $tableId);
320  $field = ilDataCollectionCache::getFieldCache($fieldId);
321  $newRefId = $field->getId();
322  // Set the new refID in the actual DC
323  $tableId = ilDataCollectionTable::_getTableIdByTitle($origTable->getTitle(), $this->getId());
324  $fieldId = ilDataCollectionField::_getFieldIdByTitle($origField->getTitle(), $tableId);
325  $field = ilDataCollectionCache::getFieldCache($fieldId);
326  $field->setPropertyvalue($newRefId, ilDataCollectionField::PROPERTYID_REFERENCE);
327  $field->doUpdate();
328  }
329  }
330  }
331  }
332 
333 
337  public function setOnline($a_val) {
338  $this->is_online = $a_val;
339  }
340 
341 
345  public function getOnline() {
346  return $this->is_online;
347  }
348 
349 
353  public function setRating($a_val) {
354  $this->rating = $a_val;
355  }
356 
357 
361  public function getRating() {
362  return $this->rating;
363  }
364 
365 
369  public function setPublicNotes($a_val) {
370  $this->public_notes = $a_val;
371  }
372 
373 
377  public function getPublicNotes() {
378  return $this->public_notes;
379  }
380 
381 
385  public function setApproval($a_val) {
386  $this->approval = $a_val;
387  }
388 
389 
393  public function getApproval() {
394  return $this->approval;
395  }
396 
397 
401  public function setNotification($a_val) {
402  $this->notification = $a_val;
403  }
404 
405 
409  public function getNotification() {
410  return $this->notification;
411  }
412 
413 
420  public static function _hasWriteAccess($ref) {
422  }
423 
424 
431  public static function _hasReadAccess($ref) {
433  }
434 
435 
439  public function getTables() {
440  global $ilDB;
441 
442  $query = "SELECT id FROM il_dcl_table WHERE obj_id = " . $ilDB->quote($this->getId(), "integer");
443  $set = $ilDB->query($query);
444  $tables = array();
445 
446  while ($rec = $ilDB->fetchAssoc($set)) {
447  $tables[$rec['id']] = ilDataCollectionCache::getTableCache($rec['id']);
448  }
449 
450  return $tables;
451  }
452 
453 
457  public function getVisibleTables() {
458  $tables = array();
459  foreach ($this->getTables() as $table) {
460  if ($table->getIsVisible()) {
461  $tables[$table->getId()] = $table;
462  }
463  }
464 
465  return $tables;
466  }
467 
468 
477  public static function _hasTableByTitle($title, $obj_id) {
478  global $ilDB;
479  $result = $ilDB->query('SELECT * FROM il_dcl_table WHERE obj_id = ' . $ilDB->quote($obj_id, 'integer') . ' AND title = '
480  . $ilDB->quote($title, 'text'));
481 
482  return ($ilDB->numRows($result)) ? true : false;
483  }
484 
485 
486  public function getStyleSheetId() { }
487 }
488 
489 ?>