Thanks
Here's my code at this stage. Not working yet. Grateful for any extra help.
define(['jquery', 'core/notification','core/ajax'],
function($, notification, ajax) {
function Ajaxcall() {
this.value = "ajax ok";
};
Ajaxcall.prototype.loadsettings = function() {
ajax.call([{
methodname: 'mod_testtest_loadsettings',
args: {itemID: 1},
done: console.log("ajax done"),//how can I get the result?
fail: notification.exception
}]);
};
return Ajaxcall;
});
<?php
require_once("$CFG->libdir/externallib.php");
class mod_testtest extends external_api {
public static function loadsettings_parameters() {
return new external_function_parameters(
array(
'settings' => new external_multiple_structure(
new external_single_structure(
array(
'itemID' => new external_value(PARAM_INT, 'id of current activity'),
)
)
)
)
);
}
public static function loadsettings_returns() {
return new external_multiple_structure(
new external_single_structure(
array(
'content' => new external_value(PARAM_RAW, 'settings content text'),
)
)
);
}
public static function loadsettings($itemID) {
global $CFG, $DB;
//$params = self::validate_parameters(self::getExample_parameters(), array());
$params = self::validate_parameters(self::loadsettings_parameters(), array('settings'=>$itemID));
$sql = 'SELECT content FROM {testtest} WHERE id = ?';
$params = array($itemID);
$db_result = $DB->get_records_sql($sql,$params);
return $db_result;
}
}
<?php
$services = array(
'mypluginservice' => array( //the name of the web service
'functions' => array ('mod_testtest_loadsettings'), //web service functions of this service
'requiredcapability' => '', //if set, the web service user need this capability to access
//any function of this service. For example: 'some/capability:specified'
'restrictedusers' =>0, //if enabled, the Moodle administrator must link some user to this service
//into the administration
'enabled'=>1, //if enabled, the service can be reachable on a default installation
)
);
$functions = array(
'mod_testtest_loadsettings' => array(
'classname' => 'mod_testtest_external',
'methodname' => 'loadsettings',
'classpath' => 'mod/testtest/externallib.php',
'description' => 'Load settings data',
'type' => 'read',
'ajax' => true,
'loginrequired' => true,
)
);