コード例 #1
0
ファイル: lib.php プロジェクト: jb-1980/ungraded_assignments
/**
 * Find the rownum for a userid and assign mod to user for grading url
 *
 * @param stdClass $cm course module object
 * @param in $userid the id of the user whose rownum we are interested in
 *
 * @return int 
 */
function ungraded_assignments_get_rownum($cm, $userid)
{
    global $COURSE;
    $mod_context = context_module::instance($cm->id);
    $assign = new assign($mod_context, $cm, $COURSE);
    $filter = get_user_preferences('assign_filter', '');
    $table = new assign_grading_table($assign, 0, $filter, 0, false);
    $useridlist = $table->get_column_data('userid');
    $rownum = array_search($userid, $useridlist);
    return $rownum;
}
コード例 #2
0
ファイル: locallib.php プロジェクト: covex-nn/moodle
 /**
  * Utility function to get the userid for every row in the grading table
  * so the order can be frozen while we iterate it.
  *
  * @return array An array of userids
  */
 protected function get_grading_userid_list()
 {
     $filter = get_user_preferences('assign_filter', '');
     $table = new assign_grading_table($this, 0, $filter, 0, false);
     $useridlist = $table->get_column_data('userid');
     return $useridlist;
 }
コード例 #3
0
    /**
     * Utility function get the userid based on the row number of the grading table.
     * This takes into account any active filters on the table.
     *
     * @param int $num The row number of the user
     * @param bool $last This is set to true if this is the last user in the table
     * @return mixed The user id of the matching user or false if there was an error
     */
    private function get_userid_for_row($num, $last) {
        if (!array_key_exists('userid_for_row', $this->cache)) {
            $this->cache['userid_for_row'] = array();
        }
        if (array_key_exists($num, $this->cache['userid_for_row'])) {
            list($userid, $last) = $this->cache['userid_for_row'][$num];
            return $userid;
        }

        $filter = get_user_preferences('assign_filter', '');
        $table = new assign_grading_table($this, 0, $filter, 0, false);

        $userid = $table->get_cell_data($num, 'userid', $last);

        $this->cache['userid_for_row'][$num] = array($userid, $last);
        return $userid;
    }
コード例 #4
0
ファイル: locallib.php プロジェクト: pzhu2004/moodle
 /**
  * Download a marking worksheet
  *
  * @return string The response html
  */
 public function download_grades()
 {
     global $CFG;
     require_capability('mod/assign:grade', $this->assignment->get_context());
     require_once $CFG->dirroot . '/mod/assign/gradingtable.php';
     $groupmode = groups_get_activity_groupmode($this->assignment->get_course_module());
     // All users.
     $groupid = 0;
     $groupname = '';
     if ($groupmode) {
         $groupid = groups_get_activity_group($this->assignment->get_course_module(), true);
         $groupname = groups_get_group_name($groupid) . '-';
     }
     $filename = clean_filename(get_string('offlinegradingworksheet', 'assignfeedback_offline') . '-' . $this->assignment->get_course()->shortname . '-' . $this->assignment->get_instance()->name . '-' . $groupname . $this->assignment->get_course_module()->id);
     $table = new assign_grading_table($this->assignment, 0, '', 0, false, $filename);
     $table->out(0, false);
     return;
 }
コード例 #5
0
 public function test_list_participants_blind_marking()
 {
     global $DB;
     $this->resetAfterTest(true);
     $course = $this->getDataGenerator()->create_course();
     $roles = $DB->get_records('role', null, '', 'shortname, id');
     $teacher = $this->getDataGenerator()->create_user();
     $this->getDataGenerator()->enrol_user($teacher->id, $course->id, $roles['teacher']->id);
     $this->setUser($teacher);
     // Enrol two students.
     $students = [];
     for ($i = 0; $i < 2; $i++) {
         $student = $this->getDataGenerator()->create_user();
         $this->getDataGenerator()->enrol_user($student->id, $course->id, $roles['student']->id);
         $students[$student->id] = $student;
     }
     $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
     $instance = $generator->create_instance(['course' => $course->id, 'blindmarking' => 1]);
     $cm = get_coursemodule_from_instance('assign', $instance->id);
     $context = context_module::instance($cm->id);
     $assign = new assign($context, $cm, $course);
     // Allocate IDs now.
     // We're testing whether the IDs are correct after allocation.
     assign::allocate_unique_ids($assign->get_instance()->id);
     $participants = $assign->list_participants(null, false);
     // There should be exactly two participants and they should be the students.
     $this->assertCount(2, $participants);
     foreach ($participants as $participant) {
         $this->assertArrayHasKey($participant->id, $students);
     }
     $keys = array_keys($participants);
     // Create a grading table, and query the DB This should have the same order.
     $table = new assign_grading_table($assign, 10, '', 0, false);
     $table->setup();
     $table->query_db(10);
     $this->assertEquals($keys, array_keys($table->rawdata));
     // Submit a file for the second student.
     $data = new stdClass();
     $data->onlinetext_editor = array('itemid' => file_get_unused_draft_itemid(), 'text' => 'Submission text', 'format' => FORMAT_MOODLE);
     static::helper_add_submission($assign, $participants[$keys[1]], $data, 'onlinetext');
     // Assign has a private cache. The easiest way to clear this is to create a new instance.
     $assign = new assign($context, $cm, $course);
     $newparticipants = $assign->list_participants(null, false);
     // There should be exactly two participants and they should be the students.
     $this->assertCount(2, $newparticipants);
     foreach ($newparticipants as $participant) {
         $this->assertArrayHasKey($participant->id, $students);
     }
     $newkeys = array_keys($newparticipants);
     // The user who submitted first should now be listed first.
     $this->assertEquals($participants[$keys[1]]->id, $newparticipants[$newkeys[0]]->id);
     $this->assertEquals($participants[$keys[0]]->id, $newparticipants[$newkeys[1]]->id);
     // Submit for the other student.
     static::helper_add_submission($assign, $participants[$keys[0]], $data, 'onlinetext');
     $assign = new assign($context, $cm, $course);
     $newparticipants = $assign->list_participants(null, false);
     // The users should still be listed in order of the first submission
     $this->assertEquals($participants[$keys[1]]->id, $newparticipants[$newkeys[0]]->id);
     $this->assertEquals($participants[$keys[0]]->id, $newparticipants[$newkeys[1]]->id);
     // The updated grading table should have the same order as the updated participant list.
     $table->query_db(10);
     $this->assertEquals($newkeys, array_keys($table->rawdata));
 }
