本文整理汇总了PHP中webservice::get_external_service_by_shortname方法的典型用法代码示例。如果您正苦于以下问题:PHP webservice::get_external_service_by_shortname方法的具体用法?PHP webservice::get_external_service_by_shortname怎么用?PHP webservice::get_external_service_by_shortname使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webservice
的用法示例。
在下文中一共展示了webservice::get_external_service_by_shortname方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_site_info
/**
* 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);
}
示例2: write_setting
/**
* Save the selected setting
*
* @param string $data The selected site
* @return string empty string or error message
*/
public function write_setting($data)
{
global $DB, $CFG;
//for install cli script, $CFG->defaultuserroleid is not set so do nothing
if (empty($CFG->defaultuserroleid)) {
return '';
}
$servicename = MOODLE_OFFICIAL_MOBILE_SERVICE;
require_once $CFG->dirroot . '/webservice/lib.php';
$webservicemanager = new webservice();
if ((string) $data === $this->yes) {
//code run when enable mobile web service
//enable web service systeme if necessary
set_config('enablewebservices', true);
//enable mobile service
$mobileservice = $webservicemanager->get_external_service_by_shortname(MOODLE_OFFICIAL_MOBILE_SERVICE);
$mobileservice->enabled = 1;
$webservicemanager->update_external_service($mobileservice);
//enable xml-rpc server
$activeprotocols = empty($CFG->webserviceprotocols) ? array() : explode(',', $CFG->webserviceprotocols);
if (!in_array('xmlrpc', $activeprotocols)) {
$activeprotocols[] = 'xmlrpc';
set_config('webserviceprotocols', implode(',', $activeprotocols));
}
//allow xml-rpc:use capability for authenticated user
$this->set_xmlrpc_cap(true);
} else {
//disable web service system if no other services are enabled
$otherenabledservices = $DB->get_records_select('external_services', 'enabled = :enabled AND (shortname != :shortname OR shortname IS NULL)', array('enabled' => 1, 'shortname' => MOODLE_OFFICIAL_MOBILE_SERVICE));
if (empty($otherenabledservices)) {
set_config('enablewebservices', false);
//also disable xml-rpc server
$activeprotocols = empty($CFG->webserviceprotocols) ? array() : explode(',', $CFG->webserviceprotocols);
$protocolkey = array_search('xmlrpc', $activeprotocols);
if ($protocolkey !== false) {
unset($activeprotocols[$protocolkey]);
set_config('webserviceprotocols', implode(',', $activeprotocols));
}
//disallow xml-rpc:use capability for authenticated user
$this->set_xmlrpc_cap(false);
}
//disable the mobile service
$mobileservice = $webservicemanager->get_external_service_by_shortname(MOODLE_OFFICIAL_MOBILE_SERVICE);
$mobileservice->enabled = 0;
$webservicemanager->update_external_service($mobileservice);
}
return parent::write_setting($data);
}