Beispiel #1
0
 /**
  * View the grading table of all submissions for this assignment.
  *
  * @return string
  */
 protected function view_grading_table()
 {
     global $USER, $CFG;
     // Include grading options form.
     require_once $CFG->dirroot . '/mod/assign/gradingoptionsform.php';
     require_once $CFG->dirroot . '/mod/assign/quickgradingform.php';
     require_once $CFG->dirroot . '/mod/assign/gradingbatchoperationsform.php';
     $o = '';
     $cmid = $this->get_course_module()->id;
     $links = array();
     if (has_capability('gradereport/grader:view', $this->get_course_context()) && has_capability('moodle/grade:viewall', $this->get_course_context())) {
         $gradebookurl = '/grade/report/grader/index.php?id=' . $this->get_course()->id;
         $links[$gradebookurl] = get_string('viewgradebook', 'assign');
     }
     if ($this->is_any_submission_plugin_enabled() && $this->count_submissions()) {
         $downloadurl = '/mod/assign/view.php?id=' . $cmid . '&action=downloadall';
         $links[$downloadurl] = get_string('downloadall', 'assign');
     }
     if ($this->is_blind_marking() && has_capability('mod/assign:revealidentities', $this->get_context())) {
         $revealidentitiesurl = '/mod/assign/view.php?id=' . $cmid . '&action=revealidentities';
         $links[$revealidentitiesurl] = get_string('revealidentities', 'assign');
     }
     foreach ($this->get_feedback_plugins() as $plugin) {
         if ($plugin->is_enabled() && $plugin->is_visible()) {
             foreach ($plugin->get_grading_actions() as $action => $description) {
                 $url = '/mod/assign/view.php' . '?id=' . $cmid . '&plugin=' . $plugin->get_type() . '&pluginsubtype=assignfeedback' . '&action=viewpluginpage&pluginaction=' . $action;
                 $links[$url] = $description;
             }
         }
     }
     // Sort links alphabetically based on the link description.
     core_collator::asort($links);
     $gradingactions = new url_select($links);
     $gradingactions->set_label(get_string('choosegradingaction', 'assign'));
     $gradingmanager = get_grading_manager($this->get_context(), 'mod_assign', 'submissions');
     $perpage = get_user_preferences('assign_perpage', 10);
     $filter = get_user_preferences('assign_filter', '');
     $markerfilter = get_user_preferences('assign_markerfilter', '');
     $workflowfilter = get_user_preferences('assign_workflowfilter', '');
     $controller = $gradingmanager->get_active_controller();
     $showquickgrading = empty($controller);
     $quickgrading = get_user_preferences('assign_quickgrading', false);
     $showonlyactiveenrolopt = has_capability('moodle/course:viewsuspendedusers', $this->context);
     $markingallocation = $this->get_instance()->markingallocation && has_capability('mod/assign:manageallocations', $this->context);
     // Get markers to use in drop lists.
     $markingallocationoptions = array();
     if ($markingallocation) {
         $markers = get_users_by_capability($this->context, 'mod/assign:grade');
         $markingallocationoptions[''] = get_string('filternone', 'assign');
         foreach ($markers as $marker) {
             $markingallocationoptions[$marker->id] = fullname($marker);
         }
     }
     $markingworkflow = $this->get_instance()->markingworkflow;
     // Get marking states to show in form.
     $markingworkflowoptions = array();
     if ($markingworkflow) {
         $notmarked = get_string('markingworkflowstatenotmarked', 'assign');
         $markingworkflowoptions[''] = get_string('filternone', 'assign');
         $markingworkflowoptions[ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED] = $notmarked;
         $markingworkflowoptions = array_merge($markingworkflowoptions, $this->get_marking_workflow_states_for_current_user());
     }
     // Print options for changing the filter and changing the number of results per page.
     $gradingoptionsformparams = array('cm' => $cmid, 'contextid' => $this->context->id, 'userid' => $USER->id, 'submissionsenabled' => $this->is_any_submission_plugin_enabled(), 'showquickgrading' => $showquickgrading, 'quickgrading' => $quickgrading, 'markingworkflowopt' => $markingworkflowoptions, 'markingallocationopt' => $markingallocationoptions, 'showonlyactiveenrolopt' => $showonlyactiveenrolopt, 'showonlyactiveenrol' => $this->show_only_active_users());
     $classoptions = array('class' => 'gradingoptionsform');
     $gradingoptionsform = new mod_assign_grading_options_form(null, $gradingoptionsformparams, 'post', '', $classoptions);
     $batchformparams = array('cm' => $cmid, 'submissiondrafts' => $this->get_instance()->submissiondrafts, 'duedate' => $this->get_instance()->duedate, 'attemptreopenmethod' => $this->get_instance()->attemptreopenmethod, 'feedbackplugins' => $this->get_feedback_plugins(), 'context' => $this->get_context(), 'markingworkflow' => $markingworkflow, 'markingallocation' => $markingallocation);
     $classoptions = array('class' => 'gradingbatchoperationsform');
     $gradingbatchoperationsform = new mod_assign_grading_batch_operations_form(null, $batchformparams, 'post', '', $classoptions);
     $gradingoptionsdata = new stdClass();
     $gradingoptionsdata->perpage = $perpage;
     $gradingoptionsdata->filter = $filter;
     $gradingoptionsdata->markerfilter = $markerfilter;
     $gradingoptionsdata->workflowfilter = $workflowfilter;
     $gradingoptionsform->set_data($gradingoptionsdata);
     $actionformtext = $this->get_renderer()->render($gradingactions);
     $header = new assign_header($this->get_instance(), $this->get_context(), false, $this->get_course_module()->id, get_string('grading', 'assign'), $actionformtext);
     $o .= $this->get_renderer()->render($header);
     $currenturl = $CFG->wwwroot . '/mod/assign/view.php?id=' . $this->get_course_module()->id . '&action=grading';
     $o .= groups_print_activity_menu($this->get_course_module(), $currenturl, true);
     // Plagiarism update status apearring in the grading book.
     if (!empty($CFG->enableplagiarism)) {
         require_once $CFG->libdir . '/plagiarismlib.php';
         $o .= plagiarism_update_status($this->get_course(), $this->get_course_module());
     }
     // Load and print the table of submissions.
     if ($showquickgrading && $quickgrading) {
         $gradingtable = new assign_grading_table($this, $perpage, $filter, 0, true);
         $table = $this->get_renderer()->render($gradingtable);
         $quickformparams = array('cm' => $this->get_course_module()->id, 'gradingtable' => $table);
         $quickgradingform = new mod_assign_quick_grading_form(null, $quickformparams);
         $o .= $this->get_renderer()->render(new assign_form('quickgradingform', $quickgradingform));
     } else {
         $gradingtable = new assign_grading_table($this, $perpage, $filter, 0, false);
         $o .= $this->get_renderer()->render($gradingtable);
     }
     $currentgroup = groups_get_activity_group($this->get_course_module(), true);
     $users = array_keys($this->list_participants($currentgroup, true));
     if (count($users) != 0) {
         // If no enrolled user in a course then don't display the batch operations feature.
         $assignform = new assign_form('gradingbatchoperationsform', $gradingbatchoperationsform);
         $o .= $this->get_renderer()->render($assignform);
     }
     $assignform = new assign_form('gradingoptionsform', $gradingoptionsform, 'M.mod_assign.init_grading_options');
     $o .= $this->get_renderer()->render($assignform);
     return $o;
 }
    /**
     * View the grading table of all submissions for this assignment
     *
     * @return string
     */
    private function view_grading_table() {
        global $USER, $CFG;
        // Include grading options form
        require_once($CFG->dirroot . '/mod/assign/gradingoptionsform.php');
        require_once($CFG->dirroot . '/mod/assign/quickgradingform.php');
        require_once($CFG->dirroot . '/mod/assign/gradingbatchoperationsform.php');
        $o = '';

        $links = array();
        if (has_capability('gradereport/grader:view', $this->get_course_context()) &&
                has_capability('moodle/grade:viewall', $this->get_course_context())) {
            $gradebookurl = '/grade/report/grader/index.php?id=' . $this->get_course()->id;
            $links[$gradebookurl] = get_string('viewgradebook', 'assign');
        }
        if ($this->is_any_submission_plugin_enabled()) {
            $downloadurl = '/mod/assign/view.php?id=' . $this->get_course_module()->id . '&action=downloadall';
            $links[$downloadurl] = get_string('downloadall', 'assign');
        }
        if ($this->is_blind_marking() && has_capability('mod/assign:revealidentities', $this->get_context())) {
            $revealidentitiesurl = '/mod/assign/view.php?id=' . $this->get_course_module()->id . '&action=revealidentities';
            $links[$revealidentitiesurl] = get_string('revealidentities', 'assign');
        }
        foreach ($this->get_feedback_plugins() as $plugin) {
            if ($plugin->is_enabled() && $plugin->is_visible()) {
                foreach ($plugin->get_grading_actions() as $action => $description) {
                    $url = '/mod/assign/view.php' .
                           '?id=' .  $this->get_course_module()->id .
                           '&plugin=' . $plugin->get_type() .
                           '&pluginsubtype=assignfeedback' .
                           '&action=viewpluginpage&pluginaction=' . $action;
                    $links[$url] = $description;
                }
            }
        }

        $gradingactions = new url_select($links);

        $gradingmanager = get_grading_manager($this->get_context(), 'mod_assign', 'submissions');

        $perpage = get_user_preferences('assign_perpage', 10);
        $filter = get_user_preferences('assign_filter', '');
        $controller = $gradingmanager->get_active_controller();
        $showquickgrading = empty($controller);
        if (optional_param('action', '', PARAM_ALPHA) == 'saveoptions') {
            $quickgrading = optional_param('quickgrading', false, PARAM_BOOL);
            set_user_preference('assign_quickgrading', $quickgrading);
        }
        $quickgrading = get_user_preferences('assign_quickgrading', false);

        // print options  for changing the filter and changing the number of results per page
        $gradingoptionsform = new mod_assign_grading_options_form(null,
                                                                  array('cm'=>$this->get_course_module()->id,
                                                                        'contextid'=>$this->context->id,
                                                                        'userid'=>$USER->id,
                                                                        'submissionsenabled'=>$this->is_any_submission_plugin_enabled(),
                                                                        'showquickgrading'=>$showquickgrading,
                                                                        'quickgrading'=>$quickgrading),
                                                                  'post', '',
                                                                  array('class'=>'gradingoptionsform'));

        $gradingbatchoperationsform = new mod_assign_grading_batch_operations_form(null,
                                                                  array('cm'=>$this->get_course_module()->id,
                                                                        'submissiondrafts'=>$this->get_instance()->submissiondrafts,
                                                                        'duedate'=>$this->get_instance()->duedate,
                                                                        'feedbackplugins'=>$this->get_feedback_plugins()),
                                                                  'post', '',
                                                                  array('class'=>'gradingbatchoperationsform'));

        $gradingoptionsdata = new stdClass();
        $gradingoptionsdata->perpage = $perpage;
        $gradingoptionsdata->filter = $filter;
        $gradingoptionsform->set_data($gradingoptionsdata);

        $actionformtext = $this->output->render($gradingactions);
        $o .= $this->output->render(new assign_header($this->get_instance(),
                                                      $this->get_context(), false, $this->get_course_module()->id, get_string('grading', 'assign'), $actionformtext));
        $o .= groups_print_activity_menu($this->get_course_module(), $CFG->wwwroot . '/mod/assign/view.php?id=' . $this->get_course_module()->id.'&action=grading', true);

        // plagiarism update status apearring in the grading book
        if (!empty($CFG->enableplagiarism)) {
            /** Include plagiarismlib.php */
            require_once($CFG->libdir . '/plagiarismlib.php');
            $o .= plagiarism_update_status($this->get_course(), $this->get_course_module());
        }

        // load and print the table of submissions
        if ($showquickgrading && $quickgrading) {
            $table = $this->output->render(new assign_grading_table($this, $perpage, $filter, 0, true));
            $quickgradingform = new mod_assign_quick_grading_form(null,
                                                                  array('cm'=>$this->get_course_module()->id,
                                                                        'gradingtable'=>$table));
            $o .= $this->output->render(new assign_form('quickgradingform', $quickgradingform));
        } else {
            $o .= $this->output->render(new assign_grading_table($this, $perpage, $filter, 0, false));
        }

        $currentgroup = groups_get_activity_group($this->get_course_module(), true);
        $users = array_keys($this->list_participants($currentgroup, true));
        if (count($users) != 0) {
            // if no enrolled user in a course then don't display the batch operations feature
            $o .= $this->output->render(new assign_form('gradingbatchoperationsform', $gradingbatchoperationsform));
        }
        $o .= $this->output->render(new assign_form('gradingoptionsform', $gradingoptionsform, 'M.mod_assign.init_grading_options'));
        return $o;
    }
