/** * This function retrieves the list of headers used in the table. * * @param bool $returnkeys T/F indicating whether the keys should be returned with the array values. * @return array Full named list of skills in the feedback * */ public function get_skills_list($returnkeys = false, $type = 'multichoice') { global $DB; $sgs = new skills_group_setting($this->courseid); $skills = array(); // If no feedback setup, return empty array. if ($sgs->get_feedback_id() == NOFEEDBACK) { return $skills; } $feedbackitems = $DB->get_records('feedback_item', array('feedback' => $sgs->get_feedback_id()), 'position'); foreach ($feedbackitems as $feedbackitem) { if ($feedbackitem->typ == $type) { if ($feedbackitem->typ == 'multichoice') { $skills[$feedbackitem->position] = $feedbackitem->name; } else { if ($feedbackitem->typ == 'label') { $skills[$feedbackitem->position] = $feedbackitem->presentation; } } } } if ($returnkeys === false) { return array_values($skills); } else { return $skills; } }
/** * 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 stores the needed variables and computes the total skill * scores for a student. * * @param int $courseid The ID of the course. * @param int $userid The ID of the user to retrieve the scores for. * @param int $itemids The IDs of the feedback items that contain valid scores. * */ public function __construct($courseid, $userid, $itemids = null) { $this->courseid = $courseid; $sgsetting = new skills_group_setting($courseid); $this->feedbackid = $sgsetting->get_feedback_id(); $this->userid = $userid; $this->compute_scores(); }
/** * This function determines the user's desired course of action -> {create, edit, drop} * and processes it accordingly. * * @param int $courseid The ID of the course. * @param object $submittedform The object contains the results of the form when changes were saved. * @return string|boolean The url to redirect the user to or false to prevent redirect. * */ function process_form($courseid, &$submittedform) { global $DB, $USER; $sgs = new skills_group_setting($courseid); if ($sgs->date_restriction() && time() > $sgs->get_date()) { // Process no data and redirect back to same form. Form will draw expired version to alert user. $url = new moodle_url('/blocks/skills_group/create_skills_group.php', array('courseid' => $courseid, 'sesskey' => $USER->sesskey)); return $url; } if ($submittedform->type == 'create') { if ($submittedform->creategroupcheck) { $sgrouping = new skills_grouping($courseid); // Blank names are OK -> plugin will autoname. $groupname = isset($submittedform->creategroup) ? $submittedform->creategroup : null; $groupid = $sgrouping->create_group($groupname); update_allow_join($groupid, $submittedform->allowjoincheck); $url = new moodle_url('/blocks/skills_group/edit_skills_group.php', array('courseid' => $courseid, 'groupid' => $groupid, 'sesskey' => $USER->sesskey)); // Logging create group action. $params = array('context' => context_course::instance($courseid), 'objectid' => $groupid, 'courseid' => $courseid, 'userid' => $USER->id); $event = \block_skills_group\event\skillsgroup_left::create($params); $event->trigger(); } else { $url = new moodle_url('/course/view.php', array('id' => $courseid)); } } else { if ($submittedform->type == 'edit') { if (isset($submittedform->leavegroup)) { if ($submittedform->leavegroup) { groups_remove_member($submittedform->groupid, $USER->id); // Logging leave group action. $params = array('context' => context_course::instance($courseid), 'objectid' => $submittedform->groupid, 'courseid' => $courseid, 'userid' => $USER->id); $event = \block_skills_group\event\skillsgroup_left::create($params); $event->trigger(); $url = new moodle_url('/course/view.php', array('id' => $courseid)); return $url; } } $groupid = $submittedform->groupid; update_allow_join($groupid, $submittedform->allowjoincheck); if ($submittedform->editmembers) { $url = new moodle_url('/blocks/skills_group/edit_skills_group.php', array('courseid' => $courseid, 'groupid' => $groupid, 'sesskey' => $USER->sesskey)); } else { $url = new moodle_url('/course/view.php', array('id' => $courseid)); } } else { $url = new moodle_url('/course/view.php', array('id' => $courseid)); } } return $url; }
/** * * This function draws links to the necessary functions depending on the user's * capability (defined by role). * * Instructor -> {Edit Group Settings} * Student -> {Create Group, Join Group} * */ public function get_content() { global $COURSE, $USER; if ($this->content !== null) { return $this->content; } $this->content = new stdClass(); $this->content->footer = ''; $context = context_course::instance($COURSE->id); if (has_capability('block/skills_group:canmanageskillsgroups', $context)) { $url = new moodle_url('/blocks/skills_group/edit_skills_group_settings.php', array('courseid' => $COURSE->id, 'sesskey' => $USER->sesskey)); $this->content->footer .= html_writer::link($url, get_string('editgroupsettings', BLOCK_SG_LANG_TABLE)); $this->content->footer .= html_writer::empty_tag('br'); } else { if (has_capability('block/skills_group:cancreateorjoinskillsgroups', $context)) { $sgs = new skills_group_setting($COURSE->id); if ($sgs->exists()) { if ($sgs->date_restriction() && time() > $sgs->get_date()) { $this->content->footer .= html_writer::nonempty_tag('p', get_string('groupexpired', BLOCK_SG_LANG_TABLE)); } else { $url = new moodle_url('/blocks/skills_group/create_skills_group.php', array('courseid' => $COURSE->id, 'sesskey' => $USER->sesskey)); $this->content->footer .= html_writer::link($url, get_string('createskillsgroup', BLOCK_SG_LANG_TABLE)); $this->content->footer .= html_writer::empty_tag('br'); } $sgrouping = new skills_grouping($COURSE->id); // Only display option to join if user is not already part of a group. if ($sgrouping->check_for_user_in_grouping($USER->id) === false) { if (!$sgs->date_restriction() || time() < $sgs->get_date()) { $url = new moodle_url('/blocks/skills_group/join_skills_group.php', array('courseid' => $COURSE->id, 'sesskey' => $USER->sesskey)); $this->content->footer .= html_writer::link($url, get_string('joinskillsgroup', BLOCK_SG_LANG_TABLE)); $this->content->footer .= html_writer::empty_tag('br'); } } else { $url = new moodle_url('/blocks/skills_group/lock_choice.php', array('courseid' => $COURSE->id, 'sesskey' => $USER->sesskey)); $this->content->footer .= html_writer::link($url, get_string('lockgrouplink', BLOCK_SG_LANG_TABLE)); $this->content->footer .= html_writer::empty_tag('br'); $url = new moodle_url('/blocks/skills_group/view_group.php', array('courseid' => $COURSE->id, 'sesskey' => $USER->sesskey)); $this->content->footer .= html_writer::link($url, get_string('viewskillsgroup', BLOCK_SG_LANG_TABLE)); $this->content->footer .= html_writer::empty_tag('br'); } } else { $this->content->footer .= html_writer::nonempty_tag('p', get_string('notconfigured', BLOCK_SG_LANG_TABLE)); } } } return $this->content; }
/** * 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(); }
require_once dirname(__FILE__) . '/../../config.php'; global $CFG; require_once $CFG->dirroot . '/blocks/skills_group/locallib.php'; require_once $CFG->dirroot . '/blocks/skills_group/classes/skills_grouping.class.php'; require_once $CFG->dirroot . '/blocks/skills_group/classes/skills_group_setting.class.php'; require_once $CFG->dirroot . '/local/yuigallerylibs/module_info.php'; global $PAGE, $OUTPUT, $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/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); } } }
/** * 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 configures the skills_group_setting class for further testing. I do not call this * on the setUp() function here, but derived testing classes can do so as needed. * * @param integer $threshold low/high score threshold * @param integer $date date in unix epoch format * @param integer $allownaming whether students can name their groups (1) or not (0) */ protected function configure_settings($threshold = 1, $date = null, $allownaming = 1) { $sgs = new skills_group_setting($this->courseid); $settings = $this->get_skills_group_settings($threshold, $date, $allownaming); $sgs->update_record($settings); // Set last student to have choice locked. $student = new skills_group_student($this->courseid, $this->users[self::NUMBEROFUSERS - 1]->id); $student->set_lock_choice(true); }
/** * This function tests the date_restriction() method. The method returns T/F depending * on if a date restriction exists. */ public function test_date_restriction() { $sgs = new skills_group_setting($this->courseid); $sgs->update_record($this->get_skills_group_settings()); $this->assertFalse((bool) $sgs->date_restriction()); $sgs->update_record($this->get_skills_group_settings(1, time())); $this->assertTrue((bool) $sgs->date_restriction()); }
/** * This function processes the submitted form by saving the IDs of the feedback activity * and the grouping. * * @param int $courseid The ID of the course. * @param object $submittedform Object holding the submitted data by the user. * */ function process_form($courseid, &$submittedform) { global $DB; $sgs = new skills_group_setting($courseid); $sgs->update_record($submittedform); }
/** * 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)); }
/** * 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; } }
global $CFG; require_once $CFG->dirroot . '/user/lib.php'; require_once $CFG->dirroot . '/blocks/skills_group/locallib.php'; require_once $CFG->dirroot . '/blocks/skills_group/classes/skills_grouping.class.php'; require_once $CFG->dirroot . '/blocks/skills_group/classes/skills_group_setting.class.php'; require_once $CFG->dirroot . '/blocks/skills_group/classes/group_records.class.php'; global $PAGE, $OUTPUT, $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/view_group.php', array('courseid' => $courseid, 'sesskey' => $USER->sesskey)); block_skills_group_setup_page($courseid, $url, get_string('viewskillsgroup', BLOCK_SG_LANG_TABLE)); $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 { $groupingid = $sgs->get_grouping_id(); $sgrouping = new skills_grouping($courseid); $groupid = $sgrouping->check_for_user_in_grouping($USER->id); // If user has - display error. if ($groupid === false) { $error = get_string('nogrouperror', BLOCK_SG_LANG_TABLE); } } set_header(); echo $OUTPUT->header(); if ($error != null) {