-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmod_openbook_files_form.php
More file actions
191 lines (160 loc) · 7.29 KB
/
mod_openbook_files_form.php
File metadata and controls
191 lines (160 loc) · 7.29 KB
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
<?php
// This file is part of mod_openbook 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 openbook files
*
* @package mod_openbook
* @author University of Geneva, E-Learning Team
* @author Academic Moodle Cooperation {@link http://www.academic-moodle-cooperation.org}
* @copyright 2025 University of Geneva {@link http://www.unige.ch}
* @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/openbook/locallib.php');
/**
* Form for displaying and changing approval for openbook files
*
* @package mod_openbook
* @author University of Geneva, E-Learning Team
* @author Academic Moodle Cooperation {@link http://www.academic-moodle-cooperation.org}
* @copyright 2025 University of Geneva {@link http://www.unige.ch}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_openbook_files_form extends moodleform {
/**
* Form definition method_exists
*/
public function definition() {
global $DB, $PAGE, $OUTPUT, $USER;
$openbook = &$this->_customdata['openbook'];
$mform = $this->_form;
$mode = $openbook->get_mode();
$openbookinstance = $openbook->get_instance();
$noticestudentstringid = '';
$noticeteacherid = '';
$noticemode = 'upload';
/* Check if files are personal */
if ($openbookinstance->filesarepersonal) {
if ($openbookinstance->obtainteacherapproval) {
$noticeteacherid = 'teacherrequired';
} else {
$noticeteacherid = 'teachernotrequired';
}
$noticestudentstringid = 'filesarepersonal';
} else {
if ($openbookinstance->obtainstudentapproval) {
$noticestudentstringid = 'studentrequired';
} else {
$noticestudentstringid = 'studentnotrequired';
}
if ($openbookinstance->obtainteacherapproval) {
$noticeteacherid = 'teacherrequired';
} else {
$noticeteacherid = 'teachernotrequired';
}
}
$table = $openbook->get_filestable();
$headerstring = get_string('myfiles', 'openbook');
$PAGE->requires->js_call_amd('mod_openbook/filesform', 'initializer', []);
$PAGE->requires->js_call_amd('mod_openbook/alignrows', 'initializer', []);
// Now we do all the table work and return 0 if there's no files to show!
$table->init();
$mode = $openbook->get_mode();
$timeremaining = false;
$openbookinstance = $openbook->get_instance();
$override = $openbook->override_get_currentuserorgroup();
if ($override && $override->approvalfromdate) {
$approvalfromdate = $override->approvalfromdate > 0 ? userdate($override->approvalfromdate) : false;
$approvaltodate = $override->approvaltodate > 0 ? userdate($override->approvaltodate) : false;
} else {
$approvalfromdate = $openbookinstance->approvalfromdate > 0 ?
userdate($openbookinstance->approvalfromdate) : false;
$approvaltodate = $openbookinstance->approvaltodate > 0 ?
userdate($openbookinstance->approvaltodate) : false;
}
$effectiveduedate = $openbookinstance->duedate;
if ($override && $override->submissionoverride && $override->duedate > 0) {
$effectiveduedate = $override->duedate;
}
if ($effectiveduedate > 0) {
$timeremainingdiff = $effectiveduedate - time();
if ($timeremainingdiff > 0) {
$timeremaining = format_time($effectiveduedate - time());
} else {
$timeremaining = get_string('overdue', 'openbook');
}
}
$tablecontext = [
'myfiles' => $table->data,
'hasmyfiles' => !empty($table->data),
'timeremaining' => $timeremaining,
'lastmodified' => userdate($table->lastmodified),
'approvalfromdate' => $approvalfromdate,
'approvaltodate' => $approvaltodate,
'myfilestitle' => $headerstring,
];
/* TODO : Add PDF.js link to myfiles table */
$myfilestable = $OUTPUT->render_from_template('mod_openbook/myfiles', $tablecontext);
$myfilestable = $myfilestable;
$mform->addElement('html', $myfilestable);
// Display submit buttons if necessary.
if ($openbookinstance->obtainstudentapproval) {
if (!empty($table) && $table->changepossible()) {
$buttonarray = [];
$onclick = 'return confirm("' . get_string('savestudentapprovalwarning', 'openbook') . '")';
$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 {
$noticehtml = html_writer::start_tag('div', ['class' => 'alert alert-secondary']);
$noticehtml .= get_string('approval_timeover', 'openbook');
$noticehtml .= html_writer::end_tag('div');
$mform->addElement('html', $noticehtml);
}
}
if (
has_capability('mod/openbook:upload', $openbook->get_context())
) {
if ($openbook->is_open()) {
$buttonarray = [];
if (empty($table)) { // This means, there are no files shown!
$label = get_string('add_uploads', 'openbook');
} else {
$label = get_string('edit_uploads', 'openbook');
}
$buttonarray[] = &$mform->createElement('submit', 'gotoupload', $label);
$mform->addGroup($buttonarray, 'uploadgrp', '', [' '], false);
} else if (has_capability('mod/openbook:upload', $openbook->get_context())) {
$mform->addElement('static', 'edittimeover', '', get_string('edit_timeover', 'openbook'));
}
}
$mform->addElement('hidden', 'id', $openbook->get_coursemodule()->id);
$mform->setType('id', PARAM_INT);
$mform->disable_form_change_checker();
}
}