/** * Process an uploaded zip file * * @param sepl $seplment - The seplment instance * @param sepl_feedback_file $fileplugin - The file feedback plugin * @return string - The html response */ public function import_zip_files($seplment, $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 = $seplment->get_context()->id; $fs = get_file_storage(); $files = $this->get_import_files($contextid); $currentgroup = groups_get_activity_group($seplment->get_course_module(), true); $allusers = $seplment->list_participants($currentgroup, false); $participants = array(); foreach ($allusers as $user) { $participants[$seplment->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($seplment, $unzippedfile, $participants, $user, $plugin, $filename)) { if ($this->is_file_modified($seplment, $user, $plugin, $filename, $unzippedfile)) { $grade = $seplment->get_user_grade($user->id, true); if ($oldfile = $fs->get_file($contextid, 'seplfeedback_file', ASSIGNFEEDBACK_FILE_FILEAREA, $grade->id, '/', $filename)) { // Update existing feedback file. $oldfile->replace_file_with($unzippedfile); $feedbackfilesupdated++; } else { // Create a new feedback file. $newfilerecord = new stdClass(); $newfilerecord->contextid = $contextid; $newfilerecord->component = 'seplfeedback_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. $seplment->notify_grade_modified($grade); } } } require_once $CFG->dirroot . '/mod/sepl/feedback/file/renderable.php'; $importsummary = new seplfeedback_file_import_summary($seplment->get_course_module()->id, count($userswithnewfeedback), $feedbackfilesadded, $feedbackfilesupdated); $seplrenderer = $seplment->get_renderer(); $renderer = $PAGE->get_renderer('seplfeedback_file'); $o = ''; $o .= $seplrenderer->render(new sepl_header($seplment->get_instance(), $seplment->get_context(), false, $seplment->get_course_module()->id, get_string('uploadzipsummary', 'seplfeedback_file'))); $o .= $renderer->render($importsummary); $o .= $seplrenderer->render_footer(); return $o; }
/** * 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 seplsubmission_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('sepl_submission', array('id' => $options->itemid)))) { throw new comment_exception('invalidcommentitemid'); } $context = $options->context; $cm = $options->cm; $course = $options->courseid; require_once $CFG->dirroot . '/mod/sepl/locallib.php'; $seplment = new sepl($context, $cm, $course); if ($seplment->get_instance()->id != $submission->seplment) { throw new comment_exception('invalidcontext'); } if ($seplment->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', 'sepl')); $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 = $seplment->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 = $seplment->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; }
/** * Print recent activity from all seplments 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 sepl_print_recent_activity($course, $viewfullnames, $timestart) { global $CFG, $USER, $DB, $OUTPUT; require_once $CFG->dirroot . '/mod/sepl/locallib.php'; // Do not use log table if possible, it may be huge. $dbparams = array($timestart, $course->id, 'sepl', 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,\n {$namefields}\n FROM {sepl_submission} asb\n JOIN {sepl} a ON a.id = asb.seplment\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 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('sepl', '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 seplment 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', 'sepl') . ':', 3); foreach ($show as $submission) { $cm = $modinfo->get_cm($submission->cmid); $context = context_module::instance($submission->cmid); $sepl = new sepl($context, $cm, $cm->course); $link = $CFG->wwwroot . '/mod/sepl/view.php?id=' . $cm->id; // Obscure first and last name if blind marking enabled. if ($sepl->is_blind_marking()) { $submission->firstname = get_string('participant', 'mod_sepl'); $submission->lastname = $sepl->get_uniqueid_for_user($submission->userid); } print_recent_activity_note($submission->timemodified, $submission, $cm->name, $link, false, $viewfullnames); } return true; }
/** * Add a column with an ID that uniquely identifies this user in this seplment. * * @param stdClass $row * @return string */ public function col_recordid(stdClass $row) { return get_string('hiddenuser', 'sepl') . $this->seplment->get_uniqueid_for_user($row->userid); }