@@ -391,9 +391,26 @@ public function load_users() {
391
391
$ this ->users = array ();
392
392
$ this ->userselect_params = array ();
393
393
} else {
394
- list ($ usql , $ params ) = $ DB ->get_in_or_equal (array_keys ($ this ->users ), SQL_PARAMS_NAMED , 'usid0 ' );
394
+ list ($ usql , $ uparams ) = $ DB ->get_in_or_equal (array_keys ($ this ->users ), SQL_PARAMS_NAMED , 'usid0 ' );
395
395
$ this ->userselect = "AND g.userid $ usql " ;
396
- $ this ->userselect_params = $ params ;
396
+ $ this ->userselect_params = $ uparams ;
397
+
398
+ //add a flag to each user indicating whether their enrolment is active
399
+ $ sql = "SELECT ue.userid
400
+ FROM {user_enrolments} ue
401
+ JOIN {enrol} e ON e.id = ue.enrolid
402
+ WHERE ue.userid $ usql
403
+ AND ue.status = :uestatus
404
+ AND e.status = :estatus
405
+ AND e.courseid = :courseid
406
+ GROUP BY ue.userid " ;
407
+ $ coursecontext = get_course_context ($ this ->context );
408
+ $ params = array_merge ($ uparams , array ('estatus ' =>ENROL_INSTANCE_ENABLED , 'uestatus ' =>ENROL_USER_ACTIVE , 'courseid ' =>$ coursecontext ->instanceid ));
409
+ $ useractiveenrolments = $ DB ->get_records_sql ($ sql , $ params );
410
+
411
+ foreach ($ this ->users as $ user ) {
412
+ $ this ->users [$ user ->id ]->suspendedenrolment = !array_key_exists ($ user ->id , $ useractiveenrolments );
413
+ }
397
414
}
398
415
399
416
return $ this ->users ;
@@ -602,13 +619,15 @@ public function get_left_rows() {
602
619
603
620
$ rowclasses = array ('even ' , 'odd ' );
604
621
622
+ $ suspendedstring = null ;
605
623
foreach ($ this ->users as $ userid => $ user ) {
606
624
$ userrow = new html_table_row ();
607
625
$ userrow ->id = 'fixed_user_ ' .$ userid ;
608
626
$ userrow ->attributes ['class ' ] = 'r ' .$ this ->rowcount ++.' ' .$ rowclasses [$ this ->rowcount % 2 ];
609
627
610
628
$ usercell = new html_table_cell ();
611
629
$ usercell ->attributes ['class ' ] = 'user ' ;
630
+
612
631
$ usercell ->header = true ;
613
632
$ usercell ->scope = 'row ' ;
614
633
@@ -618,6 +637,16 @@ public function get_left_rows() {
618
637
619
638
$ usercell ->text .= html_writer::link (new moodle_url ('/user/view.php ' , array ('id ' => $ user ->id , 'course ' => $ this ->course ->id )), fullname ($ user ));
620
639
640
+ if (!empty ($ user ->suspendedenrolment )) {
641
+ $ usercell ->attributes ['class ' ] .= ' usersuspended ' ;
642
+
643
+ //may be lots of suspended users so only get the string once
644
+ if (empty ($ suspendedstring )) {
645
+ $ suspendedstring = get_string ('userenrolmentsuspended ' , 'grades ' );
646
+ }
647
+ $ usercell ->text .= html_writer::empty_tag ('img ' , array ('src ' =>$ OUTPUT ->pix_url ('i/enrolmentsuspended ' ), 'title ' =>$ suspendedstring , 'alt ' =>$ suspendedstring , 'class ' =>'usersuspendedicon ' ));
648
+ }
649
+
621
650
$ userrow ->cells [] = $ usercell ;
622
651
623
652
if (has_capability ('gradereport/ ' .$ CFG ->grade_profilereport .':view ' , $ this ->context )) {
0 commit comments