Skip to content

Commit

Permalink
web service MDL-12886 remove tmp prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
jerome committed Mar 16, 2009
1 parent 8f732f2 commit d0977ac
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 67 deletions.
17 changes: 7 additions & 10 deletions group/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
/**
* Group external api class
*
* WORK IN PROGRESS, DO NOT USE IT
*/
final class group_external {

Expand All @@ -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();

Expand Down Expand Up @@ -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))) {

Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -138,7 +136,6 @@ static function tmp_get_groupmembers($params){

$members[] = array("groupid" => $groupid, "members" => $custommembers);
}
varlog($members);
return $members;
}
else {
Expand All @@ -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;
Expand All @@ -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) {
Expand Down
58 changes: 29 additions & 29 deletions group/simpletest/testexternal.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ function setUp() {
$user->lastname = 'mockuserfortestingX_lastname';
$user->email = '[email protected]';
$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 = '[email protected]';
$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();
Expand All @@ -97,14 +97,14 @@ function setUp() {
$user->lastname = 'mockuserfortestingZ_lastname';
$user->email = '[email protected]';
$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 = '[email protected]';
$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();
Expand All @@ -113,7 +113,7 @@ function setUp() {
$user->lastname = 'mockuserfortestingZ23_lastname';
$user->email = '[email protected]';
$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));
Expand Down Expand Up @@ -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)]);
Expand All @@ -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);
Expand All @@ -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);
}
*/
}
Expand Down
13 changes: 6 additions & 7 deletions user/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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');
Expand All @@ -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))) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -274,7 +273,7 @@ static function tmp_update_users($params) {
}

try {
if( !tmp_update_user($user)) {
if( !update_user($user)) {
$updatesuccessfull = false;
}
}
Expand Down
8 changes: 4 additions & 4 deletions user/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

/**
* DO NOT USE ANYTHING FROM THIS FILE - WORK IN PROGRESS
* User library
*/

/**
Expand All @@ -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
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit d0977ac

Please sign in to comment.