-
Notifications
You must be signed in to change notification settings - Fork 65
/
turnitintooltwo_form.class.php
160 lines (136 loc) · 5.85 KB
/
turnitintooltwo_form.class.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
<?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/>.
/**
* @package turnitintooltwo
* @copyright 2012 iParadigms LLC
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir."/formslib.php");
class turnitintooltwo_form extends moodleform {
/**
* The form definition contains a customdata array. This contains all the elements as an array,
* each element is passed with data in the following format:
* array(type e.g. "text", id/name of element, label string, string identifier for help text,
* options (e.g. for select, advcheckbox or file upload), rule, rule error msg, param_type,
* array for disabled if rule (dependent field, condition, value)
*
* @global type $CFG
*/
public function definition() {
$mform =& $this->_form;
foreach ($this->_customdata["elements"] as $element) {
switch ($element[0]) {
case "static":
case "select":
case "date_time_selector":
case "date_selector":
$mform->addElement($element[0], $element[1], $element[2], $element[4]);
break;
case "filemanager":
$mform->addElement($element[0], $element[1], $element[2], '', $element[4]);
break;
case "html":
$mform->addElement($element[0], $element[1]);
break;
case "advcheckbox":
$labelbefore = $element[2];
$labelafter = null;
if (!empty($this->_customdata["checkbox_label_after"])) {
$labelbefore = null;
$labelafter = $element[2];
}
$mform->addElement($element[0], $element[1], $labelbefore, $labelafter, null, $element[4]);
break;
case "hidden":
case "text":
$mform->addElement($element[0], $element[1], $element[2]);
$mform->setType($element[1], PARAM_RAW);
break;
default:
$mform->addElement($element[0], $element[1], $element[2]);
break;
}
// Set form data. Only used for submission form.
if (isset($_SESSION['form_data']->{$element[1]})) {
$mform->setDefault($element[1], $_SESSION['form_data']->{$element[1]});
}
if (!empty($element[3])) {
$mform->addHelpButton($element[1], $element[3], 'turnitintooltwo');
}
if (!empty($element[5])) {
$mform->setType($element[1], PARAM_TEXT);
$mform->addRule($element[1], $element[6], $element[5], null, 'client');
}
if (!empty($element[7])) {
$disabledif = $element[7];
$mform->disabledIf($element[1], $disabledif[0], $disabledif[1], $disabledif[2]);
}
}
// Apply a class to the form if specified.
if (isset($this->_customdata["class"])) {
$mform->_formname = $this->_customdata["class"];
}
// Show the moodleform standard submit and cancel buttons.
if (!isset($this->_customdata["hide_submit"])) {
$submitlabel = null;
if (isset($this->_customdata["submit_label"])) {
$submitlabel = $this->_customdata["submit_label"];
}
if (!isset($this->_customdata["show_cancel"])) {
$this->_customdata["show_cancel"] = "true";
}
$this->add_action_buttons($this->_customdata["show_cancel"], $submitlabel);
}
// Disable the form change checker - added in 2.3.2.
if (is_callable(array($mform, 'disable_form_change_checker'))) {
if (isset($this->_customdata["disable_form_change_checker"])) {
$mform->disable_form_change_checker();
}
}
// Show multiple submit buttons if needed.
if (isset($this->_customdata["multi_submit_buttons"])) {
$buttonarray = array();
foreach ($this->_customdata["multi_submit_buttons"] as $btn) {
$buttonarray[] = &$mform->createElement('submit', $btn[0], $btn[1]);
}
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
}
}
/**
* Display the form, saving the contents of the output buffer overiding Moodle's
* display function that prints to screen when called
*
* @return the form as an object to print to screen at our convenience
*/
public function display() {
ob_start();
parent::display();
$form = ob_get_contents();
ob_end_clean();
return $form;
}
}
class turnitin_plagiarism_plugin_form extends moodleform {
// Define the form.
public function definition () {
global $CFG;
$mform =& $this->_form;
require_once($CFG->dirroot.'/plagiarism/turnitin/turnitinplugin_view.class.php');
$turnitinpluginview = new turnitinplugin_view();
$turnitinpluginview->add_elements_to_settings_form($mform, array(), "defaults");
$this->add_action_buttons(true);
}
}