ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilLPStatusPlugin.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once './Services/Tracking/classes/class.ilLPStatus.php';
5
14{
21 protected static function initPluginObj($a_obj_id)
22 {
23 include_once "Services/Object/classes/class.ilObjectLP.php";
24 $olp = ilObjectLP::getInstance($a_obj_id);
25 return $olp->getPluginInstance();
26 }
27
28 function _getNotAttempted($a_obj_id)
29 {
30 $plugin = self::initPluginObj($a_obj_id);
31 if($plugin)
32 {
33 if($plugin !== ilPluginLP::INACTIVE_PLUGIN)
34 {
35 return (array)$plugin->getLPNotAttempted();
36 }
37 else
38 {
39 // re-use existing data for inactive plugin
40 return self::getLPStatusData($a_obj_id, self::LP_STATUS_NOT_ATTEMPTED_NUM);
41 }
42 }
43 return array();
44 }
45
46 function _getInProgress($a_obj_id)
47 {
48 $plugin = self::initPluginObj($a_obj_id);
49 if($plugin)
50 {
51 if($plugin !== ilPluginLP::INACTIVE_PLUGIN)
52 {
53 return (array)$plugin->getLPInProgress();
54 }
55 else
56 {
57 // re-use existing data for inactive plugin
58 return self::getLPStatusData($a_obj_id, self::LP_STATUS_IN_PROGRESS_NUM);
59 }
60 }
61 return array();
62 }
63
64 function _getCompleted($a_obj_id)
65 {
66 $plugin = self::initPluginObj($a_obj_id);
67 if($plugin)
68 {
69 if($plugin !== ilPluginLP::INACTIVE_PLUGIN)
70 {
71 return (array)$plugin->getLPCompleted();
72 }
73 else
74 {
75 // re-use existing data for inactive plugin
76 return self::getLPStatusData($a_obj_id, self::LP_STATUS_COMPLETED_NUM);
77 }
78 }
79 return array();
80 }
81
82 function _getFailed($a_obj_id)
83 {
84 $plugin = self::initPluginObj($a_obj_id);
85 if($plugin)
86 {
87 if($plugin !== ilPluginLP::INACTIVE_PLUGIN)
88 {
89 return (array)$plugin->getLPFailed();
90 }
91 else
92 {
93 // re-use existing data for inactive plugin
94 return self::getLPStatusData($a_obj_id, self::LP_STATUS_FAILED_NUM);
95 }
96 }
97 return array();
98 }
99
100 function determineStatus($a_obj_id, $a_user_id, $a_obj = null)
101 {
102 $plugin = self::initPluginObj($a_obj_id);
103 if($plugin)
104 {
105 if($plugin !== ilPluginLP::INACTIVE_PLUGIN)
106 {
107 // :TODO: create read_event here to make sure?
108 return $plugin->getLPStatusForUser($a_user_id);
109 }
110 else
111 {
112 // re-use existing data for inactive plugin
113 return self::getLPDataForUser($a_obj_id, $a_user_id);
114 }
115 }
116 // #11368
118 }
119
120 function determinePercentage($a_obj_id, $a_user_id, $a_obj = null)
121 {
122 $plugin = self::initPluginObj($a_obj_id);
123 if($plugin)
124 {
125 if($plugin !== ilPluginLP::INACTIVE_PLUGIN)
126 {
127 if (method_exists($plugin, "getPercentageForUser"))
128 {
129 return $plugin->getPercentageForUser($a_user_id);
130 }
131 }
132 // re-use existing data for inactive plugin
133 return self::getPercentageForUser($a_obj_id, $a_user_id);
134 }
135 // #11368
136 return 0;
137 }
138
146 protected static function getLPStatusData($a_obj_id, $a_status)
147 {
148 global $ilDB;
149
150 $all = array();
151
152 $set = $ilDB->query("SELECT usr_id".
153 " FROM ut_lp_marks".
154 " WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer").
155 " AND status = ".$ilDB->quote($a_status, "integer"));
156 while($row = $ilDB->fetchAssoc($set))
157 {
158 $all[] = $row["usr_id"];
159 }
160 return $all;
161 }
162
170 protected static function getLPDataForUser($a_obj_id, $a_user_id)
171 {
172 global $ilDB;
173
174 $set = $ilDB->query("SELECT status".
175 " FROM ut_lp_marks".
176 " WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer").
177 " AND usr_id = ".$ilDB->quote($a_user_id, "integer"));
178 $row = $ilDB->fetchAssoc($set);
179 $status = $row["status"];
180 if(!$status)
181 {
183 }
184 return $status;
185 }
186
187 protected static function getPercentageForUser($a_obj_id, $a_user_id)
188 {
189 global $ilDB;
190
191 $set = $ilDB->query("SELECT percentage".
192 " FROM ut_lp_marks".
193 " WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer").
194 " AND usr_id = ".$ilDB->quote($a_user_id, "integer"));
195 $row = $ilDB->fetchAssoc($set);
196 return (int) $row["percentage"];
197 }
198}
199
200?>
determineStatus($a_obj_id, $a_user_id, $a_obj=null)
Determine status.
static initPluginObj($a_obj_id)
Get ilObjectPlugin for object id.
static getLPStatusData($a_obj_id, $a_status)
Read existing LP status data.
static getLPDataForUser($a_obj_id, $a_user_id)
Read existing LP status data for user.
static getPercentageForUser($a_obj_id, $a_user_id)
determinePercentage($a_obj_id, $a_user_id, $a_obj=null)
Determine percentage.
Abstract class ilLPStatus for all learning progress modes E.g ilLPStatusManual, ilLPStatusObjectives ...
const LP_STATUS_NOT_ATTEMPTED_NUM
static getInstance($a_obj_id)
const INACTIVE_PLUGIN
global $ilDB