@@ -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 }
0 commit comments