ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilDataCollectionRecord.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once './Modules/DataCollection/classes/class.ilDataCollectionRecordField.php';
5 require_once './Modules/DataCollection/classes/class.ilDataCollectionDatatype.php';
6 require_once './Services/Exceptions/classes/class.ilException.php';
7 require_once './Services/User/classes/class.ilUserUtil.php';
8 
21 {
25  private $recordfields;
26  private $id;
27  private $table_id;
28 
32  private $table;
33  private $last_edit_by;
34 
41  public function __construct($a_id = 0)
42  {
43  if($a_id != 0)
44  {
45  $this->id = $a_id;
46  $this->doRead();
47  }
48  }
49 
50 
54  public function doUpdate()
55  {
56  global $ilDB;
57 
58  $ilDB->update("il_dcl_record", array(
59  "table_id" => array("integer", $this->getTableId()),
60  "last_update" => array("date", $this->getLastUpdate()),
61  "owner" => array("text", $this->getOwner()),
62  "last_edit_by" => array("text", $this->getLastEditBy())
63  ), array(
64  "id" => array("integer", $this->id)
65  ));
66 
67  foreach($this->getRecordFields() as $recordfield)
68  {
69  $recordfield->doUpdate();
70  }
71 
72  include_once "./Modules/DataCollection/classes/class.ilObjDataCollection.php";
73  ilObjDataCollection::sendNotification("update_record", $this->getTableId(), $this->id);
74  }
75 
79  public function doRead()
80  {
81  global $ilDB;
82  //build query
83  $query = "Select * From il_dcl_record rc WHERE rc.id = ".$ilDB->quote($this->getId(),"integer")." ORDER BY rc.id";
84 
85 
86  $set = $ilDB->query($query);
87  $rec = $ilDB->fetchAssoc($set);
88 
89  $this->setTableId($rec["table_id"]);
90  $this->setCreateDate($rec["create_date"]);
91  $this->setLastUpdate($rec["last_update"]);
92  $this->setOwner($rec["owner"]);
93  $this->setLastEditBy($rec["last_edit_by"]);
94  }
95 
102  public function doCreate()
103  {
104  global $ilDB;
105 
107  throw new ilException("The field does not have a related table!");
108 
109  // Record erzeugen
110  $id = $ilDB->nextId("il_dcl_record");
111  $this->setId($id);
112  $query = "INSERT INTO il_dcl_record (
113  id,
114  table_id,
115  create_date,
116  Last_update,
117  owner,
118  last_edit_by
119  ) VALUES (".
120  $ilDB->quote($this->getId(), "integer").",".
121  $ilDB->quote($this->getTableId(), "integer").",".
122  $ilDB->quote($this->getCreateDate(), "timestamp").",".
123  $ilDB->quote($this->getLastUpdate(), "timestamp").",".
124  $ilDB->quote($this->getOwner(), "integer").",".
125  $ilDB->quote($this->getLastEditBy(), "integer")."
126  )";
127  $ilDB->manipulate($query);
128 
129  include_once "./Modules/DataCollection/classes/class.ilObjDataCollection.php";
130  }
131 
132  /*
133  * deleteField
134  */
135  public function deleteField($field_id)
136  {
137  $this->loadRecordFields();
138  $this->recordfields[$field_id]->delete();
139  if(count($this->recordfields) == 1)
140  $this->doDelete();
141  }
142 
148  public function setId($a_id)
149  {
150  $this->id = $a_id;
151  }
152 
158  public function getId()
159  {
160  return $this->id;
161  }
162 
168  public function setTableId($a_id)
169  {
170  $this->table_id = $a_id;
171  }
172 
178  public function getTableId()
179  {
180  return $this->table_id;
181  }
182 
188  public function setCreateDate($a_datetime)
189  {
190  $this->create_date = $a_datetime;
191  }
192 
198  public function getCreateDate()
199  {
200  return $this->create_date;
201  }
202 
208  public function setLastUpdate($a_datetime)
209  {
210  $this->last_update = $a_datetime;
211  }
212 
218  public function getLastUpdate()
219  {
220  return $this->last_update;
221  }
222 
228  public function setOwner($a_id)
229  {
230  $this->owner = $a_id;
231  }
232 
238  public function getOwner()
239  {
240  return $this->owner;
241  }
242 
243  /*
244  * getLastEditBy
245  */
246  public function getLastEditBy()
247  {
248  return $this->last_edit_by;
249  }
250 
251  /*
252  * setLastEditBy
253  */
254  public function setLastEditBy($last_edit_by)
255  {
256  $this->last_edit_by = $last_edit_by;
257  }
258 
259 
266  public function setRecordFieldValue($field_id, $value)
267  {
268  $this->loadRecordFields();
269 
271  {
272  $this->setStandardField($field_id, $value);
273  }
274  else
275  {
276  $this->loadTable();
277  $this->recordfields[$field_id]->setValue($value);
278  }
279  }
280 
286  public function getRecordFieldValues()
287  {
288  $this->loadRecordFields();
289 
290  foreach($this->recordfields as $id => $record_field)
291  {
292  $return[$id] = $record_field->getValue();
293  }
294 
295  return (array) $return;
296  }
297 
304  public function getRecordFieldValue($field_id)
305  {
306  $this->loadRecordFields();
307 
309  {
310  return $this->getStandardField($field_id);
311  }
312  else
313  {
314  return $this->recordfields[$field_id]->getValue();
315  }
316  }
317 
318 
325  public function getRecordFieldExportValue($field_id)
326  {
327  $this->loadRecordFields();
328 
330  {
331  return $this->getStandardFieldHTML($field_id);
332  }
333  else
334  {
335  return $this->recordfields[$field_id]->getExportValue();
336  }
337  }
338 
339 
340 
341  /*
342  * getRecordFieldHTML
343  *
344  * @param int $field_id
345  * @param array $options
346  * @return array
347  */
348  public function getRecordFieldHTML($field_id,array $options = array())
349  {
350  global $lng;
351  $this->loadRecordFields();
352 
354  {
355  return $this->getStandardFieldHTML($field_id);
356  }
357  else
358  {
359  if(!$this->recordfields[$field_id]){
360  ilUtil::sendInfo($lng->txt("dcl_inconsistent"), true);
361  return "-";
362  }
363  return $this->recordfields[$field_id]->getHTML($options);
364  }
365  }
366  /*
367  * getRecordFieldSingleHTML
368  *
369  * @param int $field_id
370  * @param array $options
371  * @return array
372  */
373  public function getRecordFieldSingleHTML($field_id,array $options = array())
374  {
375  $this->loadRecordFields();
376 
378  {
379  return $this->getStandardFieldHTML($field_id);
380  }
381  else
382  {
383  return $this->recordfields[$field_id]->getSingleHTML($options);
384  }
385  }
386 
387 
388 
389  /*
390  * getRecordFieldFormInput
391  *
392  * @param int $field_id
393  * @return array
394  */
395  public function getRecordFieldFormInput($field_id)
396  {
397  $this->loadRecordFields();
399  {
400  return $this->getStandardField($field_id);
401  }
402  else
403  {
404  return $this->recordfields[$field_id]->getFormInput();
405  }
406  }
407 
408 
409  /*
410  * setStandardField
411  *
412  * @param int $field_id
413  * @param mixed $value
414  */
415 
416  private function setStandardField($field_id, $value)
417  {
418  switch($field_id)
419  {
420  case "last_edit_by":
421  $this->setLastEditBy($value);
422  return;
423  }
424  $this->$field_id = $value;
425  }
426 
427 
428  /*
429  * getStandardField
430  *
431  * @param int $field_id
432  * @return mixed
433  */
434  private function getStandardField($field_id)
435  {
436  switch($field_id)
437  {
438  case "last_edit_by":
439  return $this->getLastEditBy();
440  break;
441  case 'owner':
442  $usr_data = ilObjUser::_lookupName($this->getOwner());
443  return $usr_data['login'];
444  break;
445  }
446 
447  return $this->$field_id;
448  }
449 
450  /*
451  * getStandardFieldHTML
452  *
453  * @param int $field_id
454  * @return mixed
455  */
456  private function getStandardFieldHTML($field_id)
457  {
458  switch($field_id)
459  {
460  case 'owner':
461  return ilUserUtil::getNamePresentation($this->getOwner());
462  case 'last_edit_by':
464  case 'last_update':
466  case 'create_date':
468  }
469 
470  return $this->$field_id;
471  }
472 
473 
474  /*
475  * loadRecordFields
476  */
477  private function loadRecordFields()
478  {
479  if($this->recordfields == NULL)
480  {
481  $this->loadTable();
482  $recordfields = array();
483  foreach($this->table->getRecordFields() as $field)
484  {
485  if($recordfields[$field->getId()] == NULL)
486  {
487  $recordfields[$field->getId()] = ilDataCollectionCache::getRecordFieldCache($this, $field);
488  }
489  }
490 
491  $this->recordfields = $recordfields;
492  }
493  }
494 
495  /*
496  * loadTable
497  */
498  private function loadTable()
499  {
500  include_once("class.ilDataCollectionTable.php");
501 
502  if($this->table == NULL)
503  {
504  $this->table = ilDataCollectionCache::getTableCache($this->getTableId());
505  }
506  }
507 
508  /*
509  * getRecordField
510  */
511  public function getRecordField($field_id)
512  {
513  $this->loadRecordFields();
514 
515  return $this->recordfields[$field_id];
516  }
517 
518  /*
519  * doDelete
520  */
521  public function doDelete()
522  {
523  global $ilDB;
524 
525  $this->loadRecordFields();
526 
527  foreach($this->recordfields as $recordfield)
528  {
529  if($recordfield->getField()->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_FILE)
530  $this->deleteFile($recordfield->getValue());
531 
532  if($recordfield->getField()->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_MOB)
533  $this->deleteMob($recordfield->getValue());
534 
535 
536  $recordfield->delete();
537  }
538 
539 
540  $query = "DELETE FROM il_dcl_record WHERE id = ".$ilDB->quote($this->getId(), "integer");
541  $ilDB->manipulate($query);
542 
543  include_once "./Modules/DataCollection/classes/class.ilObjDataCollection.php";
544  ilObjDataCollection::sendNotification("delete_record", $this->getTableId(), $this->getId());
545  }
546 
547  /*
548  * deleteFile
549  */
550  public function deleteFile($obj_id)
551  {
552  if(ilObject2::_lookupObjId($obj_id)){
553  $file = new ilObjFile($obj_id, false);
554  $file->delete();
555  }
556  }
557 
558 
559  /*
560  * deleteMob
561  */
562  public function deleteMob($obj_id)
563  {
564  if(ilObject2::_lookupObjId($obj_id)){
565  $mob = new ilObjMediaObject($obj_id);
566  $mob->delete();
567  }
568  }
569 
570  /*
571  * passThroughFilter
572  */
573  public function passThroughFilter(array $filter)
574  {
575  $pass = true;
576  $this->loadTable();
577  foreach($this->table->getFields() as $field)
578  {
579  if(!ilDataCollectionDatatype::passThroughFilter($this, $field, $filter["filter_".$field->getId()]))
580  {
581  $pass = false;
582  }
583  }
584 
585  return $pass;
586  }
587 
588  /*
589  * hasPermissionToEdit
590  */
591  public function hasPermissionToEdit($ref)
592  {
593  return $this->getTable()->hasPermissionToEditRecord($ref, $this);
594  }
595 
596  /*
597  * hasPermissionToDelete
598  */
599  public function hasPermissionToDelete($ref)
600  {
601  return $this->getTable()->hasPermissionToDeleteRecord($ref, $this);
602  }
603 
604  /*
605  * getRecordFields
606  */
607  public function getRecordFields()
608  {
609  $this->loadRecordFields();
610 
611  return $this->recordfields;
612  }
613 
617  public function getTable()
618  {
619  $this->loadTable();
620 
621  return $this->table;
622  }
623 }
624 ?>