20 $obj_ids = array_keys($obj_refs);
23 include_once
"Services/Tracking/classes/class.ilLPObjSettings.php";
24 include_once
"Services/Tracking/classes/class.ilLPStatus.php";
27 include_once
'Modules/Course/classes/class.ilObjCourse.php';
28 $view_modes = array();
29 $query =
"SELECT obj_id, view_mode FROM crs_settings".
30 " WHERE ".$ilDB->in(
"obj_id", $obj_ids ,
false,
"integer");
31 $set = $ilDB->query(
$query);
32 while($rec = $ilDB->fetchAssoc($set))
34 $view_modes[(int)$rec[
"obj_id"]] = (
int)$rec[
"view_mode"];
39 $query =
"SELECT object_data.obj_id, title, CASE WHEN status IS NULL THEN ".LP_STATUS_NOT_ATTEMPTED_NUM.
" ELSE status END AS status,".
40 " status_changed, percentage, read_count+childs_read_count AS read_count, spent_seconds+childs_spent_seconds AS spent_seconds,".
41 " u_mode, type, visits, mark, u_comment".
43 " LEFT JOIN ut_lp_settings ON (ut_lp_settings.obj_id = object_data.obj_id)".
44 " LEFT JOIN read_event ON (read_event.obj_id = object_data.obj_id AND read_event.usr_id = ".$ilDB->quote($a_user_id,
"integer").
")".
45 " LEFT JOIN ut_lp_marks ON (ut_lp_marks.obj_id = object_data.obj_id AND ut_lp_marks.usr_id = ".$ilDB->quote($a_user_id,
"integer").
")".
47 " WHERE ".$ilDB->in(
"object_data.obj_id", $obj_ids,
false,
"integer").
49 $set = $ilDB->query(
$query);
51 while($rec = $ilDB->fetchAssoc($set))
53 $rec[
"comment"] = $rec[
"u_comment"];
54 unset($rec[
"u_comment"]);
56 $rec[
"ref_ids"] = $obj_refs[(int)$rec[
"obj_id"]];
57 $rec[
"status"] = (int)$rec[
"status"];
58 $rec[
"percentage"] = (int)$rec[
"percentage"];
59 $rec[
"read_count"] = (int)$rec[
"read_count"];
60 $rec[
"spent_seconds"] = (int)$rec[
"spent_seconds"];
61 $rec[
"u_mode"] = (int)$rec[
"u_mode"];
63 if($rec[
"type"] ==
"sess")
65 $session = $sessions[$rec[
"obj_id"]];
66 $rec[
"title"] = $session[
"title"];
75 else if(!$rec[
"u_mode"])
94 $query =
"SELECT crs_id, crs_objectives.objective_id AS obj_id, title, status, ".$ilDB->quote(
"lobj",
"text").
" AS type".
95 " FROM crs_objectives".
96 " LEFT JOIN crs_objective_status ON (crs_objectives.objective_id = crs_objective_status.objective_id AND user_id = ".$a_user_id.
")".
97 " WHERE ".$ilDB->in(
"crs_objectives.objective_id", $a_objective_ids,
false,
"integer").
99 $set = $ilDB->query(
$query);
101 while($rec = $ilDB->fetchAssoc($set))
118 $scores_raw = $scores = array();
119 include_once
'./Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php';
126 include_once
'./Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php';
128 $scores_raw = $module->getTrackingDataAgg($a_user_id);
132 include_once
'./Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModule.php';
134 $scores_raw = $module->getTrackingDataAgg($a_user_id);
139 foreach($scores_raw as $item)
141 $scores[$item[
"sco_id"]] = $item[
"score"];
147 include_once
'Services/Tracking/classes/class.ilLPStatusWrapper.php';
151 foreach($a_sco_ids as $sco_id)
154 if(in_array($a_user_id, $status_info[
"failed"][$sco_id]))
158 elseif(in_array($a_user_id, $status_info[
"completed"][$sco_id]))
162 elseif(in_array($a_user_id, $status_info[
"in_progress"][$sco_id]))
171 $items[$sco_id] = array(
172 "title" => $status_info[
"scos_title"][$sco_id],
175 "score" => (
int)$scores[$sco_id]
197 $a_offset = 0, $a_limit = 9999, array $a_filters = NULL, array $a_additional_fields = NULL,
198 $check_agreement =
false, $privacy_fields = NULL)
202 $fields = array(
"usr_data.usr_id",
"login",
"active");
206 $where[] =
"usr_data.usr_id <> ".$ilDB->quote(ANONYMOUS_USER_ID,
"integer");
215 if (is_array($a_users))
218 $where[] = $ilDB->in(
"usr_data.usr_id", $a_users,
false,
"integer");
221 $query =
" FROM usr_data ".$left.
" JOIN read_event ON (read_event.usr_id = usr_data.usr_id".
222 " AND read_event.obj_id = ".$ilDB->quote($obj_id,
"integer").
")".
223 " LEFT JOIN ut_lp_marks ON (ut_lp_marks.usr_id = usr_data.usr_id ".
224 " AND ut_lp_marks.obj_id = ".$ilDB->quote($obj_id,
"integer").
")".
225 " LEFT JOIN usr_pref ON (usr_pref.usr_id = usr_data.usr_id AND keyword = ".$ilDB->quote(
"language",
"text").
")".
228 $queries = array(array(
"fields"=>$fields,
"query"=>
$query));
231 if($a_order_field ==
"language")
233 $a_order_field =
"usr_pref.value";
240 $a_order_field =
"login";
242 else if(substr($a_order_field, 0, 4) ==
"udf_")
244 $udf_order = $a_order_field;
245 $a_order_field = null;
253 $query =
"SELECT usr_id, field_id, value FROM udf_text WHERE ".$ilDB->in(
"field_id", $udf,
false,
"integer");
254 $set = $ilDB->query(
$query);
256 while(
$row = $ilDB->fetchAssoc($set))
258 $udf[
$row[
"usr_id"]][
"udf_".$row[
"field_id"]] =
$row[
"value"];
266 include_once
"Services/Membership/classes/class.ilMemberAgreement.php";
270 $query =
"SELECT usr_id FROM usr_pref WHERE keyword = ".$ilDB->quote(
"public_profile",
"text").
271 " AND value = ".$ilDB->quote(
"y",
"text").
" OR value = ".$ilDB->quote(
"g",
"text");
272 $set = $ilDB->query(
$query);
273 $all_public = array();
274 while(
$row = $ilDB->fetchAssoc($set))
276 $all_public[] =
$row[
"usr_id"];
278 $query =
"SELECT usr_id,keyword FROM usr_pref WHERE ".$ilDB->like(
"keyword",
"text",
"public_%",
false).
279 " AND value = ".$ilDB->quote(
"y",
"text").
" AND ".$ilDB->in(
"usr_id", $all_public,
"",
"integer");
280 $set = $ilDB->query(
$query);
282 while(
$row = $ilDB->fetchAssoc($set))
284 $public[
$row[
"usr_id"]][] = substr($row[
"keyword"], 7);
292 if(isset($udf[
$row[
"usr_id"]]))
294 $result[
"set"][$idx] = $row = array_merge($row, $udf[$row[
"usr_id"]]);
298 if(
sizeof($privacy_fields) && $check_agreement && !in_array($row[
"usr_id"], $agreements))
300 foreach($privacy_fields as $field)
303 if(isset($row[$field]) && (!isset($public[$row[
"usr_id"]]) ||
304 !in_array($field, $public[$row[
"usr_id"]])))
307 if(isset($a_filters[$field]))
315 $result[
"set"][$idx][$field] =
false;
326 include_once
"Services/Utilities/classes/class.ilStr.php";
328 $udf_order, $a_order_dir);
349 static function getObjectsDataForUser($a_user_id, $a_parent_obj_id, $a_parent_ref_id, $a_order_field =
"", $a_order_dir =
"", $a_offset = 0, $a_limit = 9999,
350 array $a_filters = NULL, array $a_additional_fields = NULL, $use_collection =
true)
354 $fields = array(
"object_data.obj_id",
"title",
"type");
357 $objects =
self::getObjectIds($a_parent_obj_id, $a_parent_ref_id, $use_collection,
true, array($a_user_id));
359 $query =
" FROM object_data LEFT JOIN read_event ON (object_data.obj_id = read_event.obj_id AND".
360 " read_event.usr_id = ".$ilDB->quote($a_user_id,
"integer").
")".
361 " LEFT JOIN ut_lp_marks ON (ut_lp_marks.usr_id = ".$ilDB->quote($a_user_id,
"integer").
" AND".
362 " ut_lp_marks.obj_id = object_data.obj_id)".
363 " WHERE ".$ilDB->in(
"object_data.obj_id", $objects[
"object_ids"],
false,
"integer").
367 $queries[] = array(
"fields"=>$fields,
"query"=>
$query);
370 if($objects[
"objectives_parent_id"])
372 $objective_fields = array(
"crs_objectives.objective_id AS obj_id",
"title",
373 $ilDB->quote(
"lobj",
"text").
" as type");
375 if (is_array($a_additional_fields))
377 foreach($a_additional_fields as $field)
379 if($field !=
"status")
381 $objective_fields[] =
"NULL AS ".$field;
385 include_once(
"Services/Tracking/classes/class.ilLPStatus.php");
386 $objective_fields[] =
"CASE WHEN status IS NOT NULL THEN ".LP_STATUS_COMPLETED_NUM.
" ELSE NULL END AS status";
392 $where[] =
"crs_objectives.crs_id = ".$ilDB->quote($objects[
"objectives_parent_id"],
"integer");
394 $objectives_query =
" FROM crs_objectives".
395 " LEFT JOIN crs_objective_status ON (crs_objectives.objective_id = crs_objective_status.objective_id".
396 " AND crs_objective_status.user_id = ".$ilDB->quote($a_user_id,
"integer").
")".
399 $queries[] = array(
"fields"=>$objective_fields,
"query"=>$objectives_query,
"count"=>
"crs_objectives.objective_id");
402 if(!in_array($a_order_field, $fields))
404 $a_order_field =
"title";
413 foreach(
$result[
"set"] as $idx => $item)
415 if($item[
"type"] ==
"sess")
417 $session = $sessions[$item[
"obj_id"]];
418 $result[
"set"][$idx][
"title"] = $session[
"title"];
419 $result[
"set"][$idx][
"sort_title"] = $session[
"e_start"];
423 $result[
"set"][$idx][
"ref_id"] = $objects[
"ref_ids"][$item[
"obj_id"]];
427 if($objects[
"scorm"])
429 include_once(
"./Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php");
431 if($subtype ==
"scorm2004")
433 include_once(
"./Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModule.php");
435 $scos_tracking = $sobj->getTrackingDataAgg($a_user_id,
true);
439 include_once(
"./Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php");
441 $scos_tracking = array();
442 foreach($sobj->getTrackingDataAgg($a_user_id) as $item)
447 $time = explode(
":", $item[
"time"]);
448 $item[
"time"] = $time[0]*60*60+$time[1]*60+$time[2];
450 $scos_tracking[$item[
"sco_id"]] = array(
"session_time"=>$item[
"time"]);
454 foreach($objects[
"scorm"][
"scos"] as $sco)
456 $row = array(
"title" => $objects[
"scorm"][
"scos_title"][$sco],
460 if(in_array($a_user_id, $objects[
"scorm"][
"completed"][$sco]))
464 else if(in_array($a_user_id, $objects[
"scorm"][
"failed"][$sco]))
468 else if(in_array($a_user_id, $objects[
"scorm"][
"in_progress"][$sco]))
472 $row[
"status"] = $status;
475 if(isset($scos_tracking[$sco]))
477 if(isset($scos_tracking[$sco][
"last_access"]))
482 $row[
"spent_seconds"] = $scos_tracking[$sco][
"session_time"];
504 $query =
"SELECT obj_id, title, e_start, e_end, CASE WHEN participated = 1 THEN 2 WHEN registered = 1 THEN 1 ELSE NULL END AS status,".
507 " JOIN event_appointment ON (event.obj_id = event_appointment.event_id)".
508 " LEFT JOIN event_participants ON (event_participants.event_id = event.obj_id AND usr_id = ".$ilDB->quote($a_user_id,
"integer").
")".
509 " WHERE ".$ilDB->in(
"obj_id", $obj_ids ,
false,
"integer");
510 $set = $ilDB->query(
$query);
512 while($rec = $ilDB->fetchAssoc($set))
514 $rec[
"comment"] = $rec[
"e_comment"];
515 unset($rec[
"e_comment"]);
523 $rec[
"title"] = $date.
': '.$rec[
"title"];
527 $rec[
"title"] = $date;
529 $sessions[$rec[
"obj_id"]] = $rec;
550 static function getObjectsSummaryForObject($a_parent_obj_id, $a_parent_ref_id, $a_order_field =
"", $a_order_dir =
"", $a_offset = 0, $a_limit = 9999,
551 array $a_filters = NULL, array $a_additional_fields = NULL, $a_preselected_obj_ids = NULL)
559 if($a_preselected_obj_ids === NULL)
565 foreach($a_preselected_obj_ids as $obj_id => $ref_ids)
567 $objects[
"object_ids"][] = $obj_id;
568 $objects[
"ref_ids"][$obj_id] = array_pop($ref_ids);
576 $set = $ilDB->query(
"SELECT obj_id,title,type FROM object_data".
577 " WHERE ".$ilDB->in(
"obj_id", $objects[
"object_ids"],
false,
"integer"));
578 while($rec = $ilDB->fetchAssoc($set))
580 $object_data[$rec[
"obj_id"]] = $rec;
581 if($a_preselected_obj_ids)
583 $object_data[$rec[
"obj_id"]][
"ref_ids"] = $a_preselected_obj_ids[$rec[
"obj_id"]];
587 foreach($objects[
"ref_ids"] as $object_id =>
$ref_id)
590 if(
sizeof($object_result))
592 if($object_data[$object_id])
594 $result[] = array_merge($object_data[$object_id], $object_result);
600 if($objects[
"objectives_parent_id"])
622 $where[] =
"usr_data.usr_id <> ".$ilDB->quote(ANONYMOUS_USER_ID,
"integer");
627 if (is_array($a_users))
630 $where[] = $ilDB->in(
"usr_data.usr_id", $a_users,
false,
"integer");
636 $query =
" FROM usr_data ".$left.
" JOIN read_event ON (read_event.usr_id = usr_data.usr_id".
637 " AND obj_id = ".$ilDB->quote($obj_id,
"integer").
")".
638 " LEFT JOIN ut_lp_marks ON (ut_lp_marks.usr_id = usr_data.usr_id ".
639 " AND ut_lp_marks.obj_id = ".$ilDB->quote($obj_id,
"integer").
")".
640 " LEFT JOIN usr_pref ON (usr_pref.usr_id = usr_data.usr_id AND keyword = ".$ilDB->quote(
"language",
"text").
")".
643 $fields[] =
'COUNT(usr_data.usr_id) AS user_count';
646 $queries[] = array(
"fields"=>$fields,
"query"=>
$query,
"count"=>
"*");
650 $users_no =
$result[
"user_count"];
657 else if(isset($a_filters[
"user_total"]))
659 if($a_filters[
"user_total"][
"from"] && $users_no < $a_filters[
"user_total"][
"from"])
663 else if($a_filters[
"user_total"][
"to"] && $users_no > $a_filters[
"user_total"][
"to"])
686 $result[
"user_total"] = $users_no;
706 $field_alias = $field;
710 $field_alias = $alias;
711 $alias =
" AS ".$alias;
716 if(preg_match(
"/".preg_quote(
" [[--HAVING").
"(.+)".preg_quote(
"HAVING--]]").
"/", $base_query, $hits))
718 $having =
" HAVING ".$hits[1];
719 $base_query = str_replace($hits[0],
"", $base_query);
722 $query =
"SELECT COUNT(*) AS counter, ".$field.$alias.
" ".$base_query.
" GROUP BY ".$field.$having.
" ORDER BY counter DESC";
723 $set = $ilDB->query(
$query);
725 while($rec = $ilDB->fetchAssoc($set))
727 $result[$rec[$field_alias]] = (int)$rec[
"counter"];
749 include_once
"Modules/Course/classes/class.ilCourseParticipants.php";
751 return $member_obj->getMembers();
754 include_once
"Modules/Group/classes/class.ilGroupParticipants.php";
756 return $member_obj->getMembers();
760 $path = $tree->getPathId($a_ref_id);
762 foreach(array_reverse(
$path) as $path_ref_id)
765 if($type ==
"crs" || $type ==
"grp")
779 include_once(
"./Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php");
781 if ($subtype ==
"scorm2004")
784 include_once(
"./Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModule.php");
786 $all = $mod->getTrackedUsers(
"");
790 foreach($all as $item)
792 $a_users[] = $item[
"user_id"];
798 include_once(
"./Modules/ScormAicc/classes/SCORM/class.ilObjSCORMTracking.php");
804 include_once(
"./Modules/Exercise/classes/class.ilExerciseMembers.php");
805 include_once(
"./Modules/Exercise/classes/class.ilObjExercise.php");
808 $a_users = $members->getMembers();
812 include_once(
"./Services/Tracking/classes/class.ilLPStatusTestFinished.php");
832 static protected function buildFilters(array $where, array $a_filters = NULL, $a_aggregate =
false)
838 if(
sizeof($a_filters))
840 foreach($a_filters as $id => $value)
851 case "matriculation":
855 $where[] = $ilDB->like(
"usr_data.".$id,
"text",
"%".$value.
"%");
861 $where[] =
"usr_data.".$id.
" = ".$ilDB->quote($value ,
"text");
865 $where[] = $ilDB->like(
"ut_lp_marks.".$id,
"text",
"%".$value.
"%");
873 " OR ut_lp_marks.status IS NULL)";
879 $where[] =
"ut_lp_marks.".$id.
" = ".$ilDB->quote($value ,
"text");
887 $where[] =
"ut_lp_marks.".$id.
" >= ".$ilDB->quote($value[
"from"] ,
"integer");
891 $where[] =
"ut_lp_marks.".$id.
" <= ".$ilDB->quote($value[
"to"] ,
"integer");
898 $having[] =
"ROUND(AVG(ut_lp_marks.".$id.
")) >= ".$ilDB->quote($value[
"from"] ,
"integer");
902 $having[] =
"ROUND(AVG(ut_lp_marks.".$id.
")) <= ".$ilDB->quote($value[
"to"] ,
"integer");
908 $where[] =
"usr_pref.value = ".$ilDB->quote($value ,
"text");
925 case 'status_changed':
929 if($id ==
"registration")
940 $where[] = $id.
" >= ".$ilDB->quote($value[
"from"] ,
"date");
944 $where[] = $id.
" <= ".$ilDB->quote($value[
"to"] ,
"date");
953 $where[] =
"(read_event.".$id.
"+read_event.childs_".$id.
") >= ".$ilDB->quote($value[
"from"] ,
"integer");
957 $where[] =
"(read_event.".$id.
"+read_event.childs_".$id.
") <= ".$ilDB->quote($value[
"to"] ,
"integer");
964 $having[] =
"SUM(read_event.".$id.
"+read_event.childs_".$id.
") >= ".$ilDB->quote($value[
"from"] ,
"integer");
968 $having[] =
"SUM(read_event.".$id.
"+read_event.childs_".$id.
") <= ".$ilDB->quote($value[
"to"] ,
"integer");
973 case "spent_seconds":
978 $where[] =
"(read_event.".$id.
"+read_event.childs_".$id.
") >= ".$ilDB->quote($value[
"from"] ,
"integer");
982 $where[] =
"(read_event.".$id.
"+read_event.childs_".$id.
") <= ".$ilDB->quote($value[
"to"] ,
"integer");
989 $having[] =
"ROUND(AVG(read_event.".$id.
"+read_event.childs_".$id.
")) >= ".$ilDB->quote($value[
"from"] ,
"integer");
993 $having[] =
"ROUND(AVG(read_event.".$id.
"+read_event.childs_".$id.
")) <= ".$ilDB->quote($value[
"to"] ,
"integer");
1008 $sql .=
" WHERE ".implode(
" AND ", $where);
1013 $sql .=
" [[--HAVING ".implode(
" AND ", $having).
"HAVING--]]";
1027 static protected function buildColumns(array &$a_fields, array $a_additional_fields = NULL, $a_aggregate =
false)
1029 if(
sizeof($a_additional_fields))
1032 foreach($a_additional_fields as $field)
1034 if(substr($field, 0, 4) !=
"udf_")
1039 $pos = strrpos($field,
"_");
1044 $function = strtoupper(substr($field, $pos+1));
1045 $field = substr($field, 0, $pos);
1046 if(!in_array($function, array(
"MIN",
"MAX",
"SUM",
"AVG",
"COUNT")))
1057 $a_fields[] = $function.
"(value) AS ".$field.
"_".strtolower($function);
1061 $a_fields[] =
"value AS ".$field;
1066 case "spent_seconds":
1069 $a_fields[] =
"(".$field.
"+childs_".$field.
") AS ".$field;
1073 if($function ==
"AVG")
1075 $a_fields[] =
"ROUND(AVG(".$field.
"+childs_".$field.
"), 2) AS ".$field.
"_".strtolower($function);
1079 $a_fields[] = $function.
"(".$field.
"+childs_".$field.
") AS ".$field.
"_".strtolower($function);
1084 case "read_count_spent_seconds":
1085 if($function ==
"AVG")
1087 $a_fields[] =
"ROUND(AVG((spent_seconds+childs_spent_seconds)/(read_count+childs_read_count)), 2) AS ".$field.
"_".strtolower($function);
1094 if($function ==
"AVG")
1096 $a_fields[] =
"ROUND(AVG(".$field.
"), 2) AS ".$field.
"_".strtolower($function);
1100 $a_fields[] = $function.
"(".$field.
") AS ".$field.
"_".strtolower($function);
1105 $a_fields[] = $field;
1112 $udf[] = substr($field, 4);
1117 $a_fields = array_unique($a_fields);
1120 $udf = array_unique($udf);
1137 static public function getObjectIds($a_parent_obj_id, $a_parent_ref_id =
false, $use_collection =
true, $a_refresh_status =
true, $a_user_ids = null)
1139 include_once
"Services/Tracking/classes/class.ilLPObjSettings.php";
1141 $object_ids = array($a_parent_obj_id);
1142 $ref_ids = array($a_parent_obj_id => $a_parent_ref_id);
1143 $objectives_parent_id = $scorm =
false;
1150 include_once
"Services/Tracking/classes/class.ilLPStatusSCORM.php";
1152 $scorm = $status_scorm->_getStatusInfo($a_parent_obj_id);
1158 $objectives_parent_id = $a_parent_obj_id;
1166 include_once
'Services/Tracking/classes/class.ilLPCollectionCache.php';
1170 $object_ids[] = $child_id;
1171 $ref_ids[$child_id] = $child_ref_id;
1178 $object_ids = array_unique($object_ids);
1181 foreach($object_ids as $idx => $object_id)
1185 unset($object_ids[$idx]);
1191 if($a_refresh_status)
1196 return array(
"object_ids" => $object_ids,
1197 "ref_ids" => $ref_ids,
1198 "objectives_parent_id" => $objectives_parent_id,
1209 static protected function getSubTree($a_parent_ref_id, array &$a_object_ids, array &$a_ref_ids)
1213 $children = $tree->getChilds($a_parent_ref_id);
1216 foreach($children as $child)
1218 if($child[
"type"] ==
"adm" || $child[
"type"] ==
"rolf")
1230 include_once
"Services/Repository/classes/class.ilRepositoryObjectPluginSlot.php";
1233 $a_object_ids[] = $child[
"obj_id"];
1234 $a_ref_ids[$child[
"obj_id"]] = $child[
"ref_id"];
1239 $a_object_ids[] = $child[
"obj_id"];
1240 $a_ref_ids[$child[
"obj_id"]] = $child[
"ref_id"];
1258 static function executeQueries(array $queries, $a_order_field =
"", $a_order_dir =
"", $a_offset = 0, $a_limit = 9999)
1263 $subqueries = array();
1264 foreach($queries as $item)
1267 $item = str_replace(
"[[--HAVING",
"HAVING", $item);
1268 $item = str_replace(
"HAVING--]]",
"", $item);
1270 if(!isset($item[
"count"]))
1272 $count_field = $item[
"fields"];
1273 $count_field = array_shift($count_field);
1277 $count_field = $item[
"count"];
1279 $count_query =
"SELECT COUNT(".$count_field.
") AS cnt".$item[
"query"];
1280 $set = $ilDB->query($count_query);
1281 if ($rec = $ilDB->fetchAssoc($set))
1283 $cnt += $rec[
"cnt"];
1286 $subqueries[] =
"SELECT ".implode(
",", $item[
"fields"]).$item[
"query"];
1293 if(
sizeof($subqueries) > 1)
1295 $base = array_shift($subqueries);
1296 $query = $base.
" UNION (".implode(
") UNION (", $subqueries).
")";
1303 if ($a_order_dir !=
"asc" && $a_order_dir !=
"desc")
1305 $a_order_dir =
"asc";
1309 $query.=
" ORDER BY ".$a_order_field.
" ".strtoupper($a_order_dir);
1312 $offset = (int) $a_offset;
1313 $limit = (int) $a_limit;
1314 $ilDB->setLimit($limit, $offset);
1316 $set = $ilDB->query(
$query);
1317 while($rec = $ilDB->fetchAssoc($set))
1323 return array(
"cnt" => $cnt,
"set" =>
$result);
1338 $result = array(
"cnt"=>0,
"set"=>NULL);
1339 if(
sizeof($a_obj_ids))
1342 $where[] =
"usr_data.usr_id <> ".$ilDB->quote(ANONYMOUS_USER_ID,
"integer");
1345 $where[] = $ilDB->like(
"usr_data.login",
"text",
"%".$a_user_filter.
"%");
1351 if (is_array($a_users))
1354 $where[] = $ilDB->in(
"usr_data.usr_id", $a_users,
false,
"integer");
1357 include_once(
"./Services/Tracking/classes/class.ilLPStatus.php");
1359 $fields = array(
"usr_data.usr_id",
"login",
"active",
"status",
1360 "status_changed",
"percentage",
"last_access",
1361 "spent_seconds+childs_spent_seconds as spent_seconds");
1369 foreach($a_obj_ids as $obj_id)
1372 $query =
" FROM usr_data ".$left.
" JOIN read_event ON (read_event.usr_id = usr_data.usr_id".
1373 " AND read_event.obj_id = ".$ilDB->quote($obj_id,
"integer").
")".
1374 " LEFT JOIN ut_lp_marks ON (ut_lp_marks.usr_id = usr_data.usr_id ".
1375 " AND ut_lp_marks.obj_id = ".$ilDB->quote($obj_id,
"integer").
")".
1382 foreach($raw[
"set"] as
$row)
1384 $result[
"set"][$row[
"usr_id"]][
"login"] = $row[
"login"];
1385 $result[
"set"][$row[
"usr_id"]][
"usr_id"] = $row[
"usr_id"];
1386 $result[
"set"][$row[
"usr_id"]][
"active"] = $row[
"active"];
1387 $result[
"set"][$row[
"usr_id"]][
"objects"][$obj_id] = array(
"status"=>$row[
"status"],
1388 "percentage"=>$row[
"percentage"]);
1389 if($obj_id == $parent_obj_id)
1391 $result[
"set"][$row[
"usr_id"]][
"status_changed"] = $row[
"status_changed"];
1392 $result[
"set"][$row[
"usr_id"]][
"last_access"] = $row[
"last_access"];
1393 $result[
"set"][$row[
"usr_id"]][
"spent_seconds"] = $row[
"spent_seconds"];
1408 if($a_parent_obj_id && $a_users)
1410 include_once(
"Services/Tracking/classes/class.ilLPStatus.php");
1412 $fields = array(
"crs_objectives.objective_id AS obj_id",
"crs_objective_status.user_id AS usr_id",
"title");
1413 $fields[] =
"CASE WHEN status IS NOT NULL THEN ".LP_STATUS_COMPLETED_NUM.
" ELSE NULL END AS status";
1416 $where[] =
"crs_objectives.crs_id = ".$ilDB->quote($a_parent_obj_id,
"integer");
1418 $query =
" FROM crs_objectives".
1419 " LEFT JOIN crs_objective_status ON (crs_objectives.objective_id = crs_objective_status.objective_id".
1420 " AND ".$ilDB->in(
"crs_objective_status.user_id", $a_users,
"",
"integer").
")".
1431 $obj_ids = array_keys($a_ref_ids);
1443 $sql =
"SELECT obj_id,".$column.
",SUM(read_count) read_count,SUM(childs_read_count) childs_read_count,".
1444 "SUM(spent_seconds) spent_seconds,SUM(childs_spent_seconds) childs_spent_seconds".
1446 " WHERE ".$ilDB->in(
"obj_id", $obj_ids,
"",
"integer").
1447 " AND yyyy = ".$ilDB->quote($a_year,
"integer");
1450 $sql .=
" AND mm = ".$ilDB->quote($a_month,
"integer");
1452 $sql .=
" GROUP BY obj_id,".$column;
1453 $set = $ilDB->query($sql);
1454 while(
$row = $ilDB->fetchAssoc($set))
1456 $row[
"read_count"] +=
$row[
"childs_read_count"];
1457 $row[
"spent_seconds"] +=
$row[
"childs_spent_seconds"];
1458 $res[
$row[
"obj_id"]][
$row[$column]][
"read_count"] += $row[
"read_count"];
1459 $res[$row[
"obj_id"]][$row[$column]][
"spent_seconds"] += $row[
"spent_seconds"];
1465 $sql =
"SELECT obj_id,".$column.
",SUM(counter) counter".
1466 " FROM obj_user_stat".
1467 " WHERE ".$ilDB->in(
"obj_id", $obj_ids,
"",
"integer").
1468 " AND yyyy = ".$ilDB->quote($a_year,
"integer");
1471 $sql .=
" AND mm = ".$ilDB->quote($a_month,
"integer");
1473 $sql .=
" GROUP BY obj_id,".$column;
1474 $set = $ilDB->query($sql);
1475 while(
$row = $ilDB->fetchAssoc($set))
1477 $res[
$row[
"obj_id"]][
$row[$column]][
"users"] += $row[
"counter"];
1485 global $ilDB, $objDefinition;
1490 include_once
"Services/Tree/classes/class.ilTree.php";
1492 $sql =
"SELECT ".$tree->table_obj_data.
".obj_id,".$tree->table_obj_data.
".type,".
1493 $tree->table_tree.
".".$tree->tree_pk.
",".$tree->table_obj_reference.
".ref_id".
1494 " FROM ".$tree->table_tree.
1495 " ".$tree->buildJoin().
1496 " WHERE ".$ilDB->in($tree->table_obj_data.
".type", $types,
"",
"text");
1497 $set = $ilDB->query($sql);
1499 while(
$row = $ilDB->fetchAssoc($set))
1501 $res[
$row[
"type"]][
"type"] = $row[
"type"];
1502 $res[$row[
"type"]][
"references"]++;
1503 $res[$row[
"type"]][
"objects"][] = $row[
"obj_id"];
1504 if($row[$tree->tree_pk] < 0)
1506 $res[$row[
"type"]][
"deleted"]++;
1510 foreach(
$res as $type => $values)
1512 $res[$type][
"objects"] =
sizeof(array_unique($values[
"objects"]));
1522 $obj_ids = array_keys($a_ref_ids);
1525 $sql =
"SELECT obj_id,hh,SUM(read_count) read_count,SUM(childs_read_count) childs_read_count,".
1526 "SUM(spent_seconds) spent_seconds,SUM(childs_spent_seconds) childs_spent_seconds".
1528 " WHERE ".$ilDB->in(
"obj_id", $obj_ids,
"",
"integer").
1529 " AND yyyy = ".$ilDB->quote($a_year,
"integer");
1532 $sql .=
" AND mm = ".$ilDB->quote($a_month,
"integer");
1534 $sql .=
" GROUP BY obj_id,hh";
1535 $set = $ilDB->query($sql);
1536 while(
$row = $ilDB->fetchAssoc($set))
1538 $row[
"read_count"] +=
$row[
"childs_read_count"];
1539 $row[
"spent_seconds"] +=
$row[
"childs_spent_seconds"];
1541 $res[
$row[
"obj_id"]][(int)
$row[
"hh"]][
"spent_seconds"] +=
$row[
"spent_seconds"];
1550 $set = $ilDB->query(
"SELECT COUNT(*) AS COUNTER,yyyy,mm".
1552 " GROUP BY yyyy, mm".
1553 " ORDER BY yyyy DESC, mm DESC");
1555 while(
$row = $ilDB->fetchAssoc($set))
1558 "count"=>$row[
"counter"]);
1568 $date_compare = $ilDB->in($ilDB->concat(array(array(
"yyyy",
""),
1569 array($ilDB->quote(
"-",
"text"),
""),
1570 array(
"mm",
""))), $a_months,
"",
"text");
1571 $sql =
"DELETE FROM obj_stat".
1572 " WHERE ".$date_compare;
1573 $ilDB->manipulate($sql);
1576 $tables = array(
"obj_lp_stat",
"obj_type_stat",
"obj_user_stat");
1577 foreach($a_months as $month)
1579 $year = substr($month, 0, 4);
1580 $month = substr($month, 5);
1581 $from = $year.str_pad($month, 2,
"0", STR_PAD_LEFT).
"01";
1582 $to = $year.str_pad($month, 2,
"0", STR_PAD_LEFT).
"31";
1584 foreach($tables as $table)
1586 $sql =
"DELETE FROM ".$table.
1587 " WHERE fulldate >= ".$ilDB->quote($from,
"integer").
1588 " AND fulldate <= ".$ilDB->quote($to,
"integer");
1589 $ilDB->manipulate($sql);
1594 static public function searchObjects($a_type, $a_title = null, $a_root = null, $a_hidden = null, $a_preset_obj_ids = null)
1596 global $ilDB, $tree;
1598 if($a_type ==
"lres")
1600 $a_type = array(
'lm',
'sahs',
'htlm',
'dbk');
1603 $sql =
"SELECT r.ref_id,r.obj_id".
1604 " FROM object_data o".
1605 " JOIN object_reference r ON (o.obj_id = r.obj_id)".
1606 " JOIN tree t ON (t.child = r.ref_id)".
1607 " WHERE t.tree = ".$ilDB->quote(1,
"integer");
1609 if(!is_array($a_type))
1611 $sql .=
" AND o.type = ".$ilDB->quote($a_type,
"text");
1615 $sql .=
" AND ".$ilDB->in(
"o.type", $a_type,
"",
"text");
1620 $sql .=
" AND (".$ilDB->like(
"o.title",
"text",
"%".$a_title.
"%").
1621 " OR ".$ilDB->like(
"o.description",
"text",
"%".$a_title.
"%").
")";
1624 if(is_array($a_hidden))
1626 $sql .=
" AND ".$ilDB->in(
"o.obj_id", $a_hidden,
true,
"integer");
1629 if(is_array($a_preset_obj_ids))
1631 $sql .=
" AND ".$ilDB->in(
"o.obj_id", $a_preset_obj_ids,
false,
"integer");
1634 $set = $ilDB->query($sql);
1636 while(
$row = $ilDB->fetchAssoc($set))
1638 if($a_root && $a_root != ROOT_FOLDER_ID)
1642 if($tree->isGrandChild($a_root,
$ref_id))
1644 $res[
$row[
"obj_id"]][] = $row[
"ref_id"];
1651 $res[
$row[
"obj_id"]][] = $row[
"ref_id"];
1665 include_once(
"./Services/Tracking/classes/class.ilLPStatus.php");
1666 foreach($a_obj_ids as $obj_id)
1681 $set = $ilDB->query(
"SELECT COUNT(*) counter, MIN(tstamp) tstamp".
1682 " FROM obj_stat_log");
1683 return $ilDB->fetchAssoc($set);
1696 $column =
"mm,yyyy";
1700 $sql =
"SELECT obj_id,".$column.
",".
1701 "MIN(mem_cnt) mem_cnt_min,AVG(mem_cnt) mem_cnt_avg, MAX(mem_cnt) mem_cnt_max,".
1702 "MIN(in_progress) in_progress_min,AVG(in_progress) in_progress_avg,MAX(in_progress) in_progress_max,".
1703 "MIN(completed) completed_min,AVG(completed) completed_avg,MAX(completed) completed_max,".
1704 "MIN(failed) failed_min,AVG(failed) failed_avg,MAX(failed) failed_max,".
1705 "MIN(not_attempted) not_attempted_min,AVG(not_attempted) not_attempted_avg,MAX(not_attempted) not_attempted_max".
1706 " FROM obj_lp_stat".
1707 " WHERE ".$ilDB->in(
"obj_id", $a_obj_ids,
"",
"integer").
1708 " AND yyyy = ".$ilDB->quote($a_year,
"integer");
1711 $sql .=
" AND mm = ".$ilDB->quote($a_month,
"integer");
1713 $sql .=
" GROUP BY obj_id,".$column;
1714 $set = $ilDB->query($sql);
1715 while(
$row = $ilDB->fetchAssoc($set))
1729 $a_year = date(
"Y");
1732 $agg = strtoupper($a_aggregation);
1735 $sql =
"SELECT type,yyyy,mm,".$agg.
"(cnt_objects) cnt_objects,".$agg.
"(cnt_references) cnt_references,".
1736 "".$agg.
"(cnt_deleted) cnt_deleted FROM obj_type_stat".
1737 " WHERE yyyy = ".$ilDB->quote($a_year,
"integer").
1738 " GROUP BY type,yyyy,mm";
1739 $set = $ilDB->query($sql);
1740 while(
$row = $ilDB->fetchAssoc($set))
1742 $row[
"mm"] = str_pad(
$row[
"mm"], 2,
"0", STR_PAD_LEFT);
1744 "objects" => (
int)
$row[
"cnt_objects"],
1745 "references" => (
int)$row[
"cnt_references"],
1746 "deleted" => (
int)$row[
"cnt_deleted"]