19 declare(strict_types=1);
26 protected int $id = 0;
87 $this->
http = $DIC->http();
89 $this->db = $DIC->database();
90 $this->
user = $DIC->user();
103 $query =
"SELECT * FROM il_dcl_table WHERE id = " . $this->db->quote($this->
getId(),
"integer");
104 $set = $this->db->query($query);
105 $rec = $this->db->fetchAssoc($set);
108 if (
null !== $rec[
"title"]) {
115 if (
null !== $rec[
"export_enabled"]) {
123 if (
null !== $rec[
'description']) {
132 if (
null !== $rec[
'table_order']) {
133 $this->
setOrder($rec[
'table_order']);
142 public function doDelete(
bool $delete_only_content =
false,
bool $omit_notification =
false): void
145 $record->doDelete($omit_notification);
162 if (!$delete_only_content) {
163 $query =
"DELETE FROM il_dcl_table WHERE id = " . $this->db->quote($this->
getId(),
"integer");
164 $this->db->manipulate($query);
168 public function doCreate(
bool $create_tablefield_setting =
true,
bool $create_standardview =
true): void
170 $id = $this->db->nextId(
"il_dcl_table");
172 $query =
"INSERT INTO il_dcl_table (" .
"id" .
", obj_id" .
", title" .
", add_perm" .
", edit_perm" .
", delete_perm" .
", edit_by_owner" 173 .
", limited" .
", limit_start" .
", limit_end" .
", is_visible" .
", export_enabled" .
", import_enabled" .
", default_sort_field_id" 174 .
", default_sort_field_order" .
", description" .
", public_comments" .
", view_own_records_perm" 175 .
", delete_by_owner, save_confirmation , table_order ) VALUES (" . $this->db->quote(
179 . $this->db->quote($this->
getObjId(),
"integer") .
"," . $this->db->quote($this->
getTitle(),
"text") .
"," 180 . $this->db->quote($this->
getAddPerm() ? 1 : 0,
"integer") .
"," . $this->db->quote(
187 ) .
"," . $this->db->quote($this->
getEditByOwner() ? 1 : 0,
"integer") .
"," 188 . $this->db->quote($this->
getLimited() ? 1 : 0,
"integer") .
"," . $this->db->quote(
192 . $this->db->quote($this->
getLimitEnd(),
"timestamp") .
"," . $this->db->quote(
199 ) .
"," . $this->db->quote($this->
getImportEnabled() ? 1 : 0,
"integer") .
"," 204 . $this->db->quote($this->
getDescription(),
"text") .
"," . $this->db->quote(
211 ) .
"," . $this->db->quote($this->
getDeleteByOwner() ? 1 : 0,
'integer') .
"," 212 . $this->db->quote($this->
getSaveConfirmation() ? 1 : 0,
'integer') .
"," . $this->db->quote(
217 $this->db->manipulate($query);
219 if ($create_standardview) {
224 if ($create_tablefield_setting) {
234 "obj_id" => [
"integer", $this->
getObjId()],
235 "title" => [
"text", $this->
getTitle()],
236 "add_perm" => [
"integer", (
int) $this->
getAddPerm()],
237 "edit_perm" => [
"integer", (
int) $this->
getEditPerm()],
240 "limited" => [
"integer", $this->
getLimited()],
242 "limit_end" => [
"timestamp", $this->
getLimitEnd()],
243 "is_visible" => [
"integer", $this->
getIsVisible() ? 1 : 0],
253 'table_order' => [
'integer', $this->
getOrder()],
256 "id" => [
"integer", $this->
getId()],
264 public function setId(
int $a_id): void
279 $this->objId = $a_id;
289 $this->title = $a_title;
306 if ($this->obj ==
null) {
316 if ($this->records ==
null) {
326 $query =
"SELECT id FROM il_dcl_record WHERE table_id = " . $this->db->quote($this->
id,
"integer");
327 $set = $this->db->query($query);
329 while ($rec = $this->db->fetchAssoc($set)) {
341 foreach ($records as $record) {
342 $record->deleteField($field_id);
352 foreach ($fields as $field_1) {
353 if ($field_1->getId() == $field_id) {
368 if ($field->getId()) {
369 $field_ids[] = $field->getId();
378 if (!$this->fields) {
380 =
"SELECT DISTINCT il_dcl_field.*, il_dcl_tfield_set.field_order 382 INNER JOIN il_dcl_tfield_set 383 ON ( il_dcl_tfield_set.field NOT IN ('owner', 388 AND il_dcl_tfield_set.table_id = il_dcl_field.table_id 389 AND il_dcl_tfield_set.field = " . $this->db->cast(
"il_dcl_field.id",
"text") .
") 390 WHERE il_dcl_field.table_id = %s 391 ORDER BY il_dcl_tfield_set.field_order ASC";
393 $set = $this->db->queryF($query, [
'integer'], [$this->
getId()]);
395 while ($rec = $this->db->fetchAssoc($set)) {
412 if (!$this->fields) {
427 foreach ($fields as $field) {
428 if (!$field->isStandardField()) {
429 $place = $field->getOrder() + 1;
449 if ($tableviews ==
null) {
454 foreach ($tableviews as $tableview) {
455 $tableview->setTableviewOrder($order);
456 $tableview->update();
468 if ($this->all_fields ==
null) {
478 $this->stdFields = $this->getStandardFields();
479 $fields = array_merge($this->fields, $this->stdFields);
508 if (!$with_active_detailedview || $page->getPageObject()->isActive()) {
509 $visible_views[] = $tableView;
514 return $visible_views;
524 $tableview = array_shift($array);
526 return $tableview ? $tableview->getId() :
null;
535 $syntax_chars = array_merge(
536 array_map(
static fn(
Operators $function):
string => $function->value, Operators::cases()),
537 array_map(
static fn(
Functions $function):
string => $function->value, Functions::cases()),
542 foreach ($syntax_chars as $element) {
543 if (str_contains($field->getTitle(), $element)) {
559 public function getStandardFields(): array
561 if ($this->stdFields ==
null) {
566 foreach ($this->stdFields as $k => $field) {
567 if ($field->getId() ==
'comments') {
568 unset($this->stdFields[$k]);
596 $editableFields = [];
598 foreach ($fields as $field) {
599 $tableview_id = $this->
http->wrapper()->post()->retrieve(
603 if (!$field->getViewSetting($tableview_id)->isLocked($creation_mode)) {
604 $editableFields[] = $field;
608 return $editableFields;
618 $exportableFields = [];
619 foreach ($fields as $field) {
620 if ($field->getExportable()) {
621 $exportableFields[] = $field;
625 return $exportableFields;
747 if ($from <= $now && $now <= $to) {
750 if ($from <= $now && $to ==
null) {
753 if ($from ==
null && $now <= $to) {
757 return ($from <= $now && $now <= $to);
782 foreach ($fields as $field) {
783 $named[$field->getId()] = $field;
796 usort($array, [$this,
"compareOrder"]);
809 foreach ($fields as $field) {
810 if (!is_null($field->getOrder())) {
811 $field->setOrder($count);
812 $count = $count + $offset;
825 if ($field->getTitle() ==
$title) {
860 if ($edit_by_owner) {
878 if ($delete_by_owner) {
959 if (!in_array($default_sort_field_order, [
'asc',
'desc'])) {
960 $default_sort_field_order =
'asc';
982 $this->view_own_records_perm = (
int) $view_own_perm;
1004 return count($this->fields) > 0;
1046 $default_sort_field = 0;
1048 $org_std_fields = $original->getStandardFields();
1049 foreach ($this->getStandardFields() as $element_key => $std_field) {
1050 $std_field->clone($org_std_fields[$element_key]);
1052 $default_sort_field = $std_field->
getId();
1058 foreach ($original->
getFields() as $orig_field) {
1059 if (!$orig_field->isStandardField()) {
1060 $class_name = get_class($orig_field);
1061 $new_field =
new $class_name();
1065 $new_field->setTableId($this->
getId());
1066 $new_field->cloneStructure((
int) $orig_field->getId());
1067 $new_fields[$orig_field->getId()] = $new_field;
1070 $default_sort_field = $new_field->getId();
1079 foreach ($original->
getRecords() as $orig_record) {
1081 $new_record->setTableId($this->
getId());
1082 $new_record->cloneStructure($orig_record->getId(), $new_fields);
1088 $new_tableview->setTableId($this->
getId());
1089 $new_tableview->cloneStructure($orig_tableview, $new_fields);
1098 foreach ($this->
getFields() as $field) {
1116 $this->all_fields[$field->
getId()] = $field;
1125 $ilDB = $DIC[
'ilDB'];
1127 $query =
"SELECT * FROM il_dcl_table WHERE id = " . $table_id;
1128 $result =
$ilDB->query($query);
1130 return $result->numRows() != 0;
1139 $ilDB = $DIC[
'ilDB'];
1141 $result =
$ilDB->query(
1142 'SELECT id FROM il_dcl_table WHERE title = ' .
$ilDB->quote($title,
'text') .
' AND obj_id = ' 1143 .
$ilDB->quote($obj_id,
'integer')
1146 while ($rec =
$ilDB->fetchAssoc($result)) {
1165 if (!$this->table_order) {
1174 $result = $this->db->query(
'SELECT MAX(table_order) AS table_order FROM il_dcl_table WHERE obj_id = ' . $this->db->quote(
1175 $this->getCollectionObject()->getId(),
1178 $this->table_order = $this->db->fetchObject($result)->table_order + 10;
1179 $this->db->query(
'UPDATE il_dcl_table SET table_order = ' . $this->db->quote(
1182 ) .
' WHERE id = ' . $this->db->quote($this->
getId(),
'integer'));
1208 $ilDB = $DIC[
'ilDB'];
1209 $result =
$ilDB->query(
1210 'SELECT * FROM il_dcl_field WHERE table_id = ' .
$ilDB->quote($obj_id,
'integer') .
' AND title = ' 1211 .
$ilDB->quote($title,
'text')
1214 return (
bool)
$ilDB->numRows($result);
1235 $direction = strtolower($direction);
1236 $direction = (in_array($direction, [
'desc',
'asc'])) ? $direction :
'asc';
1239 $sort_by_status =
false;
1240 if (substr($sort, 0, 8) ==
'_status_') {
1241 $sort_by_status =
true;
1245 if (is_null($sort_field)) {
1246 $sort_field = $this->
getField(
'id');
1249 $sort_query_object = $sort_field->getRecordQuerySortObject($direction, $sort_by_status);
1251 $select_str = ($sort_query_object !=
null) ? $sort_query_object->getSelectStatement() :
'';
1252 $join_str = ($sort_query_object !=
null) ? $sort_query_object->getJoinStatement() :
'';
1253 $where_str = ($sort_query_object !=
null) ? $sort_query_object->getWhereStatement() :
'';
1254 $order_str = ($sort_query_object !=
null) ? $sort_query_object->getOrderStatement() :
'';
1255 $group_str = ($sort_query_object !=
null) ? $sort_query_object->getGroupStatement() :
'';
1257 if (count($filter)) {
1258 foreach ($filter as $key => $filter_value) {
1259 $filter_field_id = substr($key, 7);
1260 $filter_field = $this->
getField($filter_field_id);
1261 $filter_record_query_object = $filter_field->getRecordQueryFilterObject($filter_value, $sort_field);
1263 if ($filter_record_query_object) {
1264 $select_str .= $filter_record_query_object->getSelectStatement();
1265 $join_str .= $filter_record_query_object->getJoinStatement();
1266 $where_str .= $filter_record_query_object->getWhereStatement();
1267 $group_str .= $filter_record_query_object->getGroupStatement();
1273 $sql =
"SELECT DISTINCT record.id, record.owner";
1280 $sql .= rtrim($select_str,
',') .
" FROM il_dcl_record $as record ";
1282 $sql .=
" WHERE record.table_id = " . $this->db->quote($this->
getId(),
'integer');
1284 if (strlen($where_str) > 0) {
1288 if (strlen($group_str) > 0) {
1289 $sql .=
" GROUP BY " . $group_str;
1292 if (strlen($order_str) > 0) {
1293 $sql .=
" ORDER BY " . $order_str;
1296 $set = $this->db->query($sql);
1297 $total_record_ids = [];
1300 while ($rec = $this->db->fetchAssoc($set)) {
1305 $total_record_ids[] = $rec[
'id'];
1311 if ($sort_query_object !=
null) {
1312 $total_record_ids = $sort_query_object->applyCustomSorting($sort_field, $total_record_ids, $direction);
1315 if ($sort ===
'n_comments') {
1318 foreach ($total_record_ids as $id) {
1319 $comments_nr[
$id] = $DIC->notes()->domain()->getNrOfCommentsForContext($DIC->notes()->data()->context($this->
getObjId(), $id,
'dcl'));
1321 uasort($comments_nr,
static fn(
$a,
$b) => ($direction ===
'asc' ? 1 : -1) * ($a <=>
$b));
1322 $total_record_ids = array_keys($comments_nr);
1326 $record_ids = array_slice($total_record_ids, $offset, $limit);
1329 foreach ($record_ids as $id) {
1333 return [
'records' =>
$records,
'total' => count($total_record_ids)];
1338 $this->show_invalid = $value;
getEditableFields(bool $creation_mode)
doDelete(bool $delete_only_content=false, bool $omit_notification=false)
Delete table Attention this does not delete the maintable of it's the maintable of the collection...
static createOrGetStandardView(int $table_id)
sortByOrder(array &$array)
getFirstTableViewId(int $ref_id, int $user_id=0, bool $with_detailed_view=false)
get id of first (for current user) available view
static hasAccessToTableView(ilDclTableView $tableview, ?int $user_id=0)
getPublicCommentsEnabled()
int $view_own_records_perm
True if user can only view his/her own entries in the table.
getFieldByTitle(string $title)
Get a field by title.
setIsVisible(bool $is_visible)
setId(int $a_id)
Set table id.
static preloadFieldProperties(array $fields)
Preloads field properties.
addField(ilDclBaseFieldModel $field)
static _getStandardFields(int $table_id)
deleteField(int $field_id)
getFieldsForFormula()
Returns all fields of this table including the standard fields, wich are supported for formulas...
ILIAS HTTP Services $http
hasPermissionToDeleteRecord(int $ref_id, ilDclBaseRecordModel $record)
static hasAddRecordAccess(int $ref, ?int $user_id=0)
array $all_fields
table fields and std fields combined
static getFieldCache(int $field_id=0)
ilDclDetailedViewDefinitionGUI: ilPageEditorGUI, ilEditClipboardGUI, ilMediaPoolTargetSelector ilDcl...
setEditByOwner(bool $edit_by_owner)
setDeleteByOwner(bool $delete_by_owner)
setEditPerm(bool $edit_perm)
getFields()
Returns all fields of this table including the standard fields.
getVisibleTableViews(int $ref_id, bool $with_active_detailedview=false, int $user_id=0)
For current user.
setLimitStart(string $limit_start)
static _getTableIdByTitle(string $title, int $obj_id)
showInvalidFields(bool $value)
setDefaultSortFieldOrder(string $default_sort_field_order)
doesRecordBelongToUser(ilDclBaseRecordModel $record)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
sortTableViews(?array $tableviews=null)
updateFields()
Update fields.
setOrder(int $table_order)
setTitle(string $a_title)
getExportableFields()
Return all the fields that are marked as exportable.
static http()
Fetches the global http state from ILIAS.
sortFields(array &$fields)
sortFields
getPartialRecords(string $ref_id, string $sort, string $direction, ?int $limit, int $offset, array $filter=[])
Return only the needed subset of record objects for the table, according to sorting, paging and filters.
cloneStructure(ilDclTable $original)
static getAllDatatype(bool $force=false)
Get all possible Datatypes.
ILIAS Refinery Factory $refinery
string $default_sort_field_order
Default sort-order (asc|desc)
getRecordFields()
Returns all fields of this table which are NOT standard fields.
static _lookupObjectId(int $ref_id)
static getCountForTableId(int $table_id)
setLimitEnd(string $limit_end)
static hasWriteAccess(int $ref, ?int $user_id=0)
static setCloneOf(int $old, int $new, string $type)
hasPermissionToViewRecord(int $ref_id, ilDclBaseRecordModel $record, int $user_id=0)
string $description
Description for this table displayed above records.
getDefaultSortFieldOrder()
bool $public_comments
True if users can add comments on each record of this table.
getField(string $field_id)
static _hasFieldByTitle(string $title, int $obj_id)
Checks if a table has a field with the given title.
string $default_sort_field
setExportEnabled(bool $export_enabled)
hasPermissionToEditRecord(int $ref_id, ilDclBaseRecordModel $record)
setSaveConfirmation(bool $save_confirmation)
static getRecordCache(?int $record_id)
setAddPerm(bool $add_perm)
compareOrder(ilDclBaseFieldModel $a, ilDclBaseFieldModel $b)
hasPermissionToDeleteRecords(int $ref_id)
static buildFieldFromRecord(array $rec)
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
static hasReadAccess(int $ref, ?int $user_id=0)
setDeletePerm(bool $delete_perm)
static getAllForTableId(int $table_id)
setImportEnabled(bool $import_enabled)
static hasEditAccess(int $ref, ?int $user_id=0)
buildOrderFields()
buildOrderFields orders the fields.
setDescription(string $description)
static _tableExists(int $table_id)
doCreate(bool $create_tablefield_setting=true, bool $create_standardview=true)
static set(string $a_var, $a_val)
Set a value.
setDefaultSortField(string $default_sort_field)
setViewOwnRecordsPerm(bool $view_own_perm)
setPublicCommentsEnabled(bool $public_comments)
setLimited(bool $limited)
getNewFieldOrder()
getNewOrder