ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilLPCronObjectStatistics Class Reference

Cron for lp object statistics. More...

+ Inheritance diagram for ilLPCronObjectStatistics:
+ Collaboration diagram for ilLPCronObjectStatistics:

Public Member Functions

 getId ()
 
 getTitle ()
 
 getDescription ()
 
 getDefaultScheduleType ()
 
 getDefaultScheduleValue ()
 
 hasAutoActivation ()
 
 hasFlexibleSchedule ()
 
 run ()
 
- Public Member Functions inherited from ilCronJob
 isActive ($a_ts_last_run, $a_schedule_type, $a_schedule_value, $a_manual=false)
 Is job currently active? More...
 
 getScheduleType ()
 Get current schedule type (if flexible) More...
 
 getScheduleValue ()
 Get current schedule value (if flexible) More...
 
 setSchedule ($a_type, $a_value)
 Update current schedule (if flexible) More...
 
 getAllScheduleTypes ()
 Get all available schedule types. More...
 
 getScheduleTypesWithValues ()
 
 getValidScheduleTypes ()
 Returns a collection of all valid schedule types for a specific job. More...
 
 getTitle ()
 Get title. More...
 
 getDescription ()
 Get description. More...
 
 isManuallyExecutable ()
 Defines whether or not a cron job can be started manually. More...
 
 hasCustomSettings ()
 Has cron job any custom setting which can be edited? More...
 
 addCustomSettingsToForm (ilPropertyFormGUI $a_form)
 Add custom settings to form. More...
 
 saveCustomSettings (ilPropertyFormGUI $a_form)
 Save custom settings. More...
 
 addToExternalSettingsForm ($a_form_id, array &$a_fields, $a_is_active)
 Add external settings to form. More...
 
 activationWasToggled ($a_currently_active)
 Cron job status was changed. More...
 
 getId ()
 Get id. More...
 
 hasAutoActivation ()
 Is to be activated on "installation". More...
 
 hasFlexibleSchedule ()
 Can the schedule be configured? More...
 
 getDefaultScheduleType ()
 Get schedule type. More...
 
 getDefaultScheduleValue ()
 Get schedule value. More...
 
 run ()
 Run job. More...
 

Protected Member Functions

 gatherCourseLPData ()
 gather course data type $tree type $ilDB More...
 
 gatherTypesData ()
 
 gatherUserData ()
 
- Protected Member Functions inherited from ilCronJob
 checkSchedule ($a_ts_last_run, $a_schedule_type, $a_schedule_value)
 

Protected Attributes

 $date
 

Additional Inherited Members

- Data Fields inherited from ilCronJob
const SCHEDULE_TYPE_DAILY = 1
 
const SCHEDULE_TYPE_IN_MINUTES = 2
 
const SCHEDULE_TYPE_IN_HOURS = 3
 
const SCHEDULE_TYPE_IN_DAYS = 4
 
const SCHEDULE_TYPE_WEEKLY = 5
 
const SCHEDULE_TYPE_MONTHLY = 6
 
const SCHEDULE_TYPE_QUARTERLY = 7
 
const SCHEDULE_TYPE_YEARLY = 8
 

Detailed Description

Cron for lp object statistics.

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 13 of file class.ilLPCronObjectStatistics.php.

Member Function Documentation

◆ gatherCourseLPData()

ilLPCronObjectStatistics::gatherCourseLPData ( )
protected

gather course data type $tree type $ilDB

Returns
int

Definition at line 92 of file class.ilLPCronObjectStatistics.php.

References $DIC, $failed, $GLOBALS, $ilDB, $tree, ilObject\_getAllReferences(), ilObject\_getObjectsByType(), ilLPStatusWrapper\_lookupCompletedForObject(), ilLPStatusWrapper\_lookupFailedForObject(), ilLPStatusWrapper\_lookupInProgressForObject(), getId(), ilObjectLP\getInstance(), and ilCronManager\ping().

