ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilLPCronObjectStatistics Class Reference

Cron for lp object statistics. More...

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

Public Member Functions

 __construct ()
 
 getId ()
 
 getTitle ()
 
 getDescription ()
 
 getDefaultScheduleType ()
 
 getDefaultScheduleValue ()
 
 hasAutoActivation ()
 
 hasFlexibleSchedule ()
 
 run ()
 
- Public Member Functions inherited from ilCronJob
 setDateTimeProvider (?Closure $date_time_provider)
 
 isDue (?DateTimeImmutable $last_run, ?CronJobScheduleType $schedule_type, ?int $schedule_value, bool $is_manually_executed=false)
 
 getScheduleType ()
 Get current schedule type (if flexible) More...
 
 getScheduleValue ()
 Get current schedule value (if flexible) More...
 
 setSchedule (?CronJobScheduleType $a_type, ?int $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...
 
 isManuallyExecutable ()
 
 hasCustomSettings ()
 
 addCustomSettingsToForm (ilPropertyFormGUI $a_form)
 
 saveCustomSettings (ilPropertyFormGUI $a_form)
 
 addToExternalSettingsForm (int $a_form_id, array &$a_fields, bool $a_is_active)
 
 activationWasToggled (ilDBInterface $db, ilSetting $setting, bool $a_currently_active)
 Important: This method is (also) called from the setup process, where the constructor of an ilCronJob ist NOT executed. More...
 
 getId ()
 
 getTitle ()
 
 getDescription ()
 
 hasAutoActivation ()
 Is to be activated on "installation", does only work for ILIAS core cron jobs. More...
 
 hasFlexibleSchedule ()
 
 getDefaultScheduleType ()
 
 getDefaultScheduleValue ()
 
 run ()
 

Protected Member Functions

 gatherCourseLPData ()
 gather course data More...
 
 gatherTypesData ()
 
 gatherUserData ()
 

Protected Attributes

int $date = 0
 
ilLanguage $lng
 
ilDBInterface $db
 
ilTree $tree
 
ilLogger $logger
 
ilCronManager $cron_manager
 
- Protected Attributes inherited from ilCronJob
CronJobScheduleType $schedule_type = null
 
int $schedule_value = null
 
Closure $date_time_provider = null
 

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 28 of file class.ilLPCronObjectStatistics.php.

Constructor & Destructor Documentation

◆ __construct()

ilLPCronObjectStatistics::__construct ( )

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

References $DIC, ILIAS\Repository\lng(), and ILIAS\Repository\logger().

39  {
40  global $DIC;
41 
42  $this->logger = $DIC->logger()->trac();
43  $this->lng = $DIC->language();
44  $this->lng->loadLanguageModule("trac");
45  $this->db = $DIC->database();
46  $this->tree = $DIC->repositoryTree();
47  $this->cron_manager = $DIC->cron()->manager();
48  }
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ gatherCourseLPData()

ilLPCronObjectStatistics::gatherCourseLPData ( )
protected

gather course data

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

References ilObject\_getAllReferences(), ilObject\_getObjectsByType(), ilLPStatusWrapper\_lookupCompletedForObject(), ilLPStatusWrapper\_lookupFailedForObject(), ilLPStatusWrapper\_lookupInProgressForObject(), getId(), ilObjectLP\getInstance(), and ILIAS\Repository\logger().

Referenced by run().

112  : int
113  {
114  $count = 0;
115 
116  // process all courses
117  $all_courses = array_keys(ilObject::_getObjectsByType("crs"));
118  if ($all_courses) {
119  // gather objects in trash
120  $trashed_objects = $this->tree->getSavedNodeObjIds($all_courses);
121 
122  foreach ($all_courses as $crs_id) {
123  // trashed objects will not change
124  if (!in_array($crs_id, $trashed_objects)) {
125  $refs = ilObject::_getAllReferences($crs_id);
126  if (!count($refs)) {
127  $this->logger->warning(
128  'Found course without reference: obj_id = ' . $crs_id
129  );
130  continue;
131  }
132 
133  // only if LP is active
134  $olp = ilObjectLP::getInstance($crs_id);
135  if (!$olp->isActive()) {
136  continue;
137  }
138 
139  // only save once per day
140  $this->db->manipulate(
141  "DELETE FROM obj_lp_stat WHERE" .
142  " obj_id = " . $this->db->quote($crs_id, "integer") .
143  " AND fulldate = " . $this->db->quote(
144  date("Ymd", $this->date),
145  "integer"
146  )
147  );
148 
149  $members = new ilCourseParticipants($crs_id);
150  $members = $members->getMembers();
151 
152  $in_progress = count(
154  $crs_id,
155  $members
156  )
157  );
158  $completed = count(
160  $crs_id,
161  $members
162  )
163  );
164  $failed = count(
166  $crs_id,
167  $members
168  )
169  );
170 
171  // calculate with other values - there is not direct method
172  $not_attempted = count(
173  $members
174  ) - $in_progress - $completed - $failed;
175 
176  $set = array(
177  "type" => array("text", "crs"),
178  "obj_id" => array("integer", $crs_id),
179  "yyyy" => array("integer", date("Y", $this->date)),
180  "mm" => array("integer", date("m", $this->date)),
181  "dd" => array("integer", date("d", $this->date)),
182  "fulldate" => array("integer",
183  date("Ymd", $this->date)
184  ),
185  "mem_cnt" => array("integer", count($members)),
186  "in_progress" => array("integer", $in_progress),
187  "completed" => array("integer", $completed),
188  "failed" => array("integer", $failed),
189  "not_attempted" => array("integer", $not_attempted)
190  );
191 
192  $this->db->insert("obj_lp_stat", $set);
193  $count++;
194  $this->cron_manager->ping($this->getId());
195  }
196  }
197  }
198  return $count;
199  }
static _lookupInProgressForObject(int $a_obj_id, ?array $a_user_ids=null)
static _getAllReferences(int $id)
get all reference ids for object ID
static _getObjectsByType(string $obj_type="", int $owner=null)
static _lookupCompletedForObject(int $a_obj_id, ?array $a_user_ids=null)
static _lookupFailedForObject(int $a_obj_id, ?array $a_user_ids=null)
static getInstance(int $obj_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gatherTypesData()

ilLPCronObjectStatistics::gatherTypesData ( )
protected

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

References $data, getId(), and ilTrQuery\getObjectTypeStatistics().

Referenced by run().

201  : int
202  {
203  $count = 0;
205  foreach ($data as $type => $item) {
206  // only save once per day
207  $this->db->manipulate(
208  "DELETE FROM obj_type_stat WHERE" .
209  " type = " . $this->db->quote($type, "text") .
210  " AND fulldate = " . $this->db->quote(
211  date("Ymd", $this->date),
212  "integer"
213  )
214  );
215 
216  $set = array(
217  "type" => array("text", $type),
218  "yyyy" => array("integer", date("Y", $this->date)),
219  "mm" => array("integer", date("m", $this->date)),
220  "dd" => array("integer", date("d", $this->date)),
221  "fulldate" => array("integer", date("Ymd", $this->date)),
222  "cnt_references" => array("integer", (int) $item["references"]),
223  "cnt_objects" => array("integer", (int) $item["objects"]),
224  "cnt_deleted" => array("integer", isset($item["deleted"]) ? (int) $item["deleted"] : 0)
225  );
226 
227  $this->db->insert("obj_type_stat", $set);
228 
229  $count++;
230  $this->cron_manager->ping($this->getId());
231  }
232  return $count;
233  }
static getObjectTypeStatistics()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gatherUserData()

ilLPCronObjectStatistics::gatherUserData ( )
protected

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

References getId().

Referenced by run().

235  : int
236  {
237  $count = 0;
238  $to = mktime(
239  23,
240  59,
241  59,
242  date("m", $this->date),
243  date("d", $this->date),
244  date("Y", $this->date)
245  );
246 
247  $sql = "SELECT COUNT(DISTINCT(usr_id)) counter,obj_id FROM read_event" .
248  " WHERE last_access >= " . $this->db->quote(
249  $this->date,
250  "integer"
251  ) .
252  " AND last_access <= " . $this->db->quote($to, "integer") .
253  " GROUP BY obj_id";
254  $set = $this->db->query($sql);
255  while ($row = $this->db->fetchAssoc($set)) {
256  // only save once per day
257  $this->db->manipulate(
258  "DELETE FROM obj_user_stat" .
259  " WHERE fulldate = " . $this->db->quote(
260  date("Ymd", $this->date),
261  "integer"
262  ) .
263  " AND obj_id = " . $this->db->quote($row["obj_id"], "integer")
264  );
265 
266  $iset = array(
267  "obj_id" => array("integer", $row["obj_id"]),
268  "yyyy" => array("integer", date("Y", $this->date)),
269  "mm" => array("integer", date("m", $this->date)),
270  "dd" => array("integer", date("d", $this->date)),
271  "fulldate" => array("integer", date("Ymd", $this->date)),
272  "counter" => array("integer", $row["counter"])
273  );
274 
275  $this->db->insert("obj_user_stat", $iset);
276 
277  $count++;
278  $this->cron_manager->ping($this->getId());
279  }
280  return $count;
281  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDefaultScheduleType()

ilLPCronObjectStatistics::getDefaultScheduleType ( )

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

66  {
67  return CronJobScheduleType::SCHEDULE_TYPE_DAILY;
68  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ getDefaultScheduleValue()

ilLPCronObjectStatistics::getDefaultScheduleValue ( )

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

70  : ?int
71  {
72  return null;
73  }

◆ getDescription()

ilLPCronObjectStatistics::getDescription ( )

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

References ILIAS\Repository\lng().

60  : string
61  {
62  return $this->lng->txt("trac_object_statistics_info");
63  }
+ Here is the call graph for this function:

◆ getId()

ilLPCronObjectStatistics::getId ( )

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

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

50  : string
51  {
52  return "lp_object_statistics";
53  }
+ Here is the caller graph for this function:

◆ getTitle()

ilLPCronObjectStatistics::getTitle ( )

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

References ILIAS\Repository\lng().

55  : string
56  {
57  return $this->lng->txt("trac_object_statistics");
58  }
+ Here is the call graph for this function:

◆ hasAutoActivation()

ilLPCronObjectStatistics::hasAutoActivation ( )

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

75  : bool
76  {
77  return true;
78  }

◆ hasFlexibleSchedule()

ilLPCronObjectStatistics::hasFlexibleSchedule ( )

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

80  : bool
81  {
82  return false;
83  }

◆ run()

ilLPCronObjectStatistics::run ( )

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

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

86  {
87  // all date related operations are based on this timestamp
88  // should be midnight of yesterday (see gatherUserData()) to always have full day
89  $this->date = strtotime("yesterday");
90 
92  $message = array();
93 
94  $count = 0;
95  $count += $this->gatherCourseLPData();
96  $count += $this->gatherTypesData();
97  $count += $this->gatherUserData();
98 
99  if ($count) {
100  $status = ilCronJobResult::STATUS_OK;
101  }
102 
103  $result = new ilCronJobResult();
104  $result->setStatus($status);
105 
106  return $result;
107  }
final const STATUS_NO_ACTION
$message
Definition: xapiexit.php:32
+ Here is the call graph for this function:

Field Documentation

◆ $cron_manager

ilCronManager ilLPCronObjectStatistics::$cron_manager
protected

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

◆ $date

int ilLPCronObjectStatistics::$date = 0
protected

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

◆ $db

ilDBInterface ilLPCronObjectStatistics::$db
protected

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

◆ $lng

ilLanguage ilLPCronObjectStatistics::$lng
protected

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

◆ $logger

ilLogger ilLPCronObjectStatistics::$logger
protected

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

◆ $tree

ilTree ilLPCronObjectStatistics::$tree
protected

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


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