ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  {
20  $users = $status_info["user_status"]["in_progress"];
21  }
22 
23  return $users;
24  }
25 
26  public static function _getCompleted($a_obj_id)
27  {
28  $users = array();
29 
30  $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
31  if(is_array($status_info["user_status"]["completed"]))
32  {
33  $users = $status_info["user_status"]["completed"];
34  }
35 
36  return $users;
37  }
38 
39  public static function _getStatusInfo($a_parent_obj_id)
40  {
41  global $ilDB;
42 
43  $res = array();
44 
45  $coll_items = self::getCollectionItems($a_parent_obj_id, true);
46 
47  $res["items"] = array_keys($coll_items);
48  if(sizeof($res["items"]))
49  {
50  // titles
51  foreach($coll_items as $mob_id => $item)
52  {
53  $res["item_titles"][$mob_id] = $item["title"];
54  }
55 
56  // status per item
57  foreach($res["items"] as $mob_id)
58  {
59  $res["completed"][$mob_id] = array();
60  $res["in_progress"][$mob_id] = array();
61  }
62 
63  $set = $ilDB->query("SELECT obj_id, usr_id FROM read_event".
64  " WHERE ".$ilDB->in("obj_id", $res["items"], "", "integer"));
65  while($row = $ilDB->fetchAssoc($set))
66  {
67  $res["completed"][$row["obj_id"]][] = $row["usr_id"];
68  }
69 
70  // status per user
71  $tmp = array();
72  foreach($res["items"] as $mob_id)
73  {
74  foreach($res["completed"][$mob_id] as $user_id)
75  {
76  $tmp[$user_id][] = $mob_id;
77  }
78  }
79  foreach($tmp as $user_id => $completed_items)
80  {
81  if(sizeof($completed_items) == sizeof($res["items"]))
82  {
83  $res["user_status"]["completed"][] = $user_id;
84  }
85  else
86  {
87  $res["user_status"]["in_progress"][] = $user_id;
88  }
89  }
90  }
91 
92  return $res;
93  }
94 
95  protected static function getCollectionItems($a_obj_id, $a_include_titles = false)
96  {
97  $res = array();
98 
99  include_once './Services/Object/classes/class.ilObjectLP.php';
100  $olp = ilObjectLP::getInstance($a_obj_id);
101  $collection = $olp->getCollectionInstance();
102  if($collection)
103  {
104  $possible = $collection->getPossibleItems();
105 
106  // there could be invalid items in the selection
107  $valid = array_intersect($collection->getItems(),
108  array_keys($possible));
109 
110  if($a_include_titles)
111  {
112  foreach($valid as $item_id)
113  {
114  $res[$item_id] = $possible[$item_id];
115  }
116  }
117  else
118  {
119  $res = $valid;
120  }
121  }
122 
123  return $res;
124  }
125 
126  public function determineStatus($a_obj_id, $a_user_id, $a_obj = null)
127  {
128  global $ilDB;
129 
130  $status = self::LP_STATUS_NOT_ATTEMPTED_NUM;
131 
132  // an empty collection is always not attempted
133  $items = self::getCollectionItems($a_obj_id);
134  if(sizeof($items))
135  {
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  {
145  $found[] = $row["obj_id"];
146  }
147 
148  if(sizeof($found))
149  {
150  $status = self::LP_STATUS_IN_PROGRESS_NUM;
151 
152  if(sizeof($found) == sizeof($items))
153  {
154  $status = self::LP_STATUS_COMPLETED_NUM;
155  }
156  }
157  }
158 
159  return $status;
160  }
161 }
static getCollectionItems($a_obj_id, $a_include_titles=false)
$valid
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.
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)