ILIAS  release_8 Revision v8.23
ilCronFinishUnfinishedTestPasses 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 ilCronFinishUnfinishedTestPasses:
+ Collaboration diagram for ilCronFinishUnfinishedTestPasses:

Public Member Functions

 __construct ()
 
 getId ()
 
 getTitle ()
 
 getDescription ()
 
 getDefaultScheduleType ()
 
 getDefaultScheduleValue ()
 
 hasAutoActivation ()
 
 hasFlexibleSchedule ()
 
 hasCustomSettings ()
 
 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

 gatherUsersWithUnfinishedPasses ()
 
 getTestsFinishAndProcessingTime ()
 
 processPasses ()
 
 finishPassForUser ($active_id, $obj_id)
 

Protected Attributes

 $log
 
ilLanguage $lng
 
ilDBInterface $db
 
ilObjectDataCache $obj_data_cache
 
int $now
 
array $unfinished_passes
 
array $test_ids
 
array $test_ending_times
 
ilTestProcessLockerFactory $processLockerFactory
 
- 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 Class ilCronFinishUnfinishedTestPasses

Author
Guido Vollbach gvoll.nosp@m.bach.nosp@m.@data.nosp@m.bay..nosp@m.de

Definition at line 23 of file class.ilCronFinishUnfinishedTestPasses.php.

Constructor & Destructor Documentation

◆ __construct()

ilCronFinishUnfinishedTestPasses::__construct ( )

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

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

40  {
41  global $DIC;
42 
43  $this->log = ilLoggerFactory::getLogger('tst');
44  $this->lng = $DIC['lng'];
45  $this->lng->loadLanguageModule('assessment');
46  $this->db = $DIC->database();
47  $this->obj_data_cache = $DIC['ilObjDataCache'];
48  $this->now = time();
49  $this->unfinished_passes = array();
50  $this->test_ids = array();
51  $this->test_ending_times = array();
52 
53  require_once 'Modules/Test/classes/class.ilTestProcessLockerFactory.php';
54  $this->processLockerFactory = new ilTestProcessLockerFactory(
55  new ilSetting('assessment'),
56  $this->db
57  );
58  }
static getLogger(string $a_component_id)
Get component logger.
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ finishPassForUser()

ilCronFinishUnfinishedTestPasses::finishPassForUser (   $active_id,
  $obj_id 
)
protected

Definition at line 212 of file class.ilCronFinishUnfinishedTestPasses.php.

References ilObject\_exists().

Referenced by processPasses().

