/** * 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); } }
/** * Form definition with two possibilities: * * 1) User part of group -> allow user to edit or drop group. * 2) User not part of group -> allow user to create new group. * */ public function definition() { global $DB, $USER; $mform =& $this->_form; $mform->addElement('header', 'header', get_string('lockchoiceheader', BLOCK_SG_LANG_TABLE)); $sgs = new skills_group_setting($this->courseid); if ($sgs->exists()) { $sgrouping = new skills_grouping($this->courseid); $groupid = $sgrouping->check_for_user_in_grouping($USER->id); if ($groupid !== false) { $sgroup = new skills_group($groupid); $mform->addElement('static', 'existinggroup', get_string('existinggroup', BLOCK_SG_LANG_TABLE), $sgroup->get_group_name()); // Only display checkbox if student's choice isn't already locked. $student = new skills_group_student($this->courseid, $USER->id); if ($student->get_lock_choice() === true) { $mform->addElement('static', 'lockchoicewarning', get_string('status', BLOCK_SG_LANG_TABLE), get_string('choicelocked', BLOCK_SG_LANG_TABLE)); } else { $mform->addElement('advcheckbox', 'lockchoice', get_string('lockchoice', BLOCK_SG_LANG_TABLE), null, null, array(0, 1)); } $mform->addElement('static', 'lockchoicewarning', get_string('warning', BLOCK_SG_LANG_TABLE), get_string('lockchoicewarning', BLOCK_SG_LANG_TABLE)); } else { $mform->addElement('static', 'existinggroup', get_string('existinggroup', BLOCK_SG_LANG_TABLE), get_string('nogroup', BLOCK_SG_LANG_TABLE)); } } else { $mform->addElement('static', 'notconfigured', get_string('notconfiguredleft', BLOCK_SG_LANG_TABLE), get_string('notconfiguredright', BLOCK_SG_LANG_TABLE)); } // Hidden elements: courseid needed for posting. $mform->addElement('hidden', 'courseid'); $mform->setType('courseid', PARAM_INT); $this->add_action_buttons(); }
/** * 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; }
/** * 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); } }
/** * Form definition with two possibilities: * * 1) User part of group -> allow user to edit or drop group. * 2) User not part of group -> allow user to create new group. * */ public function definition() { global $DB, $USER; $mform =& $this->_form; $mform->addElement('header', 'header', get_string('creategroupheader', BLOCK_SG_LANG_TABLE)); $sgs = new skills_group_setting($this->courseid); if ($sgs->exists()) { $sgrouping = new skills_grouping($this->courseid); $groupid = $sgrouping->check_for_user_in_grouping($USER->id); if ($groupid !== false) { $sgroup = new skills_group($groupid); $mform->addElement('static', 'existinggroup', get_string('existinggroup', BLOCK_SG_LANG_TABLE), $sgroup->get_group_name()); $mform->addElement('hidden', 'groupid', $groupid); $mform->setType('groupid', PARAM_INT); if ($sgs->date_restriction() && time() > $sgs->get_date()) { $mform->addElement('static', 'dateexpired', get_string('dateexpiredleft', BLOCK_SG_LANG_TABLE), get_string('dateexpiredright', BLOCK_SG_LANG_TABLE)); $mform->addElement('hidden', 'type', 'expired'); $mform->setType('type', PARAM_TEXT); } else { $mform->addElement('advcheckbox', 'editmembers', get_string('editmembers', BLOCK_SG_LANG_TABLE), null, null, array(0, 1)); // Student can only leave if not already locked. $student = new skills_group_student($this->courseid, $USER->id); if ($student->get_lock_choice() === false) { $mform->addElement('advcheckbox', 'leavegroup', get_string('leavegroup', BLOCK_SG_LANG_TABLE), null, null, array(0, 1)); $mform->disabledIf('leavegroup', 'editmembers', 'checked'); $mform->disabledIf('editmembers', 'leavegroup', 'checked'); } $mform->addElement('hidden', 'type', 'edit'); $mform->setType('type', PARAM_TEXT); } $mform->addElement('advcheckbox', 'allowjoincheck', get_string('groupsearchable', BLOCK_SG_LANG_TABLE), null, null, array(0, 1)); $mform->disabledIf('allowjoincheck', 'leavegroup', 'checked'); } else { $mform->addElement('static', 'existinggroup', get_string('existinggroup', BLOCK_SG_LANG_TABLE), get_string('nogroup', BLOCK_SG_LANG_TABLE)); if ($sgs->date_restriction() && time() > $sgs->get_date()) { $mform->addElement('static', 'dateexpired', get_string('dateexpiredleft', BLOCK_SG_LANG_TABLE), get_string('dateexpiredright', BLOCK_SG_LANG_TABLE)); $mform->addElement('hidden', 'type', 'expired'); $mform->setType('type', PARAM_TEXT); } else { if ($sgs->get_allownaming() == true) { $pagegroup = array(); $pagegroup[] = $mform->createElement('advcheckbox', 'creategroupcheck', null, null, null, array(0, 1)); $pagegroup[] = $mform->createElement('text', 'creategroup', null, array()); $mform->setType('creategroup', PARAM_TEXT); $mform->disabledIf('creategroup', 'creategroupcheck'); $mform->addGroup($pagegroup, 'create', get_string('creategroup', BLOCK_SG_LANG_TABLE), null, false); } else { // Create element outside of group so that form spacing is correct. $mform->addElement('advcheckbox', 'creategroupcheck', get_string('creategroup', BLOCK_SG_LANG_TABLE), null, null, array(0, 1)); } $mform->addElement('hidden', 'type', 'create'); $mform->setType('type', PARAM_TEXT); $mform->addElement('advcheckbox', 'allowjoincheck', get_string('groupsearchable', BLOCK_SG_LANG_TABLE), null, null, array(0, 1)); } } } else { $mform->addElement('static', 'notconfigured', get_string('notconfiguredleft', BLOCK_SG_LANG_TABLE), get_string('notconfiguredright', BLOCK_SG_LANG_TABLE)); } // Hidden elements: courseid needed for posting. $mform->addElement('hidden', 'courseid'); $mform->setType('courseid', PARAM_INT); $this->add_action_buttons(); }
/** * 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 runs through the scores (both all and individual items) and compares * them to the desired result stored in $expected. * * @param array $expected Desired outcome of score comparison. */ private function verify_join_form_scores($expected) { for ($i = 0; $i < self::NUMBEROFGROUPS; $i++) { // Now test the group. $sgroup = new skills_group($this->groupids[$i]); $scores = $sgroup->get_join_form_score(); foreach ($scores as $score) { $this->assertEquals($score, $expected[$i]); } } // Now test getting individual score. for ($i = 0; $i < self::NUMBEROFGROUPS; $i++) { $sgroup = new skills_group($this->groupids[$i]); for ($j = 1; $j <= self::FEEDBACKITEMS; $j++) { $this->assertEquals($sgroup->get_join_form_score($j), $expected[$i]); } } }
/** * This function loads the YUI modules that I have written. I've elected to * load these last since that is generally safest. * * @param int $courseid The ID of the course being used. * @param int $groupid The ID of the group that the user belongs to. * */ function load_yui_modules($courseid, $groupid, $error = null) { global $PAGE; $params = array('courseid' => $courseid, 'groupid' => $groupid, 'errorstring' => $error); if ($error == null) { $sgsetting = new skills_group_setting($courseid); $sgrouping = new skills_grouping($courseid); $sgroup = new skills_group($groupid); // True max group size is: max group size - # of locked members. $params['maxgroupsize'] = $sgsetting->get_group_size() - count($sgroup->get_members_list(true)); $potentialstudents = $sgrouping->get_potential_students(); $params['availableids'] = array_keys($potentialstudents); $params['availablenames'] = array_values($potentialstudents); $unlockedstudents = $sgroup->get_members_list(false); $params['groupmemberids'] = array_keys($unlockedstudents); $params['groupmembernames'] = array_values($unlockedstudents); } $PAGE->requires->yui_module('moodle-block_skills_group-edit', 'M.block_skills_group.init_edit', array($params)); }