Referenced by run().

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  }
global $DIC
Definition: saml.php:7
static _lookupFailedForObject($a_obj_id, $a_user_ids=null)
Get failed users for object.
static _getObjectsByType($a_obj_type="", $a_owner="")
Get objects by type.
static _getAllReferences($a_id)
get all reference ids of object
$failed
Definition: Utf8Test.php:85
static _lookupInProgressForObject($a_obj_id, $a_user_ids=null)
Get in progress users for object.
static ping($a_job_id)
Keep cron job alive.
global $ilDB
static _lookupCompletedForObject($a_obj_id, $a_user_ids=null)
Get completed users for object.
static getInstance($a_obj_id)
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gatherTypesData()

ilLPCronObjectStatistics::gatherTypesData ( )
protected

Definition at line 169 of file class.ilLPCronObjectStatistics.php.

References $data, $DIC, $ilDB, $type, getId(), ilTrQuery\getObjectTypeStatistics(), and ilCronManager\ping().

Referenced by run().

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  }
$type
global $DIC
Definition: saml.php:7
static ping($a_job_id)
Keep cron job alive.
global $ilDB
static getObjectTypeStatistics()
$data
Definition: bench.php:6
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gatherUserData()

ilLPCronObjectStatistics::gatherUserData ( )
protected

Definition at line 207 of file class.ilLPCronObjectStatistics.php.

References $DIC, $ilDB, $row, getId(), and ilCronManager\ping().

Referenced by run().

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  }
global $DIC
Definition: saml.php:7
$row
static ping($a_job_id)
Keep cron job alive.
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDefaultScheduleType()

ilLPCronObjectStatistics::getDefaultScheduleType ( )

Definition at line 42 of file class.ilLPCronObjectStatistics.php.

43  {
44  return self::SCHEDULE_TYPE_DAILY;
45  }

◆ getDefaultScheduleValue()

ilLPCronObjectStatistics::getDefaultScheduleValue ( )

Definition at line 47 of file class.ilLPCronObjectStatistics.php.

48  {
49  return;
50  }

◆ getDescription()

ilLPCronObjectStatistics::getDescription ( )

Definition at line 32 of file class.ilLPCronObjectStatistics.php.

References $DIC, and $lng.

33  {
34  global $DIC;
35 
36  $lng = $DIC['lng'];
37 
38  $lng->loadLanguageModule("trac");
39  return $lng->txt("trac_object_statistics_info");
40  }
global $DIC
Definition: saml.php:7
$lng

◆ getId()

ilLPCronObjectStatistics::getId ( )

Definition at line 17 of file class.ilLPCronObjectStatistics.php.

Referenced by gatherCourseLPData(), gatherTypesData(), and gatherUserData().

18  {
19  return "lp_object_statistics";
20  }
+ Here is the caller graph for this function:

◆ getTitle()

ilLPCronObjectStatistics::getTitle ( )

Definition at line 22 of file class.ilLPCronObjectStatistics.php.

References $DIC, and $lng.

23  {
24  global $DIC;
25 
26  $lng = $DIC['lng'];
27 
28  $lng->loadLanguageModule("trac");
29  return $lng->txt("trac_object_statistics");
30  }
global $DIC
Definition: saml.php:7
$lng

◆ hasAutoActivation()

ilLPCronObjectStatistics::hasAutoActivation ( )

Definition at line 52 of file class.ilLPCronObjectStatistics.php.

53  {
54  return true;
55  }

◆ hasFlexibleSchedule()

ilLPCronObjectStatistics::hasFlexibleSchedule ( )

Definition at line 57 of file class.ilLPCronObjectStatistics.php.

58  {
59  return false;
60  }

◆ run()

ilLPCronObjectStatistics::run ( )

Definition at line 62 of file class.ilLPCronObjectStatistics.php.

References $message, $result, gatherCourseLPData(), gatherTypesData(), gatherUserData(), ilCronJobResult\STATUS_NO_ACTION, and ilCronJobResult\STATUS_OK.

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 
80  $result = new ilCronJobResult();
81  $result->setStatus($status);
82 
83  return $result;
84  }
$result
catch(Exception $e) $message
Cron job result data container.
gatherCourseLPData()
gather course data type $tree type $ilDB
+ Here is the call graph for this function:

Field Documentation

◆ $date

ilLPCronObjectStatistics::$date
protected

Definition at line 15 of file class.ilLPCronObjectStatistics.php.


The documentation for this class was generated from the following file: