3 declare(strict_types=0);
42 $this->log = $DIC->logger()->crs();
43 $this->
lng = $DIC->language();
44 $this->
lng->loadLanguageModule(
'crs');
45 $this->db = $DIC->database();
46 $this->obj_data_cache = $DIC[
'ilObjDataCache'];
48 self::$objects_information = [];
49 $this->users_with_exceeded_timings = [];
56 return 'crs_timings_reminder';
61 return $this->
lng->txt(
'timings_reminder_notifications');
66 return $this->
lng->txt(
'timings_reminder_notifications_info');
71 return self::SCHEDULE_TYPE_DAILY;
96 $this->log->debug(
'Start.');
107 $this->log->debug(
'End');
118 $query = $this->db->queryF(
119 'SELECT usr_id FROM usr_data WHERE 120 (active = 1 AND time_limit_unlimited = 1) OR 121 (active = 1 AND time_limit_unlimited = 0 AND time_limit_from < %s AND time_limit_until > %s)',
122 [
'integer',
'integer'],
125 while ($row = $this->db->fetchAssoc(
$query)) {
126 $usr_id = (
int) $row[
'usr_id'];
127 $this->users[$usr_id] = $usr_id;
129 $this->log->debug(
'Found ' . count($this->users) .
' users.');
135 $this->log->debug(
'Found ' . count($this->users_with_exceeded_timings) .
' users with exceeded timings.');
140 $users_with_exceeded_objects = [];
142 if (is_array($this->users_with_exceeded_timings) && $this->users_with_exceeded_timings !== []) {
143 foreach ($this->users_with_exceeded_timings as
$key => $user_id) {
145 if (is_array($objects) && $objects !== []) {
148 $objects = array_diff_key($objects, $already_notified);
149 foreach (array_keys($objects) as
$ref_id) {
151 $obj_data[
$ref_id] = $detail_data;
153 if ($obj_data !== []) {
154 $users_with_exceeded_objects[$user_id] = $obj_data;
158 $this->log->debug(
'Found ' . count($users_with_exceeded_objects) .
' users with new exceeded timings.');
166 $users_with_new_started_object = [];
168 if (is_array($this->users) && $this->users !== []) {
169 foreach ($this->users as
$key => $user_id) {
171 if (is_array($objects) && $objects !== []) {
174 $this->log->debug(
'User_id ' . $user_id .
' was already notified for ' . count($already_notified) .
' elements ');
175 $objects = array_diff_key($objects, $already_notified);
176 foreach ($objects as
$ref_id => $v) {
180 if ((isset($v[
'end']) && isset($v[
'start'])) && $v[
'end'] > $this->now) {
181 if ($v[
'start'] < $this->now) {
182 $users_with_new_started_object[$user_id][
$ref_id] = $obj_data[
$ref_id];
185 $this->log->debug(
'End is already older than today no notification send for user_id ' . $user_id .
' on ref_id ' .
$ref_id);
191 $this->log->debug(
'Found ' . count($users_with_new_started_object) .
' users with freshly started timings.');
199 $this->log->debug(
'Start.');
200 if (is_array($users_with_exceeded_objects)) {
201 $this->log->debug(
'...found ' . count($users_with_exceeded_objects));
202 foreach ($users_with_exceeded_objects as $user_id => $exceeded_objects) {
208 $this->log->debug(
'start sending exceeded mail to user: ' . $user_id);
212 $this->log->warning(
'no array given.');
215 $this->log->debug(
'end.');
220 $this->log->debug(
'start.');
221 if (is_array($users_with_freshly_started_objects)) {
222 $this->log->debug(
'...found ' . count($users_with_freshly_started_objects));
223 foreach ($users_with_freshly_started_objects as $user_id => $freshly_started_objects) {
227 if ($has_freshly_started) {
232 $this->log->debug(
'no array given.');
235 $this->log->debug(
'end.');
240 $this->log->debug(
'start...');
241 $tpl =
new ilTemplate(
'tpl.crs_timings_cron_reminder_mail.html',
true,
true,
'Modules/Course');
245 $tpl->setVariable(
'START_BODY', $this->user_lang->txt($language_variable));
246 $this->log->debug(
'for user: ' . $user_id .
' end.');
252 $has_elements =
false;
253 foreach ($objects as $object_id => $object_details) {
254 if ($object_details[
'type'] !=
'fold') {
257 $tpl->
setVariable(
'ITEM_TITLE', $object_details[
'title']);
259 $has_elements =
true;
263 $this->log->debug(
'found elements: ' . $has_elements);
264 return $has_elements;
269 $this->log->debug(
'start...');
271 $this->user_lang->loadLanguageModule(
'crs');
272 $this->user_lang->loadLanguageModule(
'mail');
273 $this->log->debug(
'user language for user ' . $user_id .
' is ' . $this->user_lang->getLangKey() .
' end.');
279 if (is_array(
$name)) {
280 $salutation = $this->user_lang->txt(
'mail_salutation_n') .
' ';
281 if ((
$name[
'gender'] ??
"") !=
'') {
282 $salutation .= $this->user_lang->txt(
'salutation_' .
$name[
'gender']) .
' ';
284 if (
$name[
'title'] !=
'') {
285 $salutation .=
$name[
'title'] .
' ';
290 $this->log->debug(
'Salutation: ' . $salutation .
' Firstname: ' .
$name[
'firstname'] .
' Lastname: ' .
$name[
'lastname']);
292 $this->log->debug(
'did not get an array from _lookupName.');
306 $this->user_lang->txt(
'timings_cron_reminder_exceeded_subject'),
311 $this->log->debug(
'...mail send for user ' . $user_id .
' to mail ' . $login .
' has exceeded timings for ' . $mail_body);
314 $this->log->debug(
'... no mail was sent because user ' . $user_id .
' has deactivated their notifications and has no coaches assigned.');
317 $this->log->debug(
'Not send. User ' . $user_id .
' has no email.');
331 $this->user_lang->txt(
'timings_cron_reminder_started_subject'),
336 $this->log->debug(
'...mail send for user ' . $user_id .
' to mail ' . $login .
' has freshly started timings for ' . $mail_body);
339 $this->log->debug(
'Not send. User ' . $user_id .
' has no email.');
345 foreach (array_keys($ref_ids) as
$ref_id) {
346 $this->db->manipulateF(
349 [
'integer',
'integer',
'integer'],
350 [$user_id, $ref_id, $this->now]
353 $this->log->debug(
'ilTimingsCronReminder->markExceededInDatabase: Marked exceeded in Database. User ' . $user_id .
' ref_id ' . $ref_id);
359 foreach (array_keys($ref_ids) as
$ref_id) {
360 $this->db->manipulateF(
363 [
'integer',
'integer',
'integer'],
364 [$user_id, $ref_id, $this->now]
367 $this->log->debug(
'ilTimingsCronReminder->markFreshlyStartedInDatabase: Marked freshly started in Database. User ' . $user_id .
' ref_id ' . $ref_id);
376 if (!$for_exceeded) {
380 $result = $this->db->queryF(
381 'SELECT * FROM ' . $table .
' WHERE ' .
387 while ($record = $this->db->fetchAssoc($result)) {
388 $ref_ids[$record[
'ref_id']] = $record[
'ref_id'];
395 if (!array_key_exists($ref_id, self::$objects_information)) {
396 $obj_id = $this->obj_data_cache->lookupObjId($ref_id);
397 $type = $this->obj_data_cache->lookupType($obj_id);
399 'title' => $this->obj_data_cache->lookupTitle($obj_id),
404 self::$objects_information[
$ref_id] = $value;
406 $this->log->debug(
'ilTimingsCronReminder->getInformationForRefId: ...cached object information for => ' . $value[
'type'] .
' => ' . $value[
'title']);
408 return self::$objects_information[
$ref_id];
421 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)
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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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)
static _getLink(?int $a_ref_id, string $a_type='', array $a_params=array(), string $append="")
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)
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
ilObjectDataCache $obj_data_cache
const CRON_TIMINGS_EXCEEDED_TABLE
static _getInstallationSignature()
static _lookupLogin(int $a_user_id)