/** * This function tests the exists() method. exists() returns T/F depending * on if the settings entry has been created. * */ public function tests_exists() { $sgs = new skills_group_setting($this->courseid); $this->assertFalse($sgs->exists()); $sgs->update_record($this->get_skills_group_settings()); $this->assertTrue($sgs->exists()); }
/** * 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 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 $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); } } } set_header(); echo $OUTPUT->header();
global $CFG; require_once $CFG->dirroot . '/blocks/skills_group/locallib.php'; 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()) {