-
Notifications
You must be signed in to change notification settings - Fork 22
/
mod_publication_files_form.php
203 lines (168 loc) · 8.27 KB
/
mod_publication_files_form.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
// This file is part of mod_publication for Moodle - http://moodle.org/
//
// It 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.
//
// It 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/>.
/**
* Contains form class for approving publication files
*
* @package mod_publication
* @author Philipp Hager
* @author Andreas Windbichler
* @copyright 2014 Academic Moodle Cooperation {@link http://www.academic-moodle-cooperation.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/course/moodleform_mod.php');
require_once($CFG->dirroot . '/mod/publication/locallib.php');
/**
* Form for displaying and changing approval for publication files
*
* @package mod_publication
* @author Hannes Laiemr
* @author Philipp Hager
* @author Andreas Windbichler
* @copyright 2014 Academic Moodle Cooperation {@link http://www.academic-moodle-cooperation.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_publication_files_form extends moodleform {
/**
* Form definition method_exists
*/
public function definition() {
global $DB, $PAGE, $OUTPUT, $USER;
$publication = &$this->_customdata['publication'];
$mform = $this->_form;
$mode = $publication->get_mode();
$publicationinstance = $publication->get_instance();
$noticestudentstringid = '';
$noticeteacherid = '';
$noticemode = '';
if ($mode == PUBLICATION_MODE_FILEUPLOAD) {
$noticemode = 'upload';
} else {
$noticemode = 'import';
}
if ($publicationinstance->obtainstudentapproval) {
if ($mode == PUBLICATION_MODE_ASSIGN_TEAMSUBMISSION) {
if ($publicationinstance->groupapproval == PUBLICATION_APPROVAL_ALL) {
$noticestudentstringid = 'all';
} else {
$noticestudentstringid = 'one';
}
$noticemode = 'group';
} else {
$noticestudentstringid = 'studentrequired';
}
} else {
$noticestudentstringid = 'studentnotrequired';
}
if ($publicationinstance->obtainteacherapproval) {
$noticeteacherid = 'teacherrequired';
} else {
$noticeteacherid = 'teachernotrequired';
}
$stringid = 'notice_' . $noticemode . '_' . $noticestudentstringid . '_' . $noticeteacherid;
if ($mode == PUBLICATION_MODE_ASSIGN_TEAMSUBMISSION) {
$headertext = get_string('mygroupfiles', 'publication');
} else {
$headertext = get_string('myfiles', 'publication');
}
$notice = get_string($stringid, 'publication');
if ($mode == PUBLICATION_MODE_ASSIGN_TEAMSUBMISSION) {
$notice = get_string('notice_files_imported_group', 'publication') . ' ' . $notice;
} else if ($mode == PUBLICATION_MODE_ASSIGN_IMPORT) {
$notice = get_string('notice_files_imported', 'publication') . ' ' . $notice;
}
if ($mode != PUBLICATION_MODE_FILEUPLOAD) {
$notice .= '<br />' . get_string('notice_changes_possible_in_original', 'publication');
}
$table = $publication->get_filestable();
$mform->addElement('header', 'myfiles', $headertext);
$mform->setExpanded('myfiles');
$PAGE->requires->js_call_amd('mod_publication/filesform', 'initializer', []);
$PAGE->requires->js_call_amd('mod_publication/alignrows', 'initializer', []);
$noticehtml = html_writer::start_tag('div', ['class' => 'alert alert-info']);
$noticehtml .= get_string('notice', 'publication') . ' ' . $notice;
$noticehtml .= html_writer::end_tag('div');
$mform->addElement('html', $noticehtml);
// Now we do all the table work and return 0 if there's no files to show!
$table->init();
$mode = $publication->get_mode();
$timeremaining = false;
$publicationinstance = $publication->get_instance();
if ($publicationinstance->duedate > 0) {
$timeremainingdiff = $publicationinstance->duedate - time();
if ($timeremainingdiff > 0) {
$timeremaining = format_time($publicationinstance->duedate - time());
} else {
$timeremaining = get_string('overdue', 'publication');
}
}
$extensionduedate = $publication->user_extensionduedate($USER->id);
$approvalfromdate = $publicationinstance->approvalfromdate > 0 ? userdate($publicationinstance->approvalfromdate) : false;
$approvaltodate = $publicationinstance->approvaltodate > 0 ? userdate($publicationinstance->approvaltodate) : false;
$extensionduedate = $extensionduedate > 0 ? userdate($extensionduedate) : false;
if (!$publicationinstance->obtainstudentapproval) {
$approvalfromdate = false;
$approvaltodate = false;
}
$tablecontext = [
'myfiles' => $table->data,
'hasmyfiles' => !empty($table->data),
'timeremaining' => $timeremaining,
'lastmodified' => userdate($table->lastmodified),
'approvalfromdate' => $approvalfromdate,
'approvaltodate' => $approvaltodate,
'extensionduedate' => $extensionduedate,
'assign' => $publication->get_importlink(),
'myfilestitle' => $mode == PUBLICATION_MODE_ASSIGN_TEAMSUBMISSION ? get_string('mygroupfiles', 'publication') : get_string('myfiles', 'publication'),
];
$myfilestable = $OUTPUT->render_from_template('mod_publication/myfiles', $tablecontext);
$myfilestable = '<table class="table table-striped w-100">' . $myfilestable . '</table>';
$mform->addElement('html', $myfilestable);
// Display submit buttons if necessary.
if ($publicationinstance->obtainstudentapproval) {
if (!empty($table) && $table->changepossible()) {
$buttonarray = [];
$onclick = 'return confirm("' . get_string('savestudentapprovalwarning', 'publication') . '")';
$buttonarray[] = &$mform->createElement('submit', 'submitbutton',
get_string('savechanges'), ['onClick' => $onclick]);
$buttonarray[] = &$mform->createElement('reset', 'resetbutton', get_string('revert'),
['class' => 'btn btn-secondary']);
$mform->addGroup($buttonarray, 'submitgrp', '', [' '], false);
} else {
$mform->addElement('static', 'approvaltimeover', '', get_string('approval_timeover', 'publication'));
}
}
if ($publication->get_instance()->mode == PUBLICATION_MODE_UPLOAD
&& has_capability('mod/publication:upload', $publication->get_context())) {
if ($publication->is_open()) {
$buttonarray = [];
if (empty($table)) { // This means, there are no files shown!
$label = get_string('add_uploads', 'publication');
} else {
$label = get_string('edit_uploads', 'publication');
}
$buttonarray[] = &$mform->createElement('submit', 'gotoupload', $label);
$mform->addGroup($buttonarray, 'uploadgrp', '', [' '], false);
} else if (has_capability('mod/publication:upload', $publication->get_context())) {
$mform->addElement('static', 'edittimeover', '', get_string('edit_timeover', 'publication'));
}
}
$mform->addElement('hidden', 'id', $publication->get_coursemodule()->id);
$mform->setType('id', PARAM_INT);
$mform->disable_form_change_checker();
}
}