156 $ilDB = $DIC[
'ilDB'];
158 $query =
"SELECT * FROM il_dcl_table WHERE id = " .
$ilDB->quote($this->
getId(),
"integer");
160 $rec =
$ilDB->fetchAssoc($set);
181 $this->
setOrder($rec[
'table_order']);
192 public function doDelete($delete_only_content =
false, $omit_notification =
false)
195 $ilDB = $DIC[
'ilDB'];
199 $record->doDelete($omit_notification);
216 if (!$delete_only_content) {
217 $query =
"DELETE FROM il_dcl_table WHERE id = " .
$ilDB->quote($this->
getId(),
"integer");
226 public function doCreate($create_tablefield_setting =
true, $create_standardview =
true)
229 $ilDB = $DIC[
'ilDB'];
231 $id =
$ilDB->nextId(
"il_dcl_table");
233 $query =
"INSERT INTO il_dcl_table (" .
"id" .
", obj_id" .
", title" .
", add_perm" .
", edit_perm" .
", delete_perm" .
", edit_by_owner" 234 .
", limited" .
", limit_start" .
", limit_end" .
", is_visible" .
", export_enabled" .
", import_enabled" .
", default_sort_field_id" 235 .
", default_sort_field_order" .
", description" .
", public_comments" .
", view_own_records_perm" 236 .
", delete_by_owner, save_confirmation , table_order ) VALUES (" .
$ilDB->quote($this->
getId(),
"integer") .
"," 250 if ($create_standardview) {
255 if ($create_tablefield_setting) {
267 $ilDB = $DIC[
'ilDB'];
272 "obj_id" => array(
"integer", $this->
getObjId()),
273 "title" => array(
"text", $this->
getTitle()),
274 "add_perm" => array(
"integer", (
int) $this->
getAddPerm()),
275 "edit_perm" => array(
"integer", (
int) $this->
getEditPerm()),
276 "delete_perm" => array(
"integer", (
int) $this->
getDeletePerm()),
277 "edit_by_owner" => array(
"integer", (
int) $this->
getEditByOwner()),
278 "limited" => array(
"integer", $this->
getLimited()),
280 "limit_end" => array(
"timestamp", $this->
getLimitEnd()),
281 "is_visible" => array(
"integer", $this->
getIsVisible() ? 1 : 0),
291 'table_order' => array(
'integer', $this->
getOrder()),
294 "id" => array(
"integer", $this->
getId()),
327 $this->objId = $a_id;
345 $this->title = $a_title;
371 if ($this->obj == null) {
382 if ($this->records == null) {
393 $ilDB = $DIC[
'ilDB'];
396 $query =
"SELECT id FROM il_dcl_record WHERE table_id = " .
$ilDB->quote($this->
id,
"integer");
399 while ($rec =
$ilDB->fetchAssoc($set)) {
416 $record->deleteField($field_id);
432 foreach (
$fields as $field_1) {
433 if ($field_1->getId() == $field_id) {
449 $field_ids = array();
451 if ($field->getId()) {
452 $field_ids[] = $field->getId();
460 protected function loadCustomFields()
464 $ilDB = $DIC[
'ilDB'];
469 =
"SELECT DISTINCT il_dcl_field.*, il_dcl_tfield_set.field_order 471 INNER JOIN il_dcl_tfield_set 472 ON ( il_dcl_tfield_set.field NOT IN ('owner', 477 AND il_dcl_tfield_set.table_id = il_dcl_field.table_id 478 AND il_dcl_tfield_set.field = " .
$ilDB->cast(
"il_dcl_field.id",
"text") .
") 479 WHERE il_dcl_field.table_id = %s 480 ORDER BY il_dcl_tfield_set.field_order ASC";
482 $set =
$ilDB->queryF(
$query, array(
'integer'), array((
int) $this->
getId()));
484 while ($rec =
$ilDB->fetchAssoc($set)) {
498 $this->loadCustomFields();
515 if (!$field->isStandardField()) {
516 $place = $field->getOrder() + 1;
538 if ($tableviews == null) {
543 foreach ($tableviews as $tableview) {
544 $tableview->setTableviewOrder($order);
545 $tableview->update();
560 if ($this->all_fields == null) {
570 $this->loadCustomFields();
571 $this->stdFields = $this->getStandardFields();
603 $visible_views = array();
607 $visible_views[] = $tableView;
612 return $visible_views;
628 return $tableview ? $tableview->getId() :
false;
637 public function getFieldsForFormula()
639 $unsupported = array(
649 $this->loadCustomFields();
650 $return = $this->getStandardFields();
654 foreach ($this->
fields as $field) {
655 if (!in_array($field->getDatatypeId(), $unsupported)) {
670 public function getStandardFields()
672 if ($this->stdFields == null) {
677 foreach ($this->stdFields as $k => $field) {
678 if ($field->getId() ==
'comments') {
679 unset($this->stdFields[$k]);
697 $this->loadCustomFields();
709 $editableFields = array();
712 if (!$field->getViewSetting(
$_POST[
"tableview_id"])->isLocked($creation_mode)) {
713 $editableFields[] = $field;
717 return $editableFields;
729 $exportableFields = array();
731 if ($field->getExportable()) {
732 $exportableFields[] = $field;
736 return $exportableFields;
872 return ($from <= $now && $now <= $to);
901 $named[$field->getId()] = $field;
916 @usort($array, array($this,
"compareOrder"));
931 if (!is_null($field->getOrder())) {
932 $field->setOrder($count);
933 $count = $count + $offset;
951 if ($field->getTitle() ==
$title) {
1218 $this->view_own_records_perm = (int) $view_own_perm;
1256 $this->loadCustomFields();
1258 return (count($this->
fields) > 0) ? true :
false;
1270 if (is_null(
$a->getOrder() == null) && is_null(
$b->getOrder() == null)) {
1273 if (is_null(
$a->getOrder())) {
1276 if (is_null(
$b->getOrder())) {
1280 return $a->getOrder() <
$b->getOrder() ? -1 : 1;
1313 $org_std_fields = $original->getStandardFields();
1314 foreach ($this->getStandardFields() as $element_key => $std_field) {
1322 $new_fields = array();
1323 foreach ($original->
getFields() as $orig_field) {
1324 if (!$orig_field->isStandardField()) {
1325 $class_name = get_class($orig_field);
1326 $new_field =
new $class_name();
1327 $new_field->setTableId($this->
getId());
1328 $new_field->cloneStructure($orig_field->getId());
1329 $new_fields[$orig_field->getId()] = $new_field;
1341 foreach ($original->
getRecords() as $orig_record) {
1343 $new_record->setTableId($this->
getId());
1344 $new_record->cloneStructure($orig_record->getId(), $new_fields);
1350 $new_tableview->setTableId($this->
getId());
1351 $new_tableview->cloneStructure($orig_tableview, $new_fields);
1364 foreach ($this->
getFields() as $field) {
1377 return (count($this->
getRecords()) > 0) ? true :
false;
1386 $this->all_fields[$field->getId()] = $field;
1398 $ilDB = $DIC[
'ilDB'];
1399 $query =
"SELECT * FROM il_dcl_table WHERE id = " . $table_id;
1402 return $result->numRows() != 0;
1415 $ilDB = $DIC[
'ilDB'];
1417 'SELECT id FROM il_dcl_table WHERE title = ' .
$ilDB->quote(
$title,
'text') .
' AND obj_id = ' 1418 .
$ilDB->quote($obj_id,
'integer')
1452 if (!$this->table_order) {
1466 $ilDB = $DIC[
'ilDB'];
1467 $result =
$ilDB->query(
'SELECT MAX(table_order) AS table_order FROM il_dcl_table WHERE obj_id = ' .
$ilDB->quote($this->getCollectionObject()->getId(),
'integer'));
1468 $this->table_order =
$ilDB->fetchObject(
$result)->table_order + 10;
1469 $ilDB->query(
'UPDATE il_dcl_table SET table_order = ' .
$ilDB->quote($this->table_order,
'integer') .
' WHERE id = ' .
$ilDB->quote($this->
getId(),
'integer'));
1511 $ilDB = $DIC[
'ilDB'];
1513 'SELECT * FROM il_dcl_field WHERE table_id = ' .
$ilDB->quote($obj_id,
'integer') .
' AND title = ' 1532 public function getPartialRecords($sort, $direction, $limit, $offset, array $filter = array())
1535 $ilDB = $DIC[
'ilDB'];
1540 $rbacreview = $DIC[
'rbacreview'];
1543 $direction = strtolower($direction);
1544 $direction = (in_array($direction, array(
'desc',
'asc'))) ? $direction :
'asc';
1547 $sort_by_status =
false;
1548 if (substr($sort, 0, 8) ==
'_status_') {
1549 $sort_by_status =
true;
1553 if (is_null($sort_field)) {
1554 $sort_field = $this->
getField(
'id');
1557 $sort_query_object = $sort_field->getRecordQuerySortObject($direction, $sort_by_status);
1559 $select_str = ($sort_query_object != null) ? $sort_query_object->getSelectStatement() :
'';
1560 $join_str = ($sort_query_object != null) ? $sort_query_object->getJoinStatement() :
'';
1561 $where_str = ($sort_query_object != null) ? $sort_query_object->getWhereStatement() :
'';
1562 $order_str = ($sort_query_object != null) ? $sort_query_object->getOrderStatement() :
'';
1563 $group_str = ($sort_query_object != null) ? $sort_query_object->getGroupStatement() :
'';
1565 if (count($filter)) {
1566 foreach ($filter as $key => $filter_value) {
1567 $filter_field_id = substr($key, 7);
1568 $filter_field = $this->
getField($filter_field_id);
1569 $filter_record_query_object = $filter_field->getRecordQueryFilterObject($filter_value, $sort_field);
1571 if ($filter_record_query_object) {
1572 $select_str .= $filter_record_query_object->getSelectStatement();
1573 $join_str .= $filter_record_query_object->getJoinStatement();
1574 $where_str .= $filter_record_query_object->getWhereStatement();
1575 $group_str .= $filter_record_query_object->getGroupStatement();
1581 $sql =
"SELECT DISTINCT record.id, record.owner";
1588 $sql .= rtrim($select_str,
',') .
" FROM il_dcl_record {$as} record ";
1590 $sql .=
" WHERE record.table_id = " .
$ilDB->quote($this->
getId(),
'integer');
1592 if (strlen($where_str) > 0) {
1596 if (strlen($group_str) > 0) {
1597 $sql .=
" GROUP BY " . $group_str;
1600 if (strlen($order_str) > 0) {
1601 $sql .=
" ORDER BY " . $order_str;
1609 $set =
$ilDB->query($sql);
1610 $total_record_ids = array();
1614 $ref = filter_input(INPUT_GET,
'ref_id');
1616 while ($rec =
$ilDB->fetchAssoc($set)) {
1621 $total_record_ids[] = $rec[
'id'];
1622 $_SESSION[
'dcl_record_ids'][] = $rec[
'id'];
1625 if ($sort_query_object != null) {
1626 $total_record_ids = $sort_query_object->applyCustomSorting($sort_field, $total_record_ids, $direction);
1630 $record_ids = array_slice($total_record_ids, $offset, $limit);
1633 foreach ($record_ids as
$id) {
1637 return array(
'records' =>
$records,
'total' => count($total_record_ids));
getEditableFields(bool $creation_mode)
static setCloneOf($old, $new, $type)
static hasAddRecordAccess($ref, $user_id=0)
setId($a_id)
Set table id.
static buildFieldFromRecord($rec)
static _getTableIdByTitle($title, $obj_id)
getPublicCommentsEnabled()
$default_sort_field_order
getVisibleTableViews($ref_id, $with_active_detailedview=false, $user_id=0)
For current user.
getFirstTableViewId($ref_id, $user_id=0)
get id of first (for current user) available view
hasPermissionToViewRecord($ref_id, $record, $user_id=0)
sortTableViews(array $tableviews=null)
static _hasFieldByTitle($title, $obj_id)
Checks if a table has a field with the given title.
static preloadFieldProperties(array $fields)
Preloads field properties.
static hasReadAccess($ref, $user_id=0)
static getFieldCache($field_id=0)
hasPermissionToDeleteRecord($ref_id, ilDclBaseRecordModel $record)
setEditByOwner($edit_by_owner)
static getAllForTableId($table_id)
static hasAccessToTableView($tableview, $user_id=0)
This only checks access to the tableview - if the full access check is required, use hasAccessTo($ref...
setPublicCommentsEnabled($public_comments)
setDefaultSortField($default_sort_field)
/**
const INPUTFORMAT_REFERENCELIST
static _lookupObjectId($a_ref_id)
getFields()
Returns all fields of this table including the standard fields.
hasPermissionToDeleteRecords($ref_id)
hasPermissionToEditRecord($ref_id, ilDclBaseRecordModel $record)
setDescription($description)
static getCountForTableId($table_id)
Class ilDclBaseFieldModel.
setExportEnabled($export_enabled)
doesRecordBelongToUser(ilDclBaseRecordModel $record)
updateFields()
Update fields.
static _getStandardFields($table_id)
getExportableFields()
Return all the fields that are marked as exportable.
static _tableExists($table_id)
cloneStructure(ilDclTable $original)
hasCustomFields()
hasCustomFields
setDeletePerm($delete_perm)
static hasEditAccess($ref, $user_id=0)
Has permission to view and edit all entries event when he is not the owner.
static hasWriteAccess($ref, $user_id=0)
static getRecordCache($record_id=0)
getRecordFields()
Returns all fields of this table which are NOT standard fields.
sortFields(&$fields)
sortFields
const INPUTFORMAT_ILIAS_REF
setSaveConfirmation($save_confirmation)
const INPUTFORMAT_FORMULA
getFieldByTitle($title)
Get a field by title.
getDefaultSortFieldOrder()
setLimitStart($limit_start)
static createOrGetStandardView($table_id, $create_default_settings=true)
const INPUTFORMAT_REFERENCE
setViewOwnRecordsPerm($view_own_perm)
Class ilDclBaseRecordModel.
setIsVisible($is_visible)
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
doCreate($create_tablefield_setting=true, $create_standardview=true)
setImportEnabled($import_enabled)
buildOrderFields()
buildOrderFields orders the fields.
Class ilObjDataCollection.
setDeleteByOwner($delete_by_owner)
setDefaultSortFieldOrder($default_sort_field_order)
getNewFieldOrder()
getNewOrder