Beispiel #3
0
    /**
     *  Display all the submissions ready for grading
     *
     * @global object
     * @global object
     * @global object
     * @global object
     * @param string $message
     * @return bool|void
     */
    function display_submissions($message='') {
        global $CFG, $DB, $USER, $DB, $OUTPUT, $PAGE;
        require_once($CFG->libdir.'/gradelib.php');

        /* first we check to see if the form has just been submitted
         * to request user_preference updates
         */

       $filters = array(self::FILTER_ALL             => get_string('all'),
                        self::FILTER_SUBMITTED       => get_string('submitted', 'assignment'),
                        self::FILTER_REQUIRE_GRADING => get_string('requiregrading', 'assignment'));

        $updatepref = optional_param('updatepref', 0, PARAM_INT);

        if (isset($_POST['updatepref'])){
            $perpage = optional_param('perpage', 10, PARAM_INT);
            $perpage = ($perpage <= 0) ? 10 : $perpage ;
            $filter = optional_param('filter', 0, PARAM_INT);
            set_user_preference('assignment_perpage', $perpage);
            set_user_preference('assignment_quickgrade', optional_param('quickgrade', 0, PARAM_BOOL));
            set_user_preference('assignment_filter', $filter);
        }

        /* next we get perpage and quickgrade (allow quick grade) params
         * from database
         */
        $perpage    = get_user_preferences('assignment_perpage', 10);
        $quickgrade = get_user_preferences('assignment_quickgrade', 0);
        $filter = get_user_preferences('assignment_filter', 0);
        $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id);

        if (!empty($CFG->enableoutcomes) and !empty($grading_info->outcomes)) {
            $uses_outcomes = true;
        } else {
            $uses_outcomes = false;
        }

        $page    = optional_param('page', 0, PARAM_INT);
        $strsaveallfeedback = get_string('saveallfeedback', 'assignment');

    /// Some shortcuts to make the code read better

        $course     = $this->course;
        $assignment = $this->assignment;
        $cm         = $this->cm;

        $tabindex = 1; //tabindex for quick grading tabbing; Not working for dropdowns yet
        add_to_log($course->id, 'assignment', 'view submission', 'submissions.php?id='.$this->cm->id, $this->assignment->id, $this->cm->id);

        $PAGE->set_title(format_string($this->assignment->name,true));
        $PAGE->set_heading($this->course->fullname);
        echo $OUTPUT->header();

        echo '<div class="usersubmissions">';

        //hook to allow plagiarism plugins to update status/print links.
        plagiarism_update_status($this->course, $this->cm);

        /// Print quickgrade form around the table
        if ($quickgrade) {
            $formattrs = array();
            $formattrs['action'] = new moodle_url('/mod/assignment/submissions.php');
            $formattrs['id'] = 'fastg';
            $formattrs['method'] = 'post';

            echo html_writer::start_tag('form', $formattrs);
            echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'id',      'value'=> $this->cm->id));
            echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'mode',    'value'=> 'fastgrade'));
            echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'page',    'value'=> $page));
            echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=> sesskey()));
        }

        $course_context = get_context_instance(CONTEXT_COURSE, $course->id);
        if (has_capability('gradereport/grader:view', $course_context) && has_capability('moodle/grade:viewall', $course_context)) {
            echo '<div class="allcoursegrades"><a href="' . $CFG->wwwroot . '/grade/report/grader/index.php?id=' . $course->id . '">'
                . get_string('seeallcoursegrades', 'grades') . '</a></div>';
        }

        if (!empty($message)) {
            echo $message;   // display messages here if any
        }

        $context = get_context_instance(CONTEXT_MODULE, $cm->id);

    /// Check to see if groups are being used in this assignment

        /// find out current groups mode
        $groupmode = groups_get_activity_groupmode($cm);
        $currentgroup = groups_get_activity_group($cm, true);
        groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/assignment/submissions.php?id=' . $this->cm->id);

        /// Get all ppl that are allowed to submit assignments
        list($esql, $params) = get_enrolled_sql($context, 'mod/assignment:view', $currentgroup);

        if ($filter == self::FILTER_ALL) {
            $sql = "SELECT u.id FROM {user} u ".
                   "LEFT JOIN ($esql) eu ON eu.id=u.id ".
                   "WHERE u.deleted = 0 AND eu.id=u.id ";
        } else {
            $wherefilter = '';
            if($filter == self::FILTER_SUBMITTED) {
               $wherefilter = ' AND s.timemodified > 0';
            } else if($filter == self::FILTER_REQUIRE_GRADING) {
                $wherefilter = ' AND s.timemarked < s.timemodified ';
            }

            $sql = "SELECT u.id FROM {user} u ".
                   "LEFT JOIN ($esql) eu ON eu.id=u.id ".
                   "LEFT JOIN {assignment_submissions} s ON (u.id = s.userid) " .
                   "WHERE u.deleted = 0 AND eu.id=u.id ".
                   'AND s.assignment = '. $this->assignment->id .
                    $wherefilter;
        }

        $users = $DB->get_records_sql($sql, $params);
        if (!empty($users)) {
            $users = array_keys($users);
        }

        // if groupmembersonly used, remove users who are not in any group
        if ($users and !empty($CFG->enablegroupmembersonly) and $cm->groupmembersonly) {
            if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
                $users = array_intersect($users, array_keys($groupingusers));
            }
        }

        $tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'status', 'finalgrade');
        if ($uses_outcomes) {
            $tablecolumns[] = 'outcome'; // no sorting based on outcomes column
        }

        $tableheaders = array('',
                              get_string('fullname'),
                              get_string('grade'),
                              get_string('comment', 'assignment'),
                              get_string('lastmodified').' ('.get_string('submission', 'assignment').')',
                              get_string('lastmodified').' ('.get_string('grade').')',
                              get_string('status'),
                              get_string('finalgrade', 'grades'));
        if ($uses_outcomes) {
            $tableheaders[] = get_string('outcome', 'grades');
        }

        require_once($CFG->libdir.'/tablelib.php');
        $table = new flexible_table('mod-assignment-submissions');

        $table->define_columns($tablecolumns);
        $table->define_headers($tableheaders);
        $table->define_baseurl($CFG->wwwroot.'/mod/assignment/submissions.php?id='.$this->cm->id.'&amp;currentgroup='.$currentgroup);

        $table->sortable(true, 'lastname');//sorted by lastname by default
        $table->collapsible(true);
        $table->initialbars(true);

        $table->column_suppress('picture');
        $table->column_suppress('fullname');

        $table->column_class('picture', 'picture');
        $table->column_class('fullname', 'fullname');
        $table->column_class('grade', 'grade');
        $table->column_class('submissioncomment', 'comment');
        $table->column_class('timemodified', 'timemodified');
        $table->column_class('timemarked', 'timemarked');
        $table->column_class('status', 'status');
        $table->column_class('finalgrade', 'finalgrade');
        if ($uses_outcomes) {
            $table->column_class('outcome', 'outcome');
        }

        $table->set_attribute('cellspacing', '0');
        $table->set_attribute('id', 'attempts');
        $table->set_attribute('class', 'submissions');
        $table->set_attribute('width', '100%');
        //$table->set_attribute('align', 'center');

        $table->no_sorting('finalgrade');
        $table->no_sorting('outcome');

        // Start working -- this is necessary as soon as the niceties are over
        $table->setup();

        if (empty($users)) {
            echo $OUTPUT->heading(get_string('nosubmitusers','assignment'));
            echo '</div>';
            return true;
        }
        if ($this->assignment->assignmenttype=='upload' || $this->assignment->assignmenttype=='online' || $this->assignment->assignmenttype=='uploadsingle') { //TODO: this is an ugly hack, where is the plugin spirit? (skodak)
            echo '<div style="text-align:right"><a href="submissions.php?id='.$this->cm->id.'&amp;download=zip">'.get_string('downloadall', 'assignment').'</a></div>';
        }
    /// Construct the SQL

        list($where, $params) = $table->get_sql_where();
        if ($where) {
            $where .= ' AND ';
        }

        if ($filter == self::FILTER_SUBMITTED) {
           $where .= 's.timemodified > 0 AND ';
        } else if($filter == self::FILTER_REQUIRE_GRADING) {
           $where .= 's.timemarked < s.timemodified AND ';
        }

        if ($sort = $table->get_sql_sort()) {
            $sort = ' ORDER BY '.$sort;
        }

        $ufields = user_picture::fields('u');

        $select = "SELECT $ufields,
                          s.id AS submissionid, s.grade, s.submissioncomment,
                          s.timemodified, s.timemarked,
                          COALESCE(SIGN(SIGN(s.timemarked) + SIGN(s.timemarked - s.timemodified)), 0) AS status ";
        $sql = 'FROM {user} u '.
               'LEFT JOIN {assignment_submissions} s ON u.id = s.userid
                AND s.assignment = '.$this->assignment->id.' '.
               'WHERE '.$where.'u.id IN ('.implode(',',$users).') ';

        $ausers = $DB->get_records_sql($select.$sql.$sort, $params, $table->get_page_start(), $table->get_page_size());

        $table->pagesize($perpage, count($users));

        ///offset used to calculate index of student in that particular query, needed for the pop up to know who's next
        $offset = $page * $perpage;
        $strupdate = get_string('update');
        $strgrade  = get_string('grade');
        $grademenu = make_grades_menu($this->assignment->grade);

        if ($ausers !== false) {
            $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, array_keys($ausers));
            $endposition = $offset + $perpage;
            $currentposition = 0;
            foreach ($ausers as $auser) {
                if ($currentposition == $offset && $offset < $endposition) {
                    $final_grade = $grading_info->items[0]->grades[$auser->id];
                    $grademax = $grading_info->items[0]->grademax;
                    $final_grade->formatted_grade = round($final_grade->grade,2) .' / ' . round($grademax,2);
                    $locked_overridden = 'locked';
                    if ($final_grade->overridden) {
                        $locked_overridden = 'overridden';
                    }

                /// Calculate user status
                    $auser->status = ($auser->timemarked > 0) && ($auser->timemarked >= $auser->timemodified);
                    $picture = $OUTPUT->user_picture($auser);

                    if (empty($auser->submissionid)) {
                        $auser->grade = -1; //no submission yet
                    }

                    if (!empty($auser->submissionid)) {
                    ///Prints student answer and student modified date
                    ///attach file or print link to student answer, depending on the type of the assignment.
                    ///Refer to print_student_answer in inherited classes.
                        if ($auser->timemodified > 0) {
                            $studentmodified = '<div id="ts'.$auser->id.'">'.$this->print_student_answer($auser->id)
                                             . userdate($auser->timemodified).'</div>';
                        } else {
                            $studentmodified = '<div id="ts'.$auser->id.'">&nbsp;</div>';
                        }
                    ///Print grade, dropdown or text
                        if ($auser->timemarked > 0) {
                            $teachermodified = '<div id="tt'.$auser->id.'">'.userdate($auser->timemarked).'</div>';

                            if ($final_grade->locked or $final_grade->overridden) {
                                $grade = '<div id="g'.$auser->id.'" class="'. $locked_overridden .'">'.$final_grade->formatted_grade.'</div>';
                            } else if ($quickgrade) {
                                $attributes = array();
                                $attributes['tabindex'] = $tabindex++;
                                $menu = html_writer::select(make_grades_menu($this->assignment->grade), 'menu['.$auser->id.']', $auser->grade, array(-1=>get_string('nograde')), $attributes);
                                $grade = '<div id="g'.$auser->id.'">'. $menu .'</div>';
                            } else {
                                $grade = '<div id="g'.$auser->id.'">'.$this->display_grade($auser->grade).'</div>';
                            }

                        } else {
                            $teachermodified = '<div id="tt'.$auser->id.'">&nbsp;</div>';
                            if ($final_grade->locked or $final_grade->overridden) {
                                $grade = '<div id="g'.$auser->id.'" class="'. $locked_overridden .'">'.$final_grade->formatted_grade.'</div>';
                            } else if ($quickgrade) {
                                $attributes = array();
                                $attributes['tabindex'] = $tabindex++;
                                $menu = html_writer::select(make_grades_menu($this->assignment->grade), 'menu['.$auser->id.']', $auser->grade, array(-1=>get_string('nograde')), $attributes);
                                $grade = '<div id="g'.$auser->id.'">'.$menu.'</div>';
                            } else {
                                $grade = '<div id="g'.$auser->id.'">'.$this->display_grade($auser->grade).'</div>';
                            }
                        }
                    ///Print Comment
                        if ($final_grade->locked or $final_grade->overridden) {
                            $comment = '<div id="com'.$auser->id.'">'.shorten_text(strip_tags($final_grade->str_feedback),15).'</div>';

                        } else if ($quickgrade) {
                            $comment = '<div id="com'.$auser->id.'">'
                                     . '<textarea tabindex="'.$tabindex++.'" name="submissioncomment['.$auser->id.']" id="submissioncomment'
                                     . $auser->id.'" rows="2" cols="20">'.($auser->submissioncomment).'</textarea></div>';
                        } else {
                            $comment = '<div id="com'.$auser->id.'">'.shorten_text(strip_tags($auser->submissioncomment),15).'</div>';
                        }
                    } else {
                        $studentmodified = '<div id="ts'.$auser->id.'">&nbsp;</div>';
                        $teachermodified = '<div id="tt'.$auser->id.'">&nbsp;</div>';
                        $status          = '<div id="st'.$auser->id.'">&nbsp;</div>';

                        if ($final_grade->locked or $final_grade->overridden) {
                            $grade = '<div id="g'.$auser->id.'">'.$final_grade->formatted_grade . '</div>';
                        } else if ($quickgrade) {   // allow editing
                            $attributes = array();
                            $attributes['tabindex'] = $tabindex++;
                            $menu = html_writer::select(make_grades_menu($this->assignment->grade), 'menu['.$auser->id.']', $auser->grade, array(-1=>get_string('nograde')), $attributes);
                            $grade = '<div id="g'.$auser->id.'">'.$menu.'</div>';
                        } else {
                            $grade = '<div id="g'.$auser->id.'">-</div>';
                        }

                        if ($final_grade->locked or $final_grade->overridden) {
                            $comment = '<div id="com'.$auser->id.'">'.$final_grade->str_feedback.'</div>';
                        } else if ($quickgrade) {
                            $comment = '<div id="com'.$auser->id.'">'
                                     . '<textarea tabindex="'.$tabindex++.'" name="submissioncomment['.$auser->id.']" id="submissioncomment'
                                     . $auser->id.'" rows="2" cols="20">'.($auser->submissioncomment).'</textarea></div>';
                        } else {
                            $comment = '<div id="com'.$auser->id.'">&nbsp;</div>';
                        }
                    }

                    if (empty($auser->status)) { /// Confirm we have exclusively 0 or 1
                        $auser->status = 0;
                    } else {
                        $auser->status = 1;
                    }

                    $buttontext = ($auser->status == 1) ? $strupdate : $strgrade;

                    ///No more buttons, we use popups ;-).
                    $popup_url = '/mod/assignment/submissions.php?id='.$this->cm->id
                               . '&amp;userid='.$auser->id.'&amp;mode=single'.'&amp;filter='.$filter.'&amp;offset='.$offset++;

                    $button = $OUTPUT->action_link($popup_url, $buttontext);

                    $status  = '<div id="up'.$auser->id.'" class="s'.$auser->status.'">'.$button.'</div>';

                    $finalgrade = '<span id="finalgrade_'.$auser->id.'">'.$final_grade->str_grade.'</span>';

                    $outcomes = '';

                    if ($uses_outcomes) {

                        foreach($grading_info->outcomes as $n=>$outcome) {
                            $outcomes .= '<div class="outcome"><label>'.$outcome->name.'</label>';
                            $options = make_grades_menu(-$outcome->scaleid);

                            if ($outcome->grades[$auser->id]->locked or !$quickgrade) {
                                $options[0] = get_string('nooutcome', 'grades');
                                $outcomes .= ': <span id="outcome_'.$n.'_'.$auser->id.'">'.$options[$outcome->grades[$auser->id]->grade].'</span>';
                            } else {
                                $attributes = array();
                                $attributes['tabindex'] = $tabindex++;
                                $attributes['id'] = 'outcome_'.$n.'_'.$auser->id;
                                $outcomes .= ' '.html_writer::select($options, 'outcome_'.$n.'['.$auser->id.']', $outcome->grades[$auser->id]->grade, array(0=>get_string('nooutcome', 'grades')), $attributes);
                            }
                            $outcomes .= '</div>';
                        }
                    }

                    $userlink = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $auser->id . '&amp;course=' . $course->id . '">' . fullname($auser, has_capability('moodle/site:viewfullnames', $this->context)) . '</a>';
                    $row = array($picture, $userlink, $grade, $comment, $studentmodified, $teachermodified, $status, $finalgrade);
                    if ($uses_outcomes) {
                        $row[] = $outcomes;
                    }

                    $table->add_data($row);
                }
                $currentposition++;
            }
        }

        $table->print_html();  /// Print the whole table

        /// Print quickgrade form around the table
        if ($quickgrade && $table->started_output){
            $mailinfopref = false;
            if (get_user_preferences('assignment_mailinfo', 1)) {
                $mailinfopref = true;
            }
            $emailnotification =  html_writer::checkbox('mailinfo', 1, $mailinfopref, get_string('enableemailnotification','assignment'));

            $emailnotification .= $OUTPUT->help_icon('enableemailnotification', 'assignment');
            echo html_writer::tag('div', $emailnotification, array('class'=>'emailnotification'));

            $savefeedback = html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'fastg', 'value'=>get_string('saveallfeedback', 'assignment')));
            echo html_writer::tag('div', $savefeedback, array('class'=>'fastgbutton'));

            echo html_writer::end_tag('form');
        } else if ($quickgrade) {
            echo html_writer::end_tag('form');
        }

        echo '</div>';
        /// End of fast grading form

        /// Mini form for setting user preference

        $formaction = new moodle_url('/mod/assignment/submissions.php', array('id'=>$this->cm->id));
        $mform = new MoodleQuickForm('optionspref', 'post', $formaction, '', array('class'=>'optionspref'));

        $mform->addElement('hidden', 'updatepref');
        $mform->setDefault('updatepref', 1);
        $mform->addElement('header', 'qgprefs', get_string('optionalsettings', 'assignment'));
        $mform->addElement('select', 'filter', get_string('show'),  $filters);

        $mform->setDefault('filter', $filter);

        $mform->addElement('text', 'perpage', get_string('pagesize', 'assignment'), array('size'=>1));
        $mform->setDefault('perpage', $perpage);

        $mform->addElement('checkbox', 'quickgrade', get_string('quickgrade','assignment'));
        $mform->setDefault('quickgrade', $quickgrade);
        $mform->addHelpButton('quickgrade', 'quickgrade', 'assignment');

        $mform->addElement('submit', 'savepreferences', get_string('savepreferences'));

        $mform->display();

        echo $OUTPUT->footer();
    }
