Skip to content

Commit c35cb23

Browse files
committed
Merge branch '1.11.x' of github.com:chamilo/chamilo-lms into 1.11.x
2 parents 031345e + fae4e47 commit c35cb23

File tree

9 files changed

+56
-48
lines changed

9 files changed

+56
-48
lines changed

main/admin/course_edit.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@
4545
// Get course teachers
4646
$table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
4747
$order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
48-
$sql = "SELECT user.user_id,lastname,firstname
48+
$sql = "SELECT user.id as user_id,lastname,firstname
4949
FROM
5050
$table_user as user,
5151
$table_course_user as course_user
5252
WHERE
5353
course_user.status='1' AND
54-
course_user.user_id=user.user_id AND
54+
course_user.user_id=user.id AND
5555
course_user.c_id ='".$courseId."'".
5656
$order_clause;
5757
$res = Database::query($sql);
@@ -63,15 +63,15 @@
6363
// Get all possible teachers without the course teachers
6464
if (api_is_multiple_url_enabled()) {
6565
$access_url_rel_user_table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
66-
$sql = "SELECT u.user_id,lastname,firstname
66+
$sql = "SELECT u.id as user_id,lastname,firstname
6767
FROM $table_user as u
6868
INNER JOIN $access_url_rel_user_table url_rel_user
69-
ON (u.user_id=url_rel_user.user_id)
69+
ON (u.id=url_rel_user.user_id)
7070
WHERE
7171
url_rel_user.access_url_id = $urlId AND
7272
status = 1".$order_clause;
7373
} else {
74-
$sql = "SELECT user_id, lastname, firstname
74+
$sql = "SELECT id as user_id, lastname, firstname
7575
FROM $table_user WHERE status='1'".$order_clause;
7676
}
7777
$courseInfo['tutor_name'] = null;

