-
Notifications
You must be signed in to change notification settings - Fork 2
/
mod_form.php
162 lines (156 loc) · 9.24 KB
/
mod_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
<?php
// This file is part of Moodle - http://moodle.org/
//
// This program 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.
//
// This program 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/>.
/**
* The main edusharing configuration form
*
* It uses the standard core Moodle formslib. For more info about them, please
* visit: http://docs.moodle.org/en/Development:lib/formslib.php
*
* @package mod_edusharing
* @copyright metaVentis GmbH — http://metaventis.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use mod_edusharing\Constants;
use mod_edusharing\EduSharingService;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/course/moodleform_mod.php');
/**
* The main edusharing configuration form
*
* @copyright metaVentis GmbH — http://metaventis.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_edusharing_mod_form extends moodleform_mod {
/**
* (non-PHPdoc)
* @see lib/moodleform::definition()
*/
public function definition(): void {
try {
$edusharingservice = new EduSharingService();
$ticket = $edusharingservice->get_ticket();
// Adding the "general" fieldset, where all the common settings are shown.
$this->_form->addElement('header', 'general', get_string('general', 'form'));
// Adding the standard "name" field.
$this->_form->addElement('text', 'name',
get_string('edusharingname', Constants::EDUSHARING_MODULE_NAME), ['size' => '64']);
$this->_form->setType('name', PARAM_TEXT);
$this->_form->addRule('name', null, 'required', null, 'client');
$this->_form->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$this->standard_intro_elements(get_string('description', Constants::EDUSHARING_MODULE_NAME));
// Repo button and version select are not to be shown for edit form.
if (!isset($_GET['update'])) {
$this->_form->addElement('header', 'object_url_fieldset',
get_string('object_url_fieldset', Constants::EDUSHARING_MODULE_NAME,
get_config('edusharing', 'application_appname')));
$this->_form->addElement('static', 'object_title',
get_string('object_title', Constants::EDUSHARING_MODULE_NAME),
get_string('object_title_help', Constants::EDUSHARING_MODULE_NAME));
$this->_form->addElement('text', 'object_url',
get_string('object_url', Constants::EDUSHARING_MODULE_NAME), ['readonly' => 'true']);
$this->_form->setType('object_url', PARAM_RAW_TRIMMED);
$this->_form->addRule('object_url', null, 'required', null, 'client');
$this->_form->addRule('object_url', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$this->_form->addHelpButton('object_url', 'object_url', Constants::EDUSHARING_MODULE_NAME);
$searchurl = get_config('edusharing', 'application_cc_gui_url');
$reposearch = trim($searchurl, '/') . '/components/search?&applyDirectories=false&reurl=WINDOW&ticket=' . $ticket;
$searchbutton = $this->_form->addElement('button', 'searchbutton',
get_string('searchrec', Constants::EDUSHARING_MODULE_NAME,
get_config('edusharing', 'application_appname')));
// phpcs:disable -- just messy html and js.
$repoonclick = "
function openRepo(){
window.addEventListener('message', function handleRepo(event) {
if (event.data.event == 'APPLY_NODE') {
const node = event.data.data;
window.console.log(node);
window.win.close();
window.document.getElementById('id_object_url').value = node.objectUrl;
let title = node.title;
if(!title){
title = node.properties['cm:name'];
}
let version = -1;
let versionArray = node.properties['cclom:version'];
if (versionArray !== undefined) {
version = node.properties['cclom:version'][0];
window.document.getElementById('id_object_version_1').value = version;
}
let aspects = node.aspects;
if (aspects.includes('ccm:published') || aspects.includes('ccm:collection_io_reference') || version === -1) {
window.document.getElementById('id_object_version_0').checked = true;
window.document.getElementById('id_object_version_1').closest('label').hidden = true;
}
window.document.getElementById('fitem_id_object_title')
.getElementsByClassName('form-control-static')[0].innerHTML = title;
if(window.document.getElementById('id_name').value === ''){
window.document.getElementById('id_name').value = title;
}
window.removeEventListener('message', handleRepo, false );
}
}, false);
window.win = window.open('" . $reposearch . "');
}
openRepo();
";
// phpcs:enable
$searchbutton->updateAttributes(
[
'title' => get_string('uploadrec', Constants::EDUSHARING_MODULE_NAME,
get_config('edusharing', 'application_appname')),
'onclick' => $repoonclick,
]
);
$this->_form->addElement('header', 'version_fieldset',
get_string('object_version_fieldset', Constants::EDUSHARING_MODULE_NAME));
$radiogroup = [];
$radiogroup[] = $this->_form->createElement('radio', 'object_version', '',
get_string('object_version_use_latest', Constants::EDUSHARING_MODULE_NAME), 0, []);
$radiogroup[] = $this->_form->createElement('radio', 'object_version', '',
get_string('object_version_use_exact', Constants::EDUSHARING_MODULE_NAME), 1, []);
$this->_form->addGroup($radiogroup, 'object_version',
get_string('object_version', Constants::EDUSHARING_MODULE_NAME), [' '], false);
$this->_form->setDefault('object_version', 0);
$this->_form->addHelpButton('object_version', 'object_version', Constants::EDUSHARING_MODULE_NAME);
}
// Display-section.
$this->_form->addElement('header', 'object_display_fieldset',
get_string('object_display_fieldset', Constants::EDUSHARING_MODULE_NAME));
$windowoptions =
[
0 => get_string('pagewindow', Constants::EDUSHARING_MODULE_NAME),
1 => get_string('newwindow', Constants::EDUSHARING_MODULE_NAME),
];
$this->_form->addElement('select', 'popup_window',
get_string('display', Constants::EDUSHARING_MODULE_NAME), $windowoptions);
$this->_form->setDefault('popup_window', !empty($CFG->resource_popup));
// Add standard elements, common to all modules.
$this->standard_coursemodule_elements();
$submit2label = get_string('savechangesandreturntocourse');
} catch (Exception $e) {
debugging($e->getLine() . ': ' . $e->getMessage());
}
$buttons = [];
if (!empty($submit2label) && $this->courseformat->has_view_page()) {
$buttons[] = $this->_form->createElement('submit', 'submitbutton2', $submit2label);
}
$buttons[] = $this->_form->createElement('cancel');
$this->_form->addGroup($buttons, 'buttonar', '', [' '], false);
$this->_form->setType('buttonar', PARAM_RAW);
$this->_form->closeHeaderBefore('buttonar');
}
}