1- <?php declare (strict_types=1 );
1+ <?php
2+
3+ declare (strict_types=1 );
24
35namespace LORIS \my_preferences ;
46
@@ -11,11 +13,11 @@ class My_Preferences extends \NDB_Form
1113{
1214 // Use gettext for error messages
1315 private const PASSWORD_ERROR_IS_EMAIL = 'Your password cannot be your email. ' ;
14- private const PASSWORD_ERROR_IS_USER =
15- 'Your password cannot be your user name. ' ;
16+ private const PASSWORD_ERROR_IS_USER
17+ = 'Your password cannot be your user name. ' ;
1618 private const PASSWORD_ERROR_NO_MATCH = 'The passwords do not match. ' ;
17- private const PASSWORD_ERROR_NO_CHANGE =
18- 'New and old passwords are identical: please choose another one ' ;
19+ private const PASSWORD_ERROR_NO_CHANGE
20+ = 'New and old passwords are identical: please choose another one ' ;
1921
2022 /**
2123 * Computes the initial values this page will be filled with.
@@ -59,22 +61,22 @@ class My_Preferences extends \NDB_Form
5961 }
6062 }
6163
62- foreach ($ defaults ['examiner ' ] as $ cid=> $ vals ) {
64+ foreach ($ defaults ['examiner ' ] as $ cid => $ vals ) {
6365 //sets pending approval info
64- if ($ cid== 'pending ' ) {
66+ if ($ cid == 'pending ' ) {
6567 $ defaults ['examiner_pending ' ] = $ vals ;
6668 continue ;
6769 }
6870 //gets radiologist Y/N from any of the active sites
69- if ($ vals [0 ]== 'Y ' ) {
70- if ($ vals [1 ]==='1 ' ) {
71+ if ($ vals [0 ] == 'Y ' ) {
72+ if ($ vals [1 ] === '1 ' ) {
7173 $ defaults ['examiner_radiologist ' ] = 'Y ' ;
7274 } else {
7375 $ defaults ['examiner_radiologist ' ] = 'N ' ;
7476 }
7577 }
76- if ($ vals [0 ]== 'Y ' ) {
77- $ defaults ['ex_ ' . $ cid ] ='on ' ;
78+ if ($ vals [0 ] == 'Y ' ) {
79+ $ defaults ['ex_ ' . $ cid ] = 'on ' ;
7880 }
7981 }
8082
@@ -83,13 +85,13 @@ class My_Preferences extends \NDB_Form
8385 $ curr_sub = \NDB_Notifier::getUserNotificationModuleServices (
8486 $ user ->getId ()
8587 );
86- foreach ($ curr_sub as $ module=> $ operations ) {
88+ foreach ($ curr_sub as $ module => $ operations ) {
8789 foreach ($ operations as $ operation => $ services ) {
8890 unset($ services ['desc ' ]);
8991 foreach ($ services as $ service => $ subscribed ) {
90- $ var_name = "notif_ " . $ module. "_ " . $ operation. "_ " . $ service ;
92+ $ var_name = "notif_ " . $ module . "_ " . $ operation . "_ " . $ service ;
9193
92- if ($ subscribed ==='Y ' ) {
94+ if ($ subscribed === 'Y ' ) {
9395 $ defaults [$ var_name ] = 'on ' ;
9496 }
9597 }
@@ -233,8 +235,10 @@ class My_Preferences extends \NDB_Form
233235 // - must have at least one non-whitespace characters (i.e. required)
234236 // - once leading and trailing spaces are stripped, the field should
235237 // not exceed 120 chars
236- $ firstNameInvalidMsg = dgettext ('my_preferences ' ,
237- "First name is required and should not exceed 120 characters " );
238+ $ firstNameInvalidMsg = dgettext (
239+ 'my_preferences ' ,
240+ "First name is required and should not exceed 120 characters "
241+ );
238242 $ this ->addBasicText (
239243 'First_name ' ,
240244 dgettext ('my_preferences ' , 'First name ' ),
@@ -250,8 +254,10 @@ class My_Preferences extends \NDB_Form
250254 // - must have at least one non-whitespace characters (i.e. required)
251255 // - once leading and trailing spaces are stripped, the field should
252256 // not exceed 120 chars
253- $ lastNameInvalidMsg = dgettext ('my_preferences ' ,
254- "Last name is required and should not exceed 120 characters " );
257+ $ lastNameInvalidMsg = dgettext (
258+ 'my_preferences ' ,
259+ "Last name is required and should not exceed 120 characters "
260+ );
255261 $ this ->addBasicText (
256262 'Last_name ' ,
257263 dgettext ('my_preferences ' , 'Last name ' ),
@@ -271,34 +277,55 @@ class My_Preferences extends \NDB_Form
271277 [],
272278 [
273279 'oninvalid ' => "this.setCustomValidity(
274- ' " . dgettext ('my_preferences ' ,
275- 'Email address is required ' ) . "') " ,
280+ ' " . dgettext (
281+ 'my_preferences ' ,
282+ 'Email address is required '
283+ ) . "') " ,
276284 'onchange ' => "this.setCustomValidity('') " ,
277285 ]
278286 );
279287
280288 // email address rules
281- $ this ->addRule ('Email ' , dgettext ('my_preferences ' ,
282- 'Email address is required ' ),
283- 'required ' );
284289 $ this ->addRule (
285290 'Email ' ,
286- dgettext ('my_preferences ' ,
287- 'Your email address must be less than 255 characters long ' ),
291+ dgettext (
292+ 'my_preferences ' ,
293+ 'Email address is required '
294+ ),
295+ 'required '
296+ );
297+ $ this ->addRule (
298+ 'Email ' ,
299+ dgettext (
300+ 'my_preferences ' ,
301+ 'Your email address must be less than 255 characters long '
302+ ),
288303 'maxlength ' ,
289304 "255 "
290305 );
291306
292307 // password
293- $ this ->form ->addElement ('password ' , 'Password_hash ' ,
294- dgettext ('my_preferences ' , 'New Password ' ));
295- $ this ->form ->addElement ('password ' , '__Confirm ' ,
296- dgettext ('my_preferences ' , 'Confirm Password ' ));
308+ $ this ->form ->addElement (
309+ 'password ' ,
310+ 'Password_hash ' ,
311+ dgettext ('my_preferences ' , 'New Password ' )
312+ );
313+ $ this ->form ->addElement (
314+ 'password ' ,
315+ '__Confirm ' ,
316+ dgettext ('my_preferences ' , 'Confirm Password ' )
317+ );
297318
298319 // language preference
299320 $ languages = \Utility::getLanguageList ();
300- $ this ->addSelect ('language_preference ' , dgettext ('my_preferences ' ,
301- 'Language preference ' ), $ languages );
321+ $ this ->addSelect (
322+ 'language_preference ' ,
323+ dgettext (
324+ 'my_preferences ' ,
325+ 'Language preference '
326+ ),
327+ $ languages
328+ );
302329
303330 // Notification headers
304331 $ nGroup = [];
@@ -318,46 +345,45 @@ class My_Preferences extends \NDB_Form
318345 unset($ nGroup );
319346
320347 // Notification rows
321- $ notification_rows =[];
322- foreach ($ notifier_list as $ module=> $ operation_services ) {
323- foreach ($ operation_services as $ operation=> $ services ) {
348+ $ notification_rows = [];
349+ foreach ($ notifier_list as $ module => $ operation_services ) {
350+ foreach ($ operation_services as $ operation => $ services ) {
324351 $ nGroup = [];
325352 $ nGroup [] = $ this ->createLabel ($ module );
326353 $ nGroup [] = $ this ->createLabel ($ operation );
327354 $ nGroup [] = $ this ->createLabel ($ services ['desc ' ]);
328355 unset($ services ['desc ' ]);
329356
330357 // Check for permissions
331- $ display =true ;
358+ $ display = true ;
332359 foreach ($ services ['perm ' ] as $ permission ) {
333360 if (!$ user ->hasPermission ($ permission )) {
334- $ display =false ;
361+ $ display = false ;
335362 break ;
336363 }
337364 }
338365 unset($ services ['perm ' ]);
339366
340- foreach ($ services as $ service=> $ avail ) {
341- if ($ avail ==='Y ' && $ display ) {
367+ foreach ($ services as $ service => $ avail ) {
368+ if ($ avail === 'Y ' && $ display ) {
342369 $ nGroup [] = $ this ->createCheckbox (
343- "notif_ " . $ module. "_ " . $ operation. "_ " . $ service ,
370+ "notif_ " . $ module . "_ " . $ operation . "_ " . $ service ,
344371 ""
345372 );
346373 } else {
347374 $ nGroup [] = $ this ->createLabel (
348375 dgettext ('my_preferences ' , "N/A " )
349376 );
350377 }
351-
352378 }
353379
354380 $ this ->addGroup (
355381 $ nGroup ,
356- "row_ " . $ module. "_ " . $ operation ,
382+ "row_ " . $ module . "_ " . $ operation ,
357383 '' ,
358384 $ this ->_GUIDelimiter
359385 );
360- $ notification_rows [] ="row_ " . $ module. "_ " . $ operation ;
386+ $ notification_rows [] = "row_ " . $ module . "_ " . $ operation ;
361387 unset($ nGroup );
362388 }
363389 }
@@ -405,21 +431,27 @@ class My_Preferences extends \NDB_Form
405431 $ plaintext = $ values ['Password_hash ' ];
406432
407433 if ($ values ['Email ' ] === $ plaintext ) {
408- $ errors ['Password_Group ' ] = dgettext ('my_preferences ' ,
409- self ::PASSWORD_ERROR_IS_EMAIL );
434+ $ errors ['Password_Group ' ] = dgettext (
435+ 'my_preferences ' ,
436+ self ::PASSWORD_ERROR_IS_EMAIL
437+ );
410438 }
411439
412440 // Make sure the user is not using their username as their password.
413441 if ($ this ->identifier === $ plaintext ) {
414- $ errors ['Password_Group ' ] = dgettext ('my_preferences ' ,
415- self ::PASSWORD_ERROR_IS_USER );
442+ $ errors ['Password_Group ' ] = dgettext (
443+ 'my_preferences ' ,
444+ self ::PASSWORD_ERROR_IS_USER
445+ );
416446 }
417447
418448 // Ensure that the password and confirm password fields match.
419449 // TODO This validation should be done on the front-end instead.
420450 if ($ values ['Password_hash ' ] !== $ values ['__Confirm ' ]) {
421- $ errors ['Password_Group ' ] = dgettext ('my_preferences ' ,
422- self ::PASSWORD_ERROR_NO_MATCH );
451+ $ errors ['Password_Group ' ] = dgettext (
452+ 'my_preferences ' ,
453+ self ::PASSWORD_ERROR_NO_MATCH
454+ );
423455 return $ errors ;
424456 }
425457
@@ -432,16 +464,21 @@ class My_Preferences extends \NDB_Form
432464 $ decoded = htmlspecialchars_decode ($ plaintext );
433465 new \Password ($ decoded );
434466 // New password must be different than current one
435- if (! \User::factory ($ this ->identifier )->isPasswordDifferent (
436- $ decoded
437- )
467+ if (
468+ ! \User::factory ($ this ->identifier )->isPasswordDifferent (
469+ $ decoded
470+ )
438471 ) {
439- $ errors ['Password_Group ' ] = dgettext ('my_preferences ' ,
440- self ::PASSWORD_ERROR_NO_CHANGE );
472+ $ errors ['Password_Group ' ] = dgettext (
473+ 'my_preferences ' ,
474+ self ::PASSWORD_ERROR_NO_CHANGE
475+ );
441476 }
442477 } catch (\InvalidArgumentException $ e ) {
443- $ errors ['Password_Group ' ] = dgettext ('my_preferences ' ,
444- $ e ->getMessage ());
478+ $ errors ['Password_Group ' ] = dgettext (
479+ 'my_preferences ' ,
480+ $ e ->getMessage ()
481+ );
445482 }
446483 }
447484
@@ -529,4 +566,3 @@ class My_Preferences extends \NDB_Form
529566 );
530567 }
531568}
532-
0 commit comments