@@ -59,24 +59,29 @@ public static function execute(string $query, string $capability): array {
5959 self ::validate_context ($ context );
6060 require_capability ('report/customsql:definequeries ' , $ context );
6161
62- $ extrafields = get_extra_user_fields ($ context );
62+ if (class_exists ('\core_user\fields ' )) {
63+ $ extrafields = \core_user \fields::for_identity ($ context , false )->get_required_fields ();
64+ $ fields = \core_user \fields::for_identity ($ context ,
65+ false )->with_userpic ()->get_sql ('u ' , false , '' , '' , false )->selects ;
66+ } else {
67+ $ extrafields = get_extra_user_fields ($ context );
68+ $ fields = \user_picture::fields ('u ' , $ extrafields );
69+ }
6370
64- $ fields = array_merge (['u.id ' ], preg_split ('~\s*,\s*~ ' ,
65- \user_picture::fields ('u ' )), $ extrafields );
6671 $ withcapabilityjoin = get_with_capability_join ($ context , $ capability , 'u.id ' );
6772 [$ wherecondition , $ whereparams ] = users_search_sql ($ query , 'u ' , true , $ extrafields );
6873 [$ sort , $ sortparams ] = users_order_by_sql ('u ' , $ query , $ context );
6974
7075 $ users = $ DB ->get_records_sql ("
71- SELECT " . implode ( ' , ' , $ fields) . "
76+ SELECT $ fields
7277 FROM {user} u
7378
7479 JOIN (
7580
7681 SELECT id
7782 FROM {user} u
78- { $ withcapabilityjoin ->joins }
79- WHERE { $ withcapabilityjoin ->wheres }
83+ $ withcapabilityjoin ->joins
84+ WHERE $ withcapabilityjoin ->wheres
8085
8186 UNION
8287
0 commit comments