function test_get_course_info()
 {
     $this->assertTrue($course = groups_get_course_info(1));
     if (isset($course)) {
         $this->courseid = $course->id;
     }
 }
Esempio n. 2
0
 /**
  * setUp/tearDown: Better in a constructor/destructor, but PHP4 doesn't do destructors :(
  */
 function setUp()
 {
     parent::setUp();
     if ($course = groups_get_course_info(1)) {
         $this->courseid = $course->id;
     }
     if ($user = groups_get_user(2)) {
         //Primary admin.
         $this->userid = $user->id;
     }
     $this->groupid = groups_create_group($this->courseid);
     $groupinfo = groups_set_default_group_settings();
     $bok = groups_set_group_settings($this->groupid, $groupinfo);
     $bok = groups_add_member($this->groupid, $this->userid);
 }
Esempio n. 3
0
 * @copyright © 2006 The Open University
 * @author N.D.Freear AT open.ac.uk
 * @author J.White AT open.ac.uk 
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 * @package groups
 */
require_once '../config.php';
require_once 'lib.php';
require_once $CFG->libdir . '/moodlelib.php';
$success = true;
$courseid = required_param('courseid', PARAM_INT);
$groupingid = required_param('grouping', PARAM_INT);
$groupid = required_param('group', PARAM_INT);
// Get the course information so we can print the header and
// check the course id is valid
$course = groups_get_course_info($courseid);
if (!$course) {
    $success = false;
    print_error('invalidcourse');
}
if (empty($groupid)) {
    $success = false;
    print_error('errorinvalidgroup', 'group', groups_home_url($courseid));
}
if ($success) {
    // Make sure that the user has permissions to manage groups.
    require_login($courseid);
    $context = get_context_instance(CONTEXT_COURSE, $courseid);
    if (!has_capability('moodle/course:managegroups', $context)) {
        redirect();
    }
Esempio n. 4
0
/**
 * Marks a set of groups as a grouping. 
 * 
 * @param array $groupidarray An array of the ids of the groups to marks as a
 * grouping. 
 * @param int $courseid The id of the course for which the groups should form
 * a grouping
 * @return int | false The id of the grouping, or false if an error occurred. 
 * Also returns false if any of the groups specified do not belong to the 
 * course. 
 */
function groups_db_create_grouping($courseid, $groupingsettings = false)
{
    if (!$courseid or !groups_get_course_info($courseid)) {
        $groupingid = false;
    } else {
        // Replace any empty groupsettings
        $groupingsettings = groups_set_default_grouping_settings($groupingsettings);
        $record = $groupingsettings;
        $record->timecreated = time();
        $groupingid = insert_record('groups_groupings', $record);
        if ($groupingid != false) {
            $record2 = new Object();
            $record2->courseid = $courseid;
            $record2->groupingid = $groupingid;
            $record2->timeadded = time();
            $id = insert_record('groups_courses_groupings', $record2);
            if (!$id) {
                $groupingid = false;
            }
        }
    }
    return $groupingid;
}