Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

/**
 * This file contains the forms to create and edit an instance of this module
 *
 * @package   assignfeedback_file
 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');

require_once($CFG->libdir.'/formslib.php');
require_once($CFG->dirroot.'/mod/assign/feedback/file/importziplib.php');

/**
 * Import zip form
 *
 * @package   assignfeedback_file
 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
class assignfeedback_file_import_zip_form extends moodleform implements renderable {

    /**
     * Create this grade import form
     */
    public function definition() {
        global $CFG, $PAGE;

        $mform = $this->_form;
        $params = $this->_customdata;

        $renderer = $PAGE->get_renderer('assign');

        // Visible elements.
        $assignment = $params['assignment'];
        $contextid = $assignment->get_context()->id;
        $importer = $params['importer'];
        $update = false;

        if (!$importer) {
< print_error('invalidarguments');
> throw new \moodle_exception('invalidarguments');
return; } $files = $importer->get_import_files($contextid); $mform->addElement('header', 'uploadzip', get_string('confirmuploadzip', 'assignfeedback_file'));
< $currentgroup = groups_get_activity_group($assignment->get_course_module(), true); < $allusers = $assignment->list_participants($currentgroup, false); < $participants = array(); < foreach ($allusers as $user) { < $participants[$assignment->get_uniqueid_for_user($user->id)] = $user; < }
> $participants = $importer->get_participant_mapping($assignment);
$fs = get_file_storage(); $updates = array(); foreach ($files as $unzippedfile) {
< $user = null;
> $users = null;
$plugin = null; $filename = '';
< if ($importer->is_valid_filename_for_import($assignment, $unzippedfile, $participants, $user, $plugin, $filename)) { < if ($importer->is_file_modified($assignment, $user, $plugin, $filename, $unzippedfile)) {
> if ($importer->is_valid_filename_for_import($assignment, $unzippedfile, $participants, $users, $plugin, $filename)) { > if ($importer->is_file_modified($assignment, $users, $plugin, $filename, $unzippedfile)) {
// Get a string we can show to identify this user.
< $userdesc = fullname($user, has_capability('moodle/site:viewfullnames', $assignment->get_context())); < $path = pathinfo($filename);
> $userdescs = []; > foreach ($users as $user) {
if ($assignment->is_blind_marking()) {
< $userdesc = get_string('hiddenuser', 'assign') .
> $userdescs[] = get_string('hiddenuser', 'assign') .
$assignment->get_uniqueid_for_user($user->id);
> } else { } > $userdescs[] = fullname($user, has_capability('moodle/site:viewfullnames', $assignment->get_context())); $grade = $assignment->get_user_grade($user->id, false); > }
> $userdesc = join(", ", $userdescs); $exists = false; > if ($grade) { > $path = pathinfo($filename);
$exists = $fs->file_exists($contextid, 'assignfeedback_file', ASSIGNFEEDBACK_FILE_FILEAREA, $grade->id, $path['dirname'], $path['basename']); } if (!$grade || !$exists) { $updates[] = get_string('feedbackfileadded', 'assignfeedback_file', array('filename'=>$filename, 'student'=>$userdesc)); } else { $updates[] = get_string('feedbackfileupdated', 'assignfeedback_file', array('filename'=>$filename, 'student'=>$userdesc)); } } } } if (count($updates)) { $mform->addElement('html', $renderer->list_block_contents(array(), $updates)); } else { $mform->addElement('html', get_string('nochanges', 'assignfeedback_file')); } $mform->addElement('hidden', 'id', $assignment->get_course_module()->id); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'action', 'viewpluginpage'); $mform->setType('action', PARAM_ALPHA); $mform->addElement('hidden', 'confirm', 'true'); $mform->setType('confirm', PARAM_BOOL); $mform->addElement('hidden', 'plugin', 'file'); $mform->setTYpe('plugin', PARAM_PLUGIN); $mform->addElement('hidden', 'pluginsubtype', 'assignfeedback'); $mform->setTYpe('pluginsubtype', PARAM_PLUGIN); $mform->addElement('hidden', 'pluginaction', 'uploadzip'); $mform->setType('pluginaction', PARAM_ALPHA); if (count($updates)) { $this->add_action_buttons(true, get_string('confirm')); } else { $mform->addElement('cancel'); $mform->closeHeaderBefore('cancel'); } } }