Ejemplo n.º 1
0
 /**
  * Return user information including profile picture + basic site information
  * Note:
  * - no capability checking because we return just known information by logged user
  * @param array $serviceshortnames of service shortnames - the functions of these services will be returned
  * @return array
  */
 public function get_site_info($serviceshortnames = array())
 {
     global $USER, $SITE, $CFG;
     $params = self::validate_parameters(self::get_site_info_parameters(), array('serviceshortnames' => $serviceshortnames));
     $profileimageurl = moodle_url::make_pluginfile_url(get_context_instance(CONTEXT_USER, $USER->id)->id, 'user', 'icon', NULL, '/', 'f1');
     require_once $CFG->dirroot . "/webservice/lib.php";
     $webservice = new webservice();
     //If no service listed always return the mobile one by default
     if (empty($params['serviceshortnames']) and $CFG->enablewebservices) {
         $mobileservice = $webservice->get_external_service_by_shortname(MOODLE_OFFICIAL_MOBILE_SERVICE);
         if ($mobileservice->enabled) {
             $params['serviceshortnames'] = array(MOODLE_OFFICIAL_MOBILE_SERVICE);
             //return mobile service by default
         }
     }
     //retrieve the functions related to the services
     $functions = $webservice->get_external_functions_by_enabled_services($params['serviceshortnames']);
     //built up the returned values of the list of functions
     $componentversions = array();
     $avalaiblefunctions = array();
     foreach ($functions as $function) {
         $functioninfo = array();
         $functioninfo['name'] = $function->name;
         if ($function->component == 'moodle') {
             $version = $CFG->version;
             //moodle version
         } else {
             $versionpath = get_component_directory($function->component) . '/version.php';
             if (is_readable($versionpath)) {
                 //we store the component version once retrieved (so we don't load twice the version.php)
                 if (!isset($componentversions[$function->component])) {
                     include $versionpath;
                     $componentversions[$function->component] = $plugin->version;
                     $version = $plugin->version;
                 } else {
                     $version = $componentversions[$function->component];
                 }
             } else {
                 //function component should always have a version.php,
                 //otherwise the function should have been described with component => 'moodle'
                 throw new moodle_exception('missingversionfile', 'webservice', '', $function->component);
             }
         }
         $functioninfo['version'] = $version;
         $avalaiblefunctions[] = $functioninfo;
     }
     return array('sitename' => $SITE->fullname, 'siteurl' => $CFG->wwwroot, 'username' => $USER->username, 'firstname' => $USER->firstname, 'lastname' => $USER->lastname, 'fullname' => fullname($USER), 'userid' => $USER->id, 'userpictureurl' => $profileimageurl->out(false), 'functions' => $avalaiblefunctions);
 }