Pause training: Change setting allow_notifications to disable_emails

pull/3400/head
Julio Montoya 5 years ago
parent e8a4ed4a11
commit 2b069b59ad
  1. 7
      main/auth/pausetraining.php
  2. 2
      main/auth/profile.php
  3. 19
      main/inc/lib/message.lib.php
  4. 2
      main/webservices/api/tests/UpdateUserPauseTrainingTest.php
  5. 15
      plugin/pausetraining/PauseTraining.php
  6. 4
      plugin/pausetraining/lang/english.php
  7. 5
      plugin/pausetraining/lang/french.php

@ -32,7 +32,7 @@ $return = $extraField->addElements(
[], [],
false, false,
false, false,
['pause_formation', 'start_pause_date', 'end_pause_date', 'allow_notifications'], ['pause_formation', 'start_pause_date', 'end_pause_date'],
[], [],
[], [],
false, false,
@ -54,11 +54,6 @@ if ($form->validate()) {
if (!isset($values['extra_pause_formation'])) { if (!isset($values['extra_pause_formation'])) {
$values['extra_pause_formation'] = 0; $values['extra_pause_formation'] = 0;
} }
if (!isset($values['extra_allow_notifications'])) {
$values['extra_allow_notifications'] = 0;
}
$extraField = new ExtraFieldValue('user'); $extraField = new ExtraFieldValue('user');
$extraField->saveFieldValues($values, true, false, [], [], true); $extraField->saveFieldValues($values, true, false, [], [], true);

@ -348,7 +348,7 @@ if ($showPassword &&
$form->addHtml($extraLink); $form->addHtml($extraLink);
$extraField = new ExtraField('user'); $extraField = new ExtraField('user');
$return = $extraField->addElements($form, api_get_user_id()); $return = $extraField->addElements($form, api_get_user_id(), ['pause_formation', 'start_pause_date', 'end_pause_date']);
$jquery_ready_content = $return['jquery_ready_content']; $jquery_ready_content = $return['jquery_ready_content'];
// the $jquery_ready_content variable collects all functions that // the $jquery_ready_content variable collects all functions that

@ -500,26 +500,29 @@ class MessageManager
if ($allowPauseFormation) { if ($allowPauseFormation) {
$extraFieldValue = new ExtraFieldValue('user'); $extraFieldValue = new ExtraFieldValue('user');
$allowEmailNotifications = $extraFieldValue->get_values_by_handler_and_field_variable( $disableEmails = $extraFieldValue->get_values_by_handler_and_field_variable(
$receiverUserId, $receiverUserId,
'allow_notifications' 'disable_emails'
); );
// User doesn't want email notifications but chamilo inbox still available (Option was not set) // User doesn't want email but chamilo inbox still available.
if (empty($allowEmailNotifications)) { if (empty($disableEmails)) {
$sendEmail = false; $sendEmail = false;
} }
// User doesn't want email notifications but chamilo inbox still available. (Option was set to "No") // User doesn't want email notifications but chamilo inbox still available.
if (!empty($allowEmailNotifications) && if (!empty($disableEmails) &&
isset($allowEmailNotifications['value']) && 0 === (int) $allowEmailNotifications['value'] isset($disableEmails['value']) && 1 === (int) $disableEmails['value']
) { ) {
$sendEmail = false; $sendEmail = false;
} }
if ($sendEmail) { if ($sendEmail) {
// Check if user pause his formation. // Check if user pause his formation.
$pause = $extraFieldValue->get_values_by_handler_and_field_variable($receiverUserId, 'pause_formation'); $pause = $extraFieldValue->get_values_by_handler_and_field_variable(
$receiverUserId,
'pause_formation'
);
if (!empty($pause) && isset($pause['value']) && 1 === (int) $pause['value']) { if (!empty($pause) && isset($pause['value']) && 1 === (int) $pause['value']) {
$startDate = $extraFieldValue->get_values_by_handler_and_field_variable( $startDate = $extraFieldValue->get_values_by_handler_and_field_variable(
$receiverUserInfo['user_id'], $receiverUserInfo['user_id'],

@ -27,7 +27,7 @@ class UpdateUserPauseTrainingTest extends V2TestCase
'pause_formation' => 0, 'pause_formation' => 0,
'start_pause_date' => '2020-06-30 10:00', 'start_pause_date' => '2020-06-30 10:00',
'end_pause_date' => '2020-06-30 11:00', 'end_pause_date' => '2020-06-30 11:00',
'allow_notifications' => 0, 'disable_emails' => 1,
]; ];
$userId = $this->integer($params); $userId = $this->integer($params);

@ -36,7 +36,7 @@ class PauseTraining extends Plugin
'pause_formation', 'pause_formation',
'start_pause_date', 'start_pause_date',
'end_pause_date', 'end_pause_date',
'allow_notifications', 'disable_emails',
]; ];
$valuesToUpdate = [ $valuesToUpdate = [
@ -61,12 +61,12 @@ class PauseTraining extends Plugin
$valuesToUpdate['extra_pause_formation']['extra_pause_formation'] = $pause; $valuesToUpdate['extra_pause_formation']['extra_pause_formation'] = $pause;
} }
$notification = (int) $valuesToUpdate['extra_allow_notifications']; $notification = (int) $valuesToUpdate['extra_disable_emails'];
if (empty($notification)) { if (empty($notification)) {
$valuesToUpdate['extra_allow_notifications'] = 0; $valuesToUpdate['extra_disable_emails'] = 0;
} else { } else {
$valuesToUpdate['extra_allow_notifications'] = []; $valuesToUpdate['extra_disable_emails'] = [];
$valuesToUpdate['extra_allow_notifications']['extra_allow_notifications'] = $notification; $valuesToUpdate['extra_disable_emails']['extra_disable_emails'] = $notification;
} }
$check = DateTime::createFromFormat('Y-m-d H:i', $valuesToUpdate['extra_start_pause_date']); $check = DateTime::createFromFormat('Y-m-d H:i', $valuesToUpdate['extra_start_pause_date']);
@ -153,7 +153,6 @@ class PauseTraining extends Plugin
if (!empty($usersNotificationPerDay)) { if (!empty($usersNotificationPerDay)) {
ksort($usersNotificationPerDay); ksort($usersNotificationPerDay);
$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);
@ -193,9 +192,9 @@ class PauseTraining extends Plugin
); );
UserManager::create_extra_field( UserManager::create_extra_field(
'allow_notifications', 'disable_emails',
ExtraField::FIELD_TYPE_CHECKBOX, ExtraField::FIELD_TYPE_CHECKBOX,
$this->get_lang('AllowEmailNotification'), $this->get_lang('DisableEmails'),
'' ''
); );
} }

@ -1,5 +1,7 @@
<?php <?php
/* For licensing terms, see /license.txt */
$strings['plugin_title'] = "Pause training"; $strings['plugin_title'] = "Pause training";
$strings['plugin_comment'] = ""; $strings['plugin_comment'] = "";
$strings['tool_enable'] = 'Enable plugin'; $strings['tool_enable'] = 'Enable plugin';
@ -10,7 +12,7 @@ $strings['cron_alert_users_if_inactive_days'] = 'Alert users if inactive days (v
$strings['PauseFormation'] = 'Pause my formation'; $strings['PauseFormation'] = 'Pause my formation';
$strings['StartPauseDateTime'] = 'Start pause date'; $strings['StartPauseDateTime'] = 'Start pause date';
$strings['EndPauseDateTime'] = 'End pause date'; $strings['EndPauseDateTime'] = 'End pause date';
$strings['AllowEmailNotification'] = 'Allow email notifications'; $strings['DisableEmails'] = 'Disable email notifications';
$strings['InactivityXDays'] = 'Inactivity for %s days'; $strings['InactivityXDays'] = 'Inactivity for %s days';
$strings['YouAreConnectedInPlatformXLinkXSinceXDays'] = ' $strings['YouAreConnectedInPlatformXLinkXSinceXDays'] = '
We have noticed that you have not connected to the platform %s (%s) for %s days. We have noticed that you have not connected to the platform %s (%s) for %s days.

@ -1,4 +1,7 @@
<?php <?php
/* For licensing terms, see /license.txt */
$strings['plugin_title'] = "Pause training"; $strings['plugin_title'] = "Pause training";
$strings['plugin_comment'] = ""; $strings['plugin_comment'] = "";
$strings['tool_enable'] = 'Enable plugin'; $strings['tool_enable'] = 'Enable plugin';
@ -9,7 +12,7 @@ $strings['cron_alert_users_if_inactive_days'] = 'Alert users if inactive days (v
$strings['PauseFormation'] = 'Mettre en pause ma formation'; $strings['PauseFormation'] = 'Mettre en pause ma formation';
$strings['StartPauseDateTime'] = 'Date de début de pause'; $strings['StartPauseDateTime'] = 'Date de début de pause';
$strings['EndPauseDateTime'] = 'Date de fin de pause'; $strings['EndPauseDateTime'] = 'Date de fin de pause';
$strings['AllowEmailNotification'] = 'Continuer à recevoir les mails de la plateforme'; $strings['DisableEmails'] = 'Désactiver les e-mails ';
$strings['InactivityXDays'] = 'Inactivité sur la plateforme depuis %s jours'; $strings['InactivityXDays'] = 'Inactivité sur la plateforme depuis %s jours';
$strings['YouAreConnectedInPlatformXLinkXSinceXDays'] = ' $strings['YouAreConnectedInPlatformXLinkXSinceXDays'] = '
Nous avons remarqué que vous ne vous êtes pas connecté à la plateforme %s (%s) depuis %s jours. Nous avons remarqué que vous ne vous êtes pas connecté à la plateforme %s (%s) depuis %s jours.

Loading…
Cancel
Save