ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $lng;
25
26 $lng->loadLanguageModule("trac");
27 return $lng->txt("trac_object_statistics");
28 }
29
30 public function getDescription()
31 {
32 global $lng;
33
34 $lng->loadLanguageModule("trac");
35 return $lng->txt("trac_object_statistics_info");
36 }
37
38 public function getDefaultScheduleType()
39 {
41 }
42
43 public function getDefaultScheduleValue()
44 {
45 return;
46 }
47
48 public function hasAutoActivation()
49 {
50 return true;
51 }
52
53 public function hasFlexibleSchedule()
54 {
55 return false;
56 }
57
58 public function run()
59 {
60 // all date related operations are based on this timestamp
61 // should be midnight of yesterday (see gatherUserData()) to always have full day
62 $this->date = strtotime("yesterday");
63
65 $message = array();
66
67 $count = 0;
68 $count += $this->gatherCourseLPData();
69 $count += $this->gatherTypesData();
70 $count += $this->gatherUserData();
71
72 if ($count) {
74 }
75
77 $result->setStatus($status);
78
79 return $result;
80 }
81
88 protected function gatherCourseLPData()
89 {
90 global $tree, $ilDB;
91
92 $logger = $GLOBALS['DIC']->logger()->trac();
93
94 $count = 0;
95
96 // process all courses
97 $all_courses = array_keys(ilObject::_getObjectsByType("crs"));
98 if ($all_courses) {
99 // gather objects in trash
100 $trashed_objects = $tree->getSavedNodeObjIds($all_courses);
101
102 include_once 'Services/Object/classes/class.ilObjectLP.php';
103 include_once "Modules/Course/classes/class.ilCourseParticipants.php";
104 include_once "Services/Tracking/classes/class.ilLPStatusWrapper.php";
105 foreach ($all_courses as $crs_id) {
106 // trashed objects will not change
107 if (!in_array($crs_id, $trashed_objects)) {
108 $refs = ilObject::_getAllReferences($crs_id);
109 if (!count($refs)) {
110 $logger->warning('Found course without reference: obj_id = ' . $crs_id);
111 continue;
112 }
113
114 // only if LP is active
115 $olp = ilObjectLP::getInstance($crs_id);
116 if (!$olp->isActive()) {
117 continue;
118 }
119
120 // only save once per day
121 $ilDB->manipulate("DELETE FROM obj_lp_stat WHERE" .
122 " obj_id = " . $ilDB->quote($crs_id, "integer") .
123 " AND fulldate = " . $ilDB->quote(date("Ymd", $this->date), "integer"));
124
125 $members = new ilCourseParticipants($crs_id);
126 $members = $members->getMembers();
127
128 $in_progress = count(ilLPStatusWrapper::_lookupInProgressForObject($crs_id, $members));
129 $completed = count(ilLPStatusWrapper::_lookupCompletedForObject($crs_id, $members));
130 $failed = count(ilLPStatusWrapper::_lookupFailedForObject($crs_id, $members));
131
132 // calculate with other values - there is not direct method
133 $not_attempted = count($members) - $in_progress - $completed - $failed;
134
135 $set = array(
136 "type" => array("text", "crs"),
137 "obj_id" => array("integer", $crs_id),
138 "yyyy" => array("integer", date("Y", $this->date)),
139 "mm" => array("integer", date("m", $this->date)),
140 "dd" => array("integer", date("d", $this->date)),
141 "fulldate" => array("integer", date("Ymd", $this->date)),
142 "mem_cnt" => array("integer", count($members)),
143 "in_progress" => array("integer", $in_progress),
144 "completed" => array("integer", $completed),
145 "failed" => array("integer", $failed),
146 "not_attempted" => array("integer", $not_attempted)
147 );
148
149 $ilDB->insert("obj_lp_stat", $set);
150
151 $count++;
152
153 // #17928
154 ilCronManager::ping($this->getId());
155 }
156 }
157 }
158
159 return $count;
160 }
161
162 protected function gatherTypesData()
163 {
164 global $ilDB;
165
166 $count = 0;
167
168 include_once "Services/Tracking/classes/class.ilTrQuery.php";
170 foreach ($data as $type => $item) {
171 // only save once per day
172 $ilDB->manipulate("DELETE FROM obj_type_stat WHERE" .
173 " type = " . $ilDB->quote($type, "text") .
174 " AND fulldate = " . $ilDB->quote(date("Ymd", $this->date), "integer"));
175
176 $set = array(
177 "type" => array("text", $type),
178 "yyyy" => array("integer", date("Y", $this->date)),
179 "mm" => array("integer", date("m", $this->date)),
180 "dd" => array("integer", date("d", $this->date)),
181 "fulldate" => array("integer", date("Ymd", $this->date)),
182 "cnt_references" => array("integer", (int) $item["references"]),
183 "cnt_objects" => array("integer", (int) $item["objects"]),
184 "cnt_deleted" => array("integer", (int) $item["deleted"])
185 );
186
187 $ilDB->insert("obj_type_stat", $set);
188
189 $count++;
190
191 // #17928
192 ilCronManager::ping($this->getId());
193 }
194
195 return $count;
196 }
197
198 protected function gatherUserData()
199 {
200 global $ilDB;
201
202 $count = 0;
203
204 $to = mktime(23, 59, 59, date("m", $this->date), date("d", $this->date), date("Y", $this->date));
205
206 $sql = "SELECT COUNT(DISTINCT(usr_id)) counter,obj_id FROM read_event" .
207 " WHERE last_access >= " . $ilDB->quote($this->date, "integer") .
208 " AND last_access <= " . $ilDB->quote($to, "integer") .
209 " GROUP BY obj_id";
210 $set = $ilDB->query($sql);
211 while ($row = $ilDB->fetchAssoc($set)) {
212 // only save once per day
213 $ilDB->manipulate("DELETE FROM obj_user_stat" .
214 " WHERE fulldate = " . $ilDB->quote(date("Ymd", $this->date), "integer") .
215 " AND obj_id = " . $ilDB->quote($row["obj_id"], "integer"));
216
217 $iset = array(
218 "obj_id" => array("integer", $row["obj_id"]),
219 "yyyy" => array("integer", date("Y", $this->date)),
220 "mm" => array("integer", date("m", $this->date)),
221 "dd" => array("integer", date("d", $this->date)),
222 "fulldate" => array("integer", date("Ymd", $this->date)),
223 "counter" => array("integer", $row["counter"])
224 );
225
226 $ilDB->insert("obj_user_stat", $iset);
227
228 $count++;
229
230 // #17928
231 ilCronManager::ping($this->getId());
232 }
233
234 return $count;
235 }
236}
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
$result
$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()
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
catch(Exception $e) $message
global $lng
Definition: privfeed.php:17
$type
global $ilDB