ILIAS  release_8 Revision v8.23
ilLPCronObjectStatistics Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. 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, ?int $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 (?int $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
int $schedule_type = null
 
int $schedule_value = null
 
Closure $date_time_provider = null
 

Additional Inherited Members

- Data Fields inherited from ilCronJob
const SCHEDULE_TYPE_DAILY = 1
 This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_IN_MINUTES = 2
 This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_IN_HOURS = 3
 This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_IN_DAYS = 4
 This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_WEEKLY = 5
 This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_MONTHLY = 6
 This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_QUARTERLY = 7
 This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_YEARLY = 8
 This will be replaced with an ENUM in ILIAS 9 More...
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning 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 27 of file class.ilLPCronObjectStatistics.php.

Constructor & Destructor Documentation

◆ __construct()

ilLPCronObjectStatistics::__construct ( )

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

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

38  {
39  global $DIC;
40 
41  $this->logger = $DIC->logger()->trac();
42  $this->lng = $DIC->language();
43  $this->lng->loadLanguageModule("trac");
44  $this->db = $DIC->database();
45  $this->tree = $DIC->repositoryTree();
46  $this->cron_manager = $DIC->cron()->manager();
47  }
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 111 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().

111  : int
112  {
113  $count = 0;
114 
115  // process all courses
116  $all_courses = array_keys(ilObject::_getObjectsByType("crs"));
117  if ($all_courses) {
118  // gather objects in trash
119  $trashed_objects = $this->tree->getSavedNodeObjIds($all_courses);
120 
121  foreach ($all_courses as $crs_id) {
122  // trashed objects will not change
123  if (!in_array($crs_id, $trashed_objects)) {
124  $refs = ilObject::_getAllReferences($crs_id);
125  if (!count($refs)) {
126  $this->logger->warning(
127  'Found course without reference: obj_id = ' . $crs_id
128  );
129  continue;
130  }
131 
132  // only if LP is active
133  $olp = ilObjectLP::getInstance($crs_id);
134  if (!$olp->isActive()) {
135  continue;
136  }
137 
138  // only save once per day
139  $this->db->manipulate(
140  "DELETE FROM obj_lp_stat WHERE" .
141  " obj_id = " . $this->db->quote($crs_id, "integer") .
142  " AND fulldate = " . $this->db->quote(
143  date("Ymd", $this->date),
144  "integer"
145  )
146  );
147 
148  $members = new ilCourseParticipants($crs_id);
149  $members = $members->getMembers();
150 
151  $in_progress = count(
153  $crs_id,
154  $members
155  )
156  );
157  $completed = count(
159  $crs_id,
160  $members
161  )
162  );
163  $failed = count(
165  $crs_id,
166  $members
167  )
168  );
169 
170  // calculate with other values - there is not direct method
171  $not_attempted = count(
172  $members
173  ) - $in_progress - $completed - $failed;
174 
175  $set = array(
176  "type" => array("text", "crs"),
177  "obj_id" => array("integer", $crs_id),
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",
182  date("Ymd", $this->date)
183  ),
184  "mem_cnt" => array("integer", count($members)),
185  "in_progress" => array("integer", $in_progress),
186  "completed" => array("integer", $completed),
187  "failed" => array("integer", $failed),
188  "not_attempted" => array("integer", $not_attempted)
189  );
190 
191  $this->db->insert("obj_lp_stat", $set);
192  $count++;
193  $this->cron_manager->ping($this->getId());
194  }
195  }
196  }
197  return $count;
198  }
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 200 of file class.ilLPCronObjectStatistics.php.

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

Referenced by run().

200  : int
201  {
202  $count = 0;
204  foreach ($data as $type => $item) {
205  // only save once per day
206  $this->db->manipulate(
207  "DELETE FROM obj_type_stat WHERE" .
208  " type = " . $this->db->quote($type, "text") .
209  " AND fulldate = " . $this->db->quote(
210  date("Ymd", $this->date),
211  "integer"
212  )
213  );
214 
215  $set = array(
216  "type" => array("text", $type),
217  "yyyy" => array("integer", date("Y", $this->date)),
218  "mm" => array("integer", date("m", $this->date)),
219  "dd" => array("integer", date("d", $this->date)),
220  "fulldate" => array("integer", date("Ymd", $this->date)),
221  "cnt_references" => array("integer", (int) $item["references"]),
222  "cnt_objects" => array("integer", (int) $item["objects"]),
223  "cnt_deleted" => array("integer", isset($item["deleted"]) ? (int) $item["deleted"] : 0)
224  );
225 
226  $this->db->insert("obj_type_stat", $set);
227 
228  $count++;
229  $this->cron_manager->ping($this->getId());
230  }
231  return $count;
232  }
$type
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 234 of file class.ilLPCronObjectStatistics.php.

References getId().

Referenced by run().

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

◆ getDefaultScheduleType()

ilLPCronObjectStatistics::getDefaultScheduleType ( )

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

64  : int
65  {
66  return self::SCHEDULE_TYPE_DAILY;
67  }

◆ getDefaultScheduleValue()

ilLPCronObjectStatistics::getDefaultScheduleValue ( )

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

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

◆ getDescription()

ilLPCronObjectStatistics::getDescription ( )

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

References ILIAS\Repository\lng().

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

◆ getId()

ilLPCronObjectStatistics::getId ( )

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

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

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

◆ getTitle()

ilLPCronObjectStatistics::getTitle ( )

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

References ILIAS\Repository\lng().

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

◆ hasAutoActivation()

ilLPCronObjectStatistics::hasAutoActivation ( )

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

74  : bool
75  {
76  return true;
77  }

◆ hasFlexibleSchedule()

ilLPCronObjectStatistics::hasFlexibleSchedule ( )

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

79  : bool
80  {
81  return false;
82  }

◆ run()

ilLPCronObjectStatistics::run ( )

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

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

85  {
86  // all date related operations are based on this timestamp
87  // should be midnight of yesterday (see gatherUserData()) to always have full day
88  $this->date = strtotime("yesterday");
89 
91  $message = array();
92 
93  $count = 0;
94  $count += $this->gatherCourseLPData();
95  $count += $this->gatherTypesData();
96  $count += $this->gatherUserData();
97 
98  if ($count) {
100  }
101 
102  $result = new ilCronJobResult();
103  $result->setStatus($status);
104 
105  return $result;
106  }
$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 35 of file class.ilLPCronObjectStatistics.php.

◆ $date

int ilLPCronObjectStatistics::$date = 0
protected

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

◆ $db

ilDBInterface ilLPCronObjectStatistics::$db
protected

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

◆ $lng

ilLanguage ilLPCronObjectStatistics::$lng
protected

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

◆ $logger

ilLogger ilLPCronObjectStatistics::$logger
protected

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

◆ $tree

ilTree ilLPCronObjectStatistics::$tree
protected

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


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