/**
  * The constructor grabs all of the groups to retrieve data for.
  *
  * @param int $courseid This is the course ID
  *
  */
 public function __construct($courseid)
 {
     global $DB, $USER;
     $this->courseid = $courseid;
     $sgs = new skills_group_setting($courseid);
     $this->records = $DB->get_records('groupings_groups', array('groupingid' => $sgs->get_grouping_id()));
 }
if (!blocks_skills_group_verify_access('block/skills_group:cancreateorjoinskillsgroups', true)) {
    redirect(new moodle_url('/course/view.php', array('id' => $courseid)));
}
$url = new moodle_url('/blocks/skills_group/join_skills_group.php', array('courseid' => $courseid, 'sesskey' => $USER->sesskey));
block_skills_group_setup_page($courseid, $url, get_string('joingroup', BLOCK_SG_LANG_TABLE), 'base');
$error = null;
$groupingid = 0;
$sgs = new skills_group_setting($courseid);
// In case user tries to manually access page - check that settings exist.
if (!$sgs->exists()) {
    $error = get_string('notconfigured', BLOCK_SG_LANG_TABLE);
} else {
    if ($sgs->date_restriction() && time() > $sgs->get_date()) {
        $error = get_string('dateexpired', BLOCK_SG_LANG_TABLE);
    } else {
        $groupingid = $sgs->get_grouping_id();
        $sgrouping = new skills_grouping($courseid);
        // If user is in group - display error.
        if ($sgrouping->check_for_user_in_grouping($USER->id) !== false) {
            $error = get_string('alreadyingroup', BLOCK_SG_LANG_TABLE);
        }
    }
}
set_header();
echo $OUTPUT->header();
display_header();
display_group_view();
display_buttons();
load_yui_modules($courseid, $groupingid, $error);
echo $OUTPUT->footer();
/**
require_once $CFG->dirroot . '/blocks/skills_group/classes/edit_skills_group_settings_form.class.php';
require_once $CFG->dirroot . '/blocks/skills_group/classes/skills_group_setting.class.php';
global $OUTPUT, $PAGE, $USER;
$courseid = required_param('courseid', PARAM_INT);
if (!blocks_skills_group_verify_access('block/skills_group:canmanageskillsgroups', true)) {
    redirect(new moodle_url('/course/view.php', array('id' => $courseid)));
}
$url = new moodle_url('/blocks/skills_group/edit_skills_group_settings.php', array('id' => $courseid, 'sesskey' => $USER->sesskey));
block_skills_group_setup_page($courseid, $url, get_string('editsettingstitle', BLOCK_SG_LANG_TABLE));
$editform = new edit_skills_group_settings_form($courseid);
$toform['courseid'] = $courseid;
// Retrieve any previously used settings.
$sgs = new skills_group_setting($courseid);
if ($sgs->exists()) {
    $toform['feedbacks'] = $sgs->get_feedback_id();
    $toform['groupings'] = $sgs->get_grouping_id();
    $toform['maxsize'] = $sgs->get_group_size();
    $toform['threshold'] = $sgs->get_threshold();
    $toform['allownaming'] = $sgs->get_allownaming();
    if ($sgs->date_restriction()) {
        $toform['datecheck'] = 1;
        $toform['date'] = $sgs->get_date();
    } else {
        $toform['datecheck'] = 0;
        $toform['date'] = null;
    }
}
$editform->set_data($toform);
if ($editform->is_cancelled()) {
    $courseurl = new moodle_url('/course/view.php', array('id' => $courseid));
    redirect($courseurl);
 /**
  * This function tests to see that the grouping ID gets correctly stored and retrieved
  * in the class.
  *
  */
 public function test_get_grouping_id()
 {
     $sgs = new skills_group_setting($this->courseid);
     // Test retrieval of grouping ID.
     $sgs->update_record($this->get_skills_group_settings());
     $this->assertEquals($sgs->get_grouping_id(), $this->groupingid);
 }
 /**
  * This function checks to see if an individual user is in a group inside
  * a grouping.  If the user is found, the ID of the group that the user
  * belongs to is returned.
  *
  * @param int $userid ID of the user to check for in the grouping.
  * @return mixed The ID of the group if found or false if not found.
  *
  */
 public function check_for_user_in_grouping($userid)
 {
     global $DB;
     $sgs = new skills_group_setting($this->courseid);
     $params = array($sgs->get_grouping_id(), $userid);
     $query = "SELECT *\n                  FROM {groupings_groups} a inner join {groups_members} b ON a.groupid = b.groupid\n                  WHERE a.groupingid = ? AND b.userid = ?";
     $record = $DB->get_record_sql($query, $params, IGNORE_MULTIPLE);
     if ($record !== false) {
         return $record->groupid;
     } else {
         return false;
     }
 }