diff --git a/group/external.php b/group/external.php index db6bcc4dbc768..93ed8f7468811 100644 --- a/group/external.php +++ b/group/external.php @@ -16,7 +16,6 @@ /** * Group external api class * - * WORK IN PROGRESS, DO NOT USE IT */ final class group_external { @@ -28,7 +27,7 @@ final class group_external { * @return array $return * @subparam integer $return:groupid */ - static function tmp_create_groups($params) { + static function create_groups($params) { global $USER; $groupids = array(); @@ -58,7 +57,7 @@ static function tmp_create_groups($params) { * @subreturn string $return:group->name * @subreturn string $return:group->enrolmentkey */ - static function tmp_get_groups($params){ + static function get_groups($params){ if (has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_SYSTEM))) { @@ -87,7 +86,7 @@ static function tmp_get_groups($params){ * @subparam integer $params:groupid * @return boolean result */ - static function tmp_delete_groups($params){ + static function delete_groups($params){ if (has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_SYSTEM))) { $deletionsuccessfull = true; @@ -110,13 +109,12 @@ static function tmp_delete_groups($params){ * @return array $return * $subparam string $return:username */ - static function tmp_get_groupmembers($params){ + static function get_groupmembers($params){ if (has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_SYSTEM))) { $members = array(); foreach ($params as $groupid) { - $groupmembers = groups_get_members($groupid); - varlog($groupmembers); + $groupmembers = groups_get_members(clean_param($groupid, PARAM_INTEGER)); $custommembers = array(); foreach ($groupmembers as $member) { $custommember = new stdClass(); @@ -138,7 +136,6 @@ static function tmp_get_groupmembers($params){ $members[] = array("groupid" => $groupid, "members" => $custommembers); } - varlog($members); return $members; } else { @@ -153,7 +150,7 @@ static function tmp_get_groupmembers($params){ * @subparam integer $params:member->userid * @return boolean result */ - static function tmp_add_groupmembers($params){ + static function add_groupmembers($params){ if (has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_SYSTEM))) { $addmembersuccessfull = true; @@ -179,7 +176,7 @@ static function tmp_add_groupmembers($params){ * @subparam integer $params:member->userid * @return boolean result */ - static function tmp_delete_groupmembers($params){ + static function delete_groupmembers($params){ if (has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_SYSTEM))) { $addmembersuccessfull = true; foreach($params as $member) { diff --git a/group/simpletest/testexternal.php b/group/simpletest/testexternal.php index 8e4e008467b69..36ffa527c67cb 100644 --- a/group/simpletest/testexternal.php +++ b/group/simpletest/testexternal.php @@ -82,13 +82,13 @@ function setUp() { $user->lastname = 'mockuserfortestingX_lastname'; $user->email = 'mockuserfortestingX@moodle.com'; $user->password = 'mockuserfortestingX_password'; - $this->userid1 = tmp_create_user($user); + $this->userid1 = create_user($user); $user->username = 'mockuserfortestingXY'; $user->firstname = 'mockuserfortestingY_firstname'; $user->lastname = 'mockuserfortestingY_lastname'; $user->email = 'mockuserfortestingY@moodle.com'; $user->password = 'mockuserfortestingY_password'; - $this->userid2 = tmp_create_user($user); + $this->userid2 = create_user($user); //create some more test users (not add yet to any group) $user = new stdClass(); @@ -97,14 +97,14 @@ function setUp() { $user->lastname = 'mockuserfortestingZ_lastname'; $user->email = 'mockuserfortestingZ@moodle.com'; $user->password = 'mockuserfortestingZ_password'; - $this->userid3 = tmp_create_user($user); + $this->userid3 = create_user($user); $user = new stdClass(); $user->username = 'mockuserfortestingZ2'; $user->firstname = 'mockuserfortestingZ2_firstname'; $user->lastname = 'mockuserfortestingZ2_lastname'; $user->email = 'mockuserfortestingZ2@moodle.com'; $user->password = 'mockuserfortestingZ2_password'; - $this->userid4 = tmp_create_user($user); + $this->userid4 = create_user($user); //create a user, don't add it to a role or group $user = new stdClass(); @@ -113,7 +113,7 @@ function setUp() { $user->lastname = 'mockuserfortestingZ23_lastname'; $user->email = 'mockuserfortestingZ23@moodle.com'; $user->password = 'mockuserfortestingZ23_password'; - $this->userid5 = tmp_create_user($user); + $this->userid5 = create_user($user); //we're creating a new test role with viewcourse capabilyt $this->context = $DB->get_record('context',array('contextlevel' => 50, 'instanceid' => $this->course->id)); @@ -175,14 +175,14 @@ function tearDown() { delete_role($this->roleid); } - function testTmp_create_groups() { + function test_create_groups() { /// create two different groups $params = array(); $group = array('groupname' => 'Create Unit Test Group 1', 'courseid' => $this->course->id); $params[] = $group; $group = array('groupname' => 'Create Unit Test Group 2', 'courseid' => $this->course->id); $params[] = $group; - $groupids = group_external::tmp_create_groups($params); + $groupids = group_external::create_groups($params); $this->assertEqual(sizeof($groupids), 2); $this->assertIsA($groupids[key($groupids)], "integer"); $this->assertNotNull($groupids[key($groupids)]); @@ -192,13 +192,13 @@ function testTmp_create_groups() { $group = array('groupname' => 'Create Unit Test Group 3', 'courseid' => 6544656); $params[] = $group; $this->expectException(new moodle_exception('coursedoesntexistcannotcreategroup')); - $groupids = group_external::tmp_create_groups($params); + $groupids = group_external::create_groups($params); } - function testTmp_get_groups() { + function test_get_groups() { /// retrieve the two groups $params = array($this->group->id, $this->group2->id); - $groups = group_external::tmp_get_groups($params); + $groups = group_external::get_groups($params); $this->assertEqual(sizeof($groups), 2); $group = $groups[key($groups)]; next($groups); @@ -211,76 +211,76 @@ function testTmp_get_groups() { $this->assertEqual($group2->name, $this->group2->name); } - function testTmp_add_group_members() { + function test_add_group_members() { //add the two members without group $params = array(array("groupid" => $this->group->id, "userid" => $this->userid3), array("groupid" => $this->group->id, "userid" => $this->userid4)); - $result = group_external::tmp_add_groupmembers($params); + $result = group_external::add_groupmembers($params); $this->assertEqual($result, true); //add them a new time $params = array(array("groupid" => $this->group->id, "userid" => $this->userid3), array("groupid" => $this->group->id, "userid" => $this->userid4)); - $result = group_external::tmp_add_groupmembers($params); + $result = group_external::add_groupmembers($params); $this->assertEqual($result, true); //One of the userid doesn't exist $params = array(array("groupid" => $this->group->id, "userid" => 654685), array("groupid" => $this->group->id, "userid" => $this->userid4)); $this->expectException(new moodle_exception('useriddoesntexist')); - $result = group_external::tmp_add_groupmembers($params); + $result = group_external::add_groupmembers($params); } - function testTmp_add_group_members2() { + function test_add_group_members2() { //the group id doesn't exist $params = array(array("groupid" => 6465465, "userid" => $this->userid3), array("groupid" => $this->group->id, "userid" => $this->userid4)); $this->expectException(new moodle_exception('cannotaddmembergroupiddoesntexist')); - $result = group_external::tmp_add_groupmembers($params); + $result = group_external::add_groupmembers($params); } - function testTmp_add_group_members3() { + function test_add_group_members3() { //the user is not a participant $params = array(array("groupid" => $this->group->id, "userid" => $this->userid5)); $this->expectException(new moodle_exception('userisnotaparticipant')); - $result = group_external::tmp_add_groupmembers($params); + $result = group_external::add_groupmembers($params); } - function testTmp_get_groupmembers() { + function test_get_groupmembers() { $params = array($this->group->id, $this->group2->id); - $groups = group_external::tmp_get_groupmembers($params); + $groups = group_external::get_groupmembers($params); $this->assertEqual(sizeof($groups), 2); $this->assertEqual(sizeof($groups[0]['members']), 2); $this->assertEqual(sizeof($groups[1]['members']), 1); } - function testTmp_delete_group_members() { + function test_delete_group_members() { //One of the userid doesn't exist $params = array(array("groupid" => $this->group->id, "userid" => 654685), array("groupid" => $this->group->id, "userid" => $this->userid2)); $this->expectException(new moodle_exception('useriddoesntexist')); - $result = group_external::tmp_delete_groupmembers($params); + $result = group_external::delete_groupmembers($params); } - function testTmp_delete_group_members2() { + function test_delete_group_members2() { //the group id doesn't exist $params = array(array("groupid" => 6465465, "userid" => $this->userid1), array("groupid" => $this->group->id, "userid" => $this->userid2)); $this->expectException(new moodle_exception('cannotaddmembergroupiddoesntexist')); - $result = group_external::tmp_delete_groupmembers($params); + $result = group_external::delete_groupmembers($params); } - function testTmp_delete_group_members3() { + function test_delete_group_members3() { //delete members from group $params = array(array("groupid" => $this->group->id, "userid" => $this->userid1), array("groupid" => $this->group->id, "userid" => $this->userid2)); - $result = group_external::tmp_delete_groupmembers($params); + $result = group_external::delete_groupmembers($params); $this->assertEqual($result, true); } - function testTmp_delete_groups() { + function test_delete_groups() { $params = array($this->group->id, $this->group2->id); - $result = group_external::tmp_delete_groups($params); + $result = group_external::delete_groups($params); $this->assertEqual($result, true); //Exception: delete same groups $params = array($this->group->id, $this->group2->id); $this->expectException(new moodle_exception('groupiddoesntexistcannotdelete')); - $result = group_external::tmp_delete_groups($params); + $result = group_external::delete_groups($params); } */ } diff --git a/user/external.php b/user/external.php index 363d60c42846a..2d3b9baca6cc2 100644 --- a/user/external.php +++ b/user/external.php @@ -25,7 +25,6 @@ require_once(dirname(dirname(__FILE__)) . '/user/lib.php'); /** - * WORK IN PROGRESS, DO NOT USE IT * users webservice api * * @author Jerome Mouneyrac @@ -51,7 +50,7 @@ final class user_external { * @subreturn string $return:user->timezone * @subreturn string $return:user->mailformat */ - static function tmp_get_users($params) { + static function get_users($params) { global $USER; $params['search'] = clean_param($params['search'], PARAM_ALPHANUM); @@ -75,7 +74,7 @@ static function tmp_get_users($params) { * @return array $return ids of new user * @subreturn integer $return:id user id */ - static function tmp_create_users($params) { + static function create_users($params) { global $USER; if (has_capability('moodle/user:create', get_context_instance(CONTEXT_SYSTEM))) { $userids = array(); @@ -147,7 +146,7 @@ static function tmp_create_users($params) { } try { - $userids[$userparams['username']] = tmp_create_user($user); + $userids[$userparams['username']] = create_user($user); } catch (dml_write_exception $e) { throw new moodle_exception('wscouldnotcreateeuserindb'); @@ -167,7 +166,7 @@ static function tmp_create_users($params) { * @subparam string $params:user->username * @return boolean result true if success */ - static function tmp_delete_users($params) { + static function delete_users($params) { global $DB,$USER; $deletionsuccessfull = true; if (has_capability('moodle/user:delete', get_context_instance(CONTEXT_SYSTEM))) { @@ -201,7 +200,7 @@ static function tmp_delete_users($params) { * @subparam string $params:user->firstname * @return boolean result true if success */ - static function tmp_update_users($params) { + static function update_users($params) { global $DB,$USER; if (has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) { $updatesuccessfull = true; @@ -274,7 +273,7 @@ static function tmp_update_users($params) { } try { - if( !tmp_update_user($user)) { + if( !update_user($user)) { $updatesuccessfull = false; } } diff --git a/user/lib.php b/user/lib.php index 32647c4779033..ce9e9908af2ee 100644 --- a/user/lib.php +++ b/user/lib.php @@ -8,7 +8,7 @@ */ /** -* DO NOT USE ANYTHING FROM THIS FILE - WORK IN PROGRESS +* User library */ /** @@ -26,7 +26,7 @@ * ->lastinitial string ? * @return array|false Array of {@link $USER} objects. False is returned if an error is encountered. */ -function tmp_get_users($sort='firstname ASC', $recordsperpage=999999, $page=0, $fields='*', $selectioncriteria=NULL) { +function get_users_2($sort='firstname ASC', $recordsperpage=999999, $page=0, $fields='*', $selectioncriteria=NULL) { global $DB; ///WS: convert array into an object @@ -101,7 +101,7 @@ function tmp_get_users($sort='firstname ASC', $recordsperpage=999999, $page=0, $ * * @return string or thrown exceptions */ -function tmp_create_user($user) { +function create_user($user) { global $CFG, $DB; /// WS: convert user array into an user object if (is_array($user)) { @@ -148,7 +148,7 @@ function tmp_create_user($user) { * @param object $user * @return boolean */ -function tmp_update_user($user) { +function update_user($user) { global $DB; //check that the user exist diff --git a/user/simpletest/testexternal.php b/user/simpletest/testexternal.php index 34bebfdb0bdf0..6bbaf9b5f09af 100644 --- a/user/simpletest/testexternal.php +++ b/user/simpletest/testexternal.php @@ -49,7 +49,7 @@ function tearDown() { } /* - function testTmp_create_users() { + function test_create_users() { /// test that we create multiple users $params = array(); for ($i=0;$i<2;$i=$i+1) { @@ -61,7 +61,7 @@ function testTmp_create_users() { $user['password'] = 'mockuserfortesting'.$i.'_password'; $params[] = $user; } - $result = user_external::tmp_create_users($params); + $result = user_external::create_users($params); $this->assertEqual(sizeof($result), 2); //just test that value are integer and not null $this->assertIsA($result[key($result)], "integer"); @@ -81,7 +81,7 @@ function testTmp_create_users() { $user['lang']='en_utf8'; $user['auth']='manual'; $params[] = $user; - $result = user_external::tmp_create_users($params); + $result = user_external::create_users($params); $this->assertEqual($result, true); @@ -91,11 +91,11 @@ function testTmp_create_users() { $user['username'] = 'mockuserfortestingY'; $params[] = $user; $this->expectException(new moodle_exception('missingrequiredfield')); - $result = user_external::tmp_create_users($params); + $result = user_external::create_users($params); } - function testTmp_create_users_2() { + function test_create_users_2() { /// test we cannot create a user because the username already exist $params = array(); $user = array(); @@ -107,12 +107,14 @@ function testTmp_create_users_2() { $params[] = $user; $this->expectException(new moodle_exception('wscouldnotcreateeuserindb')); - $result = user_external::tmp_create_users($params); + $result = user_external::create_users($params); } - function testTmp_get_users() { + function test_get_users() { $params = array('search' => 'mockuserfortestingXX'); - $users = user_external::tmp_get_users($params); + + $users = user_external::get_users($params); + foreach ($users as $user) { $this->assertEqual($user->username, 'mockuserfortestingXX'); $this->assertEqual($user->firstname, 'mockuserfortesting_firstname'); @@ -127,7 +129,7 @@ function testTmp_get_users() { } - function testTmp_update_users() { + function test_update_users() { /// update several users with full information $params = array(); $user = array(); @@ -156,7 +158,7 @@ function testTmp_update_users() { $user['lang']='en_utf8'; $user['auth']='manual'; $params[] = $user; - $result = user_external::tmp_update_users($params); + $result = user_external::update_users($params); $this->assertEqual($result, true); /// Exception: update non existing user @@ -166,22 +168,22 @@ function testTmp_update_users() { $user['newusername'] = 'mockuserfortesting0Y'; $params[] = $user; $this->expectException(new moodle_exception('wscouldnotupdatenoexistinguser')); //TODO catch the write exception - $result = user_external::tmp_update_users($params); + $result = user_external::update_users($params); } - function testTmp_update_users_2() { + function test_update_users_2() { /// update an existing user with an already existing username $params = array(); $user = array(); $user['username'] = 'mockuserfortesting0Y'; $user['newusername'] = 'mockuserfortestingXY'; $params[] = $user; - + $this->expectException(new moodle_exception('wscouldnotupdateuserindb')); - $result = user_external::tmp_update_users($params); + $result = user_external::update_users($params); } - function testTmp_delete_users() { + function test_delete_users() { /// we delete all previously created users $params = array(); $user = array(); @@ -193,12 +195,12 @@ function testTmp_delete_users() { $user = array(); $user['username'] = 'mockuserfortesting1'; $params[] = $user; - $result = user_external::tmp_delete_users($params); + $result = user_external::delete_users($params); $this->assertEqual($result, true); /// try to delete them a new time, should return exception $this->expectException(new moodle_exception('wscouldnotdeletenoexistinguser')); - $result = user_external::tmp_delete_users($params); + $result = user_external::delete_users($params); } */ }