212  : void
213  {
214  $processLocker = $this->processLockerFactory->withContextId((int) $active_id)->getLocker();
215 
216  $testSession = new ilTestSession();
217  $testSession->loadFromDb($active_id);
218 
219  if(ilObject::_exists($obj_id)) {
220  $test = new ilObjTest($obj_id, false);
221 
222  assQuestion::_updateTestPassResults(
223  $active_id,
224  $testSession->getPass(),
225  $test->areObligationsEnabled(),
226  null,
227  $obj_id
228  );
229 
230  $pass_finisher = new ilTestPassFinishTasks($active_id, $obj_id);
231  $pass_finisher->performFinishTasks($processLocker);
232 
233  $this->log->info('Test session with active id (' . $active_id . ') and obj_id (' . $obj_id . ') is now finished.');
234  } else {
235  $this->log->info('Test object with id (' . $obj_id . ') does not exist.');
236  }
237  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gatherUsersWithUnfinishedPasses()

ilCronFinishUnfinishedTestPasses::gatherUsersWithUnfinishedPasses ( )
protected

Definition at line 128 of file class.ilCronFinishUnfinishedTestPasses.php.

References $query.

Referenced by run().

128  : void
129  {
130  $query = "SELECT tst_active.active_id,
131  tst_active.tries,
132  tst_active.user_fi usr_id,
133  tst_active.test_fi test_fi,
134  usr_data.login,
135  usr_data.lastname,
136  usr_data.firstname,
137  tst_active.submitted test_finished,
138  usr_data.matriculation,
139  usr_data.active,
140  tst_active.lastindex,
141  tst_active.last_started_pass last_started
142  FROM tst_active
143  LEFT JOIN usr_data
144  ON tst_active.user_fi = usr_data.usr_id
145  WHERE IFNULL(tst_active.last_finished_pass, -1) <> tst_active.last_started_pass
146  ";
147  $result = $this->db->query($query);
148  while ($row = $this->db->fetchAssoc($result)) {
149  $this->unfinished_passes[] = $row;
150  $this->test_ids[] = $row['test_fi'];
151  }
152  }
$query
+ Here is the caller graph for this function:

◆ getDefaultScheduleType()

ilCronFinishUnfinishedTestPasses::getDefaultScheduleType ( )

Definition at line 81 of file class.ilCronFinishUnfinishedTestPasses.php.

81  : int
82  {
83  return self::SCHEDULE_TYPE_DAILY;
84  }

◆ getDefaultScheduleValue()

ilCronFinishUnfinishedTestPasses::getDefaultScheduleValue ( )

Definition at line 86 of file class.ilCronFinishUnfinishedTestPasses.php.

86  : int
87  {
88  return 1;
89  }

◆ getDescription()

ilCronFinishUnfinishedTestPasses::getDescription ( )

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

References $DIC, and ilLanguage\txt().

73  : string
74  {
75  global $DIC;
76  $lng = $DIC['lng'];
77 
78  return $lng->txt("finish_unfinished_passes_desc");
79  }
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

◆ getId()

ilCronFinishUnfinishedTestPasses::getId ( )

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

60  : string
61  {
62  return 'finish_unfinished_passes';
63  }

◆ getTestsFinishAndProcessingTime()

ilCronFinishUnfinishedTestPasses::getTestsFinishAndProcessingTime ( )
protected

Definition at line 154 of file class.ilCronFinishUnfinishedTestPasses.php.

References $query.

Referenced by run().

154  : void
155  {
156  $query = 'SELECT test_id, obj_fi, ending_time, ending_time_enabled, processing_time, enable_processing_time FROM tst_tests WHERE ' .
157  $this->db->in('test_id', $this->test_ids, false, 'integer');
158  $result = $this->db->query($query);
159  while ($row = $this->db->fetchAssoc($result)) {
160  $this->test_ending_times[$row['test_id']] = $row;
161  }
162  $this->log->info('Gathered data for ' . count($this->test_ids) . ' test id(s) => (' . implode(',', $this->test_ids) . ')');
163  }
$query
+ Here is the caller graph for this function:

◆ getTitle()

ilCronFinishUnfinishedTestPasses::getTitle ( )

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

References $DIC, and ilLanguage\txt().

65  : string
66  {
67  global $DIC;
68  $lng = $DIC['lng'];
69 
70  return $lng->txt("finish_unfinished_passes");
71  }
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

◆ hasAutoActivation()

ilCronFinishUnfinishedTestPasses::hasAutoActivation ( )

Definition at line 91 of file class.ilCronFinishUnfinishedTestPasses.php.

91  : bool
92  {
93  return false;
94  }

◆ hasCustomSettings()

ilCronFinishUnfinishedTestPasses::hasCustomSettings ( )

Definition at line 101 of file class.ilCronFinishUnfinishedTestPasses.php.

101  : bool
102  {
103  return true;
104  }

◆ hasFlexibleSchedule()

ilCronFinishUnfinishedTestPasses::hasFlexibleSchedule ( )

Definition at line 96 of file class.ilCronFinishUnfinishedTestPasses.php.

96  : bool
97  {
98  return true;
99  }

◆ processPasses()

ilCronFinishUnfinishedTestPasses::processPasses ( )
protected

Definition at line 165 of file class.ilCronFinishUnfinishedTestPasses.php.

References $data, ILIAS\LTI\ToolProvider\$key, ilObject\_exists(), and finishPassForUser().

Referenced by run().

165  : void
166  {
167  $now = time();
168  foreach ($this->unfinished_passes as $key => $data) {
169  $test_id = $data['test_fi'];
170  $can_not_be_finished = true;
171  if (array_key_exists($test_id, $this->test_ending_times)) {
172  if ($this->test_ending_times[$test_id]['ending_time_enabled'] == 1) {
173  $this->log->info('Test (' . $test_id . ') has ending time (' . $this->test_ending_times[$test_id]['ending_time'] . ')');
174  $ending_time = $this->test_ending_times[$test_id]['ending_time'];
175  if ($ending_time < $now) {
176  $this->finishPassForUser($data['active_id'], $this->test_ending_times[$test_id]['obj_fi']);
177  $can_not_be_finished = false;
178  } else {
179  $this->log->info('Test (' . $test_id . ') ending time (' . $this->test_ending_times[$test_id]['ending_time'] . ') > now (' . $now . ') is not reached.');
180  }
181  } else {
182  $this->log->info('Test (' . $test_id . ') has no ending time.');
183  }
184  if ($this->test_ending_times[$test_id]['enable_processing_time'] == 1) {
185  $this->log->info('Test (' . $test_id . ') has processing time (' . $this->test_ending_times[$test_id]['processing_time'] . ')');
186  $obj_id = $this->test_ending_times[$test_id]['obj_fi'];
187  if(ilObject::_exists($obj_id)) {
188  $test_obj = new ilObjTest($obj_id, false);
189  $startingTime = $test_obj->getStartingTimeOfUser($data['active_id']);
190  $max_processing_time = $test_obj->isMaxProcessingTimeReached($startingTime, $data['active_id']);
191  if ($max_processing_time) {
192  $this->log->info('Max Processing time reached for user id (' . $data['usr_id'] . ') so test with active id (' . $data['active_id'] . ') will be finished.');
193  $this->finishPassForUser($data['active_id'], $this->test_ending_times[$test_id]['obj_fi']);
194  $can_not_be_finished = false;
195  } else {
196  $this->log->info('Max Processing time not reached for user id (' . $data['usr_id'] . ') in test with active id (' . $data['active_id'] . '). Starting time: ' . $startingTime . ' Processing time: ' . $test_obj->getProcessingTime() . ' / ' . $test_obj->getProcessingTimeInSeconds() . 's');
197  }
198  } else {
199  $this->log->info('Test object with id (' . $obj_id . ') does not exist.');
200  }
201  } else {
202  $this->log->info('Test (' . $test_id . ') has no processing time.');
203  }
204 
205  if ($can_not_be_finished) {
206  $this->log->info('Test session with active id (' . $data['active_id'] . ') can not be finished by this cron job.');
207  }
208  }
209  }
210  }
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
string $key
Consumer key/client ID value.
Definition: System.php:193
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ run()

ilCronFinishUnfinishedTestPasses::run ( )

Definition at line 106 of file class.ilCronFinishUnfinishedTestPasses.php.

References gatherUsersWithUnfinishedPasses(), getTestsFinishAndProcessingTime(), processPasses(), and ilCronJobResult\STATUS_OK.

107  {
108  $this->log->info('start inf cronjob...');
109 
110  $result = new ilCronJobResult();
111 
113  if (count($this->unfinished_passes) > 0) {
114  $this->log->info('found ' . count($this->unfinished_passes) . ' unfinished passes starting analyses.');
116  $this->processPasses();
117  } else {
118  $this->log->info('No unfinished passes found.');
119  }
120 
121  $result->setStatus(ilCronJobResult::STATUS_OK);
122 
123  $this->log->info(' ...finishing cronjob.');
124 
125  return $result;
126  }
+ Here is the call graph for this function:

Field Documentation

◆ $db

ilDBInterface ilCronFinishUnfinishedTestPasses::$db
protected

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

◆ $lng

ilLanguage ilCronFinishUnfinishedTestPasses::$lng
protected

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

◆ $log

ilCronFinishUnfinishedTestPasses::$log
protected

Definition at line 28 of file class.ilCronFinishUnfinishedTestPasses.php.

◆ $now

int ilCronFinishUnfinishedTestPasses::$now
protected

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

◆ $obj_data_cache

ilObjectDataCache ilCronFinishUnfinishedTestPasses::$obj_data_cache
protected

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

◆ $processLockerFactory

ilTestProcessLockerFactory ilCronFinishUnfinishedTestPasses::$processLockerFactory
protected

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

◆ $test_ending_times

array ilCronFinishUnfinishedTestPasses::$test_ending_times
protected

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

◆ $test_ids

array ilCronFinishUnfinishedTestPasses::$test_ids
protected

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

◆ $unfinished_passes

array ilCronFinishUnfinishedTestPasses::$unfinished_passes
protected

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


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