5 include_once
'./Modules/DataCollection/classes/class.ilDataCollectionStandardField.php';
6 include_once
'./Modules/DataCollection/classes/class.ilDataCollectionRecord.php';
92 $query =
"SELECT * FROM il_dcl_table WHERE id = " . $ilDB->quote($this->
getId(),
"integer");
93 $set = $ilDB->query(
$query);
94 $rec = $ilDB->fetchAssoc($set);
118 public function doDelete($delete_main_table =
false) {
132 $exec_delete =
false;
133 if ($delete_main_table) {
140 $query =
"DELETE FROM il_dcl_table WHERE id = " . $ilDB->quote($this->
getId(),
"integer");
141 $ilDB->manipulate(
$query);
144 $set = $ilDB->query(
'SELECT * FROM il_dcl_view WHERE table_id = ' . $ilDB->quote($this->getId(),
'integer'));
146 while (
$row = $ilDB->fetchObject($set)) {
147 $view_ids[] =
$row->id;
149 if (count($view_ids)) {
150 $ilDB->manipulate(
"DELETE FROM il_dcl_viewdefinition WHERE view_id IN (" . implode(
',', $view_ids) .
")");
152 $ilDB->manipulate(
"DELETE FROM il_dcl_view WHERE table_id = " . $ilDB->quote($this->getId(),
'integer'));
163 $id = $ilDB->nextId(
"il_dcl_table");
165 $query =
"INSERT INTO il_dcl_table (" .
"id" .
", obj_id" .
", title" .
", add_perm" .
", edit_perm" .
", delete_perm" .
", edit_by_owner"
166 .
", limited" .
", limit_start" .
", limit_end" .
", is_visible" .
", export_enabled" .
", description" .
" ) VALUES ("
167 . $ilDB->quote($this->
getId(),
"integer") .
"," . $ilDB->quote($this->
getObjId(),
"integer") .
","
168 . $ilDB->quote($this->
getTitle(),
"text") .
"," . $ilDB->quote($this->
getAddPerm() ? 1 : 0,
"integer") .
","
169 . $ilDB->quote($this->
getEditPerm() ? 1 : 0,
"integer") .
"," . $ilDB->quote($this->
getDeletePerm() ? 1 : 0,
"integer") .
","
170 . $ilDB->quote($this->
getEditByOwner() ? 1 : 0,
"integer") .
"," . $ilDB->quote($this->
getLimited() ? 1 : 0,
"integer") .
","
174 $ilDB->manipulate(
$query);
177 $view_id = $ilDB->nextId(
"il_dcl_view");
178 $query =
"INSERT INTO il_dcl_view (id, table_id, type, formtype) VALUES (" . $ilDB->quote($view_id,
"integer") .
", "
180 . $ilDB->quote(1,
"integer") .
")";
181 $ilDB->manipulate(
$query);
184 $view_id = $ilDB->nextId(
"il_dcl_view");
185 $query =
"INSERT INTO il_dcl_view (id, table_id, type, formtype) VALUES (" . $ilDB->quote($view_id,
"integer") .
", "
187 . $ilDB->quote(1,
"integer") .
")";
188 $ilDB->manipulate(
$query);
191 $view_id = $ilDB->nextId(
"il_dcl_view");
192 $query =
"INSERT INTO il_dcl_view (id, table_id, type, formtype) VALUES (" . $ilDB->quote($view_id,
"integer") .
", "
194 . $ilDB->quote(1,
"integer") .
")";
195 $ilDB->manipulate(
$query);
198 $view_id = $ilDB->nextId(
"il_dcl_view");
199 $query =
"INSERT INTO il_dcl_view (id, table_id, type, formtype) VALUES (" . $ilDB->quote($view_id,
"integer") .
", "
201 . $ilDB->quote(1,
"integer") .
")";
202 $ilDB->manipulate(
$query);
214 $ilDB->update(
"il_dcl_table", array(
215 "obj_id" => array(
"integer", $this->
getObjId() ),
216 "title" => array(
"text", $this->
getTitle() ),
217 "add_perm" => array(
"integer", $this->
getAddPerm() ),
218 "edit_perm" => array(
"integer", $this->
getEditPerm() ),
221 "limited" => array(
"integer", $this->
getLimited() ),
222 "limit_start" => array(
"timestamp", $this->
getLimitStart() ),
223 "limit_end" => array(
"timestamp", $this->
getLimitEnd() ),
224 "is_visible" => array(
"integer", $this->
getIsVisible() ? 1 : 0 ),
228 "id" => array(
"integer", $this->
getId() )
259 $this->objId = $a_id;
279 $this->title = $a_title;
309 if ($this->obj == NULL) {
339 if (! count($filter)) {
344 if ($record->passThroughFilter($filter)) {
345 $filtered[] = $record;
357 if ($this->records == NULL) {
361 $query =
"SELECT id FROM il_dcl_record WHERE table_id = " . $ilDB->quote($this->
id,
"integer");
362 $set = $ilDB->query(
$query);
364 while ($rec = $ilDB->fetchAssoc($set)) {
385 WHERE obj_id = " . $ilDB->quote($a_id,
"integer");
386 $set = $ilDB->query(
$query);
389 while ($rec = $ilDB->fetchAssoc($set)) {
390 $all[$rec[
'id']] = $rec;
405 $record->deleteField($field_id);
418 foreach (
$fields as $field_1) {
419 if ($field_1->getId() == $field_id) {
440 if ($this->
fields == NULL) {
443 $query =
"SELECT DISTINCT field.* FROM il_dcl_field AS field
444 INNER JOIN il_dcl_view AS view ON view.table_id = field.table_id
445 INNER JOIN il_dcl_viewdefinition AS def ON def.view_id = view.id
446 WHERE field.table_id =" . $ilDB->quote($this->
getId(),
"integer") .
"
447 ORDER BY def.field_order DESC";
449 $set = $ilDB->query(
$query);
451 while ($rec = $ilDB->fetchAssoc($set)) {
453 $fields[$field->getId()] = $field;
470 if ($field->isVisible()) {
471 $place = $field->getOrder() + 1;
486 if ($this->stdFields == NULL) {
502 if ($this->stdFields == NULL) {
530 $visibleFields = array();
533 if ($field->isVisible()) {
534 $visibleFields[] = $field;
538 return $visibleFields;
547 $editableFields = array();
550 if (! $field->getLocked()) {
551 $editableFields[] = $field;
555 return $editableFields;
567 $filterableFields = array();
570 if ($field->isFilterable()) {
571 $filterableFields[] = $field;
575 return $filterableFields;
586 $exportableFields = array();
588 if ($field->getExportable()) {
589 $exportableFields[] = $field;
593 return $exportableFields;
649 if ($this->
getEditByOwner() && $ilUser->getId() != $record->getOwner()) {
665 return ($from <= $now && $now <= $to);
693 $named[$field->getId()] = $field;
705 usort($array, array( $this,
"compareOrder" ));
722 if (! is_null($field->getOrder())) {
723 $field->setOrder($count);
724 $count = $count + $offset;
739 if ($field->getTitle() == $name) {
901 return (count($this->
fields) > 0) ?
true :
false;
906 if (is_null($a->getOrder() == NULL) && is_null($b->getOrder() == NULL)) {
909 if (is_null($a->getOrder())) {
912 if (is_null($b->getOrder())) {
916 return $a->getOrder() < $b->getOrder() ? - 1 : 1;
932 $this->
setTitle($original->getTitle());
936 foreach ($original->getRecordFields() as $field) {
938 $new_field->setTableId($this->
getId());
939 $new_field->cloneStructure($field->getId());
944 $old_view->setTableId($original_id);
946 $viewdef->setTableId($this->
id);
947 $viewdef->setXMLContent($old_view->getXMLContent(
false));
959 return (count($this->
getRecords()) > 0) ?
true :
false;
967 $this->
fields[$field->getId()] = $field;
978 $query =
"SELECT * FROM il_dcl_table WHERE id = " . $table_id;
981 return $result->numRows() != 0;
993 $result = $ilDB->query(
'SELECT id FROM il_dcl_table WHERE title = ' . $ilDB->quote(
$title,
'text') .
' AND obj_id = '
994 . $ilDB->quote($obj_id,
'integer'));
996 while ($rec = $ilDB->fetchAssoc(
$result)) {
1008 $query =
" SELECT stloc.value AS val rec_field AS FROM il_dcl_stloc1_value stloc
1009 INNER JOIN il_dcl_record_field rec_field ON rec_field.field_id = 2
1010 WHERE stloc.record_field_id = rec_field.id";
1040 $result = $ilDB->query(
'SELECT * FROM il_dcl_field WHERE table_id = ' . $ilDB->quote($obj_id,
'integer') .
' AND title = '
1041 . $ilDB->quote(
$title,
'text'));
1043 return ($ilDB->numRows(
$result)) ?
true :
false;
1062 $direction = strtolower($direction);
1063 $direction = (in_array($direction, array(
'desc',
'asc' ))) ? $direction :
'asc';
1066 $sortByStatus =
false;
1067 if (substr($sort, 0, 8) ==
'_status_') {
1068 $sortByStatus =
true;
1072 if (is_null($sortField)) {
1073 $sortField = $this->
getField(
'id');
1076 $id = $sortField->getId();
1077 $stl = $sortField->getStorageLocation();
1080 $where_additions =
'';
1083 if ($sortField->isStandardField()) {
1084 if (
$id ==
'owner' ||
$id ==
'last_edit_by') {
1085 $joinStr .=
"LEFT JOIN usr_data AS sort_usr_data_{$id} ON (sort_usr_data_{$id}.usr_id = record.{$id})";
1086 $selectStr .=
" sort_usr_data_{$id}.login AS field_{$id},";
1088 $selectStr .=
" record.{$id} AS field_{$id},";
1091 switch ($sortField->getDatatypeId()) {
1093 $rating_joined =
true;
1095 $joinStr .=
"LEFT JOIN (SELECT (ROUND(AVG(rating), 1) * 10000 + COUNT(rating)) as rating, obj_id FROM il_rating GROUP BY obj_id) AS average ON average.obj_id = record.id";
1096 $selectStr .=
" average.rating AS field_{$id},";
1100 "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 = "
1101 . $ilDB->quote($sortField->getId(),
'integer') .
") ";
1102 $joinStr .=
"LEFT JOIN il_dcl_stloc{$stl}_value AS sort_stloc_{$id} ON (sort_stloc_{$id}.record_field_id = sort_record_field_{$id}.id) ";
1103 $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)";
1104 $joinStr .=
"LEFT JOIN object_data AS sort_object_data_{$id} ON (sort_object_data_{$id}.obj_id = sort_object_reference_{$id}.obj_id)";
1105 if ($sortByStatus) {
1107 $joinStr .=
"LEFT JOIN ut_lp_marks AS ut ON (ut.obj_id = sort_object_data_{$id}.obj_id AND ut.usr_id = "
1108 . $ilDB->quote($ilUser->getId(),
'integer') .
") ";
1110 $selectStr .= (! $sortByStatus) ?
" sort_object_data_{$id}.title AS field_{$id}," :
" ut.status AS field_{$id}";
1115 "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 = "
1116 . $ilDB->quote($sortField->getId(),
'integer') .
") ";
1117 $joinStr .=
"LEFT JOIN il_dcl_stloc{$stl}_value AS sort_stloc_{$id} ON (sort_stloc_{$id}.record_field_id = sort_record_field_{$id}.id) ";
1118 $joinStr .=
"LEFT JOIN object_data AS sort_object_data_{$id} ON (sort_object_data_{$id}.obj_id = sort_stloc_{$id}.value) ";
1119 $selectStr .=
" sort_object_data_{$id}.title AS field_{$id},";
1122 $prop = $sortField->getPropertyvalues();
1128 $selectStr .= ($nRef) ?
" GROUP_CONCAT(stloc_{$id}_joined.value) AS field_{$id}" :
"stloc_{$id}_joined.value AS field_{$id},";
1130 "LEFT JOIN il_dcl_record_field AS record_field_{$id} ON (record_field_{$id}.record_id = record.id AND record_field_{$id}.field_id = "
1131 . $ilDB->quote($sortField->getId(),
'integer') .
") ";
1132 $joinStr .=
"LEFT JOIN il_dcl_stloc{$stl}_value AS stloc_{$id} ON (stloc_{$id}.record_field_id = record_field_{$id}.id) ";
1134 "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 = "
1135 . $ilDB->quote($refField->getId(),
'integer') .
") ";
1136 $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) ";
1142 $selectStr .=
" sort_stloc_{$id}.value AS field_{$id},";
1144 "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 = "
1145 . $ilDB->quote($sortField->getId(),
'integer') .
") ";
1146 $joinStr .=
"LEFT JOIN il_dcl_stloc{$stl}_value AS sort_stloc_{$id} ON (sort_stloc_{$id}.record_field_id = sort_record_field_{$id}.id) ";
1151 if (count($filter)) {
1152 foreach ($filter as $key => $filter_value) {
1153 $filter_field_id = substr($key, 7);
1154 $filterField = $this->
getField($filter_field_id);
1155 switch ($filterField->getDatatypeId()) {
1157 if(!$rating_joined) {
1158 $joinStr .=
"LEFT JOIN (SELECT (ROUND(AVG(rating), 1) * 10000 + COUNT(rating)) as rating, obj_id FROM il_rating GROUP BY obj_id) AS average ON average.obj_id = record.id";
1161 $where_additions .=
" AND average.rating >= " . $ilDB->quote($filter_value * 10000,
'integer');
1166 "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 = "
1167 . $ilDB->quote($filter_field_id,
'integer') .
") ";
1168 $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) ";
1169 $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 ) ";
1171 "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 "
1172 . $ilDB->quote(
"%$filter_value%",
'text') .
") ";
1177 "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 = "
1178 . $ilDB->quote($filter_field_id,
'integer') .
") ";
1179 $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) ";
1181 "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 "
1182 . $ilDB->quote(
"%$filter_value%",
'text') .
") ";
1185 $dateFrom = (isset($filter_value[
'from']) && is_object($filter_value[
'from'])) ? $filter_value[
'from'] : NULL;
1186 $dateTo = (isset($filter_value[
'to']) && is_object($filter_value[
'to'])) ? $filter_value[
'to'] : NULL;
1187 if ($filterField->isStandardField()) {
1189 $where_additions .=
" AND (record.{$filter_field_id} >= " . $ilDB->quote($dateFrom,
'date') .
")";
1192 $where_additions .=
" AND (record.{$filter_field_id} <= " . $ilDB->quote($dateTo,
'date') .
")";
1196 "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 = "
1197 . $ilDB->quote($filter_field_id,
'integer') .
") ";
1198 $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 ";
1200 $joinStr .=
"AND filter_stloc_{$filter_field_id}.value >= " . $ilDB->quote($dateFrom,
'date') .
" ";
1203 $joinStr .=
"AND filter_stloc_{$filter_field_id}.value <= " . $ilDB->quote($dateTo,
'date') .
" ";
1209 $from = (isset($filter_value[
'from'])) ? (
int)$filter_value[
'from'] : NULL;
1210 $to = (isset($filter_value[
'to'])) ? (
int)$filter_value[
'to'] : NULL;
1211 if ($filterField->isStandardField()) {
1212 if (! is_null($from)) {
1213 $where_additions .=
" AND record.{$filter_field_id} >= " . $ilDB->quote($from,
'integer');
1215 if (! is_null($to)) {
1216 $where_additions .=
" AND record.{$filter_field_id} <= " . $ilDB->quote($to,
'integer');
1220 "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 = "
1221 . $ilDB->quote($filter_field_id,
'integer') .
") ";
1222 $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";
1223 if (! is_null($from)) {
1224 $joinStr .=
" AND filter_stloc_{$filter_field_id}.value >= " . $ilDB->quote($from,
'integer');
1226 if (! is_null($to)) {
1227 $joinStr .=
" AND filter_stloc_{$filter_field_id}.value <= " . $ilDB->quote($to,
'integer');
1233 if ($filter_value ==
"checked") {
1235 "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 = "
1236 . $ilDB->quote($filter_field_id,
'integer') .
") ";
1237 $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";
1238 $joinStr .=
" AND filter_stloc_{$filter_field_id}.value = " . $ilDB->quote(1,
'integer');
1241 "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 = "
1242 . $ilDB->quote($filter_field_id,
'integer') .
") ";
1243 $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";
1244 $where_additions .=
" AND (filter_stloc_{$filter_field_id}.value <> " . $ilDB->quote(1,
'integer')
1245 .
" OR filter_stloc_{$filter_field_id}.value is NULL)";
1250 if ($filterField->isStandardField()) {
1252 "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 "
1253 . $ilDB->quote(
"%$filter_value%",
'text') .
") ";
1256 " 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 = "
1257 . $ilDB->quote($filter_field_id,
'integer') .
") ";
1259 " 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 "
1260 . $ilDB->quote(
"%$filter_value%",
'text') .
") ";
1265 " 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 = "
1266 . $ilDB->quote($filter_field_id,
'integer') .
") ";
1267 $prop = $filterField->getPropertyvalues();
1271 " 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 "
1272 . $ilDB->quote(
"%$filter_value%",
'text') .
") ";
1275 " 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 = "
1276 . $ilDB->quote($filter_value,
'integer') .
") ";
1284 $sql =
"SELECT DISTINCT record.id, ";
1285 $sql .= rtrim($selectStr,
',') .
" FROM il_dcl_record AS record ";
1287 $sql .=
" WHERE record.table_id = " . $ilDB->quote($this->
getId(),
'integer') . $where_additions;
1289 $sql .=
" GROUP BY record.id";
1291 $sql .=
" ORDER BY field_{$id} {$direction}";
1292 $set = $ilDB->query($sql);
1293 $totalRecordIds = array();
1294 while ($rec = $ilDB->fetchAssoc($set)) {
1295 $totalRecordIds[] = $rec[
'id'];
1298 $recordIds = array_slice($totalRecordIds, $offset, $limit);
1300 foreach ($recordIds as
$id) {
1304 return array(
'records' =>
$records,
'total' => count($totalRecordIds) );