5 include_once
'./Modules/DataCollection/classes/class.ilDataCollectionStandardField.php';
6 include_once
'./Modules/DataCollection/classes/class.ilDataCollectionRecord.php';
93 $query =
"SELECT * FROM il_dcl_table WHERE id = ".$ilDB->quote($this->
getId(),
"integer");
94 $set = $ilDB->query(
$query);
95 $rec = $ilDB->fetchAssoc($set);
116 public function doDelete($delete_main_table =
false)
133 $exec_delete =
false;
134 if ($delete_main_table) {
141 $query =
"DELETE FROM il_dcl_table WHERE id = ".$ilDB->quote($this->
getId(),
"integer");
142 $ilDB->manipulate(
$query);
153 $id = $ilDB->nextId(
"il_dcl_table");
155 $query =
"INSERT INTO il_dcl_table (".
169 $ilDB->quote($this->
getId(),
"integer")
170 .
",".$ilDB->quote($this->
getObjId(),
"integer")
171 .
",".$ilDB->quote($this->
getTitle(),
"text")
172 .
",".$ilDB->quote($this->
getAddPerm()?1:0,
"integer")
173 .
",".$ilDB->quote($this->
getEditPerm()?1:0,
"integer")
176 .
",".$ilDB->quote($this->
getLimited()?1:0,
"integer")
178 .
",".$ilDB->quote($this->
getLimitEnd(),
"timestamp")
182 $ilDB->manipulate(
$query);
185 $view_id = $ilDB->nextId(
"il_dcl_view");
186 $query =
"INSERT INTO il_dcl_view (id, table_id, type, formtype) VALUES (".$ilDB->quote($view_id,
"integer").
", ".$ilDB->quote($this->
id,
"integer").
", ".$ilDB->quote(
ilDataCollectionField::VIEW_VIEW,
"integer").
", ".$ilDB->quote(1,
"integer").
")";
187 $ilDB->manipulate(
$query);
190 $view_id = $ilDB->nextId(
"il_dcl_view");
191 $query =
"INSERT INTO il_dcl_view (id, table_id, type, formtype) VALUES (".$ilDB->quote($view_id,
"integer").
", ".$ilDB->quote($this->
id,
"integer").
", ".$ilDB->quote(
ilDataCollectionField::EDIT_VIEW,
"integer").
", ".$ilDB->quote(1,
"integer").
")";
192 $ilDB->manipulate(
$query);
195 $view_id = $ilDB->nextId(
"il_dcl_view");
196 $query =
"INSERT INTO il_dcl_view (id, table_id, type, formtype) VALUES (".$ilDB->quote($view_id,
"integer").
", ".$ilDB->quote($this->
id,
"integer").
", ".$ilDB->quote(
ilDataCollectionField::FILTER_VIEW,
"integer").
", ".$ilDB->quote(1,
"integer").
")";
197 $ilDB->manipulate(
$query);
209 $ilDB->update(
"il_dcl_table", array(
210 "obj_id" => array(
"integer", $this->
getObjId()),
211 "title" => array(
"text", $this->
getTitle()),
212 "add_perm" => array(
"integer",$this->
getAddPerm()),
213 "edit_perm" => array(
"integer",$this->
getEditPerm()),
216 "limited" => array(
"integer",$this->
getLimited()),
218 "limit_end" => array(
"timestamp",$this->
getLimitEnd()),
219 "is_visible" => array(
"integer",$this->
getIsVisible()?1:0),
222 "id" => array(
"integer", $this->
getId())
253 $this->objId = $a_id;
273 $this->title = $a_title;
302 if($this->obj == NULL)
332 if (!count($filter)) {
337 if($record->passThroughFilter($filter)) {
338 $filtered[] = $record;
349 if($this->records == NULL)
354 $query =
"SELECT id FROM il_dcl_record WHERE table_id = ".$ilDB->quote($this->
id,
"integer");
355 $set = $ilDB->query(
$query);
357 while($rec = $ilDB->fetchAssoc($set))
380 WHERE obj_id = ".$ilDB->quote($a_id,
"integer");
381 $set = $ilDB->query(
$query);
384 while($rec = $ilDB->fetchAssoc($set))
386 $all[$rec[
'id']] = $rec;
403 $record->deleteField($field_id);
419 if($field_1->getId() == $field_id)
445 $query =
"SELECT field.id, field.table_id, field.title, field.description, field.datatype_id, field.required, field.is_unique, field.is_locked FROM il_dcl_field field INNER JOIN il_dcl_view view ON view.table_id = field.table_id INNER JOIN il_dcl_viewdefinition def ON def.view_id = view.id WHERE field.table_id =".$ilDB->quote($this->
getId(),
"integer").
" ORDER BY def.field_order DESC";
447 $set = $ilDB->query(
$query);
449 while($rec = $ilDB->fetchAssoc($set))
454 $fields[$field->getId()] = $field;
471 if($field->isVisible())
473 $place = $field->getOrder() + 1;
487 if($this->stdFields == NULL)
516 $visibleFields = array();
520 if($field->isVisible())
522 $visibleFields[] = $field;
526 return $visibleFields;
535 $editableFields = array();
539 if(!$field->getLocked())
541 array_push($editableFields, $field);
545 return $editableFields;
556 $filterableFields = array();
560 if($field->isFilterable())
562 array_push($filterableFields, $field);
566 return $filterableFields;
618 if($this->
getEditByOwner() && $ilUser->getId() != $record->getOwner())
637 if(!($from <= $now && $now <= $to))
668 $named[$field->getId()] = $field;
680 usort($array, array($this,
"compareOrder"));
698 if(!is_null($field->getOrder()))
700 $field->setOrder($count);
701 $count = $count + $offset;
714 if($field->getTitle() == $name){
857 return (count($this->
fields) > 0) ?
true :
false;
862 if(is_null($a->getOrder() == NULL) && is_null($b->getOrder() == NULL))
866 if(is_null($a->getOrder()))
870 if(is_null($b->getOrder()))
875 return $a->getOrder() < $b->getOrder() ? -1 : 1;
891 $this->
setTitle($original->getTitle());
895 foreach($original->getRecordFields() as $field)
898 $new_field->setTableId($this->
getId());
899 $new_field->cloneStructure($field->getId());
905 $viewdef->setXMLContent($old_view->getXMLContent(
false));
916 return (count($this->
getRecords()) > 0) ?
true :
false;
923 $this->
fields[$field->getId()] = $field;
932 $query =
"SELECT * FROM il_dcl_table WHERE id = ".$table_id;
934 return $result->numRows() != 0;
944 $result = $ilDB->query(
'SELECT id FROM il_dcl_table WHERE title = ' . $ilDB->quote(
$title,
'text') .
' AND obj_id = ' . $ilDB->quote($obj_id,
'integer'));
946 while($rec = $ilDB->fetchAssoc(
$result)) {
956 $query =
" SELECT stloc.value AS val rec_field AS FROM il_dcl_stloc1_value stloc
957 INNER JOIN il_dcl_record_field rec_field ON rec_field.field_id = 2
958 WHERE stloc.record_field_id = rec_field.id";
985 $result = $ilDB->query(
'SELECT * FROM il_dcl_field WHERE table_id = ' . $ilDB->quote($obj_id,
'integer') .
' AND title = ' . $ilDB->quote(
$title,
'text'));
986 return ($ilDB->numRows(
$result)) ?
true :
false;
999 public function getPartialRecords($sort, $direction, $limit, $offset, array $filter = array()) {
1003 $direction = strtolower($direction);
1004 $direction = (in_array($direction, array(
'desc',
'asc'))) ? $direction :
'asc';
1007 $sortByStatus =
false;
1008 if (substr($sort, 0, 8) ==
'_status_') {
1009 $sortByStatus =
true;
1015 $id = $sortField->getId();
1016 $stl = $sortField->getStorageLocation();
1019 $where_additions =
'';
1021 if ($sortField->isStandardField()) {
1022 if (
$id ==
'owner' ||
$id ==
'last_edit_by') {
1023 $joinStr .=
"LEFT JOIN usr_data AS sort_usr_data_{$id} ON (sort_usr_data_{$id}.usr_id = record.{$id})";
1024 $selectStr .=
" sort_usr_data_{$id}.login AS field_{$id},";
1026 $selectStr .=
" record.{$id} AS field_{$id},";
1029 switch ($sortField->getDatatypeId()) {
1031 $joinStr .=
"LEFT JOIN (SELECT AVG(sort_avg_rating.rating) AS avg_rating, sort_avg_rating.obj_id AS obj_id FROM il_rating as sort_avg_rating WHERE sort_avg_rating.sub_obj_id = {$sortField->getId()} GROUP BY sort_avg_rating.obj_id) AS sort_avg_rating on sort_avg_rating.obj_id = record.id ";
1032 $selectStr .=
" sort_avg_rating.avg_rating AS field_{$id},";
1035 $joinStr .=
"LEFT JOIN il_dcl_record_field AS sort_record_field_{$id} ON (sort_record_field_{$id}.record_id = record.id AND sort_record_field_{$id}.field_id = " . $ilDB->quote($sortField->getId(),
'integer') .
") ";
1036 $joinStr .=
"LEFT JOIN il_dcl_stloc{$stl}_value AS sort_stloc_{$id} ON (sort_stloc_{$id}.record_field_id = sort_record_field_{$id}.id) ";
1037 $joinStr .=
"LEFT JOIN object_reference AS sort_object_reference_{$id} ON (sort_object_reference_{$id}.ref_id = sort_stloc_{$id}.value AND sort_object_reference_{$id}.deleted IS NULL)";
1038 $joinStr .=
"LEFT JOIN object_data AS sort_object_data_{$id} ON (sort_object_data_{$id}.obj_id = sort_object_reference_{$id}.obj_id)";
1039 if ($sortByStatus) {
1041 $joinStr .=
"LEFT JOIN ut_lp_marks AS ut ON (ut.obj_id = sort_object_data_{$id}.obj_id AND ut.usr_id = " . $ilDB->quote($ilUser->getId(),
'integer') .
") ";
1043 $selectStr .= (!$sortByStatus) ?
" sort_object_data_{$id}.title AS field_{$id}," :
" ut.status AS field_{$id}";
1047 $joinStr .=
"LEFT JOIN il_dcl_record_field AS sort_record_field_{$id} ON (sort_record_field_{$id}.record_id = record.id AND sort_record_field_{$id}.field_id = " . $ilDB->quote($sortField->getId(),
'integer') .
") ";
1048 $joinStr .=
"LEFT JOIN il_dcl_stloc{$stl}_value AS sort_stloc_{$id} ON (sort_stloc_{$id}.record_field_id = sort_record_field_{$id}.id) ";
1049 $joinStr .=
"LEFT JOIN object_data AS sort_object_data_{$id} ON (sort_object_data_{$id}.obj_id = sort_stloc_{$id}.value) ";
1050 $selectStr .=
" sort_object_data_{$id}.title AS field_{$id},";
1053 $prop = $sortField->getPropertyvalues();
1055 $selectStr .=
"stloc_{$id}_joined.value AS field_{$id},";
1056 $joinStr .=
"LEFT JOIN il_dcl_record_field AS record_field_{$id} ON (record_field_{$id}.record_id = record.id AND record_field_{$id}.field_id = " . $ilDB->quote($sortField->getId(),
'integer') .
") ";
1057 $joinStr .=
"LEFT JOIN il_dcl_stloc{$stl}_value AS stloc_{$id} ON (stloc_{$id}.record_field_id = record_field_{$id}.id) ";
1058 $joinStr .=
"LEFT JOIN il_dcl_record_field AS record_field_{$id}_joined ON (record_field_{$id}_joined.record_id = stloc_{$id}.value AND record_field_{$id}_joined.field_id = " . $ilDB->quote($refField->getId(),
'integer') .
") ";
1059 $joinStr .=
"LEFT JOIN il_dcl_stloc{$refField->getStorageLocation()}_value AS stloc_{$id}_joined ON (stloc_{$id}_joined.record_field_id = record_field_{$id}_joined.id) ";
1065 $selectStr .=
" sort_stloc_{$id}.value AS field_{$id},";
1066 $joinStr .=
"LEFT JOIN il_dcl_record_field AS sort_record_field_{$id} ON (sort_record_field_{$id}.record_id = record.id AND sort_record_field_{$id}.field_id = " . $ilDB->quote($sortField->getId(),
'integer') .
") ";
1067 $joinStr .=
"LEFT JOIN il_dcl_stloc{$stl}_value AS sort_stloc_{$id} ON (sort_stloc_{$id}.record_field_id = sort_record_field_{$id}.id) ";
1072 if(count($filter)) {
1073 foreach($filter as $key => $filter_value)
1075 $filter_field_id = substr($key, 7);
1076 $filterField = $this->
getField($filter_field_id);
1077 switch ($filterField->getDatatypeId()) {
1079 $joinStr .=
"INNER JOIN (SELECT AVG(avg_rating.rating) AS avg_rating, avg_rating.obj_id AS obj_id FROM il_rating as avg_rating WHERE avg_rating.sub_obj_id = {$filter_field_id} GROUP BY avg_rating.obj_id) AS avg_rating on avg_rating.avg_rating >= ".$ilDB->quote($filter_value,
'integer') .
" AND avg_rating.obj_id = record.id ";
1082 $joinStr .=
"INNER JOIN il_dcl_record_field AS filter_record_field_{$filter_field_id} ON (filter_record_field_{$filter_field_id}.record_id = record.id AND filter_record_field_{$filter_field_id}.field_id = " . $ilDB->quote($filter_field_id,
'integer') .
") ";
1083 $joinStr .=
"INNER JOIN il_dcl_stloc{$filterField->getStorageLocation()}_value AS filter_stloc_{$filter_field_id} ON (filter_stloc_{$filter_field_id}.record_field_id = filter_record_field_{$filter_field_id}.id) ";
1084 $joinStr .=
"INNER JOIN object_reference AS filter_object_reference_{$filter_field_id} ON (filter_object_reference_{$filter_field_id}.ref_id = filter_stloc_{$filter_field_id}.value ) ";
1085 $joinStr .=
"INNER JOIN object_data AS filter_object_data_{$filter_field_id} ON (filter_object_data_{$filter_field_id}.obj_id = filter_object_reference_{$filter_field_id}.obj_id AND filter_object_data_{$filter_field_id}.title LIKE " . $ilDB->quote(
"%$filter_value%",
'text') .
") ";
1089 $joinStr .=
"INNER JOIN il_dcl_record_field AS filter_record_field_{$filter_field_id} ON (filter_record_field_{$filter_field_id}.record_id = record.id AND filter_record_field_{$filter_field_id}.field_id = " . $ilDB->quote($filter_field_id,
'integer') .
") ";
1090 $joinStr .=
"INNER JOIN il_dcl_stloc{$filterField->getStorageLocation()}_value AS filter_stloc_{$filter_field_id} ON (filter_stloc_{$filter_field_id}.record_field_id = filter_record_field_{$filter_field_id}.id) ";
1091 $joinStr .=
"INNER JOIN object_data AS filter_object_data_{$filter_field_id} ON (filter_object_data_{$filter_field_id}.obj_id = filter_stloc_{$filter_field_id}.value AND filter_object_data_{$filter_field_id}.title LIKE " . $ilDB->quote(
"%$filter_value%",
'text') .
") ";
1094 $dateFrom = (isset($filter_value[
'from']) && is_object($filter_value[
'from'])) ? $filter_value[
'from'] : null;
1095 $dateTo = (isset($filter_value[
'to']) && is_object($filter_value[
'to'])) ? $filter_value[
'to'] : null;
1096 if ($filterField->isStandardField()) {
1097 if ($dateFrom) $where_additions .=
" AND (record.{$filter_field_id} >= " . $ilDB->quote($dateFrom,
'date') .
")";
1098 if ($dateTo) $where_additions .=
" AND (record.{$filter_field_id} <= " . $ilDB->quote($dateTo,
'date') .
")";
1100 $joinStr .=
"INNER JOIN il_dcl_record_field AS filter_record_field_{$filter_field_id} ON (filter_record_field_{$filter_field_id}.record_id = record.id AND filter_record_field_{$filter_field_id}.field_id = " . $ilDB->quote($filter_field_id,
'integer') .
") ";
1101 $joinStr .=
"INNER JOIN il_dcl_stloc{$filterField->getStorageLocation()}_value AS filter_stloc_{$filter_field_id} ON (filter_stloc_{$filter_field_id}.record_field_id = filter_record_field_{$filter_field_id}.id ";
1102 if ($dateFrom) $joinStr .=
"AND filter_stloc_{$filter_field_id}.value >= " . $ilDB->quote($dateFrom,
'date') .
" ";
1103 if ($dateTo) $joinStr .=
"AND filter_stloc_{$filter_field_id}.value <= " . $ilDB->quote($dateTo,
'date') .
" ";
1108 $from = (isset($filter_value[
'from'])) ? (
int) $filter_value[
'from'] : null;
1109 $to = (isset($filter_value[
'to'])) ? (
int) $filter_value[
'to'] : null;
1110 if ($filterField->isStandardField()) {
1111 if (!is_null($from)) $where_additions .=
" AND record.{$filter_field_id} >= " . $ilDB->quote($from,
'integer');
1112 if (!is_null($to)) $where_additions .=
" AND record.{$filter_field_id} <= " . $ilDB->quote($to,
'integer');
1114 $joinStr .=
"INNER JOIN il_dcl_record_field AS filter_record_field_{$filter_field_id} ON (filter_record_field_{$filter_field_id}.record_id = record.id AND filter_record_field_{$filter_field_id}.field_id = " . $ilDB->quote($filter_field_id,
'integer') .
") ";
1115 $joinStr .=
"INNER JOIN il_dcl_stloc{$filterField->getStorageLocation()}_value AS filter_stloc_{$filter_field_id} ON (filter_stloc_{$filter_field_id}.record_field_id = filter_record_field_{$filter_field_id}.id";
1116 if (!is_null($from)) $joinStr .=
" AND filter_stloc_{$filter_field_id}.value >= " . $ilDB->quote($from,
'integer');
1117 if (!is_null($to)) $joinStr .=
" AND filter_stloc_{$filter_field_id}.value <= " . $ilDB->quote($to,
'integer');
1122 if($filter_value ==
"checked") {
1123 $joinStr .=
"INNER JOIN il_dcl_record_field AS filter_record_field_{$filter_field_id} ON (filter_record_field_{$filter_field_id}.record_id = record.id AND filter_record_field_{$filter_field_id}.field_id = " . $ilDB->quote($filter_field_id,
'integer') .
") ";
1124 $joinStr .=
"INNER JOIN il_dcl_stloc{$filterField->getStorageLocation()}_value AS filter_stloc_{$filter_field_id} ON (filter_stloc_{$filter_field_id}.record_field_id = filter_record_field_{$filter_field_id}.id";
1125 $joinStr .=
" AND filter_stloc_{$filter_field_id}.value = " . $ilDB->quote(1,
'integer');
1127 $joinStr .=
"INNER JOIN il_dcl_record_field AS filter_record_field_{$filter_field_id} ON (filter_record_field_{$filter_field_id}.record_id = record.id AND filter_record_field_{$filter_field_id}.field_id = " . $ilDB->quote($filter_field_id,
'integer') .
") ";
1128 $joinStr .=
"LEFT JOIN il_dcl_stloc{$filterField->getStorageLocation()}_value AS filter_stloc_{$filter_field_id} ON (filter_stloc_{$filter_field_id}.record_field_id = filter_record_field_{$filter_field_id}.id";
1129 $where_additions .=
" AND (filter_stloc_{$filter_field_id}.value <> " . $ilDB->quote(1,
'integer').
" OR filter_stloc_{$filter_field_id}.value is NULL)";
1134 if ($filterField->isStandardField()) {
1135 $joinStr .=
"INNER JOIN usr_data AS filter_usr_data_{$filter_field_id} ON (filter_usr_data_{$filter_field_id}.usr_id = record.{$filter_field_id} AND filter_usr_data_{$filter_field_id}.login LIKE " . $ilDB->quote(
"%$filter_value%",
'text') .
") ";
1137 $joinStr .=
" INNER JOIN il_dcl_record_field AS filter_record_field_{$filter_field_id} ON (filter_record_field_{$filter_field_id}.record_id = record.id AND filter_record_field_{$filter_field_id}.field_id = " . $ilDB->quote($filter_field_id,
'integer') .
") ";
1138 $joinStr .=
" INNER JOIN il_dcl_stloc{$filterField->getStorageLocation()}_value AS filter_stloc_{$filter_field_id} ON (filter_stloc_{$filter_field_id}.record_field_id = filter_record_field_{$filter_field_id}.id AND filter_stloc_{$filter_field_id}.value LIKE " . $ilDB->quote(
"%$filter_value%",
'text') .
") ";
1142 $joinStr .=
" INNER JOIN il_dcl_record_field AS filter_record_field_{$filter_field_id} ON (filter_record_field_{$filter_field_id}.record_id = record.id AND filter_record_field_{$filter_field_id}.field_id = " . $ilDB->quote($filter_field_id,
'integer') .
") ";
1143 $joinStr .=
" INNER JOIN il_dcl_stloc{$filterField->getStorageLocation()}_value AS filter_stloc_{$filter_field_id} ON (filter_stloc_{$filter_field_id}.record_field_id = filter_record_field_{$filter_field_id}.id AND filter_stloc_{$filter_field_id}.value = " . $ilDB->quote($filter_value,
'integer') .
") ";
1150 $sql =
"SELECT DISTINCT record.id, ";
1151 $sql .= rtrim($selectStr,
',') .
" FROM il_dcl_record AS record ";
1153 $sql .=
" WHERE record.table_id = " . $ilDB->quote($this->
getId(),
'integer') . $where_additions;
1154 $sql .=
" ORDER BY field_{$id} {$direction}";
1156 $set = $ilDB->query($sql);
1157 $totalRecordIds = array();
1158 while ($rec = $ilDB->fetchAssoc($set)) {
1159 $totalRecordIds[] = $rec[
'id'];
1162 $recordIds = array_slice($totalRecordIds, $offset, $limit);
1164 foreach ($recordIds as
$id) {
1168 return array(
'records' =>
$records,
'total' => count($totalRecordIds));