5 include_once
'./Modules/DataCollection/classes/Fields/Base/class.ilDclStandardField.php';
6 include_once
'./Modules/DataCollection/classes/Fields/Base/class.ilDclBaseRecordModel.php';
7 include_once
'./Modules/DataCollection/classes/TableView/class.ilDclTableView.php';
160 $ilDB = $DIC[
'ilDB'];
162 $query =
"SELECT * FROM il_dcl_table WHERE id = " .
$ilDB->quote($this->
getId(),
"integer");
164 $rec =
$ilDB->fetchAssoc($set);
185 $this->
setOrder($rec[
'table_order']);
196 public function doDelete($delete_only_content =
false, $omit_notification =
false)
199 $ilDB = $DIC[
'ilDB'];
203 $record->doDelete($omit_notification);
220 if (!$delete_only_content) {
221 $query =
"DELETE FROM il_dcl_table WHERE id = " .
$ilDB->quote($this->
getId(),
"integer");
230 public function doCreate($create_tablefield_setting =
true, $create_standardview =
true)
233 $ilDB = $DIC[
'ilDB'];
235 $id =
$ilDB->nextId(
"il_dcl_table");
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") .
"," 254 if ($create_standardview) {
259 if ($create_tablefield_setting) {
271 $ilDB = $DIC[
'ilDB'];
276 "obj_id" => array(
"integer", $this->
getObjId()),
277 "title" => array(
"text", $this->
getTitle()),
278 "add_perm" => array(
"integer", (
int) $this->
getAddPerm()),
279 "edit_perm" => array(
"integer", (
int) $this->
getEditPerm()),
280 "delete_perm" => array(
"integer", (
int) $this->
getDeletePerm()),
281 "edit_by_owner" => array(
"integer", (
int) $this->
getEditByOwner()),
282 "limited" => array(
"integer", $this->
getLimited()),
284 "limit_end" => array(
"timestamp", $this->
getLimitEnd()),
285 "is_visible" => array(
"integer", $this->
getIsVisible() ? 1 : 0),
295 'table_order' => array(
'integer', $this->
getOrder()),
298 "id" => array(
"integer", $this->
getId()),
331 $this->objId = $a_id;
349 $this->title = $a_title;
375 if ($this->obj == null) {
386 if ($this->records == null) {
397 $ilDB = $DIC[
'ilDB'];
400 $query =
"SELECT id FROM il_dcl_record WHERE table_id = " .
$ilDB->quote($this->
id,
"integer");
403 while ($rec =
$ilDB->fetchAssoc($set)) {
420 $record->deleteField($field_id);
436 foreach (
$fields as $field_1) {
437 if ($field_1->getId() == $field_id) {
453 $field_ids = array();
455 if ($field->getId()) {
456 $field_ids[] = $field->getId();
464 protected function loadCustomFields()
468 $ilDB = $DIC[
'ilDB'];
473 =
"SELECT DISTINCT il_dcl_field.*, il_dcl_tfield_set.field_order 475 INNER JOIN il_dcl_tfield_set 476 ON ( il_dcl_tfield_set.field NOT IN ('owner', 481 AND il_dcl_tfield_set.table_id = il_dcl_field.table_id 482 AND il_dcl_tfield_set.field = " .
$ilDB->cast(
"il_dcl_field.id",
"text") .
") 483 WHERE il_dcl_field.table_id = %s 484 ORDER BY il_dcl_tfield_set.field_order ASC";
486 $set =
$ilDB->queryF(
$query, array(
'integer'), array((
int) $this->
getId()));
488 while ($rec =
$ilDB->fetchAssoc($set)) {
502 $this->loadCustomFields();
519 if (!$field->isStandardField()) {
520 $place = $field->getOrder() + 1;
542 if ($tableviews == null) {
547 foreach ($tableviews as $tableview) {
548 $tableview->setTableviewOrder($order);
549 $tableview->update();
564 if ($this->all_fields == null) {
574 $this->loadCustomFields();
575 $this->stdFields = $this->getStandardFields();
607 $visible_views = array();
611 $visible_views[] = $tableView;
616 return $visible_views;
632 return $tableview ? $tableview->getId() :
false;
641 public function getFieldsForFormula()
643 $unsupported = array(
653 $this->loadCustomFields();
654 $return = $this->getStandardFields();
658 foreach ($this->
fields as $field) {
659 if (!in_array($field->getDatatypeId(), $unsupported)) {
674 public function getStandardFields()
676 if ($this->stdFields == null) {
681 foreach ($this->stdFields as $k => $field) {
682 if ($field->getId() ==
'comments') {
683 unset($this->stdFields[$k]);
701 $this->loadCustomFields();
713 $editableFields = array();
716 if (!$field->getLocked()) {
717 $editableFields[] = $field;
721 return $editableFields;
733 $exportableFields = array();
735 if ($field->getExportable()) {
736 $exportableFields[] = $field;
740 return $exportableFields;
875 return (
$from <= $now && $now <= $to);
904 $named[$field->getId()] = $field;
919 @usort($array, array($this,
"compareOrder"));
934 if (!is_null($field->getOrder())) {
935 $field->setOrder($count);
936 $count = $count + $offset;
954 if ($field->getTitle() ==
$title) {
1221 $this->view_own_records_perm = (int) $view_own_perm;
1259 $this->loadCustomFields();
1261 return (count($this->
fields) > 0) ? true :
false;
1273 if (is_null($a->getOrder() == null) && is_null($b->getOrder() == null)) {
1276 if (is_null($a->getOrder())) {
1279 if (is_null($b->getOrder())) {
1283 return $a->getOrder() < $b->getOrder() ? -1 : 1;
1316 $org_std_fields = $original->getStandardFields();
1317 foreach ($this->getStandardFields() as $element_key => $std_field) {
1325 $new_fields = array();
1326 foreach ($original->
getFields() as $orig_field) {
1327 if (!$orig_field->isStandardField()) {
1328 $class_name = get_class($orig_field);
1329 $new_field =
new $class_name();
1330 $new_field->setTableId($this->
getId());
1331 $new_field->cloneStructure($orig_field->getId());
1332 $new_fields[$orig_field->getId()] = $new_field;
1344 foreach ($original->
getRecords() as $orig_record) {
1346 $new_record->setTableId($this->
getId());
1347 $new_record->cloneStructure($orig_record->getId(), $new_fields);
1353 $new_tableview->setTableId($this->
getId());
1354 $new_tableview->cloneStructure($orig_tableview, $new_fields);
1367 foreach ($this->
getFields() as $field) {
1380 return (count($this->
getRecords()) > 0) ? true :
false;
1389 $this->all_fields[$field->getId()] = $field;
1401 $ilDB = $DIC[
'ilDB'];
1402 $query =
"SELECT * FROM il_dcl_table WHERE id = " . $table_id;
1405 return $result->numRows() != 0;
1418 $ilDB = $DIC[
'ilDB'];
1420 'SELECT id FROM il_dcl_table WHERE title = ' .
$ilDB->quote(
$title,
'text') .
' AND obj_id = ' 1421 .
$ilDB->quote($obj_id,
'integer')
1455 if (!$this->table_order) {
1469 $ilDB = $DIC[
'ilDB'];
1470 $result =
$ilDB->query(
'SELECT MAX(table_order) AS table_order FROM il_dcl_table WHERE obj_id = ' .
$ilDB->quote($this->getCollectionObject()->getId(),
'integer'));
1471 $this->table_order =
$ilDB->fetchObject(
$result)->table_order + 10;
1472 $ilDB->query(
'UPDATE il_dcl_table SET table_order = ' .
$ilDB->quote($this->table_order,
'integer') .
' WHERE id = ' .
$ilDB->quote($this->
getId(),
'integer'));
1514 $ilDB = $DIC[
'ilDB'];
1516 'SELECT * FROM il_dcl_field WHERE table_id = ' .
$ilDB->quote($obj_id,
'integer') .
' AND title = ' 1535 public function getPartialRecords($sort, $direction, $limit, $offset, array $filter = array())
1538 $ilDB = $DIC[
'ilDB'];
1543 $rbacreview = $DIC[
'rbacreview'];
1546 $direction = strtolower($direction);
1547 $direction = (in_array($direction, array(
'desc',
'asc'))) ? $direction :
'asc';
1550 $sort_by_status =
false;
1551 if (substr($sort, 0, 8) ==
'_status_') {
1552 $sort_by_status =
true;
1556 if (is_null($sort_field)) {
1557 $sort_field = $this->
getField(
'id');
1560 $sort_query_object = $sort_field->getRecordQuerySortObject($direction, $sort_by_status);
1562 $select_str = ($sort_query_object != null) ? $sort_query_object->getSelectStatement() :
'';
1563 $join_str = ($sort_query_object != null) ? $sort_query_object->getJoinStatement() :
'';
1564 $where_str = ($sort_query_object != null) ? $sort_query_object->getWhereStatement() :
'';
1565 $order_str = ($sort_query_object != null) ? $sort_query_object->getOrderStatement() :
'';
1566 $group_str = ($sort_query_object != null) ? $sort_query_object->getGroupStatement() :
'';
1568 if (count($filter)) {
1569 foreach ($filter as
$key => $filter_value) {
1570 $filter_field_id = substr(
$key, 7);
1571 $filter_field = $this->
getField($filter_field_id);
1572 $filter_record_query_object = $filter_field->getRecordQueryFilterObject($filter_value, $sort_field);
1574 if ($filter_record_query_object) {
1575 $select_str .= $filter_record_query_object->getSelectStatement();
1576 $join_str .= $filter_record_query_object->getJoinStatement();
1577 $where_str .= $filter_record_query_object->getWhereStatement();
1578 $group_str .= $filter_record_query_object->getGroupStatement();
1584 $sql =
"SELECT DISTINCT record.id, record.owner";
1591 $sql .= rtrim($select_str,
',') .
" FROM il_dcl_record {$as} record ";
1593 $sql .=
" WHERE record.table_id = " .
$ilDB->quote($this->
getId(),
'integer');
1595 if (strlen($where_str) > 0) {
1599 if (strlen($group_str) > 0) {
1600 $sql .=
" GROUP BY " . $group_str;
1603 if (strlen($order_str) > 0) {
1604 $sql .=
" ORDER BY " . $order_str;
1612 $set =
$ilDB->query($sql);
1613 $total_record_ids = array();
1617 $ref = filter_input(INPUT_GET,
'ref_id');
1619 while ($rec =
$ilDB->fetchAssoc($set)) {
1624 $total_record_ids[] = $rec[
'id'];
1625 $_SESSION[
'dcl_record_ids'][] = $rec[
'id'];
1628 if ($sort_query_object != null) {
1629 $total_record_ids = $sort_query_object->applyCustomSorting($sort_field, $total_record_ids, $direction);
1633 $record_ids = array_slice($total_record_ids, $offset, $limit);
1636 foreach ($record_ids as
$id) {
1640 return array(
'records' =>
$records,
'total' => count($total_record_ids));
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)
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