1
- <?php declare (strict_types=1 );
1
+ <?php
2
+
3
+ declare (strict_types=1 );
2
4
3
5
namespace LORIS \my_preferences ;
4
6
@@ -11,11 +13,11 @@ class My_Preferences extends \NDB_Form
11
13
{
12
14
// Use gettext for error messages
13
15
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. ' ;
16
18
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 ' ;
19
21
20
22
/**
21
23
* Computes the initial values this page will be filled with.
@@ -59,22 +61,22 @@ class My_Preferences extends \NDB_Form
59
61
}
60
62
}
61
63
62
- foreach ($ defaults ['examiner ' ] as $ cid=> $ vals ) {
64
+ foreach ($ defaults ['examiner ' ] as $ cid => $ vals ) {
63
65
//sets pending approval info
64
- if ($ cid== 'pending ' ) {
66
+ if ($ cid == 'pending ' ) {
65
67
$ defaults ['examiner_pending ' ] = $ vals ;
66
68
continue ;
67
69
}
68
70
//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 ' ) {
71
73
$ defaults ['examiner_radiologist ' ] = 'Y ' ;
72
74
} else {
73
75
$ defaults ['examiner_radiologist ' ] = 'N ' ;
74
76
}
75
77
}
76
- if ($ vals [0 ]== 'Y ' ) {
77
- $ defaults ['ex_ ' . $ cid ] ='on ' ;
78
+ if ($ vals [0 ] == 'Y ' ) {
79
+ $ defaults ['ex_ ' . $ cid ] = 'on ' ;
78
80
}
79
81
}
80
82
@@ -83,13 +85,13 @@ class My_Preferences extends \NDB_Form
83
85
$ curr_sub = \NDB_Notifier::getUserNotificationModuleServices (
84
86
$ user ->getId ()
85
87
);
86
- foreach ($ curr_sub as $ module=> $ operations ) {
88
+ foreach ($ curr_sub as $ module => $ operations ) {
87
89
foreach ($ operations as $ operation => $ services ) {
88
90
unset($ services ['desc ' ]);
89
91
foreach ($ services as $ service => $ subscribed ) {
90
- $ var_name = "notif_ " . $ module. "_ " . $ operation. "_ " . $ service ;
92
+ $ var_name = "notif_ " . $ module . "_ " . $ operation . "_ " . $ service ;
91
93
92
- if ($ subscribed ==='Y ' ) {
94
+ if ($ subscribed === 'Y ' ) {
93
95
$ defaults [$ var_name ] = 'on ' ;
94
96
}
95
97
}
@@ -233,8 +235,10 @@ class My_Preferences extends \NDB_Form
233
235
// - must have at least one non-whitespace characters (i.e. required)
234
236
// - once leading and trailing spaces are stripped, the field should
235
237
// 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
+ );
238
242
$ this ->addBasicText (
239
243
'First_name ' ,
240
244
dgettext ('my_preferences ' , 'First name ' ),
@@ -250,8 +254,10 @@ class My_Preferences extends \NDB_Form
250
254
// - must have at least one non-whitespace characters (i.e. required)
251
255
// - once leading and trailing spaces are stripped, the field should
252
256
// 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
+ );
255
261
$ this ->addBasicText (
256
262
'Last_name ' ,
257
263
dgettext ('my_preferences ' , 'Last name ' ),
@@ -271,34 +277,55 @@ class My_Preferences extends \NDB_Form
271
277
[],
272
278
[
273
279
'oninvalid ' => "this.setCustomValidity(
274
- ' " . dgettext ('my_preferences ' ,
275
- 'Email address is required ' ) . "') " ,
280
+ ' " . dgettext (
281
+ 'my_preferences ' ,
282
+ 'Email address is required '
283
+ ) . "') " ,
276
284
'onchange ' => "this.setCustomValidity('') " ,
277
285
]
278
286
);
279
287
280
288
// email address rules
281
- $ this ->addRule ('Email ' , dgettext ('my_preferences ' ,
282
- 'Email address is required ' ),
283
- 'required ' );
284
289
$ this ->addRule (
285
290
'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
+ ),
288
303
'maxlength ' ,
289
304
"255 "
290
305
);
291
306
292
307
// 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
+ );
297
318
298
319
// language preference
299
320
$ 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
+ );
302
329
303
330
// Notification headers
304
331
$ nGroup = [];
@@ -318,46 +345,45 @@ class My_Preferences extends \NDB_Form
318
345
unset($ nGroup );
319
346
320
347
// 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 ) {
324
351
$ nGroup = [];
325
352
$ nGroup [] = $ this ->createLabel ($ module );
326
353
$ nGroup [] = $ this ->createLabel ($ operation );
327
354
$ nGroup [] = $ this ->createLabel ($ services ['desc ' ]);
328
355
unset($ services ['desc ' ]);
329
356
330
357
// Check for permissions
331
- $ display =true ;
358
+ $ display = true ;
332
359
foreach ($ services ['perm ' ] as $ permission ) {
333
360
if (!$ user ->hasPermission ($ permission )) {
334
- $ display =false ;
361
+ $ display = false ;
335
362
break ;
336
363
}
337
364
}
338
365
unset($ services ['perm ' ]);
339
366
340
- foreach ($ services as $ service=> $ avail ) {
341
- if ($ avail ==='Y ' && $ display ) {
367
+ foreach ($ services as $ service => $ avail ) {
368
+ if ($ avail === 'Y ' && $ display ) {
342
369
$ nGroup [] = $ this ->createCheckbox (
343
- "notif_ " . $ module. "_ " . $ operation. "_ " . $ service ,
370
+ "notif_ " . $ module . "_ " . $ operation . "_ " . $ service ,
344
371
""
345
372
);
346
373
} else {
347
374
$ nGroup [] = $ this ->createLabel (
348
375
dgettext ('my_preferences ' , "N/A " )
349
376
);
350
377
}
351
-
352
378
}
353
379
354
380
$ this ->addGroup (
355
381
$ nGroup ,
356
- "row_ " . $ module. "_ " . $ operation ,
382
+ "row_ " . $ module . "_ " . $ operation ,
357
383
'' ,
358
384
$ this ->_GUIDelimiter
359
385
);
360
- $ notification_rows [] ="row_ " . $ module. "_ " . $ operation ;
386
+ $ notification_rows [] = "row_ " . $ module . "_ " . $ operation ;
361
387
unset($ nGroup );
362
388
}
363
389
}
@@ -405,21 +431,27 @@ class My_Preferences extends \NDB_Form
405
431
$ plaintext = $ values ['Password_hash ' ];
406
432
407
433
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
+ );
410
438
}
411
439
412
440
// Make sure the user is not using their username as their password.
413
441
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
+ );
416
446
}
417
447
418
448
// Ensure that the password and confirm password fields match.
419
449
// TODO This validation should be done on the front-end instead.
420
450
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
+ );
423
455
return $ errors ;
424
456
}
425
457
@@ -432,16 +464,21 @@ class My_Preferences extends \NDB_Form
432
464
$ decoded = htmlspecialchars_decode ($ plaintext );
433
465
new \Password ($ decoded );
434
466
// 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
+ )
438
471
) {
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
+ );
441
476
}
442
477
} 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
+ );
445
482
}
446
483
}
447
484
@@ -529,4 +566,3 @@ class My_Preferences extends \NDB_Form
529
566
);
530
567
}
531
568
}
532
-
0 commit comments