ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilLPCronObjectStatistics.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once "Services/Cron/classes/class.ilCronJob.php";
6
14{
15 protected $date; // [string]
16
17 public function getId()
18 {
19 return "lp_object_statistics";
20 }
21
22 public function getTitle()
23 {
24 global $DIC;
25
26 $lng = $DIC['lng'];
27
28 $lng->loadLanguageModule("trac");
29 return $lng->txt("trac_object_statistics");
30 }
31
32 public function getDescription()
33 {
34 global $DIC;
35
36 $lng = $DIC['lng'];
37
38 $lng->loadLanguageModule("trac");
39 return $lng->txt("trac_object_statistics_info");
40 }
41
42 public function getDefaultScheduleType()
43 {
45 }
46
47 public function getDefaultScheduleValue()
48 {
49 return;
50 }
51
52 public function hasAutoActivation()
53 {
54 return true;
55 }
56
57 public function hasFlexibleSchedule()
58 {
59 return false;
60 }
61
62 public function run()
63 {
64 // all date related operations are based on this timestamp
65 // should be midnight of yesterday (see gatherUserData()) to always have full day
66 $this->date = strtotime("yesterday");
67
69 $message = array();
70
71 $count = 0;
72 $count += $this->gatherCourseLPData();
73 $count += $this->gatherTypesData();
74 $count += $this->gatherUserData();
75
76 if ($count) {
78 }
79
81 $result->setStatus($status);
82
83 return $result;
84 }
85
92 protected function gatherCourseLPData()
93 {
94 global $DIC;
95
96 $tree = $DIC['tree'];
97 $ilDB = $DIC['ilDB'];
98
99 $logger = $GLOBALS['DIC']->logger()->trac();
100
101 $count = 0;
102
103 // process all courses
104 $all_courses = array_keys(ilObject::_getObjectsByType("crs"));
105 if ($all_courses) {
106 // gather objects in trash
107 $trashed_objects = $tree->getSavedNodeObjIds($all_courses);
108
109 include_once 'Services/Object/classes/class.ilObjectLP.php';
110 include_once "Modules/Course/classes/class.ilCourseParticipants.php";
111 include_once "Services/Tracking/classes/class.ilLPStatusWrapper.php";
112 foreach ($all_courses as $crs_id) {
113 // trashed objects will not change
114 if (!in_array($crs_id, $trashed_objects)) {
115 $refs = ilObject::_getAllReferences($crs_id);
116 if (!count($refs)) {
117 $logger->warning('Found course without reference: obj_id = ' . $crs_id);
118 continue;
119 }
120
121 // only if LP is active
122 $olp = ilObjectLP::getInstance($crs_id);
123 if (!$olp->isActive()) {
124 continue;
125 }
126
127 // only save once per day
128 $ilDB->manipulate("DELETE FROM obj_lp_stat WHERE" .
129 " obj_id = " . $ilDB->quote($crs_id, "integer") .
130 " AND fulldate = " . $ilDB->quote(date("Ymd", $this->date), "integer"));
131
132 $members = new ilCourseParticipants($crs_id);
133 $members = $members->getMembers();
134
135 $in_progress = count(ilLPStatusWrapper::_lookupInProgressForObject($crs_id, $members));
136 $completed = count(ilLPStatusWrapper::_lookupCompletedForObject($crs_id, $members));
137 $failed = count(ilLPStatusWrapper::_lookupFailedForObject($crs_id, $members));
138
139 // calculate with other values - there is not direct method
140 $not_attempted = count($members) - $in_progress - $completed - $failed;
141
142 $set = array(
143 "type" => array("text", "crs"),
144 "obj_id" => array("integer", $crs_id),
145 "yyyy" => array("integer", date("Y", $this->date)),
146 "mm" => array("integer", date("m", $this->date)),
147 "dd" => array("integer", date("d", $this->date)),
148 "fulldate" => array("integer", date("Ymd", $this->date)),
149 "mem_cnt" => array("integer", count($members)),
150 "in_progress" => array("integer", $in_progress),
151 "completed" => array("integer", $completed),
152 "failed" => array("integer", $failed),
153 "not_attempted" => array("integer", $not_attempted)
154 );
155
156 $ilDB->insert("obj_lp_stat", $set);
157
158 $count++;
159
160 // #17928
161 ilCronManager::ping($this->getId());
162 }
163 }
164 }
165
166 return $count;
167 }
168
169 protected function gatherTypesData()
170 {
171 global $DIC;
172
173 $ilDB = $DIC['ilDB'];
174
175 $count = 0;
176
177 include_once "Services/Tracking/classes/class.ilTrQuery.php";
179 foreach ($data as $type => $item) {
180 // only save once per day
181 $ilDB->manipulate("DELETE FROM obj_type_stat WHERE" .
182 " type = " . $ilDB->quote($type, "text") .
183 " AND fulldate = " . $ilDB->quote(date("Ymd", $this->date), "integer"));
184
185 $set = array(
186 "type" => array("text", $type),
187 "yyyy" => array("integer", date("Y", $this->date)),
188 "mm" => array("integer", date("m", $this->date)),
189 "dd" => array("integer", date("d", $this->date)),
190 "fulldate" => array("integer", date("Ymd", $this->date)),
191 "cnt_references" => array("integer", (int) $item["references"]),
192 "cnt_objects" => array("integer", (int) $item["objects"]),
193 "cnt_deleted" => array("integer", (int) $item["deleted"])
194 );
195
196 $ilDB->insert("obj_type_stat", $set);
197
198 $count++;
199
200 // #17928
201 ilCronManager::ping($this->getId());
202 }
203
204 return $count;
205 }
206
207 protected function gatherUserData()
208 {
209 global $DIC;
210
211 $ilDB = $DIC['ilDB'];
212
213 $count = 0;
214
215 $to = mktime(23, 59, 59, date("m", $this->date), date("d", $this->date), date("Y", $this->date));
216
217 $sql = "SELECT COUNT(DISTINCT(usr_id)) counter,obj_id FROM read_event" .
218 " WHERE last_access >= " . $ilDB->quote($this->date, "integer") .
219 " AND last_access <= " . $ilDB->quote($to, "integer") .
220 " GROUP BY obj_id";
221 $set = $ilDB->query($sql);
222 while ($row = $ilDB->fetchAssoc($set)) {
223 // only save once per day
224 $ilDB->manipulate("DELETE FROM obj_user_stat" .
225 " WHERE fulldate = " . $ilDB->quote(date("Ymd", $this->date), "integer") .
226 " AND obj_id = " . $ilDB->quote($row["obj_id"], "integer"));
227
228 $iset = array(
229 "obj_id" => array("integer", $row["obj_id"]),
230 "yyyy" => array("integer", date("Y", $this->date)),
231 "mm" => array("integer", date("m", $this->date)),
232 "dd" => array("integer", date("d", $this->date)),
233 "fulldate" => array("integer", date("Ymd", $this->date)),
234 "counter" => array("integer", $row["counter"])
235 );
236
237 $ilDB->insert("obj_user_stat", $iset);
238
239 $count++;
240
241 // #17928
242 ilCronManager::ping($this->getId());
243 }
244
245 return $count;
246 }
247}
$result
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
$failed
Definition: Utf8Test.php:85
An exception for terminatinating execution or to throw for unit testing.
Cron job result data container.
Cron job application base class.
const SCHEDULE_TYPE_DAILY
static ping($a_job_id)
Keep cron job alive.
Cron for lp object statistics.
gatherCourseLPData()
gather course data @global type $tree @global type $ilDB
hasFlexibleSchedule()
Can the schedule be configured?
hasAutoActivation()
Is to be activated on "installation".
static _lookupCompletedForObject($a_obj_id, $a_user_ids=null)
Get completed users for object.
static _lookupFailedForObject($a_obj_id, $a_user_ids=null)
Get failed users for object.
static _lookupInProgressForObject($a_obj_id, $a_user_ids=null)
Get in progress users for object.
static getInstance($a_obj_id)
static _getObjectsByType($a_obj_type="", $a_owner="")
Get objects by type.
static _getAllReferences($a_id)
get all reference ids of object
static getObjectTypeStatistics()
global $DIC
Definition: goto.php:24
$type
$lng
global $ilDB
$data
Definition: storeScorm.php:23
$message
Definition: xapiexit.php:14