Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
            throw new \moodle_exception('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
        $participants = $importer->get_participant_mapping($assignment);
66
 
67
        $fs = get_file_storage();
68
 
69
        $updates = array();
70
        foreach ($files as $unzippedfile) {
71
            $users = null;
72
            $plugin = null;
73
            $filename = '';
74
 
75
            if ($importer->is_valid_filename_for_import($assignment, $unzippedfile, $participants, $users, $plugin, $filename)) {
76
                if ($importer->is_file_modified($assignment, $users, $plugin, $filename, $unzippedfile)) {
77
                    // Get a string we can show to identify this user.
78
                    $userdescs = [];
79
                    foreach ($users as $user) {
80
                        if ($assignment->is_blind_marking()) {
81
                            $userdescs[] = get_string('hiddenuser', 'assign') .
82
                                    $assignment->get_uniqueid_for_user($user->id);
83
                        } else {
84
                            $userdescs[] = fullname($user, has_capability('moodle/site:viewfullnames', $assignment->get_context()));
85
                        }
86
                    }
87
                    $userdesc = join(", ", $userdescs);
88
 
89
                    $path = pathinfo($filename);
90
                    $grade = $assignment->get_user_grade($user->id, false);
91
 
92
                    $exists = false;
93
                    if ($grade) {
94
                        $exists = $fs->file_exists($contextid,
95
                                                   'assignfeedback_file',
96
                                                   ASSIGNFEEDBACK_FILE_FILEAREA,
97
                                                   $grade->id,
98
                                                   $path['dirname'],
99
                                                   $path['basename']);
100
                    }
101
 
102
                    if (!$grade || !$exists) {
103
                        $updates[] = get_string('feedbackfileadded', 'assignfeedback_file',
104
                                            array('filename'=>$filename, 'student'=>$userdesc));
105
                    } else {
106
                        $updates[] = get_string('feedbackfileupdated', 'assignfeedback_file',
107
                                            array('filename'=>$filename, 'student'=>$userdesc));
108
                    }
109
                }
110
            }
111
        }
112
 
113
        if (count($updates)) {
114
            $mform->addElement('html', $renderer->list_block_contents(array(), $updates));
115
        } else {
116
            $mform->addElement('html', get_string('nochanges', 'assignfeedback_file'));
117
        }
118
 
119
        $mform->addElement('hidden', 'id', $assignment->get_course_module()->id);
120
        $mform->setType('id', PARAM_INT);
121
        $mform->addElement('hidden', 'action', 'viewpluginpage');
122
        $mform->setType('action', PARAM_ALPHA);
123
        $mform->addElement('hidden', 'confirm', 'true');
124
        $mform->setType('confirm', PARAM_BOOL);
125
        $mform->addElement('hidden', 'plugin', 'file');
126
        $mform->setTYpe('plugin', PARAM_PLUGIN);
127
        $mform->addElement('hidden', 'pluginsubtype', 'assignfeedback');
128
        $mform->setTYpe('pluginsubtype', PARAM_PLUGIN);
129
        $mform->addElement('hidden', 'pluginaction', 'uploadzip');
130
        $mform->setType('pluginaction', PARAM_ALPHA);
131
        if (count($updates)) {
132
            $this->add_action_buttons(true, get_string('confirm'));
133
        } else {
134
            $mform->addElement('cancel');
135
            $mform->closeHeaderBefore('cancel');
136
        }
137
    }
138
}
139