/**
  * 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();
 }
Пример #2
0
/**
 * This function determines the if user has locked in choice and updates database.
 *
 * @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 The url to redirect the user to.
 *
 */
function process_form($courseid, &$submittedform)
{
    global $USER;
    if (isset($submittedform->lockchoice)) {
        if ($submittedform->lockchoice) {
            $student = new skills_group_student($courseid, $USER->id);
            $student->set_lock_choice(true);
            $url = new moodle_url('/course/view.php', array('id' => $courseid));
        }
    } else {
        $url = new moodle_url('/course/view.php', array('id' => $courseid));
    }
    return $url;
}
 /**
  * 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 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 accumulates the total score for all members across items on the feedback
  * activity.
  *
  */
 private function compute_scores()
 {
     global $DB;
     $courseid = $DB->get_field('groups', 'courseid', array('id' => $this->groupid));
     $threshold = (new skills_group_setting($courseid))->get_threshold();
     $members = $DB->get_records('groups_members', array('groupid' => $this->groupid));
     $this->numberofmembers = count($members);
     foreach ($members as $member) {
         $sgs = new skills_group_student($courseid, $member->userid);
         $scores = $sgs->get_scores();
         foreach ($scores as $key => $score) {
             if (isset($this->accumulatedscores[$key])) {
                 $this->accumulatedscores[$key] += $score;
             } else {
                 $this->accumulatedscores[$key] = $score;
             }
             // Count number of scores greater than threshold.
             if ($score > $threshold) {
                 if (isset($this->highscores[$key])) {
                     $this->highscores[$key]++;
                 } else {
                     $this->highscores[$key] = 1;
                 }
             } else {
                 // Ensure that a zero gets entered at some point for the key.
                 if (!isset($this->highscores[$key])) {
                     $this->highscores[$key] = 0;
                 }
             }
         }
     }
     $this->scorescomputed = true;
 }
 /**
  * This function tests the flag that locks a student's choice.  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_lock_choice()
 {
     global $DB;
     $this->configure_settings();
     $sgroup = new skills_group_student($this->courseid, $this->users[0]->id);
     $this->assertFalse($sgroup->get_lock_choice());
     $sgroup->set_lock_choice(true);
     $lockchoice = $DB->get_field('skills_group_student', 'finalizegroup', array('userid' => $this->users[0]->id));
     $this->assertEquals($lockchoice, 1);
     $this->assertTrue($sgroup->get_lock_choice());
     $sgroup->set_lock_choice(false);
     $this->assertFalse($sgroup->get_lock_choice());
 }
Пример #7
0
/**
 * This function draws the group stats table.
 *
 */
function display_group_stats($groupid)
{
    global $DB;
    $courseid = required_param('courseid', PARAM_INT);
    $members = $DB->get_records('groups_members', array('groupid' => $groupid));
    $fullscores = array();
    foreach ($members as $member) {
        $sgs = new skills_group_student($courseid, $member->userid);
        $fullscores[] = $sgs->get_scores();
    }
    $gr = new group_records($courseid);
    $skillslist = $gr->get_skills_list(true, 'multichoice');
    $labellist = $gr->get_skills_list(true, 'label');
    echo html_writer::start_div('yui3-skin-sam', array('id' => 'viewgroup'));
    echo html_writer::start_tag('table', array('class' => 'yui3-datatable-table'));
    draw_table_header($members);
    draw_table_results($members, $skillslist, $labellist, $fullscores, $courseid);
    echo html_writer::end_tag('table');
    echo html_writer::end_div();
}