Beispiel #4
0
 /**
  * View the grading table of all submissions for this assignment
  *
  * @return string
  */
 private function view_grading_table()
 {
     global $USER, $CFG;
     // Include grading options form
     require_once $CFG->dirroot . '/mod/assign/gradingoptionsform.php';
     require_once $CFG->dirroot . '/mod/assign/gradingactionsform.php';
     require_once $CFG->dirroot . '/mod/assign/quickgradingform.php';
     require_once $CFG->dirroot . '/mod/assign/gradingbatchoperationsform.php';
     $o = '';
     $links = array();
     $selecturl = (string) new moodle_url('/mod/assign/view.php', array('action' => 'grading', 'id' => $this->get_course_module()->id));
     $links[$selecturl] = get_string('selectlink', 'assign');
     if (has_capability('gradereport/grader:view', $this->get_course_context()) && has_capability('moodle/grade:viewall', $this->get_course_context())) {
         $gradebookurl = (string) new moodle_url('/grade/report/grader/index.php', array('id' => $this->get_course()->id));
         $links[$gradebookurl] = get_string('viewgradebook', 'assign');
     }
     if ($this->is_any_submission_plugin_enabled()) {
         $downloadurl = (string) new moodle_url('/mod/assign/view.php', array('id' => $this->get_course_module()->id, 'action' => 'downloadall'));
         $links[$downloadurl] = get_string('downloadall', 'assign');
     }
     $gradingactionsform = new mod_assign_grading_actions_form(null, array('links' => $links, 'cm' => $this->get_course_module()->id), 'post', '', array('class' => 'gradingactionsform'));
     $gradingmanager = get_grading_manager($this->get_context(), 'mod_assign', 'submissions');
     $perpage = get_user_preferences('assign_perpage', 10);
     $filter = get_user_preferences('assign_filter', '');
     $controller = $gradingmanager->get_active_controller();
     $showquickgrading = empty($controller);
     if (optional_param('action', '', PARAM_ALPHA) == 'saveoptions') {
         $quickgrading = optional_param('quickgrading', false, PARAM_BOOL);
         set_user_preference('assign_quickgrading', $quickgrading);
     }
     $quickgrading = get_user_preferences('assign_quickgrading', false);
     // print options  for changing the filter and changing the number of results per page
     $gradingoptionsform = new mod_assign_grading_options_form(null, array('cm' => $this->get_course_module()->id, 'contextid' => $this->context->id, 'userid' => $USER->id, 'showquickgrading' => $showquickgrading, 'quickgrading' => $quickgrading), 'post', '', array('class' => 'gradingoptionsform'));
     $gradingbatchoperationsform = new mod_assign_grading_batch_operations_form(null, array('cm' => $this->get_course_module()->id, 'submissiondrafts' => $this->get_instance()->submissiondrafts), 'post', '', array('class' => 'gradingbatchoperationsform'));
     $gradingoptionsdata = new stdClass();
     $gradingoptionsdata->perpage = $perpage;
     $gradingoptionsdata->filter = $filter;
     $gradingoptionsform->set_data($gradingoptionsdata);
     // plagiarism update status apearring in the grading book
     if (!empty($CFG->enableplagiarism)) {
         /** Include plagiarismlib.php */
         require_once $CFG->libdir . '/plagiarismlib.php';
         plagiarism_update_status($this->get_course(), $this->get_course_module());
     }
     $o .= $this->output->render(new assign_form('gradingactionsform', $gradingactionsform));
     $o .= $this->output->render(new assign_form('gradingoptionsform', $gradingoptionsform, 'M.mod_assign.init_grading_options'));
     // load and print the table of submissions
     if ($showquickgrading && $quickgrading) {
         $table = $this->output->render(new assign_grading_table($this, $perpage, $filter, 0, true));
         $quickgradingform = new mod_assign_quick_grading_form(null, array('cm' => $this->get_course_module()->id, 'gradingtable' => $table));
         $o .= $this->output->render(new assign_form('quickgradingform', $quickgradingform));
     } else {
         $o .= $this->output->render(new assign_grading_table($this, $perpage, $filter, 0, false));
     }
     $currentgroup = groups_get_activity_group($this->get_course_module(), true);
     $users = array_keys($this->list_participants($currentgroup, true));
     if (count($users) != 0) {
         // if no enrolled user in a course then don't display the batch operations feature
         $o .= $this->output->render(new assign_form('gradingbatchoperationsform', $gradingbatchoperationsform));
     }
     return $o;
 }