Hi Juan,
I am waiting for the reply. Below is the description of the web service for forum rating.
I am passing following parameters for calling forum rating
forumid, itemid, scaleid, rating, userid.
It also need cm and context id that I am calculating in the forum rating function. Its working fine if I run from client.php, but when I call the web service from mobile app It gives an error "Invalid parameters are detected." And the message in debug info is "Missing required key in single structure: rate" . There are actually 2 cases: 1. if I pass data "Invalid parameters are detected." error comes. 2. If I pass d "We lost connection you need to reconnect.Your token is invalid." However if I call the forum_rating webservice by client.php it works fine.
Below I am sharing the ratepost function code.
ratepost: function(forumId, userid, ratevalue, postid, scaleid ) {
var data = {
"post[0][forumid]" : forumId,
"post[0][itemid]" : postid,
"post[0][scaleid]" : scaleid,
"post[0][rating]" : ratevalue,
"post[0][userid]" : userid
};
var d = new Array();
d[0] = data;
MM.moodleWSCall('local_forum_rating', data, function(resrate) {
alert("check");
});
}
Forum rating webservice
public static function forum_rating_parameters() {
return new external_function_parameters(
array(
'rate' => new external_multiple_structure(
new external_single_structure(
array(
'forumid' => new external_value(PARAM_INT, 'contextid'),
'itemid' => new external_value(PARAM_INT, 'itemid'),
'scaleid' => new external_value(PARAM_INT, 'scaleid'),
'rating' => new external_value(PARAM_INT, 'rating'),
'userid' => new external_value(PARAM_INT, 'userid'),
)
)
)
)
);
}
public static function forum_rating($rate = array()) {
global $CFG, $DB;
require_once($CFG->dirroot . '/rating/lib.php');
$ob = array();
$params = self::validate_parameters(self::forum_rating_parameters(), array('rate' => $rate));
$rateperpost = $params['rate'];
foreach ($rateperpost as $rateonpost) {
$userrating = $rateonpost['rating'];
$forumid = $rateonpost['forumid'];
$cm = get_coursemodule_from_id('forum', $forumid);
$context = context_module::instance($cm->id);
if ($userrating != RATING_UNSET_RATING) {
$ratingoptions = new stdClass;
$ratingoptions->context = $context;
$ratingoptions->component = 'mod_forum';
$ratingoptions->ratingarea = 'post';
$ratingoptions->itemid = $rateonpost['itemid'];
$ratingoptions->scaleid = $rateonpost['scaleid'];
$ratingoptions->userid = $rateonpost['userid'];
$rating = new rating($ratingoptions);
$rating->update_rating($userrating);
// $html[] = (array)$group;
$html[] = array('rate' => $userrating);
}
}
return $html;
}
public static function forum_rating_returns() {
return new external_multiple_structure(
new external_single_structure(
array(
'rate' => new external_value(PARAM_RAW, 'rating'),
)
)
);
}
Please let me know why am I unable to call the web service by mobile app? Thanks in advance.