Search moodle.org's
Developer Documentation

   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);
  84                      if ($assignment->is_blind_marking()) {
  85                          $userdesc = get_string('hiddenuser', 'assign') .
  86                                      $assignment->get_uniqueid_for_user($user->id);
  87                      }
  88                      $grade = $assignment->get_user_grade($user->id, false);
  89  
  90                      $exists = false;
  91                      if ($grade) {
  92                          $exists = $fs->file_exists($contextid,
  93                                                     'assignfeedback_file',
  94                                                     ASSIGNFEEDBACK_FILE_FILEAREA,
  95                                                     $grade->id,
  96                                                     '/',
  97                                                     $filename);
  98                      }
  99  
 100                      if (!$grade || !$exists) {
 101                          $updates[] = get_string('feedbackfileadded', 'assignfeedback_file',
 102                                              array('filename'=>$filename, 'student'=>$userdesc));
 103                      } else {
 104                          $updates[] = get_string('feedbackfileupdated', 'assignfeedback_file',
 105                                              array('filename'=>$filename, 'student'=>$userdesc));
 106                      }
 107                  }
 108              }
 109          }
 110  
 111          if (count($updates)) {
 112              $mform->addElement('html', $renderer->list_block_contents(array(), $updates));
 113          } else {
 114              $mform->addElement('html', get_string('nochanges', 'assignfeedback_file'));
 115          }
 116  
 117          $mform->addElement('hidden', 'id', $assignment->get_course_module()->id);
 118          $mform->setType('id', PARAM_INT);
 119          $mform->addElement('hidden', 'action', 'viewpluginpage');
 120          $mform->setType('action', PARAM_ALPHA);
 121          $mform->addElement('hidden', 'confirm', 'true');
 122          $mform->setType('confirm', PARAM_BOOL);
 123          $mform->addElement('hidden', 'plugin', 'file');
 124          $mform->setTYpe('plugin', PARAM_PLUGIN);
 125          $mform->addElement('hidden', 'pluginsubtype', 'assignfeedback');
 126          $mform->setTYpe('pluginsubtype', PARAM_PLUGIN);
 127          $mform->addElement('hidden', 'pluginaction', 'uploadzip');
 128          $mform->setType('pluginaction', PARAM_ALPHA);
 129          if (count($updates)) {
 130              $this->add_action_buttons(true, get_string('confirm'));
 131          } else {
 132              $mform->addElement('cancel');
 133              $mform->closeHeaderBefore('cancel');
 134          }
 135      }
 136  }
 137  

Search This Site: