/** * Return things to the renderer. * * @return int the course module id */ public function get_course_module_id() { return $this->setaskment->get_course_module()->id; }
/** * Process an uploaded zip file * * @param setask $setaskment - The setaskment instance * @param setask_feedback_file $fileplugin - The file feedback plugin * @return string - The html response */ public function import_zip_files($setaskment, $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 = $setaskment->get_context()->id; $fs = get_file_storage(); $files = $this->get_import_files($contextid); $currentgroup = groups_get_activity_group($setaskment->get_course_module(), true); $allusers = $setaskment->list_participants($currentgroup, false); $participants = array(); foreach ($allusers as $user) { $participants[$setaskment->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($setaskment, $unzippedfile, $participants, $user, $plugin, $filename)) { if ($this->is_file_modified($setaskment, $user, $plugin, $filename, $unzippedfile)) { $grade = $setaskment->get_user_grade($user->id, true); if ($oldfile = $fs->get_file($contextid, 'setaskfeedback_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 = 'setaskfeedback_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. $setaskment->notify_grade_modified($grade); } } } require_once $CFG->dirroot . '/mod/setask/feedback/file/renderable.php'; $importsummary = new setaskfeedback_file_import_summary($setaskment->get_course_module()->id, count($userswithnewfeedback), $feedbackfilesadded, $feedbackfilesupdated); $setaskrenderer = $setaskment->get_renderer(); $renderer = $PAGE->get_renderer('setaskfeedback_file'); $o = ''; $o .= $setaskrenderer->render(new setask_header($setaskment->get_instance(), $setaskment->get_context(), false, $setaskment->get_course_module()->id, get_string('uploadzipsummary', 'setaskfeedback_file'))); $o .= $renderer->render($importsummary); $o .= $setaskrenderer->render_footer(); return $o; }