ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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)
73 {
75 }
76
78 $result->setStatus($status);
79
80 return $result;
81 }
82
83 protected function gatherCourseLPData()
84 {
85 global $tree, $ilDB;
86
87 $count = 0;
88
89 // process all courses
90 $all_courses = array_keys(ilObject::_getObjectsByType("crs"));
91 if($all_courses)
92 {
93 // gather objects in trash
94 $trashed_objects = $tree->getSavedNodeObjIds($all_courses);
95
96 include_once 'Services/Object/classes/class.ilObjectLP.php';
97 include_once "Modules/Course/classes/class.ilCourseParticipants.php";
98 include_once "Services/Tracking/classes/class.ilLPStatusWrapper.php";
99 foreach($all_courses as $crs_id)
100 {
101 // trashed objects will not change
102 if(!in_array($crs_id, $trashed_objects))
103 {
104 // only if LP is active
105 $olp = ilObjectLP::getInstance($crs_id);
106 if(!$olp->isActive())
107 {
108 continue;
109 }
110
111 // only save once per day
112 $ilDB->manipulate("DELETE FROM obj_lp_stat WHERE".
113 " obj_id = ".$ilDB->quote($crs_id, "integer").
114 " AND fulldate = ".$ilDB->quote(date("Ymd", $this->date), "integer"));
115
116 $members = new ilCourseParticipants($crs_id);
117 $members = $members->getMembers();
118
119 $in_progress = count(ilLPStatusWrapper::_lookupInProgressForObject($crs_id, $members));
120 $completed = count(ilLPStatusWrapper::_lookupCompletedForObject($crs_id, $members));
121 $failed = count(ilLPStatusWrapper::_lookupFailedForObject($crs_id, $members));
122
123 // calculate with other values - there is not direct method
124 $not_attempted = count($members) - $in_progress - $completed - $failed;
125
126 $set = array(
127 "type" => array("text", "crs"),
128 "obj_id" => array("integer", $crs_id),
129 "yyyy" => array("integer", date("Y", $this->date)),
130 "mm" => array("integer", date("m", $this->date)),
131 "dd" => array("integer", date("d", $this->date)),
132 "fulldate" => array("integer", date("Ymd", $this->date)),
133 "mem_cnt" => array("integer", count($members)),
134 "in_progress" => array("integer", $in_progress),
135 "completed" => array("integer", $completed),
136 "failed" => array("integer", $failed),
137 "not_attempted" => array("integer", $not_attempted)
138 );
139
140 $ilDB->insert("obj_lp_stat", $set);
141
142 $count++;
143
144 // #17928
145 ilCronManager::ping($this->getId());
146 }
147 }
148 }
149
150 return $count;
151 }
152
153 protected function gatherTypesData()
154 {
155 global $ilDB;
156
157 $count = 0;
158
159 include_once "Services/Tracking/classes/class.ilTrQuery.php";
161 foreach($data as $type => $item)
162 {
163 // only save once per day
164 $ilDB->manipulate("DELETE FROM obj_type_stat WHERE".
165 " type = ".$ilDB->quote($type, "text").
166 " AND fulldate = ".$ilDB->quote(date("Ymd", $this->date), "integer"));
167
168 $set = array(
169 "type" => array("text", $type),
170 "yyyy" => array("integer", date("Y", $this->date)),
171 "mm" => array("integer", date("m", $this->date)),
172 "dd" => array("integer", date("d", $this->date)),
173 "fulldate" => array("integer", date("Ymd", $this->date)),
174 "cnt_references" => array("integer", (int)$item["references"]),
175 "cnt_objects" => array("integer", (int)$item["objects"]),
176 "cnt_deleted" => array("integer", (int)$item["deleted"])
177 );
178
179 $ilDB->insert("obj_type_stat", $set);
180
181 $count++;
182
183 // #17928
184 ilCronManager::ping($this->getId());
185 }
186
187 return $count;
188 }
189
190 protected function gatherUserData()
191 {
192 global $ilDB;
193
194 $count = 0;
195
196 $to = mktime(23, 59, 59, date("m", $this->date), date("d", $this->date), date("Y", $this->date));
197
198 $sql = "SELECT COUNT(DISTINCT(usr_id)) counter,obj_id FROM read_event".
199 " WHERE last_access >= ".$ilDB->quote($this->date, "integer").
200 " AND last_access <= ".$ilDB->quote($to, "integer").
201 " GROUP BY obj_id";
202 $set = $ilDB->query($sql);
203 while($row = $ilDB->fetchAssoc($set))
204 {
205 // only save once per day
206 $ilDB->manipulate("DELETE FROM obj_user_stat".
207 " WHERE fulldate = ".$ilDB->quote(date("Ymd", $this->date), "integer").
208 " AND obj_id = ".$ilDB->quote($row["obj_id"], "integer"));
209
210 $iset = array(
211 "obj_id" => array("integer", $row["obj_id"]),
212 "yyyy" => array("integer", date("Y", $this->date)),
213 "mm" => array("integer", date("m", $this->date)),
214 "dd" => array("integer", date("d", $this->date)),
215 "fulldate" => array("integer", date("Ymd", $this->date)),
216 "counter" => array("integer", $row["counter"])
217 );
218
219 $ilDB->insert("obj_user_stat", $iset);
220
221 $count++;
222
223 // #17928
224 ilCronManager::ping($this->getId());
225 }
226
227 return $count;
228 }
229}
230
231?>
$result
$failed
Definition: Utf8Test.php:86
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.
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.
$data
global $lng
Definition: privfeed.php:40
global $ilDB