/** * This function tests the flag that lets others join a group. I'm testing * both the getter and the setter. Check to ensure that the record defaults * to false when no record exists. * */ public function test_allow_others_to_join() { global $DB; $sgroup = new skills_group($this->groupids[0]); $this->assertFalse($sgroup->get_allow_others_to_join()); $sgroup->set_allow_others_to_join(true); $allowjoin = $DB->get_field('skills_group', 'allowjoin', array('groupid' => $this->groupids[0])); $this->assertEquals($allowjoin, 1); $this->assertTrue($sgroup->get_allow_others_to_join()); $sgroup->set_allow_others_to_join(false); $this->assertFalse($sgroup->get_allow_others_to_join()); }
/** * This function loops through each group, calculates, and formats the scores. * * @return array List of all scores for each of the valid groups a user could join. * */ public function get_table_rows() { global $DB; $sgs = new skills_group_setting($this->courseid); $tablerows = array(); foreach ($this->records as $group) { $sgroup = new skills_group($group->groupid); if ($sgroup->count_members() < $sgs->get_group_size() && $sgroup->get_allow_others_to_join() === true) { $scores = $sgs->get_feedback_id() == 0 ? array() : $sgroup->get_join_form_score(); $name = $sgroup->get_group_name(); $temp = array_merge(array('id' => $group->groupid, 'name' => $name), $scores); $tablerows[] = $temp; } } return $tablerows; }
require_once $CFG->dirroot . '/blocks/skills_group/classes/skills_grouping.class.php'; require_once $CFG->dirroot . '/blocks/skills_group/classes/skills_group.class.php'; require_once $CFG->dirroot . '/group/lib.php'; global $OUTPUT, $PAGE, $USER; $courseid = required_param('courseid', PARAM_INT); 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/create_skills_group.php', array('courseid' => $courseid, 'sesskey' => $USER->sesskey)); block_skills_group_setup_page($courseid, $url, get_string('creategrouptitle', BLOCK_SG_LANG_TABLE)); $creategroupform = new create_skills_group_form($courseid); $sgrouping = new skills_grouping($courseid); $groupid = $sgrouping->check_for_user_in_grouping($USER->id); if ($groupid !== false) { $sgroup = new skills_group($groupid); if ($sgroup->get_allow_others_to_join() === true) { $toform['allowjoincheck'] = 1; } } $toform['courseid'] = $courseid; $creategroupform->set_data($toform); if ($creategroupform->is_cancelled()) { $courseurl = new moodle_url('/course/view.php', array('id' => $courseid)); redirect($courseurl); } else { if ($fromform = $creategroupform->get_data()) { $url = process_form($courseid, $fromform); redirect($url); } else { $site = get_site(); echo $OUTPUT->header();
/** * This function allows the user to join a group if they are not already part * of a group. * */ private function join_group() { global $USER; $groupid = required_param('groupid', PARAM_INT); $groupingid = required_param('groupingid', PARAM_INT); $this->courseid = required_param('courseid', PARAM_INT); $sgs = new skills_group_setting($this->courseid); $sgrouping = new skills_grouping($this->courseid); $sgroup = new skills_group($groupid); if ($sgroup->count_members() < $sgs->get_group_size() && $sgroup->get_allow_others_to_join() === true) { if ($sgrouping->check_for_user_in_grouping($USER->id) === false) { groups_add_member($groupid, $USER->id); // Logging join group action. $params = array('context' => context_course::instance($this->courseid), 'objectid' => $groupid, 'courseid' => $this->courseid, 'userid' => $USER->id); $event = \block_skills_group\event\skillsgroup_joined::create($params); $event->trigger(); echo json_encode(array('result' => 'true', 'text' => get_string('groupjoinsuccess', BLOCK_SG_LANG_TABLE))); } else { echo json_encode(array('result' => 'false', 'text' => get_string('alreadyingroup', BLOCK_SG_LANG_TABLE))); } } else { echo json_encode(array('result' => 'false', 'text' => get_string('toomanymembers', BLOCK_SG_LANG_TABLE))); } }
/** * This function draws any additional settings. Currently there is only one: * whether the user wishes to let others join. * * @param int $groupid The ID of the group that the user belongs to. * */ function display_settings($groupid) { $sgroup = new skills_group($groupid); echo html_writer::start_div('', array('id' => 'allowuserstojoinsetting')); $attributes = array('id' => 'allowuserstojoin', 'type' => 'checkbox'); if ($sgroup->get_allow_others_to_join()) { $attributes['checked'] = 'checked'; } echo html_writer::empty_tag('input', $attributes); echo get_string('allowuserstojoin', BLOCK_SG_LANG_TABLE); echo html_writer::end_div(); echo html_writer::empty_tag('br'); }