3 declare(strict_types=0);
44 $this->log = $DIC->logger()->crs();
45 $this->
lng = $DIC->language();
46 $this->
lng->loadLanguageModule(
'crs');
47 $this->db = $DIC->database();
48 $this->obj_data_cache = $DIC[
'ilObjDataCache'];
50 self::$objects_information = [];
51 $this->users_with_exceeded_timings = [];
58 return 'crs_timings_reminder';
63 return $this->
lng->txt(
'timings_reminder_notifications');
68 return $this->
lng->txt(
'timings_reminder_notifications_info');
73 return CronJobScheduleType::SCHEDULE_TYPE_DAILY;
98 $this->log->debug(
'Start.');
109 $this->log->debug(
'End');
120 $query = $this->db->queryF(
121 'SELECT usr_id FROM usr_data WHERE 122 (active = 1 AND time_limit_unlimited = 1) OR 123 (active = 1 AND time_limit_unlimited = 0 AND time_limit_from < %s AND time_limit_until > %s)',
124 [
'integer',
'integer'],
127 while ($row = $this->db->fetchAssoc($query)) {
128 $usr_id = (
int) $row[
'usr_id'];
129 $this->users[$usr_id] = $usr_id;
131 $this->log->debug(
'Found ' . count($this->users) .
' users.');
137 $this->log->debug(
'Found ' . count($this->users_with_exceeded_timings) .
' users with exceeded timings.');
142 $users_with_exceeded_objects = [];
144 if (is_array($this->users_with_exceeded_timings) && $this->users_with_exceeded_timings !== []) {
145 foreach ($this->users_with_exceeded_timings as
$key => $user_id) {
147 if (is_array($objects) && $objects !== []) {
150 $objects = array_diff_key($objects, $already_notified);
151 foreach (array_keys($objects) as
$ref_id) {
153 $obj_data[
$ref_id] = $detail_data;
155 if ($obj_data !== []) {
156 $users_with_exceeded_objects[$user_id] = $obj_data;
160 $this->log->debug(
'Found ' . count($users_with_exceeded_objects) .
' users with new exceeded timings.');
168 $users_with_new_started_object = [];
170 if (is_array($this->users) && $this->users !== []) {
171 foreach ($this->users as
$key => $user_id) {
173 if (is_array($objects) && $objects !== []) {
176 $this->log->debug(
'User_id ' . $user_id .
' was already notified for ' . count($already_notified) .
' elements ');
177 $objects = array_diff_key($objects, $already_notified);
178 foreach ($objects as
$ref_id => $v) {
182 if ((isset($v[
'end']) && isset($v[
'start'])) && $v[
'end'] > $this->now) {
183 if ($v[
'start'] < $this->now) {
184 $users_with_new_started_object[$user_id][
$ref_id] = $obj_data[
$ref_id];
187 $this->log->debug(
'End is already older than today no notification send for user_id ' . $user_id .
' on ref_id ' .
$ref_id);
193 $this->log->debug(
'Found ' . count($users_with_new_started_object) .
' users with freshly started timings.');
201 $this->log->debug(
'Start.');
202 if (is_array($users_with_exceeded_objects)) {
203 $this->log->debug(
'...found ' . count($users_with_exceeded_objects));
204 foreach ($users_with_exceeded_objects as $user_id => $exceeded_objects) {
205 $tpl = $this->
buildTopMailBody($user_id,
'timings_cron_reminder_exceeded_start');
210 $this->log->debug(
'start sending exceeded mail to user: ' . $user_id);
214 $this->log->warning(
'no array given.');
217 $this->log->debug(
'end.');
222 $this->log->debug(
'start.');
223 if (is_array($users_with_freshly_started_objects)) {
224 $this->log->debug(
'...found ' . count($users_with_freshly_started_objects));
225 foreach ($users_with_freshly_started_objects as $user_id => $freshly_started_objects) {
226 $tpl = $this->
buildTopMailBody($user_id,
'timings_cron_reminder_freshly_start');
229 if ($has_freshly_started) {
234 $this->log->debug(
'no array given.');
237 $this->log->debug(
'end.');
242 $this->log->debug(
'start...');
243 $tpl =
new ilTemplate(
'tpl.crs_timings_cron_reminder_mail.html',
true,
true,
'Modules/Course');
247 $tpl->setVariable(
'START_BODY', $this->user_lang->txt($language_variable));
248 $this->log->debug(
'for user: ' . $user_id .
' end.');
254 $has_elements =
false;
255 foreach ($objects as $object_id => $object_details) {
256 if ($object_details[
'type'] !=
'fold') {
259 $tpl->
setVariable(
'ITEM_TITLE', $object_details[
'title']);
261 $has_elements =
true;
265 $this->log->debug(
'found elements: ' . $has_elements);
266 return $has_elements;
271 $this->log->debug(
'start...');
273 $this->user_lang->loadLanguageModule(
'crs');
274 $this->user_lang->loadLanguageModule(
'mail');
275 $this->log->debug(
'user language for user ' . $user_id .
' is ' . $this->user_lang->getLangKey() .
' end.');
281 if (is_array($name)) {
282 $salutation = $this->user_lang->txt(
'mail_salutation_n') .
' ';
283 if (($name[
'gender'] ??
"") !=
'') {
284 $salutation .= $this->user_lang->txt(
'salutation_' . $name[
'gender']) .
' ';
286 if ($name[
'title'] !=
'') {
287 $salutation .= $name[
'title'] .
' ';
290 $tpl->
setVariable(
'FIRSTNAME', $name[
'firstname']);
292 $this->log->debug(
'Salutation: ' . $salutation .
' Firstname: ' . $name[
'firstname'] .
' Lastname: ' . $name[
'lastname']);
294 $this->log->debug(
'did not get an array from _lookupName.');
308 $this->user_lang->txt(
'timings_cron_reminder_exceeded_subject'),
313 $this->log->debug(
'...mail send for user ' . $user_id .
' to mail ' . $login .
' has exceeded timings for ' . $mail_body);
316 $this->log->debug(
'... no mail was sent because user ' . $user_id .
' has deactivated their notifications and has no coaches assigned.');
319 $this->log->debug(
'Not send. User ' . $user_id .
' has no email.');
333 $this->user_lang->txt(
'timings_cron_reminder_started_subject'),
338 $this->log->debug(
'...mail send for user ' . $user_id .
' to mail ' . $login .
' has freshly started timings for ' . $mail_body);
341 $this->log->debug(
'Not send. User ' . $user_id .
' has no email.');
347 foreach (array_keys($ref_ids) as
$ref_id) {
348 $this->db->manipulateF(
351 [
'integer',
'integer',
'integer'],
352 [$user_id, $ref_id, $this->now]
355 $this->log->debug(
'ilTimingsCronReminder->markExceededInDatabase: Marked exceeded in Database. User ' . $user_id .
' ref_id ' . $ref_id);
361 foreach (array_keys($ref_ids) as
$ref_id) {
362 $this->db->manipulateF(
365 [
'integer',
'integer',
'integer'],
366 [$user_id, $ref_id, $this->now]
369 $this->log->debug(
'ilTimingsCronReminder->markFreshlyStartedInDatabase: Marked freshly started in Database. User ' . $user_id .
' ref_id ' . $ref_id);
378 if (!$for_exceeded) {
382 $result = $this->db->queryF(
383 'SELECT * FROM ' . $table .
' WHERE ' .
389 while ($record = $this->db->fetchAssoc($result)) {
390 $ref_ids[$record[
'ref_id']] = $record[
'ref_id'];
397 if (!array_key_exists($ref_id, self::$objects_information)) {
398 $obj_id = $this->obj_data_cache->lookupObjId($ref_id);
399 $type = $this->obj_data_cache->lookupType($obj_id);
401 'title' => $this->obj_data_cache->lookupTitle($obj_id),
403 'url' => ilLink::_getLink($ref_id, $type),
406 self::$objects_information[
$ref_id] = $value;
408 $this->log->debug(
'ilTimingsCronReminder->getInformationForRefId: ...cached object information for => ' . $value[
'type'] .
' => ' . $value[
'title']);
410 return self::$objects_information[
$ref_id];
423 return $meta[$user_id] ?? [];
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
getUserLanguage(int $user_id)
getExceededObjectsForUser(int $user_id)
getFreshlyStartedObjectsForUser()
buildTopMailBody(int $user_id, string $language_variable)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
markExceededInDatabase(int $user_id, array $ref_ids)
getObjectsWithTimingsForUser(int $user_id)
hasUserActivatedNotification(int $user_id)
getInformationForRefId(int $ref_id)
gatherUsers()
Read all active users.
static lookupTimings(array $a_user_ids, array &$a_meta=null, bool $a_only_exceeded=true)
Lookup references, users with exceeded timings.
static _lookupName(int $a_user_id)
lookup user name
fillObjectListForMailBody(array $objects, ilTemplate $tpl)
buildMailSalutation(int $user_id, ilTemplate $tpl)
buildExceededMails(array $users_with_exceeded_objects)
gatherUsersWithExceededTimings()
__construct()
Constructor.
setVariable($variable, $value='')
Sets a variable value.
static _getLanguageOfUser(int $a_usr_id)
Get language object of user.
array $users_with_exceeded_timings
sendExceededMail(int $user_id, array $ref_ids, string $mail_body)
buildFreshlyStartedMails(array $users_with_freshly_started_objects)
const CRON_TIMINGS_STARTED_TABLE
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
getNewExceededObjectForUser()
getDefaultScheduleValue()
static array $objects_information
static lookupTimingsExceededByUser(array $a_user_ids)
Check if users currently exceeded ANY object.
markFreshlyStartedInDatabase(int $user_id, array $ref_ids)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
sendFreshlyStartedMail(int $user_id, array $ref_ids, string $mail_body)
getAlreadySentNotifications(int $user_id, bool $for_exceeded=true)
ilObjectDataCache $obj_data_cache
const CRON_TIMINGS_EXCEEDED_TABLE
static _getInstallationSignature()
static _lookupLogin(int $a_user_id)