diff --git a/group/externallib.php b/group/externallib.php index 800f12ec4bb..97e5170d37b 100644 --- a/group/externallib.php +++ b/group/externallib.php @@ -124,15 +124,14 @@ class moodle_group_external extends external_api { } /** - * Get groups definition + * Get groups definition specified by ids * @param array $groupids arrays of group ids * @return array of group objects (id, courseid, name, enrolmentkey) */ public static function get_groups($groupids) { - $groups = array(); - $params = self::validate_parameters(self::get_groups_parameters(), array('groupids'=>$groupids)); + $groups = array(); foreach ($params['groupids'] as $groupid) { // validate params $group = groups_get_group($groupid, 'id, courseid, name, description, enrolmentkey', MUST_EXIST); @@ -166,6 +165,59 @@ class moodle_group_external extends external_api { ); } + /** + * Returns description of method parameters + * @return external_function_parameters + */ + public static function get_course_groups_parameters() { + return new external_function_parameters( + array( + 'courseid' => new external_value(PARAM_INT, 'id of course'), + ) + ); + } + + /** + * Get all groups in the specified course + * @param int $courseid id of course + * @return array of group objects (id, courseid, name, enrolmentkey) + */ + public static function get_course_groups($courseid) { + $params = self::validate_parameters(self::get_course_groups_parameters(), array('courseid'=>$courseid)); + + // now security checks + $context = get_context_instance(CONTEXT_COURSE, $params['courseid']); + self::validate_context($context); + require_capability('moodle/course:managegroups', $context); + + $gs = groups_get_all_groups($params['courseid'], 0, 0, 'g.id, g.courseid, g.name, g.description, g.enrolmentkey'); + + $groups = array(); + foreach ($gs as $group) { + $groups[] = (array)$group; + } + + return $groups; + } + + /** + * Returns description of method result value + * @return external_description + */ + public static function get_course_groups_returns() { + return new external_multiple_structure( + new external_single_structure( + array( + 'id' => new external_value(PARAM_INT, 'group record id'), + 'courseid' => new external_value(PARAM_INT, 'id of course'), + 'name' => new external_value(PARAM_TEXT, 'multilang compatible name, course unique'), + 'description' => new external_value(PARAM_RAW, 'group description text'), + 'enrolmentkey' => new external_value(PARAM_RAW, 'group enrol secret phrase'), + ) + ) + ); + } + public static function delete_groups_parameters() { //TODO } diff --git a/lib/db/services.php b/lib/db/services.php index 72a30600c38..56447df2e10 100644 --- a/lib/db/services.php +++ b/lib/db/services.php @@ -43,6 +43,15 @@ $functions = array( 'description' => 'Returns group details.', 'type' => 'read', ), + + 'moodle_group_get_course_groups' => array( + 'classname' => 'moodle_group_external', + 'methodname' => 'get_course_groups', + 'classpath' => 'group/externallib.php', + 'description' => 'Returns all groups in specified course.', + 'type' => 'read', + ), + /* 'moodle_group_delete_groups' => array( 'classname' => 'moodle_group_external', diff --git a/version.php b/version.php index 8ef71103da9..3c7e5db8ac1 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2009102200; // YYYYMMDD = date of the last version bump + $version = 2009102201; // YYYYMMDD = date of the last version bump // XX = daily increments $release = '2.0 dev (Build: 20091022)'; // Human-friendly version name diff --git a/webservice/rest/locallib.php b/webservice/rest/locallib.php index 03e3a345daa..c6eab0d5a7e 100644 --- a/webservice/rest/locallib.php +++ b/webservice/rest/locallib.php @@ -140,8 +140,8 @@ class webservice_rest_server extends webservice_base_server { $single = ''."\n"; foreach ($desc->keys as $key=>$subdesc) { if (!array_key_exists($key, $returns)) { - if ($subdesc->rewquired) { - $single .= 'Missing required key'; + if ($subdesc->required) { + $single .= 'Missing required key "'.$key.'"'; continue; } else { //optional field diff --git a/webservice/testclient.php b/webservice/testclient.php index c2e6829fff2..f6b2de85ea6 100644 --- a/webservice/testclient.php +++ b/webservice/testclient.php @@ -36,7 +36,8 @@ require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)); // list of all available functions for testing - please note there must be explicit // support for testing of each functions, the parameter conversion and form is hardcoded -$functions = array('moodle_group_create_groups', 'moodle_group_get_groups'); +// TODO: automate this list by fetching all known functiosn from db and looking if client form defined +$functions = array('moodle_group_create_groups', 'moodle_group_get_groups', 'moodle_group_get_course_groups'); $functions = array_combine($functions, $functions); if (!isset($functions[$function])) { // whitelisting security $function = ''; @@ -109,6 +110,9 @@ if ($mform->is_cancelled()) { $params['groupids'][] = $data->groupids[$i]; } + } else if ($function === 'moodle_group_get_course_groups') { + $params['courseid'] = $data->courseid; + } else { throw new coding_exception('Testing of function '.$function.' not implemented yet!'); } diff --git a/webservice/testclient_forms.php b/webservice/testclient_forms.php index 0221e9974c4..08ddef3a3a0 100644 --- a/webservice/testclient_forms.php +++ b/webservice/testclient_forms.php @@ -22,32 +22,6 @@ class webservice_test_client_form extends moodleform { // === Test client forms === -class moodle_group_get_groups_form extends moodleform { - public function definition() { - global $CFG; - - $mform = $this->_form; - - $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice')); - - //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters - $mform->addElement('text', 'wsusername', 'wsusername'); - $mform->addElement('text', 'wspassword', 'wspassword'); - $mform->addElement('text', 'groupids[0]', 'groupids[0]'); - $mform->addElement('text', 'groupids[1]', 'groupids[1]'); - $mform->addElement('text', 'groupids[2]', 'groupids[2]'); - $mform->addElement('text', 'groupids[3]', 'groupids[3]'); - - $mform->addElement('hidden', 'function'); - $mform->setType('function', PARAM_SAFEDIR); - - $mform->addElement('hidden', 'protocol'); - $mform->setType('protocol', PARAM_SAFEDIR); - - $this->add_action_buttons(true, get_string('execute', 'webservice')); - } -} - class moodle_group_create_groups_form extends moodleform { public function definition() { global $CFG; @@ -75,3 +49,53 @@ class moodle_group_create_groups_form extends moodleform { $this->add_action_buttons(true, get_string('execute', 'webservice')); } } + +class moodle_group_get_groups_form extends moodleform { + public function definition() { + global $CFG; + + $mform = $this->_form; + + $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice')); + + //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters + $mform->addElement('text', 'wsusername', 'wsusername'); + $mform->addElement('text', 'wspassword', 'wspassword'); + $mform->addElement('text', 'groupids[0]', 'groupids[0]'); + $mform->addElement('text', 'groupids[1]', 'groupids[1]'); + $mform->addElement('text', 'groupids[2]', 'groupids[2]'); + $mform->addElement('text', 'groupids[3]', 'groupids[3]'); + + $mform->addElement('hidden', 'function'); + $mform->setType('function', PARAM_SAFEDIR); + + $mform->addElement('hidden', 'protocol'); + $mform->setType('protocol', PARAM_SAFEDIR); + + $this->add_action_buttons(true, get_string('execute', 'webservice')); + } +} + +class moodle_group_get_course_groups_form extends moodleform { + public function definition() { + global $CFG; + + $mform = $this->_form; + + $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice')); + + //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters + $mform->addElement('text', 'wsusername', 'wsusername'); + $mform->addElement('text', 'wspassword', 'wspassword'); + $mform->addElement('text', 'courseid', 'courseid'); + + $mform->addElement('hidden', 'function'); + $mform->setType('function', PARAM_SAFEDIR); + + $mform->addElement('hidden', 'protocol'); + $mform->setType('protocol', PARAM_SAFEDIR); + + $this->add_action_buttons(true, get_string('execute', 'webservice')); + } +} +