Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * This file contains the forms to create and edit an instance of this module
  19   *
  20   * @package   assignfeedback_file
  21   * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
  26  
  27  require_once($CFG->libdir.'/formslib.php');
  28  require_once($CFG->dirroot.'/mod/assign/feedback/file/importziplib.php');
  29  
  30  /**
  31   * Import zip form
  32   *
  33   * @package   assignfeedback_file
  34   * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
  35   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  36   */
  37  class assignfeedback_file_import_zip_form extends moodleform implements renderable {
  38  
  39      /**
  40       * Create this grade import form
  41       */
  42      public function definition() {
  43          global $CFG, $PAGE;
  44  
  45          $mform = $this->_form;
  46          $params = $this->_customdata;
  47  
  48          $renderer = $PAGE->get_renderer('assign');
  49  
  50          // Visible elements.
  51          $assignment = $params['assignment'];
  52          $contextid = $assignment->get_context()->id;
  53          $importer = $params['importer'];
  54          $update = false;
  55  
  56          if (!$importer) {
  57              print_error('invalidarguments');
  58              return;
  59          }
  60  
  61          $files = $importer->get_import_files($contextid);
  62  
  63          $mform->addElement('header', 'uploadzip', get_string('confirmuploadzip', 'assignfeedback_file'));
  64  
  65          $currentgroup = groups_get_activity_group($assignment->get_course_module(), true);
  66          $allusers = $assignment->list_participants($currentgroup, false);
  67          $participants = array();
  68          foreach ($allusers as $user) {
  69              $participants[$assignment->get_uniqueid_for_user($user->id)] = $user;
  70          }
  71  
  72          $fs = get_file_storage();
  73  
  74          $updates = array();
  75          foreach ($files as $unzippedfile) {
  76              $user = null;
  77              $plugin = null;
  78              $filename = '';
  79  
  80              if ($importer->is_valid_filename_for_import($assignment, $unzippedfile, $participants, $user, $plugin, $filename)) {
  81                  if ($importer->is_file_modified($assignment, $user, $plugin, $filename, $unzippedfile)) {
  82                      // Get a string we can show to identify this user.
  83                      $userdesc = fullname($user, has_capability('moodle/site:viewfullnames', $assignment->get_context()));
  84                      $path = pathinfo($filename);
  85                      if ($assignment->is_blind_marking()) {
  86                          $userdesc = get_string('hiddenuser', 'assign') .
  87                                      $assignment->get_uniqueid_for_user($user->id);
  88                      }
  89                      $grade = $assignment->get_user_grade($user->id, false);
  90  
  91                      $exists = false;
  92                      if ($grade) {
  93                          $exists = $fs->file_exists($contextid,
  94                                                     'assignfeedback_file',
  95                                                     ASSIGNFEEDBACK_FILE_FILEAREA,
  96                                                     $grade->id,
  97                                                     $path['dirname'],
  98                                                     $path['basename']);
  99                      }
 100  
 101                      if (!$grade || !$exists) {
 102                          $updates[] = get_string('feedbackfileadded', 'assignfeedback_file',
 103                                              array('filename'=>$filename, 'student'=>$userdesc));
 104                      } else {
 105                          $updates[] = get_string('feedbackfileupdated', 'assignfeedback_file',
 106                                              array('filename'=>$filename, 'student'=>$userdesc));
 107                      }
 108                  }
 109              }
 110          }
 111  
 112          if (count($updates)) {
 113              $mform->addElement('html', $renderer->list_block_contents(array(), $updates));
 114          } else {
 115              $mform->addElement('html', get_string('nochanges', 'assignfeedback_file'));
 116          }
 117  
 118          $mform->addElement('hidden', 'id', $assignment->get_course_module()->id);
 119          $mform->setType('id', PARAM_INT);
 120          $mform->addElement('hidden', 'action', 'viewpluginpage');
 121          $mform->setType('action', PARAM_ALPHA);
 122          $mform->addElement('hidden', 'confirm', 'true');
 123          $mform->setType('confirm', PARAM_BOOL);
 124          $mform->addElement('hidden', 'plugin', 'file');
 125          $mform->setTYpe('plugin', PARAM_PLUGIN);
 126          $mform->addElement('hidden', 'pluginsubtype', 'assignfeedback');
 127          $mform->setTYpe('pluginsubtype', PARAM_PLUGIN);
 128          $mform->addElement('hidden', 'pluginaction', 'uploadzip');
 129          $mform->setType('pluginaction', PARAM_ALPHA);
 130          if (count($updates)) {
 131              $this->add_action_buttons(true, get_string('confirm'));
 132          } else {
 133              $mform->addElement('cancel');
 134              $mform->closeHeaderBefore('cancel');
 135          }
 136      }
 137  }
 138