/** * This function sets it so that all groups have enabled the flag that lets * other students join their group. * */ private function allow_group_join() { for ($i = 0; $i < self::NUMBEROFGROUPS; $i++) { $sgroup = new skills_group($this->groupids[$i]); $sgroup->set_allow_others_to_join(true); } }
/** * 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()); }
/** * Small helper function that parses the {0, 1} return from the advanced checkbox * and passes it to the skills_group class to be updated. * * @param int $groupid The ID of the group to update * @param int $allowjoin {0, 1} indicating status of allowjoin flag * */ function update_allow_join($groupid, $allowjoin) { $sgroup = new skills_group($groupid); if ($allowjoin == 1) { $sgroup->set_allow_others_to_join(true); } else { $sgroup->set_allow_others_to_join(false); } }
/** * This is function adds members to a particular group. * */ private function add_members() { global $DB, $USER; $groupid = required_param('groupid', PARAM_INT); $members = required_param('members', PARAM_TEXT); $allowjoin = required_param('allowjoin', PARAM_TEXT); $this->courseid = required_param('courseid', PARAM_INT); // Update allowjoin flag. $sgroup = new skills_group($groupid); // The boolean encoding with json gets messed up -> so check for the string version here. if ($allowjoin == 'true') { $sgroup->set_allow_others_to_join(true); } else { $sgroup->set_allow_others_to_join(false); } $decodedmembers = json_decode($members, true); $decodedmembers = is_array($decodedmembers) ? array_unique($decodedmembers) : array(); // Add the list of IDs of locked members to the list of individuals to add to the group. // TODO: would be nice if this was part of the skills_group class? $lockedmembers = $sgroup->get_members_list($lock = true); foreach ($lockedmembers as $key => $lockedmember) { $decodedmembers[] = $key; } $sgsetting = new skills_group_setting($this->courseid); // Wipe out old group. $DB->delete_records('groups_members', array('groupid' => $groupid)); // Add self. groups_add_member($groupid, $USER->id); // Logging edit 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(); if (count($decodedmembers) <= $sgsetting->get_group_size() - 1) { foreach ($decodedmembers as $dm) { groups_add_member($groupid, $dm); } echo json_encode(array('result' => 'true', 'text' => get_string('groupupdatesuccess', BLOCK_SG_LANG_TABLE))); } else { echo json_encode(array('result' => 'false', 'text' => get_string('toomanymembers', BLOCK_SG_LANG_TABLE))); } }