/**
  * 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;
 }
 /**
  * Return things to the renderer.
  *
  * @return int the course module id
  */
 public function get_course_module_id()
 {
     return $this->seplment->get_course_module()->id;
 }