main/admin/course_information.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
2+
23
/* For licensing terms, see /license.txt */
4+
35
/**
46
* This script gives information about a course.
57
*
@@ -68,15 +70,15 @@ function get_course_usage($course, $session_id = 0)
6870

6971
$usage = [];
7072
$conditionSession = '';
71-
if ($session_id !== '') {
72-
$session_id = intval($session_id);
73+
if ('' !== $session_id) {
74+
$session_id = (int) $session_id;
7375
$conditionSession = " AND session_id = '$session_id' ";
7476
}
7577

7678
foreach ($tables as $tableInfo) {
7779
$table = $tableInfo[0];
7880
$title = $tableInfo[1];
79-
$sql = "SELECT COUNT(*) count FROM $table
81+
$sql = "SELECT COUNT(*) count FROM $table
8082
WHERE c_id = '$courseId' $conditionSession ";
8183
$rs = Database::query($sql);
8284
$row = Database::fetch_array($rs);
@@ -128,12 +130,12 @@ function get_course_usage($course, $session_id = 0)
128130
FROM $table_course_user cu, $table_user u";
129131
if (api_is_multiple_url_enabled()) {
130132
$sql .= " INNER JOIN ".Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER)." url_rel_user
131-
ON
132-
u.user_id = url_rel_user.user_id AND
133+
ON
134+
u.id = url_rel_user.user_id AND
133135
url_rel_user.access_url_id = ".api_get_current_access_url_id();
134136
}
135137
$sql .= " WHERE
136-
cu.user_id = u.user_id AND
138+
cu.user_id = u.id AND
137139
cu.c_id = '".$courseId."' AND
138140
cu.relation_type <> ".COURSE_RELATION_TYPE_RRHH;
139141
$res = Database::query($sql);

main/auth/pausetraining.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
[],
3333
false,
3434
false,
35-
['pause_formation', 'start_pause_date', 'end_pause_date', 'allow_notifications'],
35+
['pause_formation', 'start_pause_date', 'end_pause_date'],
3636
[],
3737
[],
3838
false,
@@ -54,11 +54,6 @@
5454
if (!isset($values['extra_pause_formation'])) {
5555
$values['extra_pause_formation'] = 0;
5656
}
57-
58-
if (!isset($values['extra_allow_notifications'])) {
59-
$values['extra_allow_notifications'] = 0;
60-
}
61-
6257
$extraField = new ExtraFieldValue('user');
6358
$extraField->saveFieldValues($values, true, false, [], [], true);
6459

main/auth/profile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ function show_image(image,width,height) {
348348
$form->addHtml($extraLink);
349349

350350
$extraField = new ExtraField('user');
351-
$return = $extraField->addElements($form, api_get_user_id());
351+
$return = $extraField->addElements($form, api_get_user_id(), ['pause_formation', 'start_pause_date', 'end_pause_date']);
352352
$jquery_ready_content = $return['jquery_ready_content'];
353353

354354
// the $jquery_ready_content variable collects all functions that

main/inc/lib/message.lib.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -500,26 +500,24 @@ public static function send_message(
500500

501501
if ($allowPauseFormation) {
502502
$extraFieldValue = new ExtraFieldValue('user');
503-
$allowEmailNotifications = $extraFieldValue->get_values_by_handler_and_field_variable(
503+
$disableEmails = $extraFieldValue->get_values_by_handler_and_field_variable(
504504
$receiverUserId,
505-
'allow_notifications'
505+
'disable_emails'
506506
);
507507

508-
// User doesn't want email notifications but chamilo inbox still available (Option was not set)
509-
if (empty($allowEmailNotifications)) {
510-
$sendEmail = false;
511-
}
512-
513-
// User doesn't want email notifications but chamilo inbox still available. (Option was set to "No")
514-
if (!empty($allowEmailNotifications) &&
515-
isset($allowEmailNotifications['value']) && 0 === (int) $allowEmailNotifications['value']
508+
// User doesn't want email notifications but chamilo inbox still available.
509+
if (!empty($disableEmails) &&
510+
isset($disableEmails['value']) && 1 === (int) $disableEmails['value']
516511
) {
517512
$sendEmail = false;
518513
}
519514

520515
if ($sendEmail) {
521516
// Check if user pause his formation.
522-
$pause = $extraFieldValue->get_values_by_handler_and_field_variable($receiverUserId, 'pause_formation');
517+
$pause = $extraFieldValue->get_values_by_handler_and_field_variable(
518+
$receiverUserId,
519+
'pause_formation'
520+
);
523521
if (!empty($pause) && isset($pause['value']) && 1 === (int) $pause['value']) {
524522
$startDate = $extraFieldValue->get_values_by_handler_and_field_variable(
525523
$receiverUserInfo['user_id'],
@@ -536,7 +534,7 @@ public static function send_message(
536534
) {
537535
$now = time();
538536
$start = api_strtotime($startDate['value']);
539-
$end = api_strtotime($startDate['value']);
537+
$end = api_strtotime($endDate['value']);
540538

541539
if ($now > $start && $now < $end) {
542540
$sendEmail = false;

main/webservices/api/tests/UpdateUserPauseTrainingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testUpdate()
2727
'pause_formation' => 0,
2828
'start_pause_date' => '2020-06-30 10:00',
2929
'end_pause_date' => '2020-06-30 11:00',
30-
'allow_notifications' => 0,
30+
'disable_emails' => 1,
3131
];
3232
$userId = $this->integer($params);
3333

plugin/pausetraining/PauseTraining.php

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function updateUserPauseTraining($userId, $values)
3636
'pause_formation',
3737
'start_pause_date',
3838
'end_pause_date',
39-
'allow_notifications',
39+
'disable_emails',
4040
];
4141

4242
$valuesToUpdate = [
@@ -61,12 +61,12 @@ public function updateUserPauseTraining($userId, $values)
6161
$valuesToUpdate['extra_pause_formation']['extra_pause_formation'] = $pause;
6262
}
6363

64-
$notification = (int) $valuesToUpdate['extra_allow_notifications'];
64+
$notification = (int) $valuesToUpdate['extra_disable_emails'];
6565
if (empty($notification)) {
66-
$valuesToUpdate['extra_allow_notifications'] = 0;
66+
$valuesToUpdate['extra_disable_emails'] = 0;
6767
} else {
68-
$valuesToUpdate['extra_allow_notifications'] = [];
69-
$valuesToUpdate['extra_allow_notifications']['extra_allow_notifications'] = $notification;
68+
$valuesToUpdate['extra_disable_emails'] = [];
69+
$valuesToUpdate['extra_disable_emails']['extra_disable_emails'] = $notification;
7070
}
7171

7272
$check = DateTime::createFromFormat('Y-m-d H:i', $valuesToUpdate['extra_start_pause_date']);
@@ -119,7 +119,8 @@ public function runCron()
119119
$enableDaysList = explode(',', $enableDays);
120120
rsort($enableDaysList);
121121

122-
$loginTable = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
122+
$track = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
123+
$login = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
123124
$userTable = Database::get_main_table(TABLE_MAIN_USER);
124125
$now = api_get_utc_datetime();
125126
$usersNotificationPerDay = [];
@@ -128,16 +129,22 @@ public function runCron()
128129
$day = (int) $day;
129130

130131
$sql = "SELECT
131-
stats_login.user_id,
132-
MAX(stats_login.login_course_date) max_date
133-
FROM $loginTable stats_login
132+
t.user_id,
133+
MAX(t.logout_course_date) max_course_date,
134+
MAX(l.logout_date) max_login_date
135+
FROM $track t
134136
INNER JOIN $userTable u
135-
ON (u.id = stats_login.user_id)
137+
ON (u.id = t.user_id)
138+
INNER JOIN $login l
139+
ON (u.id = l.login_user_id)
136140
WHERE
137141
u.status <> ".ANONYMOUS." AND
138142
u.active = 1
139-
GROUP BY stats_login.user_id
140-
HAVING DATE_SUB('$now', INTERVAL '$day' DAY) > max_date ";
143+
GROUP BY t.user_id
144+
HAVING
145+
DATE_SUB('$now', INTERVAL '$day' DAY) > max_course_date AND
146+
DATE_SUB('$now', INTERVAL '$day' DAY) > max_login_date
147+
";
141148

142149
$rs = Database::query($sql);
143150
while ($user = Database::fetch_array($rs)) {
@@ -153,7 +160,6 @@ public function runCron()
153160

154161
if (!empty($usersNotificationPerDay)) {
155162
ksort($usersNotificationPerDay);
156-
$extraFieldValue = new ExtraFieldValue('user');
157163
foreach ($usersNotificationPerDay as $day => $userList) {
158164
$template = new Template();
159165
$title = sprintf($this->get_lang('InactivityXDays'), $day);
@@ -164,9 +170,11 @@ public function runCron()
164170
$template->assign('user', $userInfo);
165171
$content = $template->fetch('pausetraining/view/notification_content.tpl');
166172
MessageManager::send_message_simple($userId, $title, $content, $senderId);
173+
echo 'Sending message "'.$title.'" to user #'.$userId.' '.$userInfo['complete_name'].PHP_EOL;
167174
}
168175
}
169176
}
177+
exit;
170178
}
171179

172180
public function install()
@@ -193,9 +201,9 @@ public function install()
193201
);
194202

195203
UserManager::create_extra_field(
196-
'allow_notifications',
204+
'disable_emails',
197205
ExtraField::FIELD_TYPE_CHECKBOX,
198-
$this->get_lang('AllowEmailNotification'),
206+
$this->get_lang('DisableEmails'),
199207
''
200208
);
201209
}

plugin/pausetraining/lang/english.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
/* For licensing terms, see /license.txt */
4+
35
$strings['plugin_title'] = "Pause training";
46
$strings['plugin_comment'] = "";
57
$strings['tool_enable'] = 'Enable plugin';
@@ -10,7 +12,7 @@
1012
$strings['PauseFormation'] = 'Pause my formation';
1113
$strings['StartPauseDateTime'] = 'Start pause date';
1214
$strings['EndPauseDateTime'] = 'End pause date';
13-
$strings['AllowEmailNotification'] = 'Allow email notifications';
15+
$strings['DisableEmails'] = 'Disable email notifications';
1416
$strings['InactivityXDays'] = 'Inactivity for %s days';
1517
$strings['YouAreConnectedInPlatformXLinkXSinceXDays'] = '
1618
We have noticed that you have not connected to the platform %s (%s) for %s days.

plugin/pausetraining/lang/french.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
/* For licensing terms, see /license.txt */
4+
25
$strings['plugin_title'] = "Pause training";
36
$strings['plugin_comment'] = "";
47
$strings['tool_enable'] = 'Enable plugin';
@@ -9,7 +12,7 @@
912
$strings['PauseFormation'] = 'Mettre en pause ma formation';
1013
$strings['StartPauseDateTime'] = 'Date de début de pause';
1114
$strings['EndPauseDateTime'] = 'Date de fin de pause';
12-
$strings['AllowEmailNotification'] = 'Continuer à recevoir les mails de la plateforme';
15+
$strings['DisableEmails'] = 'Désactiver les e-mails ';
1316
$strings['InactivityXDays'] = 'Inactivité sur la plateforme depuis %s jours';
1417
$strings['YouAreConnectedInPlatformXLinkXSinceXDays'] = '
1518
Nous avons remarqué que vous ne vous êtes pas connecté à la plateforme %s (%s) depuis %s jours.

0 commit comments

Comments
 (0)