|
|
|
@ -4,8 +4,6 @@ |
|
|
|
|
|
|
|
|
|
|
|
class PauseTraining extends Plugin |
|
|
|
class PauseTraining extends Plugin |
|
|
|
{ |
|
|
|
{ |
|
|
|
public $isCoursePlugin = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function __construct() |
|
|
|
protected function __construct() |
|
|
|
{ |
|
|
|
{ |
|
|
|
parent::__construct( |
|
|
|
parent::__construct( |
|
|
|
@ -15,6 +13,7 @@ class PauseTraining extends Plugin |
|
|
|
'tool_enable' => 'boolean', |
|
|
|
'tool_enable' => 'boolean', |
|
|
|
'allow_users_to_edit_pause_formation' => 'boolean', |
|
|
|
'allow_users_to_edit_pause_formation' => 'boolean', |
|
|
|
'cron_alert_users_if_inactive_days' => 'text', // Example: "5" or "5,10,15" |
|
|
|
'cron_alert_users_if_inactive_days' => 'text', // Example: "5" or "5,10,15" |
|
|
|
|
|
|
|
'sender_id' => 'user', |
|
|
|
] |
|
|
|
] |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -94,64 +93,80 @@ class PauseTraining extends Plugin |
|
|
|
public function runCron() |
|
|
|
public function runCron() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$enable = $this->get('tool_enable'); |
|
|
|
$enable = $this->get('tool_enable'); |
|
|
|
|
|
|
|
$senderId = $this->get('sender_id'); |
|
|
|
$enableDays = $this->get('cron_alert_users_if_inactive_days'); |
|
|
|
$enableDays = $this->get('cron_alert_users_if_inactive_days'); |
|
|
|
|
|
|
|
|
|
|
|
if ($enable && !empty($enableDays)) { |
|
|
|
if ('true' !== $enable) { |
|
|
|
$enableDaysList = explode(',', $enableDays); |
|
|
|
echo 'Plugin not enabled'; |
|
|
|
rsort($enableDaysList); |
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
$loginTable = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS); |
|
|
|
|
|
|
|
$userTable = Database::get_main_table(TABLE_MAIN_USER); |
|
|
|
if (empty($senderId)) { |
|
|
|
$now = api_get_utc_datetime(); |
|
|
|
echo 'Sender id not configured'; |
|
|
|
$usersNotificationPerDay = []; |
|
|
|
return false; |
|
|
|
$users = []; |
|
|
|
} |
|
|
|
foreach ($enableDaysList as $day) { |
|
|
|
|
|
|
|
$day = (int) $day; |
|
|
|
$senderInfo = api_get_user_info($senderId); |
|
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT |
|
|
|
if (empty($senderInfo)) { |
|
|
|
stats_login.user_id, |
|
|
|
echo "Sender #$senderId not found"; |
|
|
|
MAX(stats_login.login_course_date) max_date |
|
|
|
return false; |
|
|
|
FROM $loginTable stats_login |
|
|
|
} |
|
|
|
INNER JOIN $userTable u |
|
|
|
|
|
|
|
ON (u.id = stats_login.user_id) |
|
|
|
$enableDaysList = explode(',', $enableDays); |
|
|
|
WHERE |
|
|
|
rsort($enableDaysList); |
|
|
|
u.status <> ".ANONYMOUS." AND |
|
|
|
|
|
|
|
u.active = 1 |
|
|
|
$loginTable = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS); |
|
|
|
GROUP BY stats_login.user_id |
|
|
|
$userTable = Database::get_main_table(TABLE_MAIN_USER); |
|
|
|
HAVING DATE_SUB('$now', INTERVAL '$day' DAY) > max_date "; |
|
|
|
$now = api_get_utc_datetime(); |
|
|
|
|
|
|
|
$usersNotificationPerDay = []; |
|
|
|
$rs = Database::query($sql); |
|
|
|
$users = []; |
|
|
|
while ($user = Database::fetch_array($rs)) { |
|
|
|
foreach ($enableDaysList as $day) { |
|
|
|
$userId = $user['user_id']; |
|
|
|
$day = (int) $day; |
|
|
|
|
|
|
|
|
|
|
|
if (in_array($userId, $users)) { |
|
|
|
$sql = "SELECT |
|
|
|
continue; |
|
|
|
stats_login.user_id, |
|
|
|
} |
|
|
|
MAX(stats_login.login_course_date) max_date |
|
|
|
$users[] = $userId; |
|
|
|
FROM $loginTable stats_login |
|
|
|
$usersNotificationPerDay[$day][] = $userId; |
|
|
|
INNER JOIN $userTable u |
|
|
|
|
|
|
|
ON (u.id = stats_login.user_id) |
|
|
|
|
|
|
|
WHERE |
|
|
|
|
|
|
|
u.status <> ".ANONYMOUS." AND |
|
|
|
|
|
|
|
u.active = 1 |
|
|
|
|
|
|
|
GROUP BY stats_login.user_id |
|
|
|
|
|
|
|
HAVING DATE_SUB('$now', INTERVAL '$day' DAY) > max_date "; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$rs = Database::query($sql); |
|
|
|
|
|
|
|
while ($user = Database::fetch_array($rs)) { |
|
|
|
|
|
|
|
$userId = $user['user_id']; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (in_array($userId, $users)) { |
|
|
|
|
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$users[] = $userId; |
|
|
|
|
|
|
|
$usersNotificationPerDay[$day][] = $userId; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!empty($usersNotificationPerDay)) { |
|
|
|
if (!empty($usersNotificationPerDay)) { |
|
|
|
ksort($usersNotificationPerDay); |
|
|
|
ksort($usersNotificationPerDay); |
|
|
|
$extraFieldValue = new ExtraFieldValue('user'); |
|
|
|
$extraFieldValue = new ExtraFieldValue('user'); |
|
|
|
foreach ($usersNotificationPerDay as $day => $userList) { |
|
|
|
foreach ($usersNotificationPerDay as $day => $userList) { |
|
|
|
$template = new Template(); |
|
|
|
$template = new Template(); |
|
|
|
$title = sprintf($this->get_lang('InactivityXDays'), $day); |
|
|
|
$title = sprintf($this->get_lang('InactivityXDays'), $day); |
|
|
|
|
|
|
|
|
|
|
|
foreach ($userList as $userId) { |
|
|
|
foreach ($userList as $userId) { |
|
|
|
$userInfo = api_get_user_info($userId); |
|
|
|
$userInfo = api_get_user_info($userId); |
|
|
|
$pause = $extraFieldValue->get_values_by_handler_and_field_variable($userId, 'pause_formation'); |
|
|
|
$pause = $extraFieldValue->get_values_by_handler_and_field_variable($userId, 'pause_formation'); |
|
|
|
if (!empty($pause) && isset($pause['value']) && 1 == $pause['value']) { |
|
|
|
if (!empty($pause) && isset($pause['value']) && 1 == $pause['value']) { |
|
|
|
// Skip user because he paused his formation. |
|
|
|
// Skip user because he paused his formation. |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$template->assign('days', $day); |
|
|
|
|
|
|
|
$template->assign('user', $userInfo); |
|
|
|
|
|
|
|
$content = $template->fetch('pausetraining/view/notification_content.tpl'); |
|
|
|
|
|
|
|
MessageManager::send_message($userId, $title, $content); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$template->assign('days', $day); |
|
|
|
|
|
|
|
$template->assign('user', $userInfo); |
|
|
|
|
|
|
|
$content = $template->fetch('pausetraining/view/notification_content.tpl'); |
|
|
|
|
|
|
|
MessageManager::send_message_simple($userId, $title, $content, $senderId); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|