Parent Directory
|
Revision Log
uploading Moodle API&webservices
<?php
/**
* Created on 05/03/2008
*
* groups control api
*
* @author Ferran Recio
* @author David Castro Garcia
*/
/**
* public api functions definition
*/
function mdl_group_info () {
$info = new stdClass;
//api name
$info->description = 'Group control api';
//api version
$info->version = 2008031001;
//data structures and arrays
$info->structs = array();
//group_list
$stru = new stdClass;
$stru->name = 'group_list';
$stru->type = 'array';
$stru->elems = 'group';
$info->structs[$stru->name] = $stru;
//group
$stru = new stdClass;
$stru->name = 'group';
$stru->type = 'struct';
$stru->elems = array(
'id' => 'integer',
'courseid' => 'integer',
'name' => 'string',
'description' => 'string'
);
$info->structs[$stru->name] = $stru;
//function list
$info->functions = array();
$func = new stdClass;
$func->name = 'mdl_group_add_instance';
$func->params = array('name' => 'string','courseid' => 'integer', 'description' => 'string');
$func->doc = "creates a group in a course";
$func->ret = 'integer';
$info->functions[$func->name] = $func;
$func = new stdClass;
$func->name = 'mdl_group_delete_instance';
$func->params = array('groupid' => 'integer');
$func->doc = "removes a group";
$func->ret = 'boolean';
$info->functions[$func->name] = $func;
$func = new stdClass;
$func->name = 'mdl_group_add_member';
$func->params = array('groupid' => 'integer', 'userid' => 'integer');
$func->doc = "add a user into a group";
$func->ret = 'boolean';
$info->functions[$func->name] = $func;
$func = new stdClass;
$func->name = 'mdl_group_remove_member';
$func->params = array('groupid'=>'integer', 'userid'=>'integer');
$func->doc = "remove an user from a group";
$func->ret = 'boolean';
$info->functions[$func->name] = $func;
$func = new stdClass;
$func->name = 'mdl_group_get_groups_by_course';
$func->params = array('courseid'=>'integer');
$func->doc = "gets the groups of a specific course";
$func->ret = 'group_list';
$info->functions[$func->name] = $func;
return $info;
}
/**
* Creates a new group in a course
*
* @param string $name The name of the group
* @param int $courseid The course id
* @param string $description The description of the group
* @return id of group
*/
function mdl_group_add_instance($name, $courseid, $description) {
mdl_require_callable('mdl_group_add_instance');
$group = new stdClass;
$group->courseid = $courseid;
$group->name = $name;
$group->description = $description;
$returnValue = groups_create_group($group, false);
if(!$returnValue) return 0;
return $returnValue;
}
/**
* Delete a group best effort, first removing members and links with courses and groupings.
* @param int $groupid The group to delete
* @return boolean True if deletion was successful, false otherwise
*/
function mdl_group_delete_instance($groupid){
mdl_require_callable('mdl_group_delete_instance');
$returnValue = groups_delete_group($groupid);
if(!$returnValue) return false;
return true;
}
/**
* Adds a specified user to a group
* @param int $groupid The group id
* @param int $userid The user id
* @return boolean True if user added successfully or the user is already a
* member of the group, false otherwise.
*/
function mdl_group_add_member($groupid, $userid) {
mdl_require_callable('mdl_group_add_member');
return groups_add_member($groupid, $userid);
}
/**
* Removes an user from group.
* @param int $groupid The group to delete the user from
* @param int $userid The user to delete
* @return boolean True if deletion was successful, false otherwise
*/
function mdl_group_remove_member($groupid, $userid) {
mdl_require_callable('mdl_group_remove_member');
return groups_remove_member($groupid, $userid);
}
/**
* Gets array of all groups in a specified course.
* @param int $courseid The id of the course.
* @param mixed $userid optional user id or array of ids, returns only groups of the user.
* @param int $groupingid optional returns only groups in the specified grouping.
* @return array | false Returns an array of the group objects or false if no records
* or an error occurred. (userid field returned if array in $userid)
*/
function mdl_group_get_groups_by_course($courseid) {
mdl_require_callable('mdl_group_get_groups_by_course');
$returnValue = groups_get_all_groups($courseid);
if(!$returnValue) return array();
return $returnValue;
}
?>
| Moodle CVS Admin | ViewVC Help |
| Powered by ViewVC 1.0.7 |