ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
4 require_once 'Services/Tracking/classes/class.ilLPStatus.php';
5 require_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 
22  return $users;
23  }
24 
25  public static function _getCompleted($a_obj_id)
26  {
27  $users = array();
28 
29  $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
30  if (is_array($status_info["user_status"]["completed"])) {
31  $users = $status_info["user_status"]["completed"];
32  }
33 
34  return $users;
35  }
36 
37  public static function _getStatusInfo($a_parent_obj_id)
38  {
39  global $ilDB;
40 
41  $res = array();
42 
43  $coll_items = self::getCollectionItems($a_parent_obj_id, true);
44 
45  $res["items"] = array_keys($coll_items);
46  if (sizeof($res["items"])) {
47  // titles
48  foreach ($coll_items as $mob_id => $item) {
49  $res["item_titles"][$mob_id] = $item["title"];
50  }
51 
52  // status per item
53  foreach ($res["items"] as $mob_id) {
54  $res["completed"][$mob_id] = array();
55  $res["in_progress"][$mob_id] = array();
56  }
57 
58  $set = $ilDB->query("SELECT obj_id, usr_id FROM read_event" .
59  " WHERE " . $ilDB->in("obj_id", $res["items"], "", "integer"));
60  while ($row = $ilDB->fetchAssoc($set)) {
61  $res["completed"][$row["obj_id"]][] = $row["usr_id"];
62  }
63 
64  // status per user
65  $tmp = array();
66  foreach ($res["items"] as $mob_id) {
67  foreach ($res["completed"][$mob_id] as $user_id) {
68  $tmp[$user_id][] = $mob_id;
69  }
70  }
71  foreach ($tmp as $user_id => $completed_items) {
72  if (sizeof($completed_items) == sizeof($res["items"])) {
73  $res["user_status"]["completed"][] = $user_id;
74  } else {
75  $res["user_status"]["in_progress"][] = $user_id;
76  }
77  }
78  }
79 
80  return $res;
81  }
82 
83  protected static function getCollectionItems($a_obj_id, $a_include_titles = false)
84  {
85  $res = array();
86 
87  include_once './Services/Object/classes/class.ilObjectLP.php';
88  $olp = ilObjectLP::getInstance($a_obj_id);
89  $collection = $olp->getCollectionInstance();
90  if ($collection) {
91  $possible = $collection->getPossibleItems();
92 
93  // there could be invalid items in the selection
94  $valid = array_intersect(
95  $collection->getItems(),
96  array_keys($possible)
97  );
98 
99  if ($a_include_titles) {
100  foreach ($valid as $item_id) {
101  $res[$item_id] = $possible[$item_id];
102  }
103  } else {
104  $res = $valid;
105  }
106  }
107 
108  return $res;
109  }
110 
111  public function determineStatus($a_obj_id, $a_user_id, $a_obj = null)
112  {
113  global $ilDB;
114 
115  $status = self::LP_STATUS_NOT_ATTEMPTED_NUM;
116 
117  // an empty collection is always not attempted
118  $items = self::getCollectionItems($a_obj_id);
119  if (sizeof($items)) {
120  // process mob status for user
121 
122  $found = array();
123 
124  $set = $ilDB->query("SELECT obj_id FROM read_event" .
125  " WHERE usr_id = " . $ilDB->quote($a_user_id, "integer") .
126  " AND " . $ilDB->in("obj_id", $items, "", "integer"));
127  while ($row = $ilDB->fetchAssoc($set)) {
128  $found[] = $row["obj_id"];
129  }
130 
131  if (sizeof($found)) {
132  $status = self::LP_STATUS_IN_PROGRESS_NUM;
133 
134  if (sizeof($found) == sizeof($items)) {
135  $status = self::LP_STATUS_COMPLETED_NUM;
136  }
137  }
138  }
139 
140  return $status;
141  }
142 }
static getCollectionItems($a_obj_id, $a_include_titles=false)
$valid
foreach($_POST as $key=> $value) $res
determineStatus($a_obj_id, $a_user_id, $a_obj=null)
Create styles array
The data for the language used.
static _getStatusInfo($a_obj_id)
Reads informations about the object e.g test results, tlt, number of visits.
$users
Definition: authpage.php:44
global $ilDB
Abstract class ilLPStatus for all learning progress modes E.g ilLPStatusManual, ilLPStatusObjectives ...
static _getStatusInfo($a_parent_obj_id)
static getInstance($a_obj_id)