ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 public static function _getNotAttempted($a_obj_id)
29 {
30 $plugin = self::initPluginObj($a_obj_id);
31 if ($plugin) {
32 if ($plugin !== ilPluginLP::INACTIVE_PLUGIN) {
33 return (array) $plugin->getLPNotAttempted();
34 } else {
35 // re-use existing data for inactive plugin
36 return self::getLPStatusData($a_obj_id, self::LP_STATUS_NOT_ATTEMPTED_NUM);
37 }
38 }
39 return array();
40 }
41
42 public static function _getInProgress($a_obj_id)
43 {
44 $plugin = self::initPluginObj($a_obj_id);
45 if ($plugin) {
46 if ($plugin !== ilPluginLP::INACTIVE_PLUGIN) {
47 return (array) $plugin->getLPInProgress();
48 } else {
49 // re-use existing data for inactive plugin
50 return self::getLPStatusData($a_obj_id, self::LP_STATUS_IN_PROGRESS_NUM);
51 }
52 }
53 return array();
54 }
55
56 public static function _getCompleted($a_obj_id)
57 {
58 $plugin = self::initPluginObj($a_obj_id);
59 if ($plugin) {
60 if ($plugin !== ilPluginLP::INACTIVE_PLUGIN) {
61 return (array) $plugin->getLPCompleted();
62 } else {
63 // re-use existing data for inactive plugin
64 return self::getLPStatusData($a_obj_id, self::LP_STATUS_COMPLETED_NUM);
65 }
66 }
67 return array();
68 }
69
70 public static function _getFailed($a_obj_id)
71 {
72 $plugin = self::initPluginObj($a_obj_id);
73 if ($plugin) {
74 if ($plugin !== ilPluginLP::INACTIVE_PLUGIN) {
75 return (array) $plugin->getLPFailed();
76 } else {
77 // re-use existing data for inactive plugin
78 return self::getLPStatusData($a_obj_id, self::LP_STATUS_FAILED_NUM);
79 }
80 }
81 return array();
82 }
83
84 public function determineStatus($a_obj_id, $a_user_id, $a_obj = null)
85 {
86 $plugin = self::initPluginObj($a_obj_id);
87 if ($plugin) {
88 if ($plugin !== ilPluginLP::INACTIVE_PLUGIN) {
89 // :TODO: create read_event here to make sure?
90 return $plugin->getLPStatusForUser($a_user_id);
91 } else {
92 // re-use existing data for inactive plugin
93 return self::getLPDataForUser($a_obj_id, $a_user_id);
94 }
95 }
96 // #11368
98 }
99
100 public function determinePercentage($a_obj_id, $a_user_id, $a_obj = null)
101 {
102 $plugin = self::initPluginObj($a_obj_id);
103 if ($plugin) {
104 if ($plugin !== ilPluginLP::INACTIVE_PLUGIN) {
105 if (method_exists($plugin, "getPercentageForUser")) {
106 return $plugin->getPercentageForUser($a_user_id);
107 }
108 }
109 // re-use existing data for inactive plugin
110 return self::getPercentageForUser($a_obj_id, $a_user_id);
111 }
112 // #11368
113 return 0;
114 }
115
123 protected static function getLPStatusData($a_obj_id, $a_status)
124 {
125 global $ilDB;
126
127 $all = array();
128
129 $set = $ilDB->query("SELECT usr_id" .
130 " FROM ut_lp_marks" .
131 " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
132 " AND status = " . $ilDB->quote($a_status, "integer"));
133 while ($row = $ilDB->fetchAssoc($set)) {
134 $all[] = $row["usr_id"];
135 }
136 return $all;
137 }
138
146 protected static function getLPDataForUser($a_obj_id, $a_user_id)
147 {
148 global $ilDB;
149
150 $set = $ilDB->query("SELECT status" .
151 " FROM ut_lp_marks" .
152 " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
153 " AND usr_id = " . $ilDB->quote($a_user_id, "integer"));
154 $row = $ilDB->fetchAssoc($set);
155 $status = $row["status"];
156 if (!$status) {
158 }
159 return $status;
160 }
161
162 protected static function getPercentageForUser($a_obj_id, $a_user_id)
163 {
164 global $ilDB;
165
166 $set = $ilDB->query("SELECT percentage" .
167 " FROM ut_lp_marks" .
168 " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
169 " AND usr_id = " . $ilDB->quote($a_user_id, "integer"));
170 $row = $ilDB->fetchAssoc($set);
171 return (int) $row["percentage"];
172 }
173}
An exception for terminatinating execution or to throw for unit testing.
determineStatus($a_obj_id, $a_user_id, $a_obj=null)
Determine status.
static initPluginObj($a_obj_id)
Get ilObjectPlugin for object id.
static _getInProgress($a_obj_id)
static _getFailed($a_obj_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)
static _getCompleted($a_obj_id)
determinePercentage($a_obj_id, $a_user_id, $a_obj=null)
Determine percentage.
static _getNotAttempted($a_obj_id)
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