/** * Format a column of data for display. * * @param stdClass $row * @return string */ public function col_grade(stdClass $row) { $o = ''; $link = ''; $separator = $this->output->spacer(array(), true); $grade = ''; $gradingdisabled = $this->assignment->grading_disabled($row->id); if (!$this->is_downloading() && $this->hasgrade) { $name = fullname($row); if ($this->assignment->is_blind_marking()) { $name = get_string('hiddenuser', 'assign') . $this->assignment->get_uniqueid_for_user($row->userid); } $icon = $this->output->pix_icon('gradefeedback', get_string('gradeuser', 'assign', $name), 'mod_assign'); $urlparams = array('id' => $this->assignment->get_course_module()->id, 'rownum'=>$this->rownum, 'action'=>'grade'); $url = new moodle_url('/mod/assign/view.php', $urlparams); $link = $this->output->action_link($url, $icon); $grade .= $link . $separator; } $grade .= $this->display_grade($row->grade, $this->quickgrading && !$gradingdisabled, $row->userid, $row->timemarked); return $grade; }
/** * Format a column of data for display. * * @param stdClass $row * @return string */ public function col_grade(stdClass $row) { $o = ''; $link = ''; $separator = $this->output->spacer(array(), true); $grade = ''; $gradingdisabled = $this->assignment->grading_disabled($row->id); if (!$this->is_downloading() && $this->hasgrade) { $urlparams = array('id' => $this->assignment->get_course_module()->id, 'rownum' => 0, 'action' => 'grader'); if ($this->assignment->is_blind_marking()) { $urlparams['blindid'] = $this->assignment->get_uniqueid_for_user($row->userid); } else { $urlparams['userid'] = $row->userid; } $url = new moodle_url('/mod/assign/view.php', $urlparams); $link = '<a href="' . $url . '" class="btn btn-primary">' . get_string('grade') . '</a>'; $grade .= $link . $separator; } $grade .= $this->display_grade($row->grade, $this->quickgrading && !$gradingdisabled, $row->userid, $row->timemarked); return $grade; }
/** * Add a column with an ID that uniquely identifies this user in this assignment. * * @param stdClass $row * @return string */ public function col_recordid(stdClass $row) { return get_string('hiddenuser', 'assign') . $this->assignment->get_uniqueid_for_user($row->userid); }
/** * Format a column of data for display. * * @param stdClass $row * @return string */ public function col_userid(stdClass $row) { global $USER; $edit = ''; $actions = array(); $urlparams = array('id' => $this->assignment->get_course_module()->id, 'rownum' => 0, 'action' => 'grader'); if ($this->assignment->is_blind_marking()) { $urlparams['blindid'] = $this->assignment->get_uniqueid_for_user($row->userid); } else { $urlparams['userid'] = $row->userid; } $url = new moodle_url('/mod/assign/view.php', $urlparams); $noimage = null; if (!$row->grade) { $description = get_string('grade'); } else { $description = get_string('updategrade', 'assign'); } $actions['grade'] = new action_menu_link_secondary($url, $noimage, $description); // Everything we need is in the row. $submission = $row; $flags = $row; if ($this->assignment->get_instance()->teamsubmission) { // Use the cache for this. $submission = false; $group = false; $this->get_group_and_submission($row->id, $group, $submission, -1); } $submissionsopen = $this->assignment->submissions_open($row->id, true, $submission, $flags, $this->gradinginfo); $caneditsubmission = $this->assignment->can_edit_submission($row->id, $USER->id); // Hide for offline assignments. if ($this->assignment->is_any_submission_plugin_enabled()) { if (!$row->status || $row->status == ASSIGN_SUBMISSION_STATUS_DRAFT || !$this->assignment->get_instance()->submissiondrafts) { if (!$row->locked) { $urlparams = array('id' => $this->assignment->get_course_module()->id, 'userid' => $row->id, 'action' => 'lock', 'sesskey' => sesskey(), 'page' => $this->currpage); $url = new moodle_url('/mod/assign/view.php', $urlparams); $description = get_string('preventsubmissionsshort', 'assign'); $actions['lock'] = new action_menu_link_secondary($url, $noimage, $description); } else { $urlparams = array('id' => $this->assignment->get_course_module()->id, 'userid' => $row->id, 'action' => 'unlock', 'sesskey' => sesskey(), 'page' => $this->currpage); $url = new moodle_url('/mod/assign/view.php', $urlparams); $description = get_string('allowsubmissionsshort', 'assign'); $actions['unlock'] = new action_menu_link_secondary($url, $noimage, $description); } } if ($submissionsopen && $USER->id != $row->id && $caneditsubmission) { $urlparams = array('id' => $this->assignment->get_course_module()->id, 'userid' => $row->id, 'action' => 'editsubmission', 'sesskey' => sesskey(), 'page' => $this->currpage); $url = new moodle_url('/mod/assign/view.php', $urlparams); $description = get_string('editsubmission', 'assign'); $actions['editsubmission'] = new action_menu_link_secondary($url, $noimage, $description); } } if (($this->assignment->get_instance()->duedate || $this->assignment->get_instance()->cutoffdate) && $this->hasgrantextension) { $urlparams = array('id' => $this->assignment->get_course_module()->id, 'userid' => $row->id, 'action' => 'grantextension', 'sesskey' => sesskey(), 'page' => $this->currpage); $url = new moodle_url('/mod/assign/view.php', $urlparams); $description = get_string('grantextension', 'assign'); $actions['grantextension'] = new action_menu_link_secondary($url, $noimage, $description); } if ($row->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED && $this->assignment->get_instance()->submissiondrafts) { $urlparams = array('id' => $this->assignment->get_course_module()->id, 'userid' => $row->id, 'action' => 'reverttodraft', 'sesskey' => sesskey(), 'page' => $this->currpage); $url = new moodle_url('/mod/assign/view.php', $urlparams); $description = get_string('reverttodraftshort', 'assign'); $actions['reverttodraft'] = new action_menu_link_secondary($url, $noimage, $description); } if ($row->status == ASSIGN_SUBMISSION_STATUS_DRAFT && $this->assignment->get_instance()->submissiondrafts && $caneditsubmission && $submissionsopen && $row->id != $USER->id) { $urlparams = array('id' => $this->assignment->get_course_module()->id, 'userid' => $row->id, 'action' => 'submitotherforgrading', 'sesskey' => sesskey(), 'page' => $this->currpage); $url = new moodle_url('/mod/assign/view.php', $urlparams); $description = get_string('submitforgrading', 'assign'); $actions['submitforgrading'] = new action_menu_link_secondary($url, $noimage, $description); } $ismanual = $this->assignment->get_instance()->attemptreopenmethod == ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL; $hassubmission = !empty($row->status); $notreopened = $hassubmission && $row->status != ASSIGN_SUBMISSION_STATUS_REOPENED; $isunlimited = $this->assignment->get_instance()->maxattempts == ASSIGN_UNLIMITED_ATTEMPTS; $hasattempts = $isunlimited || $row->attemptnumber < $this->assignment->get_instance()->maxattempts - 1; if ($ismanual && $hassubmission && $notreopened && $hasattempts) { $urlparams = array('id' => $this->assignment->get_course_module()->id, 'userid' => $row->id, 'action' => 'addattempt', 'sesskey' => sesskey(), 'page' => $this->currpage); $url = new moodle_url('/mod/assign/view.php', $urlparams); $description = get_string('addattempt', 'assign'); $actions['addattempt'] = new action_menu_link_secondary($url, $noimage, $description); } $menu = new action_menu(); $menu->set_owner_selector('.gradingtable-actionmenu'); $menu->set_alignment(action_menu::TL, action_menu::BL); $menu->set_constraint('.gradingtable > .no-overflow'); $menu->set_menu_trigger(get_string('edit')); foreach ($actions as $action) { $menu->add($action); } // Prioritise the menu ahead of all other actions. $menu->prioritise = true; $edit .= $this->output->render($menu); return $edit; }
/** * Print recent activity from all assignments in a given course * * This is used by the recent activity block * @param mixed $course the course to print activity for * @param bool $viewfullnames boolean to determine whether to show full names or not * @param int $timestart the time the rendering started * @return bool true if activity was printed, false otherwise. */ function assign_print_recent_activity($course, $viewfullnames, $timestart) { global $CFG, $USER, $DB, $OUTPUT; require_once $CFG->dirroot . '/mod/assign/locallib.php'; // Do not use log table if possible, it may be huge. $dbparams = array($timestart, $course->id, 'assign', ASSIGN_SUBMISSION_STATUS_SUBMITTED); $namefields = user_picture::fields('u', null, 'userid'); if (!($submissions = $DB->get_records_sql("SELECT asb.id, asb.timemodified, cm.id AS cmid, um.id as recordid,\n {$namefields}\n FROM {assign_submission} asb\n JOIN {assign} a ON a.id = asb.assignment\n JOIN {course_modules} cm ON cm.instance = a.id\n JOIN {modules} md ON md.id = cm.module\n JOIN {user} u ON u.id = asb.userid\n LEFT JOIN {assign_user_mapping} um ON um.userid = u.id AND um.assignment = a.id\n WHERE asb.timemodified > ? AND\n asb.latest = 1 AND\n a.course = ? AND\n md.name = ? AND\n asb.status = ?\n ORDER BY asb.timemodified ASC", $dbparams))) { return false; } $modinfo = get_fast_modinfo($course); $show = array(); $grader = array(); $showrecentsubmissions = get_config('assign', 'showrecentsubmissions'); foreach ($submissions as $submission) { if (!array_key_exists($submission->cmid, $modinfo->get_cms())) { continue; } $cm = $modinfo->get_cm($submission->cmid); if (!$cm->uservisible) { continue; } if ($submission->userid == $USER->id) { $show[] = $submission; continue; } $context = context_module::instance($submission->cmid); // The act of submitting of assignment may be considered private - // only graders will see it if specified. if (empty($showrecentsubmissions)) { if (!array_key_exists($cm->id, $grader)) { $grader[$cm->id] = has_capability('moodle/grade:viewall', $context); } if (!$grader[$cm->id]) { continue; } } $groupmode = groups_get_activity_groupmode($cm, $course); if ($groupmode == SEPARATEGROUPS && !has_capability('moodle/site:accessallgroups', $context)) { if (isguestuser()) { // Shortcut - guest user does not belong into any group. continue; } // This will be slow - show only users that share group with me in this cm. if (!$modinfo->get_groups($cm->groupingid)) { continue; } $usersgroups = groups_get_all_groups($course->id, $submission->userid, $cm->groupingid); if (is_array($usersgroups)) { $usersgroups = array_keys($usersgroups); $intersect = array_intersect($usersgroups, $modinfo->get_groups($cm->groupingid)); if (empty($intersect)) { continue; } } } $show[] = $submission; } if (empty($show)) { return false; } echo $OUTPUT->heading(get_string('newsubmissions', 'assign') . ':', 3); foreach ($show as $submission) { $cm = $modinfo->get_cm($submission->cmid); $context = context_module::instance($submission->cmid); $assign = new assign($context, $cm, $cm->course); $link = $CFG->wwwroot . '/mod/assign/view.php?id=' . $cm->id; // Obscure first and last name if blind marking enabled. if ($assign->is_blind_marking()) { $submission->firstname = get_string('participant', 'mod_assign'); if (empty($submission->recordid)) { $submission->recordid = $assign->get_uniqueid_for_user($submission->userid); } $submission->lastname = $submission->recordid; } print_recent_activity_note($submission->timemodified, $submission, $cm->name, $link, false, $viewfullnames); } return true; }
/** * Callback called by comment::get_comments() and comment::add(). Gives an opportunity to enforce blind-marking. * * @param array $comments * @param stdClass $options * @return array * @throws comment_exception */ function assignsubmission_comments_comment_display($comments, $options) { global $CFG, $DB, $USER; if ($options->commentarea != 'submission_comments' && $options->commentarea != 'submission_comments_upgrade') { throw new comment_exception('invalidcommentarea'); } if (!($submission = $DB->get_record('assign_submission', array('id' => $options->itemid)))) { throw new comment_exception('invalidcommentitemid'); } $context = $options->context; $cm = $options->cm; $course = $options->courseid; require_once $CFG->dirroot . '/mod/assign/locallib.php'; $assignment = new assign($context, $cm, $course); if ($assignment->get_instance()->id != $submission->assignment) { throw new comment_exception('invalidcontext'); } if ($assignment->is_blind_marking() && !empty($comments)) { // Blind marking is being used, may need to map unique anonymous ids to the comments. $usermappings = array(); $hiddenuserstr = trim(get_string('hiddenuser', 'assign')); $guestuser = guest_user(); foreach ($comments as $comment) { // Anonymize the comments. if (empty($usermappings[$comment->userid])) { // The blind-marking information for this commenter has not been generated; do so now. $anonid = $assignment->get_uniqueid_for_user($comment->userid); $commenter = new stdClass(); $commenter->firstname = $hiddenuserstr; $commenter->lastname = $anonid; $commenter->picture = 0; $commenter->id = $guestuser->id; $commenter->email = $guestuser->email; $commenter->imagealt = $guestuser->imagealt; // Temporarily store blind-marking information for use in later comments if necessary. $usermappings[$comment->userid]->fullname = fullname($commenter); $usermappings[$comment->userid]->avatar = $assignment->get_renderer()->user_picture($commenter, array('size' => 18, 'link' => false)); } // Set blind-marking information for this comment. $comment->fullname = $usermappings[$comment->userid]->fullname; $comment->avatar = $usermappings[$comment->userid]->avatar; $comment->profileurl = null; } } return $comments; }
/** * Process an uploaded zip file * * @param assign $assignment - The assignment instance * @param assign_feedback_file $fileplugin - The file feedback plugin * @return string - The html response */ public function import_zip_files($assignment, $fileplugin) { global $USER, $CFG, $PAGE, $DB; @set_time_limit(ASSIGNFEEDBACK_FILE_MAXFILEUNZIPTIME); $packer = get_file_packer('application/zip'); $feedbackfilesupdated = 0; $feedbackfilesadded = 0; $userswithnewfeedback = array(); $contextid = $assignment->get_context()->id; $fs = get_file_storage(); $files = $fs->get_directory_files($contextid, 'assignfeedback_file', ASSIGNFEEDBACK_FILE_IMPORT_FILEAREA, $USER->id, '/import/'); $currentgroup = groups_get_activity_group($assignment->get_course_module(), true); $allusers = $assignment->list_participants($currentgroup, false); $participants = array(); foreach ($allusers as $user) { $participants[$assignment->get_uniqueid_for_user($user->id)] = $user; } foreach ($files as $unzippedfile) { // Set the timeout for unzipping each file. $user = null; $plugin = null; $filename = ''; if ($this->is_valid_filename_for_import($assignment, $unzippedfile, $participants, $user, $plugin, $filename)) { if ($this->is_file_modified($assignment, $user, $plugin, $filename, $unzippedfile)) { $grade = $assignment->get_user_grade($user->id, true); if ($oldfile = $fs->get_file($contextid, 'assignfeedback_file', ASSIGNFEEDBACK_FILE_FILEAREA, $grade->id, '/', $filename)) { // Update existing feedback file. $oldfile->replace_content_with($unzippedfile); $feedbackfilesupdated++; } else { // Create a new feedback file. $newfilerecord = new stdClass(); $newfilerecord->contextid = $contextid; $newfilerecord->component = 'assignfeedback_file'; $newfilerecord->filearea = ASSIGNFEEDBACK_FILE_FILEAREA; $newfilerecord->filename = $filename; $newfilerecord->filepath = '/'; $newfilerecord->itemid = $grade->id; $fs->create_file_from_storedfile($newfilerecord, $unzippedfile); $feedbackfilesadded++; } $userswithnewfeedback[$user->id] = 1; // Update the number of feedback files for this user. $fileplugin->update_file_count($grade); // Update the last modified time on the grade which will trigger student notifications. $assignment->notify_grade_modified($grade); } } } require_once($CFG->dirroot . '/mod/assign/feedback/file/renderable.php'); $importsummary = new assignfeedback_file_import_summary($assignment->get_course_module()->id, count($userswithnewfeedback), $feedbackfilesadded, $feedbackfilesupdated); $assignrenderer = $assignment->get_renderer(); $renderer = $PAGE->get_renderer('assignfeedback_file'); $o = ''; $o .= $assignrenderer->render(new assign_header($assignment->get_instance(), $assignment->get_context(), false, $assignment->get_course_module()->id, get_string('uploadzipsummary', 'assignfeedback_file'))); $o .= $renderer->render($importsummary); $o .= $assignrenderer->render_footer(); return $o; }
/** * Process an uploaded zip file * * @param assign $assignment - The assignment instance * @param assign_feedback_file $fileplugin - The file feedback plugin * @return string - The html response */ public function import_zip_files($assignment, $fileplugin) { global $CFG, $PAGE, $DB; core_php_time_limit::raise(ASSIGNFEEDBACK_FILE_MAXFILEUNZIPTIME); $packer = get_file_packer('application/zip'); $feedbackfilesupdated = 0; $feedbackfilesadded = 0; $userswithnewfeedback = array(); $contextid = $assignment->get_context()->id; $fs = get_file_storage(); $files = $this->get_import_files($contextid); $currentgroup = groups_get_activity_group($assignment->get_course_module(), true); $allusers = $assignment->list_participants($currentgroup, false); $participants = array(); foreach ($allusers as $user) { $participants[$assignment->get_uniqueid_for_user($user->id)] = $user; } foreach ($files as $unzippedfile) { // Set the timeout for unzipping each file. $user = null; $plugin = null; $filename = ''; if ($this->is_valid_filename_for_import($assignment, $unzippedfile, $participants, $user, $plugin, $filename)) { if ($this->is_file_modified($assignment, $user, $plugin, $filename, $unzippedfile)) { $grade = $assignment->get_user_grade($user->id, true); // In 3.1 the default download structure of the submission files changed so that each student had their own // separate folder, the files were not renamed and the folder structure was kept. It is possible that // a user downloaded the submission files in 3.0 (or earlier) and edited the zip to add feedback or // changed the behavior back to the previous format, the following code means that we will still support the // old file structure. For more information please see - MDL-52489 / MDL-56022. $path = pathinfo($filename); if ($path['dirname'] == '.') { // Student submissions are not in separate folders. $basename = $filename; $dirname = "/"; $dirnamewslash = "/"; } else { $basename = $path['basename']; $dirname = $path['dirname']; $dirnamewslash = $dirname . "/"; } if ($oldfile = $fs->get_file($contextid, 'assignfeedback_file', ASSIGNFEEDBACK_FILE_FILEAREA, $grade->id, $dirname, $basename)) { // Update existing feedback file. $oldfile->replace_file_with($unzippedfile); $feedbackfilesupdated++; } else { // Create a new feedback file. $newfilerecord = new stdClass(); $newfilerecord->contextid = $contextid; $newfilerecord->component = 'assignfeedback_file'; $newfilerecord->filearea = ASSIGNFEEDBACK_FILE_FILEAREA; $newfilerecord->filename = $basename; $newfilerecord->filepath = $dirnamewslash; $newfilerecord->itemid = $grade->id; $fs->create_file_from_storedfile($newfilerecord, $unzippedfile); $feedbackfilesadded++; } $userswithnewfeedback[$user->id] = 1; // Update the number of feedback files for this user. $fileplugin->update_file_count($grade); // Update the last modified time on the grade which will trigger student notifications. $assignment->notify_grade_modified($grade); } } } require_once $CFG->dirroot . '/mod/assign/feedback/file/renderable.php'; $importsummary = new assignfeedback_file_import_summary($assignment->get_course_module()->id, count($userswithnewfeedback), $feedbackfilesadded, $feedbackfilesupdated); $assignrenderer = $assignment->get_renderer(); $renderer = $PAGE->get_renderer('assignfeedback_file'); $o = ''; $o .= $assignrenderer->render(new assign_header($assignment->get_instance(), $assignment->get_context(), false, $assignment->get_course_module()->id, get_string('uploadzipsummary', 'assignfeedback_file'))); $o .= $renderer->render($importsummary); $o .= $assignrenderer->render_footer(); return $o; }