コード例 #6
0
 /**
  * Work out the userid from the return parameters.
  * @return bool
  */
 protected function get_userid_because_assign_really_does_not_want_to_tell_me()
 {
     $rownum = $this->get_rownum();
     if ($rownum === false) {
         return false;
     }
     // This part is copied out of the 'assign' class (as it is private, so I can't use it directly).
     $filter = get_user_preferences('assign_filter', '');
     $table = new assign_grading_table($this->assignment, 0, $filter, 0, false);
     $useridlist = $table->get_column_data('userid');
     $userid = $useridlist[$rownum];
     return $userid;
 }
 /**
  * Makes the grading interface for the pop up. Robbed from /mod/assign/locallib.php
  * line 1583ish - view_single_grade_page().
  *
  * @param array $params From $_GET
  * @param object $coursemodule The coursemodule object that the user has been authenticated
  * against
  * @param bool $data
  * @throws coding_exception
  * @global $PAGE
  * @global stdClass $CFG
  * @global moodle_database $DB
  * @global $OUTPUT
  * @global stdClass $USER
  * @return string
  */
 public function grading_popup($params, $coursemodule, $data = false)
 {
     global $PAGE, $CFG, $DB;
     $modulecontext = context_module::instance($coursemodule->id);
     $course = $DB->get_record('course', array('id' => $coursemodule->course));
     $coursecontext = context_course::instance($course->id);
     $assign = new assign($modulecontext, $coursemodule, $course);
     /* @var mod_assign_renderer $renderer */
     $renderer = $PAGE->get_renderer('mod_assign');
     $output = '';
     // Include grade form.
     require_once $CFG->dirroot . '/mod/assign/gradeform.php';
     // Need submit permission to submit an assignment.
     require_capability('mod/assign:grade', $modulecontext);
     /* Pinched from private method assign::get_grading_userid_list() */
     $filter = get_user_preferences('assign_filter', '');
     $table = new assign_grading_table($assign, 0, $filter, 0, false);
     $useridlist = $table->get_column_data('userid');
     $userid = $params['userid'];
     $rownum = 0;
     foreach ($useridlist as $key => $useridinlist) {
         if ($useridinlist == $userid) {
             $rownum = $key;
             reset($useridlist);
             // Just in case.
             break;
         }
     }
     $last = false;
     if ($rownum == count($useridlist) - 1) {
         $last = true;
     }
     $user = $DB->get_record('user', array('id' => $userid));
     if ($user) {
         $output .= $renderer->render(new assign_user_summary($user, $course->id, has_capability('moodle/site:viewfullnames', $coursecontext)));
     }
     $submission = $DB->get_record('assign_submission', array('assignment' => $assign->get_instance()->id, 'userid' => $userid));
     // Get the current grade. Pinched from assign::get_user_grade().
     $grade = $DB->get_record('assign_grades', array('assignment' => $assign->get_instance()->id, 'userid' => $userid));
     // Pinched from assign::is_graded().
     $isgraded = !empty($grade) && $grade->grade !== null && $grade->grade >= 0;
     if ($assign->can_view_submission($userid)) {
         $gradelocked = $grade && $grade->locked || $assign->grading_disabled($userid);
         $widget = new assign_submission_status($assign->get_instance()->allowsubmissionsfromdate, $assign->get_instance()->alwaysshowdescription, $submission, $assign->is_any_submission_plugin_enabled(), $gradelocked, $isgraded, $assign->get_instance()->duedate, $assign->get_submission_plugins(), $assign->get_return_action(), $assign->get_return_params(), $assign->get_course_module()->id, assign_submission_status::GRADER_VIEW, false, false);
         $output .= $renderer->render($widget);
     }
     if ($grade) {
         $data = new stdClass();
         if ($grade->grade !== null && $grade->grade >= 0) {
             $data->grade = format_float($grade->grade, 2);
         }
     } else {
         $data = new stdClass();
         $data->grade = '';
     }
     // Now show the grading form.
     $customdata = array('useridlist' => $useridlist, 'rownum' => $rownum, 'last' => $last);
     $mform = new mod_assign_grade_form(block_ajax_marking_form_url($params), array($assign, $data, $customdata), 'post', '', array('class' => 'gradeform'));
     $output .= $renderer->render(new assign_form('gradingform', $mform));
     $assign->add_to_log('view grading form', get_string('viewgradingformforstudent', 'assign', array('id' => $user->id, 'fullname' => fullname($user))));
     return $output;
 }