ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 ILIAS\Cron\CronJob
 setDateTimeProvider (?\Closure $date_time_provider)
 
 isDue (?\DateTimeImmutable $last_run, ?JobScheduleType $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 (?JobScheduleType $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 ()
 
 usesLegacyForms ()
 
 getCustomConfigurationInput (\ILIAS\UI\Factory $ui_factory, \ILIAS\Refinery\Factory $factory, \ilLanguage $lng)
 
 addCustomSettingsToForm (\ilPropertyFormGUI $a_form)
 
 saveCustomConfiguration (mixed $form_data)
 
 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
 
JobManager $cron_manager
 
- Protected Attributes inherited from ILIAS\Cron\CronJob
JobScheduleType $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 31 of file class.ilLPCronObjectStatistics.php.

Constructor & Destructor Documentation

◆ __construct()

ilLPCronObjectStatistics::__construct ( )

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

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

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

Member Function Documentation

◆ gatherCourseLPData()

ilLPCronObjectStatistics::gatherCourseLPData ( )
protected

gather course data

Definition at line 115 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().

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

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

Referenced by run().

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

References getId().

Referenced by run().

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

◆ getDefaultScheduleType()

ilLPCronObjectStatistics::getDefaultScheduleType ( )

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

69  {
70  return JobScheduleType::DAILY;
71  }

◆ getDefaultScheduleValue()

ilLPCronObjectStatistics::getDefaultScheduleValue ( )

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

References null.

73  : ?int
74  {
75  return null;
76  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null

◆ getDescription()

ilLPCronObjectStatistics::getDescription ( )

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

References ILIAS\Repository\lng().

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

◆ getId()

ilLPCronObjectStatistics::getId ( )

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

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

53  : string
54  {
55  return "lp_object_statistics";
56  }
+ Here is the caller graph for this function:

◆ getTitle()

ilLPCronObjectStatistics::getTitle ( )

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

References ILIAS\Repository\lng().

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

◆ hasAutoActivation()

ilLPCronObjectStatistics::hasAutoActivation ( )

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

78  : bool
79  {
80  return true;
81  }

◆ hasFlexibleSchedule()

ilLPCronObjectStatistics::hasFlexibleSchedule ( )

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

83  : bool
84  {
85  return false;
86  }

◆ run()

ilLPCronObjectStatistics::run ( )

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

References $message, gatherCourseLPData(), gatherTypesData(), and gatherUserData().

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

Field Documentation

◆ $cron_manager

JobManager ilLPCronObjectStatistics::$cron_manager
protected

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

◆ $date

int ilLPCronObjectStatistics::$date = 0
protected

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

◆ $db

ilDBInterface ilLPCronObjectStatistics::$db
protected

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

◆ $lng

ilLanguage ilLPCronObjectStatistics::$lng
protected

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

◆ $logger

ilLogger ilLPCronObjectStatistics::$logger
protected

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

◆ $tree

ilTree ilLPCronObjectStatistics::$tree
protected

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


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