ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilDclTable.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
5include_once './Modules/DataCollection/classes/Fields/Base/class.ilDclStandardField.php';
6include_once './Modules/DataCollection/classes/Fields/Base/class.ilDclBaseRecordModel.php';
7include_once './Modules/DataCollection/classes/TableView/class.ilDclTableView.php';
8
22{
23
27 protected $id = 0;
31 protected $objId;
35 protected $obj;
39 protected $title;
43 protected $fields;
47 protected $stdFields;
51 protected $records;
55 protected $is_visible;
59 protected $add_perm;
63 protected $edit_perm;
67 protected $delete_perm;
71 protected $edit_by_owner;
83 protected $limited;
87 protected $limit_start;
91 protected $limit_end;
95 protected $export_enabled;
99 protected $table_order;
109 protected $default_sort_field = 0;
115 protected $default_sort_field_order = 'asc';
121 protected $description = '';
127 protected $public_comments = 0;
134
139 protected $all_fields = null;
140
141
145 public function __construct($a_id = 0)
146 {
147 if ($a_id != 0) {
148 $this->id = $a_id;
149 $this->doRead();
150 }
151 }
152
153
157 public function doRead()
158 {
159 global $DIC;
160 $ilDB = $DIC['ilDB'];
161
162 $query = "SELECT * FROM il_dcl_table WHERE id = " . $ilDB->quote($this->getId(), "integer");
163 $set = $ilDB->query($query);
164 $rec = $ilDB->fetchAssoc($set);
165
166 $this->setObjId($rec["obj_id"]);
167 $this->setTitle($rec["title"]);
168 $this->setAddPerm($rec["add_perm"]);
169 $this->setEditPerm($rec["edit_perm"]);
170 $this->setDeletePerm($rec["delete_perm"]);
171 $this->setEditByOwner($rec["edit_by_owner"]);
172 $this->setExportEnabled($rec["export_enabled"]);
173 $this->setImportEnabled($rec["import_enabled"]);
174 $this->setLimited($rec["limited"]);
175 $this->setLimitStart($rec["limit_start"]);
176 $this->setLimitEnd($rec["limit_end"]);
177 $this->setIsVisible($rec["is_visible"]);
178 $this->setDescription($rec['description']);
179 $this->setDefaultSortField($rec['default_sort_field_id']);
180 $this->setDefaultSortFieldOrder($rec['default_sort_field_order']);
181 $this->setPublicCommentsEnabled($rec['public_comments']);
182 $this->setViewOwnRecordsPerm($rec['view_own_records_perm']);
183 $this->setDeleteByOwner($rec['delete_by_owner']);
184 $this->setSaveConfirmation($rec['save_confirmation']);
185 $this->setOrder($rec['table_order']);
186 }
187
188
196 public function doDelete($delete_only_content = false, $omit_notification = false)
197 {
198 global $DIC;
199 $ilDB = $DIC['ilDB'];
200
202 foreach ($this->getRecords() as $record) {
203 $record->doDelete($omit_notification);
204 }
205
206 foreach ($this->getRecordFields() as $field) {
207 $field->doDelete();
208 }
209
210 // // SW: Fix #12794 und #11405
211 // // Problem is that when the DC object gets deleted, $this::getCollectionObject() tries to load the DC but it's not in the DB anymore
212 // // If $delete_main_table is true, avoid getting the collection object
213 // $exec_delete = false;
214 // if ($delete_main_table) {
215 // $exec_delete = true;
216 // }
217 // if (!$exec_delete && $this->getCollectionObject()->getFirstVisibleTableId() != $this->getId()) {
218 // $exec_delete = true;
219 // }
220 if (!$delete_only_content) {
221 $query = "DELETE FROM il_dcl_table WHERE id = " . $ilDB->quote($this->getId(), "integer");
222 $ilDB->manipulate($query);
223 }
224 }
225
226
230 public function doCreate($create_tablefield_setting = true, $create_standardview = true)
231 {
232 global $DIC;
233 $ilDB = $DIC['ilDB'];
234
235 $id = $ilDB->nextId("il_dcl_table");
236 $this->setId($id);
237 $query = "INSERT INTO il_dcl_table (" . "id" . ", obj_id" . ", title" . ", add_perm" . ", edit_perm" . ", delete_perm" . ", edit_by_owner"
238 . ", limited" . ", limit_start" . ", limit_end" . ", is_visible" . ", export_enabled" . ", import_enabled" . ", default_sort_field_id"
239 . ", default_sort_field_order" . ", description" . ", public_comments" . ", view_own_records_perm"
240 . ", delete_by_owner, save_confirmation , table_order ) VALUES (" . $ilDB->quote($this->getId(), "integer") . ","
241 . $ilDB->quote($this->getObjId(), "integer") . "," . $ilDB->quote($this->getTitle(), "text") . ","
242 . $ilDB->quote($this->getAddPerm() ? 1 : 0, "integer") . "," . $ilDB->quote($this->getEditPerm() ? 1 : 0, "integer") . ","
243 . $ilDB->quote($this->getDeletePerm() ? 1 : 0, "integer") . "," . $ilDB->quote($this->getEditByOwner() ? 1 : 0, "integer") . ","
244 . $ilDB->quote($this->getLimited() ? 1 : 0, "integer") . "," . $ilDB->quote($this->getLimitStart(), "timestamp") . ","
245 . $ilDB->quote($this->getLimitEnd(), "timestamp") . "," . $ilDB->quote($this->getIsVisible() ? 1 : 0, "integer") . ","
246 . $ilDB->quote($this->getExportEnabled() ? 1 : 0, "integer") . "," . $ilDB->quote($this->getImportEnabled() ? 1 : 0, "integer") . ","
247 . $ilDB->quote($this->getDefaultSortField(), "text") . "," . $ilDB->quote($this->getDefaultSortFieldOrder(), "text") . ","
248 . $ilDB->quote($this->getDescription(), "text") . "," . $ilDB->quote($this->getPublicCommentsEnabled(), "integer") . ","
249 . $ilDB->quote($this->getViewOwnRecordsPerm(), "integer") . "," . $ilDB->quote($this->getDeleteByOwner() ? 1 : 0, 'integer') . ","
250 . $ilDB->quote($this->getSaveConfirmation() ? 1 : 0, 'integer') . "," . $ilDB->quote($this->getOrder(), 'integer') . ")";
251
252 $ilDB->manipulate($query);
253
254 if ($create_standardview) {
255 //standard tableview
257 }
258
259 if ($create_tablefield_setting) {
260 $this->buildOrderFields();
261 }
262 }
263
264 /*
265 * doUpdate
266 */
267 public function doUpdate()
268 {
269 global $DIC;
270 $ilDB = $DIC['ilDB'];
271
272 $ilDB->update("il_dcl_table", array(
273 "obj_id" => array( "integer", $this->getObjId() ),
274 "title" => array( "text", $this->getTitle() ),
275 "add_perm" => array( "integer", (int) $this->getAddPerm() ),
276 "edit_perm" => array( "integer", (int) $this->getEditPerm() ),
277 "delete_perm" => array( "integer", (int) $this->getDeletePerm() ),
278 "edit_by_owner" => array( "integer", (int) $this->getEditByOwner() ),
279 "limited" => array( "integer", $this->getLimited() ),
280 "limit_start" => array( "timestamp", $this->getLimitStart() ),
281 "limit_end" => array( "timestamp", $this->getLimitEnd() ),
282 "is_visible" => array( "integer", $this->getIsVisible() ? 1 : 0 ),
283 "export_enabled" => array( "integer", $this->getExportEnabled() ? 1 : 0 ),
284 "import_enabled" => array( "integer", $this->getImportEnabled() ? 1 : 0 ),
285 "description" => array( "text", $this->getDescription() ),
286 "default_sort_field_id" => array( "text", $this->getDefaultSortField() ),
287 "default_sort_field_order" => array( "text", $this->getDefaultSortFieldOrder() ),
288 "public_comments" => array( "integer", $this->getPublicCommentsEnabled() ? 1 : 0 ),
289 "view_own_records_perm" => array( "integer", $this->getViewOwnRecordsPerm() ),
290 'delete_by_owner' => array( 'integer', $this->getDeleteByOwner() ? 1 : 0 ),
291 'save_confirmation' => array( 'integer', $this->getSaveConfirmation() ? 1 : 0 ),
292 'table_order' => array( 'integer', $this->getOrder() ),
293 ), array(
294 "id" => array( "integer", $this->getId() )
295 ));
296 }
297
298
304 public function setId($a_id)
305 {
306 $this->id = $a_id;
307 }
308
309
315 public function getId()
316 {
317 return $this->id;
318 }
319
320
324 public function setObjId($a_id)
325 {
326 $this->objId = $a_id;
327 }
328
329
333 public function getObjId()
334 {
335 return $this->objId;
336 }
337
338
342 public function setTitle($a_title)
343 {
344 $this->title = $a_title;
345 }
346
347
351 public function getTitle()
352 {
353 return $this->title;
354 }
355
356
360 public function getCollectionObject()
361 {
362 $this->loadObj();
363
364 return $this->obj;
365 }
366
367
368 protected function loadObj()
369 {
370 if ($this->obj == null) {
371 $this->obj = new ilObjDataCollection($this->objId, false);
372 }
373 }
374
375
379 public function getRecords()
380 {
381 if ($this->records == null) {
382 $this->loadRecords();
383 }
384
385 return $this->records;
386 }
387
388 public function loadRecords()
389 {
390 global $DIC;
391 $ilDB = $DIC['ilDB'];
392
393 $records = array();
394 $query = "SELECT id FROM il_dcl_record WHERE table_id = " . $ilDB->quote($this->id, "integer");
395 $set = $ilDB->query($query);
396
397 while ($rec = $ilDB->fetchAssoc($set)) {
398 $records[$rec['id']] = ilDclCache::getRecordCache($rec['id']);
399 }
400
401 $this->records = $records;
402 }
403
407 public function deleteField($field_id)
408 {
409 $field = ilDclCache::getFieldCache($field_id);
410 $records = $this->getRecords();
411
412 foreach ($records as $record) {
413 $record->deleteField($field_id);
414 }
415
416 $field->doDelete();
417 }
418
419
425 public function getField($field_id)
426 {
427 $fields = $this->getFields();
428 $field = null;
429 foreach ($fields as $field_1) {
430 if ($field_1->getId() == $field_id) {
431 $field = $field_1;
432 }
433 }
434
435 return $field;
436 }
437
442 public function getFieldIds()
443 {
444 $field_ids = array();
445 foreach ($this->getFields() as $field) {
446 if ($field->getId()) {
447 $field_ids[] = $field->getId();
448 }
449 }
450 return $field_ids;
451 }
452
453
454 protected function loadCustomFields()
455 {
456 if (!$this->fields) {
457 global $DIC;
458 $ilDB = $DIC['ilDB'];
462 $query = "SELECT DISTINCT il_dcl_field.*, il_dcl_tfield_set.field_order
463 FROM il_dcl_field
464 INNER JOIN il_dcl_tfield_set
465 ON ( il_dcl_tfield_set.field NOT IN ('owner',
466 'last_update',
467 'last_edit_by',
468 'id',
469 'create_date')
470 AND il_dcl_tfield_set.table_id = il_dcl_field.table_id
471 AND il_dcl_tfield_set.field = " . $ilDB->cast("il_dcl_field.id", "text") . ")
472 WHERE il_dcl_field.table_id = %s
473 ORDER BY il_dcl_tfield_set.field_order ASC";
474
475 $set = $ilDB->queryF($query, array('integer'), array((int) $this->getId()));
476 $fields = array();
477 while ($rec = $ilDB->fetchAssoc($set)) {
479 $fields[] = $field;
480 }
481 $this->fields = $fields;
482
484 }
485 }
486
487 public function getCustomFields()
488 {
489 if (!$this->fields) {
490 $this->loadCustomFields();
491 }
492 return $this->fields;
493 }
494
495
501 public function getNewFieldOrder()
502 {
503 $fields = $this->getFields();
504 $place = 0;
505 foreach ($fields as $field) {
506 if (!$field->isStandardField()) {
507 $place = $field->getOrder() + 1;
508 }
509 }
510
511 return $place;
512 }
513
517 public function getNewTableviewOrder()
518 {
519 return (ilDclTableView::getCountForTableId($this->getId()) + 1) * 10;
520 }
521
525 public function sortTableViews(array $tableviews = null)
526 {
527 if ($tableviews == null) {
528 $tableviews = $this->getTableViews();
529 }
530
531 $order = 10;
532 foreach ($tableviews as $tableview) {
533 $tableview->setTableviewOrder($order);
534 $tableview->update();
535 $order += 10;
536 }
537 }
538
539
546 public function getFields()
547 {
548 if ($this->all_fields == null) {
549 $this->reloadFields();
550 }
551
552 return $this->all_fields;
553 }
554
555 public function reloadFields()
556 {
557 $this->loadCustomFields();
558 $this->stdFields = $this->getStandardFields();
559 $fields = array_merge($this->fields, $this->stdFields);
560
561 $this->sortByOrder($fields);
562
563 $this->all_fields = $fields;
564 }
565
569 public function getTableViews()
570 {
572 }
573
581 public function getVisibleTableViews($ref_id, $with_active_detailedview = false, $user_id = 0)
582 {
583 if (ilObjDataCollectionAccess::hasWriteAccess($ref_id, $user_id) && !$with_active_detailedview) {
584 return $this->getTableViews();
585 }
586
587 $visible_views = array();
588 foreach ($this->getTableViews() as $tableView) {
589 if (ilObjDataCollectionAccess::hasAccessToTableView($tableView, $user_id)) {
590 if (!$with_active_detailedview || ilDclDetailedViewDefinition::isActive($tableView->getId())) {
591 $visible_views[] = $tableView;
592 }
593 }
594 }
595 return $visible_views;
596 }
597
605 public function getFirstTableViewId($ref_id, $user_id = 0)
606 {
607 $tableview = array_shift($this->getVisibleTableViews($ref_id, false, $user_id));
608 return $tableview ? $tableview->getId() : false;
609 }
610
616 public function getFieldsForFormula()
617 {
618 $unsupported = array(
627 );
628
629 $this->loadCustomFields();
630 $return = $this->getStandardFields();
634 foreach ($this->fields as $field) {
635 if (!in_array($field->getDatatypeId(), $unsupported)) {
636 $return[] = $field;
637 }
638 }
639
640 return $return;
641 }
642
643
650 public function getStandardFields()
651 {
652 if ($this->stdFields == null) {
653 $this->stdFields = ilDclStandardField::_getStandardFields($this->id);
654 // Don't return comments as field if this feature is not activated in the settings
655 if (!$this->getPublicCommentsEnabled()) {
657 foreach ($this->stdFields as $k => $field) {
658 if ($field->getId() == 'comments') {
659 unset($this->stdFields[$k]);
660 break;
661 }
662 }
663 }
664 }
665
666 return $this->stdFields;
667 }
668
669
675 public function getRecordFields()
676 {
677 $this->loadCustomFields();
678
679 return $this->fields;
680 }
681
685 public function getEditableFields()
686 {
687 $fields = $this->getRecordFields();
688 $editableFields = array();
689
690 foreach ($fields as $field) {
691 if (!$field->getLocked()) {
692 $editableFields[] = $field;
693 }
694 }
695
696 return $editableFields;
697 }
698
704 public function getExportableFields()
705 {
706 $fields = $this->getFields();
707 $exportableFields = array();
708 foreach ($fields as $field) {
709 if ($field->getExportable()) {
710 $exportableFields[] = $field;
711 }
712 }
713
714 return $exportableFields;
715 }
716
717
724 public function hasPermissionToEditRecord($ref_id, ilDclBaseRecordModel $record)
725 {
726 if ($this->getObjId() != ilObjDataCollection::_lookupObjectId($ref_id)) {
727 return false;
728 }
730 return true;
731 }
733 return false;
734 }
735 if (!$this->checkLimit()) {
736 return false;
737 }
738 if ($this->getEditPerm() && !$this->getEditByOwner()) {
739 return true;
740 }
741 if ($this->getEditByOwner()) {
742 return $this->doesRecordBelongToUser($record);
743 }
744
745 return false;
746 }
747
748
755 public function hasPermissionToDeleteRecord($ref_id, ilDclBaseRecordModel $record)
756 {
757 if ($this->getObjId() != ilObjDataCollection::_lookupObjectId($ref_id)) {
758 return false;
759 }
761 return true;
762 }
764 return false;
765 }
766 if (!$this->checkLimit()) {
767 return false;
768 }
769 if ($this->getDeletePerm() && !$this->getDeleteByOwner()) {
770 return true;
771 }
772 if ($this->getDeleteByOwner()) {
773 return $this->doesRecordBelongToUser($record);
774 }
775
776 return false;
777 }
778
779
785 public function hasPermissionToDeleteRecords($ref_id)
786 {
787 if ($this->getObjId() != ilObjDataCollection::_lookupObjectId($ref_id)) {
788 return false;
789 }
792 }
793
794
802 public function hasPermissionToViewRecord($ref_id, $record, $user_id = 0)
803 {
804 global $DIC;
805 $ilUser = $DIC['ilUser'];
806 if ($this->getObjId() != ilObjDataCollection::_lookupObjectId($ref_id)) {
807 return false;
808 }
809 if (ilObjDataCollectionAccess::hasWriteAccess($ref_id, $user_id) || ilObjDataCollectionAccess::hasEditAccess($ref_id, $user_id)) {
810 return true;
811 }
813 // Check for view only own entries setting
814 if ($this->getViewOwnRecordsPerm() && ($user_id ? $user_id : $ilUser->getId()) != $record->getOwner()) {
815 return false;
816 }
817
818 return true;
819 }
820
821 return false;
822 }
823
824
831 {
832 global $DIC;
833 $ilUser = $DIC['ilUser'];
834
835 return ($ilUser->getId() == $record->getOwner());
836 }
837
838
842 public function checkLimit()
843 {
844 if ($this->getLimited()) {
845 $now = new ilDateTime(date("Y-m-d H:i:s"), IL_CAL_DATE);
846 $from = new ilDateTime($this->getLimitStart(), IL_CAL_DATE);
847 $to = new ilDateTime($this->getLimitEnd(), IL_CAL_DATE);
848
849 return ($from <= $now && $now <= $to);
850 }
851
852 return true;
853 }
854
855
859 public function updateFields()
860 {
861 foreach ($this->getFields() as $field) {
862 $field->doUpdate();
863 }
864 }
865
871 public function sortFields(&$fields)
872 {
873 $this->sortByOrder($fields);
874 //After sorting the array loses it's keys respectivly their keys are set form $field->id to 1,2,3... so we reset the keys.
875 $named = array();
876 foreach ($fields as $field) {
877 $named[$field->getId()] = $field;
878 }
879
880 $fields = $named;
881 }
882
883
888 protected function sortByOrder(&$array)
889 {
890 // php-bug: https://bugs.php.net/bug.php?id=50688
891 // fixed in php 7 but for now we need the @ a workaround
892 @usort($array, array( $this, "compareOrder" ));
893 }
894
895
900 public function buildOrderFields()
901 {
902 $fields = $this->getFields();
903 $this->sortByOrder($fields);
904 $count = 10;
905 $offset = 10;
906 foreach ($fields as $field) {
907 if (!is_null($field->getOrder())) {
908 $field->setOrder($count);
909 $count = $count + $offset;
910 $field->doUpdate();
911 }
912 }
913 }
914
915
923 public function getFieldByTitle($title)
924 {
925 $return = null;
926 foreach ($this->getFields() as $field) {
927 if ($field->getTitle() == $title) {
928 $return = $field;
929 break;
930 }
931 }
932
933 return $return;
934 }
935
936
940 public function setAddPerm($add_perm)
941 {
942 $this->add_perm = $add_perm;
943 }
944
945
949 public function getAddPerm()
950 {
951 return (bool) $this->add_perm;
952 }
953
954
959 {
960 $this->delete_perm = $delete_perm;
961 if (!$delete_perm) {
962 $this->setDeleteByOwner(false);
963 }
964 }
965
966
970 public function getDeletePerm()
971 {
972 return (bool) $this->delete_perm;
973 }
974
975
980 {
981 $this->edit_by_owner = $edit_by_owner;
982 if ($edit_by_owner) {
983 $this->setEditPerm(true);
984 }
985 }
986
987
991 public function getEditByOwner()
992 {
993 return (bool) $this->edit_by_owner;
994 }
995
996
1000 public function getDeleteByOwner()
1001 {
1002 return (bool) $this->delete_by_owner;
1003 }
1004
1005
1010 {
1011 $this->delete_by_owner = $delete_by_owner;
1012 if ($delete_by_owner) {
1013 $this->setDeletePerm(true);
1014 }
1015 }
1016
1017
1021 public function setEditPerm($edit_perm)
1022 {
1023 $this->edit_perm = $edit_perm;
1024 if (!$edit_perm) {
1025 $this->setEditByOwner(false);
1026 }
1027 }
1028
1029
1033 public function getEditPerm()
1034 {
1035 return (bool) $this->edit_perm;
1036 }
1037
1038
1042 public function setLimited($limited)
1043 {
1044 $this->limited = $limited;
1045 }
1046
1047
1051 public function getLimited()
1052 {
1053 return $this->limited;
1054 }
1055
1056
1060 public function setLimitEnd($limit_end)
1061 {
1062 $this->limit_end = $limit_end;
1063 }
1064
1065
1069 public function getLimitEnd()
1070 {
1071 return $this->limit_end;
1072 }
1073
1074
1079 {
1080 $this->limit_start = $limit_start;
1081 }
1082
1083
1087 public function getLimitStart()
1088 {
1089 return $this->limit_start;
1090 }
1091
1092
1096 public function setIsVisible($is_visible)
1097 {
1098 $this->is_visible = $is_visible;
1099 }
1100
1101
1105 public function getIsVisible()
1106 {
1107 return $this->is_visible;
1108 }
1109
1110
1115 {
1116 $this->description = $description;
1117 }
1118
1119
1123 public function getDescription()
1124 {
1125 return $this->description;
1126 }
1127
1128
1135 {
1136 $default_sort_field = ($default_sort_field) ? $default_sort_field : 0; // Change null or empty strings to zero
1137 $this->default_sort_field = $default_sort_field;
1138 }
1139
1140
1144 public function getDefaultSortField()
1145 {
1147 }
1148
1149
1154 {
1155 if (!in_array($default_sort_field_order, array( 'asc', 'desc' ))) {
1157 }
1158 $this->default_sort_field_order = $default_sort_field_order;
1159 }
1160
1161
1166 {
1168 }
1169
1170
1175 {
1176 $this->public_comments = $public_comments;
1177 }
1178
1179
1184 {
1186 }
1187
1188
1192 public function setViewOwnRecordsPerm($view_own_perm)
1193 {
1194 $this->view_own_records_perm = (int) $view_own_perm;
1195 }
1196
1197
1201 public function getViewOwnRecordsPerm()
1202 {
1203 return (bool) $this->view_own_records_perm;
1204 }
1205
1206
1210 public function getSaveConfirmation()
1211 {
1213 }
1214
1215
1220 {
1221 $this->save_confirmation = $save_confirmation;
1222 }
1223
1224
1230 public function hasCustomFields()
1231 {
1232 $this->loadCustomFields();
1233
1234 return (count($this->fields) > 0) ? true : false;
1235 }
1236
1237
1243 public function compareOrder($a, $b)
1244 {
1245 if (is_null($a->getOrder() == null) && is_null($b->getOrder() == null)) {
1246 return 0;
1247 }
1248 if (is_null($a->getOrder())) {
1249 return 1;
1250 }
1251 if (is_null($b->getOrder())) {
1252 return -1;
1253 }
1254
1255 return $a->getOrder() < $b->getOrder() ? -1 : 1;
1256 }
1257
1258
1262 public function cloneStructure(ilDclTable $original)
1263 {
1264 $this->setTitle($original->getTitle());
1265 $this->setDescription($original->getDescription());
1266 $this->setIsVisible($original->getIsVisible());
1267 $this->setEditByOwner($original->getEditByOwner());
1268 $this->setAddPerm($original->getAddPerm());
1269 $this->setEditPerm($original->getEditPerm());
1270 $this->setDeleteByOwner($original->getDeleteByOwner());
1271 $this->setSaveConfirmation($original->getSaveConfirmation());
1272 $this->setDeletePerm($original->getDeletePerm());
1273 $this->setLimited($original->getLimited());
1274 $this->setLimitStart($original->getLimitStart());
1275 $this->setLimitEnd($original->getLimitEnd());
1276 $this->setViewOwnRecordsPerm($original->getViewOwnRecordsPerm());
1277 $this->setExportEnabled($original->getExportEnabled());
1278 $this->setImportEnabled($original->getImportEnabled());
1281 $this->setOrder($original->getOrder());
1282
1283 $this->doCreate(true, false);
1284 // reset stdFields to get new for the created object
1285
1287 // Clone standard-fields
1288 $org_std_fields = $original->getStandardFields();
1289 foreach ($this->getStandardFields() as $element_key => $std_field) {
1290 $std_field->cloneStructure($org_std_fields[$element_key]);
1291 if ($std_field->getId() === $original->getDefaultSortField()) {
1292 $default_sort_field = $std_field->getId();
1293 }
1294 }
1295
1296 // Clone fields
1297 $new_fields = array();
1298 foreach ($original->getFields() as $orig_field) {
1299 if (!$orig_field->isStandardField()) {
1300 $class_name = get_class($orig_field);
1301 $new_field = new $class_name();
1302 $new_field->setTableId($this->getId());
1303 $new_field->cloneStructure($orig_field->getId());
1304 $new_fields[$orig_field->getId()] = $new_field;
1305
1306 if ($orig_field->getId() === $original->getDefaultSortField()) {
1307 $default_sort_field = $new_field->getId();
1308 }
1309 }
1310 }
1311
1313 $this->doUpdate();
1314
1315 // Clone Records with recordfields
1316 foreach ($original->getRecords() as $orig_record) {
1317 $new_record = new ilDclBaseRecordModel();
1318 $new_record->setTableId($this->getId());
1319 $new_record->cloneStructure($orig_record->getId(), $new_fields);
1320 }
1321
1322 //clone tableviews (includes pageobjects)
1323 foreach ($original->getTableViews() as $orig_tableview) {
1324 $new_tableview = new ilDclTableView();
1325 $new_tableview->setTableId($this->getId());
1326 $new_tableview->cloneStructure($orig_tableview, $new_fields);
1327 }
1328
1329 // mandatory for all cloning functions
1330 ilDclCache::setCloneOf($original->getId(), $this->getId(), ilDclCache::TYPE_TABLE);
1331 }
1332
1333
1337 public function afterClone()
1338 {
1339 foreach ($this->getFields() as $field) {
1340 $field->afterClone($this->getRecords());
1341 }
1342 }
1343
1344
1350 public function _hasRecords()
1351 {
1352 return (count($this->getRecords()) > 0) ? true : false;
1353 }
1354
1355
1359 public function addField($field)
1360 {
1361 $this->all_fields[$field->getId()] = $field;
1362 }
1363
1364
1370 public static function _tableExists($table_id)
1371 {
1372 global $DIC;
1373 $ilDB = $DIC['ilDB'];
1374 $query = "SELECT * FROM il_dcl_table WHERE id = " . $table_id;
1375 $result = $ilDB->query($query);
1376
1377 return $result->numRows() != 0;
1378 }
1379
1380
1387 public static function _getTableIdByTitle($title, $obj_id)
1388 {
1389 global $DIC;
1390 $ilDB = $DIC['ilDB'];
1391 $result = $ilDB->query('SELECT id FROM il_dcl_table WHERE title = ' . $ilDB->quote($title, 'text') . ' AND obj_id = '
1392 . $ilDB->quote($obj_id, 'integer'));
1393 $id = 0;
1394 while ($rec = $ilDB->fetchAssoc($result)) {
1395 $id = $rec['id'];
1396 }
1397
1398 return $id;
1399 }
1400
1405 {
1406 $this->export_enabled = $export_enabled;
1407 }
1408
1409
1413 public function getExportEnabled()
1414 {
1415 return $this->export_enabled;
1416 }
1417
1421 public function getOrder()
1422 {
1423 if (!$this->table_order) {
1424 $this->updateOrder();
1425 }
1426 return $this->table_order;
1427 }
1428
1432 public function updateOrder()
1433 {
1434 global $DIC;
1435 $ilDB = $DIC['ilDB'];
1436 $result = $ilDB->query('SELECT MAX(table_order) AS table_order FROM il_dcl_table WHERE obj_id = ' . $ilDB->quote($this->getCollectionObject()->getId(), 'integer'));
1437 $this->table_order = $ilDB->fetchObject($result)->table_order + 10;
1438 $ilDB->query('UPDATE il_dcl_table SET table_order = ' . $ilDB->quote($this->table_order, 'integer') . ' WHERE id = ' . $ilDB->quote($this->getId(), 'integer'));
1439 }
1440
1444 public function setOrder($table_order)
1445 {
1446 $this->table_order = $table_order;
1447 }
1448
1449
1454 {
1455 $this->import_enabled = $import_enabled;
1456 }
1457
1458
1462 public function getImportEnabled()
1463 {
1464 return $this->import_enabled;
1465 }
1466
1467
1476 public static function _hasFieldByTitle($title, $obj_id)
1477 {
1478 global $DIC;
1479 $ilDB = $DIC['ilDB'];
1480 $result = $ilDB->query('SELECT * FROM il_dcl_field WHERE table_id = ' . $ilDB->quote($obj_id, 'integer') . ' AND title = '
1481 . $ilDB->quote($title, 'text'));
1482
1483 return ($ilDB->numRows($result)) ? true : false;
1484 }
1485
1486
1498 public function getPartialRecords($sort, $direction, $limit, $offset, array $filter = array())
1499 {
1500 global $DIC;
1501 $ilDB = $DIC['ilDB'];
1505 $ilUser = $DIC['ilUser'];
1506 $rbacreview = $DIC['rbacreview'];
1507
1508 $sort_field = ($sort) ? $this->getFieldByTitle($sort) : $this->getField('id');
1509 $direction = strtolower($direction);
1510 $direction = (in_array($direction, array( 'desc', 'asc' ))) ? $direction : 'asc';
1511
1512 // Sorting by a status from an ILIAS Ref field. This column is added dynamically to the table, there is no field model
1513 $sort_by_status = false;
1514 if (substr($sort, 0, 8) == '_status_') {
1515 $sort_by_status = true;
1516 $sort_field = $this->getFieldByTitle(substr($sort, 8));
1517 }
1518
1519 if (is_null($sort_field)) {
1520 $sort_field = $this->getField('id');
1521 }
1522
1523 $sort_query_object = $sort_field->getRecordQuerySortObject($direction, $sort_by_status);
1524
1525 $select_str = ($sort_query_object != null) ? $sort_query_object->getSelectStatement() : '';
1526 $join_str = ($sort_query_object != null) ? $sort_query_object->getJoinStatement() : '';
1527 $where_str = ($sort_query_object != null) ? $sort_query_object->getWhereStatement() : '';
1528 $order_str = ($sort_query_object != null) ? $sort_query_object->getOrderStatement() : '';
1529 $group_str = ($sort_query_object != null) ? $sort_query_object->getGroupStatement() : '';
1530
1531 if (count($filter)) {
1532 foreach ($filter as $key => $filter_value) {
1533 $filter_field_id = substr($key, 7);
1534 $filter_field = $this->getField($filter_field_id);
1535 $filter_record_query_object = $filter_field->getRecordQueryFilterObject($filter_value, $sort_field);
1536
1537 if ($filter_record_query_object) {
1538 $select_str .= $filter_record_query_object->getSelectStatement();
1539 $join_str .= $filter_record_query_object->getJoinStatement();
1540 $where_str .= $filter_record_query_object->getWhereStatement();
1541 $group_str .= $filter_record_query_object->getGroupStatement();
1542 }
1543 }
1544 }
1545
1546 // Build the query string
1547 $sql = "SELECT DISTINCT record.id, record.owner";
1548 if ($select_str) {
1549 $sql .= ', ';
1550 }
1551
1552 $as = $ilDB->getDBType() == 'oracle' ? '' : ' AS ';
1553
1554 $sql .= rtrim($select_str, ',') . " FROM il_dcl_record {$as} record ";
1555 $sql .= $join_str;
1556 $sql .= " WHERE record.table_id = " . $ilDB->quote($this->getId(), 'integer');
1557
1558 if (strlen($where_str) > 0) {
1559 $sql .= $where_str;
1560 }
1561
1562 if (strlen($group_str) > 0) {
1563 $sql .= " GROUP BY " . $group_str;
1564 }
1565
1566 if (strlen($order_str) > 0) {
1567 $sql .= " ORDER BY " . $order_str;
1568 }
1569
1570 //var_dump($sql);
1571 /*global $DIC;
1572 /*$ilLog = $DIC['ilLog'];
1573 $ilLog->write($sql, ilLogLevel::CRITICAL);*/
1574
1575 $set = $ilDB->query($sql);
1576 $total_record_ids = array();
1577 // Save record-ids in session to enable prev/next links in detail view
1578 $_SESSION['dcl_record_ids'] = array();
1579 $_SESSION['dcl_table_id'] = $this->getId();
1580 $ref = filter_input(INPUT_GET, 'ref_id');
1582 while ($rec = $ilDB->fetchAssoc($set)) {
1583 // Quick check if the current user is allowed to view the record
1584 if (!$is_allowed_to_view && ($this->getViewOwnRecordsPerm() && $ilUser->getId() != $rec['owner'])) {
1585 continue;
1586 }
1587 $total_record_ids[] = $rec['id'];
1588 $_SESSION['dcl_record_ids'][] = $rec['id'];
1589 }
1590
1591 if ($sort_query_object != null) {
1592 $total_record_ids = $sort_query_object->applyCustomSorting($sort_field, $total_record_ids, $direction);
1593 }
1594
1595 // Now slice the array to load only the needed records in memory
1596 $record_ids = array_slice($total_record_ids, $offset, $limit);
1597
1598 $records = array();
1599 foreach ($record_ids as $id) {
1601 }
1602
1603 return array( 'records' => $records, 'total' => count($total_record_ids) );
1604 }
1605}
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
$result
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATE
@classDescription Date and time handling
Class ilDclBaseRecordModel.
static getRecordCache($record_id=0)
static buildFieldFromRecord($rec)
static setCloneOf($old, $new, $type)
static getFieldCache($field_id=0)
static preloadFieldProperties(array $fields)
Preloads field properties.
static _getStandardFields($table_id)
Class ilDclTableView.
static getCountForTableId($table_id)
static createOrGetStandardView($table_id, $create_default_settings=true)
static getAllForTableId($table_id)
Class ilDclBaseFieldModel.
updateFields()
Update fields.
setViewOwnRecordsPerm($view_own_perm)
_hasRecords()
_hasRecords
getRecordFields()
Returns all fields of this table which are NOT standard fields.
setId($a_id)
Set table id.
buildOrderFields()
buildOrderFields orders the fields.
sortFields(&$fields)
sortFields
hasPermissionToDeleteRecord($ref_id, ilDclBaseRecordModel $record)
setPublicCommentsEnabled($public_comments)
setDefaultSortField($default_sort_field)
/**
hasPermissionToViewRecord($ref_id, $record, $user_id=0)
doesRecordBelongToUser(ilDclBaseRecordModel $record)
getField($field_id)
getExportableFields()
Return all the fields that are marked as exportable.
setLimited($limited)
getFirstTableViewId($ref_id, $user_id=0)
get id of first (for current user) available view
hasPermissionToEditRecord($ref_id, ilDclBaseRecordModel $record)
setEditByOwner($edit_by_owner)
getVisibleTableViews($ref_id, $with_active_detailedview=false, $user_id=0)
For current user.
hasCustomFields()
hasCustomFields
sortTableViews(array $tableviews=null)
setDeleteByOwner($delete_by_owner)
setDefaultSortFieldOrder($default_sort_field_order)
setSaveConfirmation($save_confirmation)
setImportEnabled($import_enabled)
setExportEnabled($export_enabled)
getNewFieldOrder()
getNewOrder
deleteField($field_id)
cloneStructure(ilDclTable $original)
static _getTableIdByTitle($title, $obj_id)
static _tableExists($table_id)
getFieldByTitle($title)
Get a field by title.
setLimitEnd($limit_end)
setOrder($table_order)
setDescription($description)
sortByOrder(&$array)
__construct($a_id=0)
getFields()
Returns all fields of this table including the standard fields.
compareOrder($a, $b)
setEditPerm($edit_perm)
setDeletePerm($delete_perm)
doCreate($create_tablefield_setting=true, $create_standardview=true)
doRead()
Read table.
getId()
Get table id.
setAddPerm($add_perm)
hasPermissionToDeleteRecords($ref_id)
setTitle($a_title)
static _hasFieldByTitle($title, $obj_id)
Checks if a table has a field with the given title.
setIsVisible($is_visible)
setLimitStart($limit_start)
static hasAccessToTableView($tableview, $user_id=0)
This only checks access to the tableview - if the full access check is required, use hasAccessTo($ref...
static hasEditAccess($ref, $user_id=0)
Has permission to view and edit all entries event when he is not the owner.
Class ilObjDataCollection.
static _lookupObjectId($a_ref_id)
lookup object id
$as
$key
Definition: croninfo.php:18
$query
global $DIC
Definition: saml.php:7
global $ilDB
$from
$errors fields
Definition: imgupload.php:51
$ilUser
Definition: imgupload.php:18