ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCronObjectStatisticsCheck.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
35 {
36  function __construct()
37  {
38  global $ilLog,$ilDB;
39 
40  $this->log =& $ilLog;
41  $this->db =& $ilDB;
42 
43  // all date related operations are based on this timestamp
44  // should be midnight of yesterday (see gatherUserData()) to always have full day
45  $this->date = strtotime("yesterday");
46  }
47 
48  function check()
49  {
50  $this->gatherCourseLPData();
51  $this->gatherTypesData();
52  $this->gatherUserData();
53  }
54 
55  function gatherCourseLPData()
56  {
57  global $tree, $ilDB;
58 
59  // process all courses
60  $all_courses = array_keys(ilObject::_getObjectsByType("crs"));
61  if($all_courses)
62  {
63  // gather objects in trash
64  $trashed_objects = $tree->getSavedNodeObjIds($all_courses);
65 
66  include_once 'Services/Tracking/classes/class.ilLPObjSettings.php';
67  include_once "Modules/Course/classes/class.ilCourseParticipants.php";
68  include_once "Services/Tracking/classes/class.ilLPStatusWrapper.php";
69  foreach($all_courses as $crs_id)
70  {
71  // trashed objects will not change
72  if(!in_array($crs_id, $trashed_objects))
73  {
74  // only if LP is active
75  $mode = ilLPObjSettings::_lookupMode($crs_id);
76  if($mode == LP_MODE_DEACTIVATED || $mode == LP_MODE_UNDEFINED)
77  {
78  continue;
79  }
80 
81  // only save once per day
82  $ilDB->manipulate("DELETE FROM obj_lp_stat WHERE".
83  " obj_id = ".$ilDB->quote($crs_id, "integer").
84  " AND fulldate = ".$ilDB->quote(date("Ymd", $this->date), "integer"));
85 
86  $members = new ilCourseParticipants($crs_id);
87  $members = $members->getMembers();
88 
89  $in_progress = count(ilLPStatusWrapper::_lookupInProgressForObject($crs_id, $members));
90  $completed = count(ilLPStatusWrapper::_lookupCompletedForObject($crs_id, $members));
91  $failed = count(ilLPStatusWrapper::_lookupFailedForObject($crs_id, $members));
92 
93  // calculate with other values - there is not direct method
94  $not_attempted = count($members) - $in_progress - $completed - $failed;
95 
96  $set = array(
97  "type" => array("text", "crs"),
98  "obj_id" => array("integer", $crs_id),
99  "yyyy" => array("integer", date("Y", $this->date)),
100  "mm" => array("integer", date("m", $this->date)),
101  "dd" => array("integer", date("d", $this->date)),
102  "fulldate" => array("integer", date("Ymd", $this->date)),
103  "mem_cnt" => array("integer", count($members)),
104  "in_progress" => array("integer", $in_progress),
105  "completed" => array("integer", $completed),
106  "failed" => array("integer", $failed),
107  "not_attempted" => array("integer", $not_attempted)
108  );
109 
110  $ilDB->insert("obj_lp_stat", $set);
111  }
112  }
113  }
114  }
115 
116  function gatherTypesData()
117  {
118  global $ilDB;
119 
120  include_once "Services/Tracking/classes/class.ilTrQuery.php";
122  foreach($data as $type => $item)
123  {
124  // only save once per day
125  $ilDB->manipulate("DELETE FROM obj_type_stat WHERE".
126  " type = ".$ilDB->quote($type, "text").
127  " AND fulldate = ".$ilDB->quote(date("Ymd", $this->date), "integer"));
128 
129  $set = array(
130  "type" => array("text", $type),
131  "yyyy" => array("integer", date("Y", $this->date)),
132  "mm" => array("integer", date("m", $this->date)),
133  "dd" => array("integer", date("d", $this->date)),
134  "fulldate" => array("integer", date("Ymd", $this->date)),
135  "cnt_references" => array("integer", (int)$item["references"]),
136  "cnt_objects" => array("integer", (int)$item["objects"]),
137  "cnt_deleted" => array("integer", (int)$item["deleted"])
138  );
139 
140  $ilDB->insert("obj_type_stat", $set);
141  }
142  }
143 
144  function gatherUserData()
145  {
146  global $ilDB;
147 
148  $to = mktime(23, 59, 59, date("m", $this->date), date("d", $this->date), date("Y", $this->date));
149 
150  $sql = "SELECT COUNT(DISTINCT(usr_id)) counter,obj_id FROM read_event".
151  " WHERE last_access >= ".$ilDB->quote($this->date, "integer").
152  " AND last_access <= ".$ilDB->quote($to, "integer").
153  " GROUP BY obj_id";
154  $set = $ilDB->query($sql);
155  while($row = $ilDB->fetchAssoc($set))
156  {
157  // only save once per day
158  $ilDB->manipulate("DELETE FROM obj_user_stat".
159  " WHERE fulldate = ".$ilDB->quote(date("Ymd", $this->date), "integer").
160  " AND obj_id = ".$ilDB->quote($row["obj_id"], "integer"));
161 
162  $iset = array(
163  "obj_id" => array("integer", $row["obj_id"]),
164  "yyyy" => array("integer", date("Y", $this->date)),
165  "mm" => array("integer", date("m", $this->date)),
166  "dd" => array("integer", date("d", $this->date)),
167  "fulldate" => array("integer", date("Ymd", $this->date)),
168  "counter" => array("integer", $row["counter"])
169  );
170 
171  $ilDB->insert("obj_user_stat", $iset);
172  }
173  }
174 }
175 ?>