Merge branch 'MDL-27564-wip' of git://github.com/mouneyrac/moodle with changes for...
[moodle.git] / enrol / externallib.php
index a9dad34..9813ef5 100644 (file)
@@ -64,7 +64,12 @@ class moodle_enrol_external extends external_api {
 
         // Do basic automatic PARAM checks on incoming data, using params description
         // If any problems are found then exceptions are thrown with helpful error messages
-        $params = self::validate_parameters(self::get_enrolled_users_parameters(), array('courseid'=>$courseid, 'withcapability'=>$withcapability, 'groupid'=>$groupid, 'onlyactive'=>$onlyactive));
+        $params = self::validate_parameters(self::get_enrolled_users_parameters(), array(
+            'courseid'=>$courseid,
+            'withcapability'=>$withcapability,
+            'groupid'=>$groupid,
+            'onlyactive'=>$onlyactive)
+        );
 
         $coursecontext = get_context_instance(CONTEXT_COURSE, $params['courseid']);
         if ($courseid == SITEID) {
@@ -76,11 +81,10 @@ class moodle_enrol_external extends external_api {
         try {
             self::validate_context($context);
         } catch (Exception $e) {
-                $exceptionparam = new stdClass();
-                $exceptionparam->message = $e->getMessage();
-                $exceptionparam->courseid = $params['courseid'];
-                throw new moodle_exception(
-                        get_string('errorcoursecontextnotvalid' , 'webservice', $exceptionparam));
+            $exceptionparam = new stdClass();
+            $exceptionparam->message = $e->getMessage();
+            $exceptionparam->courseid = $params['courseid'];
+            throw new moodle_exception(get_string('errorcoursecontextnotvalid' , 'webservice', $exceptionparam));
         }
 
         if ($courseid == SITEID) {
@@ -92,10 +96,8 @@ class moodle_enrol_external extends external_api {
         if ($withcapability) {
             require_capability('moodle/role:review', $coursecontext);
         }
-        if ($groupid) {
-            if (groups_is_member($groupid)) {
-                require_capability('moodle/site:accessallgroups', $coursecontext);
-            }
+        if ($groupid && groups_is_member($groupid)) {
+            require_capability('moodle/site:accessallgroups', $coursecontext);
         }
         if ($onlyactive) {
             require_capability('moodle/course:enrolreview', $coursecontext);
@@ -112,20 +114,24 @@ class moodle_enrol_external extends external_api {
         $params['courseid'] = $courseid;
         $enrolledusers = $DB->get_records_sql($sql, $params);
         $result = array();
+        $isadmin = is_siteadmin($USER);
+        $canviewfullnames = has_capability('moodle/site:viewfullnames', $context);
         foreach ($enrolledusers as $enrolleduser) {
             $profilimgurl = moodle_url::make_pluginfile_url($enrolleduser->usercontextid, 'user', 'icon', NULL, '/', 'f1');
             $profilimgurlsmall = moodle_url::make_pluginfile_url($enrolleduser->usercontextid, 'user', 'icon', NULL, '/', 'f2');
-            $resultuser = array('courseid' => $enrolleduser->courseid,
-                'userid' => $enrolleduser->userid, 'fullname' => fullname($enrolleduser),
+            $resultuser = array(
+                'courseid' => $enrolleduser->courseid,
+                'userid' => $enrolleduser->userid, 
+                'fullname' => fullname($enrolleduser),
                 'profileimgurl' => $profilimgurl->out(false),
-                'profileimgurlsmall' => $profilimgurlsmall->out(false));
-            //check if we can return username
-            $isadmin = is_siteadmin($USER);
+                'profileimgurlsmall' => $profilimgurlsmall->out(false)
+            );
+            // check if we can return username
             if ($isadmin) {
                 $resultuser['username'] = $enrolleduser->username;
             }
-            //check if we can return first and last name
-            if ($isadmin or has_capability('moodle/site:viewfullnames', $context)) {
+            // check if we can return first and last name
+            if ($isadmin or $canviewfullnames) {
                 $resultuser['firstname'] = $enrolleduser->firstname;
                 $resultuser['lastname'] = $enrolleduser->lastname;
             }
@@ -156,7 +162,6 @@ class moodle_enrol_external extends external_api {
         );
     }
 
-
     /**
      * Returns description of method parameters
      * @return external_function_parameters