Is web service is allowed for moodle block???

Is web service is allowed for moodle block???

by Abhishek Pawar -
Number of replies: 0

Dear all,


Good morning


I want to know that Is web service is allowed for moodle block???


Please reply me .

Thanks and Regards,

Abhishek



Hey hi all,

I am beginner in moodle web service. Please provide me your valuable opinions 

this is my two file service.php and externallib.php 

I already upgrade plugin version.php


Please help me what should i do for this error

////////////////////////////// service.php //////////////////////////////


<?php

$services = array(
'readytohelpservice' => array(
'functions' => array ('block_readytohelp_list_cat'),
'requiredcapability' => '',
'restrictedusers' => 0,
'enabled'=>1,
)
);

$functions = array(
'block_readytohelp_list_cat' => array(
'classname' => 'block_readytohelp_external',
'methodname' => 'list_cat',
'classpath' => 'blocks/readytohelp/externallib.php',
'description' => 'Return Hello World FIRSTNAME. Can change the text (Hello World) sending a new text as parameter',
'type' => 'read',
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE)
)
);

////////////////////////////// externallib.php //////////////////////////////


<?php

require_once($CFG->libdir . "/externallib.php");

class block_readytohelp_external extends external_api {
/**
* Returns description of method parameters
* @return external_function_parameters
*/
public static function list_cat_parameters() {
return new external_function_parameters(
array('welcomemessage' => new external_value(PARAM_TEXT, 'The welcome message. By default it is "Hello world,"', VALUE_DEFAULT, 'Hello world, '))
);
}
/**
* Returns welcome message
* @return string welcome message
*/
public static function list_cat($welcomemessage = 'Hello world, ') {
global $USER;
//Parameter validation
//REQUIRED
$params = self::validate_parameters(self::list_cat_parameters(),
array('welcomemessage' => $welcomemessage));
//Context validation
//OPTIONAL but in most web service it should present
$context = get_context_instance(CONTEXT_USER, $USER->id);
self::validate_context($context);
//Capability checking
//OPTIONAL but in most web service it should present
if (!has_capability('moodle/user:viewdetails', $context)) {
throw new moodle_exception('cannotviewprofile');
}
return $params['welcomemessage'] . $USER->firstname ;;
}
/**
* Returns description of method result value
* @return external_description
*/
public static function list_cat_returns() {
return new external_value(PARAM_TEXT, 'The welcome message + user first name');
}
}

Average of ratings: -