ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilLPStatusCollectionMobs.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/Tracking/classes/class.ilLPStatus.php';
5require_once 'Services/Tracking/classes/class.ilLearningProgress.php';
6
12{
13 public static function _getInProgress($a_obj_id)
14 {
15 $users = array();
16
17 $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
18 if (is_array($status_info["user_status"]["in_progress"])) {
19 $users = $status_info["user_status"]["in_progress"];
20 }
21 return $users;
22 }
23
24 public static function _getCompleted($a_obj_id)
25 {
26 $users = array();
27
28 $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
29 if (is_array($status_info["user_status"]["completed"])) {
30 $users = $status_info["user_status"]["completed"];
31 }
32
33 return $users;
34 }
35
36 public static function _getStatusInfo($a_parent_obj_id)
37 {
38 global $DIC;
39
40 $ilDB = $DIC['ilDB'];
41
42 $res = array();
43
44 $coll_items = self::getCollectionItems($a_parent_obj_id, true);
45
46 $res["items"] = array_keys($coll_items);
47 if (sizeof($res["items"])) {
48 // titles
49 foreach ($coll_items as $mob_id => $item) {
50 $res["item_titles"][$mob_id] = $item["title"];
51 }
52
53 // status per item
54 foreach ($res["items"] as $mob_id) {
55 $res["completed"][$mob_id] = array();
56 $res["in_progress"][$mob_id] = array();
57 }
58
59 $set = $ilDB->query("SELECT obj_id, usr_id FROM read_event" .
60 " WHERE " . $ilDB->in("obj_id", $res["items"], "", "integer"));
61 while ($row = $ilDB->fetchAssoc($set)) {
62 $res["completed"][$row["obj_id"]][] = $row["usr_id"];
63 }
64
65 // status per user
66 $tmp = array();
67 foreach ($res["items"] as $mob_id) {
68 foreach ($res["completed"][$mob_id] as $user_id) {
69 $tmp[$user_id][] = $mob_id;
70 }
71 }
72 foreach ($tmp as $user_id => $completed_items) {
73 if (sizeof($completed_items) == sizeof($res["items"])) {
74 $res["user_status"]["completed"][] = $user_id;
75 } else {
76 $res["user_status"]["in_progress"][] = $user_id;
77 }
78 }
79 }
80
81 include_once './Services/Tracking/classes/class.ilChangeEvent.php';
82 $users = ilChangeEvent::lookupUsersInProgress($a_parent_obj_id);
83 foreach ($users as $user_id) {
84 if ((!is_array($res["user_status"]["in_progress"]) || !in_array($user_id, $res["user_status"]["in_progress"])) &&
85 (!is_array($res["user_status"]["completed"]) || !in_array($user_id, $res["user_status"]["completed"]))) {
86 $res["user_status"]["in_progress"][] = $user_id;
87 }
88 }
89
90 return $res;
91 }
92
93 protected static function getCollectionItems($a_obj_id, $a_include_titles = false)
94 {
95 $res = array();
96
97 include_once './Services/Object/classes/class.ilObjectLP.php';
98 $olp = ilObjectLP::getInstance($a_obj_id);
99 $collection = $olp->getCollectionInstance();
100 if ($collection) {
101 $possible = $collection->getPossibleItems();
102
103 // there could be invalid items in the selection
104 $valid = array_intersect(
105 $collection->getItems(),
106 array_keys($possible)
107 );
108
109 if ($a_include_titles) {
110 foreach ($valid as $item_id) {
111 $res[$item_id] = $possible[$item_id];
112 }
113 } else {
114 $res = $valid;
115 }
116 }
117
118 return $res;
119 }
120
121 public function determineStatus($a_obj_id, $a_user_id, $a_obj = null)
122 {
123 global $DIC;
124
125 $ilDB = $DIC['ilDB'];
126
128
129 if (ilChangeEvent::hasAccessed($a_obj_id, $a_user_id)) {
131 }
132
133 // an empty collection is always not attempted
134 $items = self::getCollectionItems($a_obj_id);
135 if (sizeof($items)) {
136 // process mob status for user
137
138 $found = array();
139
140 $set = $ilDB->query("SELECT obj_id FROM read_event" .
141 " WHERE usr_id = " . $ilDB->quote($a_user_id, "integer") .
142 " AND " . $ilDB->in("obj_id", $items, "", "integer"));
143 while ($row = $ilDB->fetchAssoc($set)) {
144 $found[] = $row["obj_id"];
145 }
146
147 if (sizeof($found)) {
149
150 if (sizeof($found) == sizeof($items)) {
152 }
153 }
154 }
155
156 return $status;
157 }
158}
An exception for terminatinating execution or to throw for unit testing.
static lookupUsersInProgress($a_obj_id)
Lookup users in progress.
static hasAccessed($a_obj_id, $a_usr_id)
Has accessed.
determineStatus($a_obj_id, $a_user_id, $a_obj=null)
Determine status.
static getCollectionItems($a_obj_id, $a_include_titles=false)
static _getStatusInfo($a_parent_obj_id)
static _getStatusInfo($a_obj_id)
Reads informations about the object e.g test results, tlt, number of visits.
Abstract class ilLPStatus for all learning progress modes E.g ilLPStatusManual, ilLPStatusObjectives ...
const LP_STATUS_COMPLETED_NUM
const LP_STATUS_IN_PROGRESS_NUM
const LP_STATUS_NOT_ATTEMPTED_NUM
static getInstance($a_obj_id)
$valid
global $DIC
Definition: goto.php:24
foreach($_POST as $key=> $value) $res
global $ilDB