MDL-47494 ddimageortext: OU-1597 Renaming question types.
[moodle.git] / question / type / ddimageortext / edit_ddimageortext_form.php
CommitLineData
a2bb148a 1<?php
a2bb148a
TH
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
d2c112fd
JP
17require_once($CFG->dirroot.'/question/type/ddimageortext/edit_ddtoimage_form_base.php');
18
a2bb148a 19/**
e79dad73 20 * Defines the editing form for the drag-and-drop images onto images question type.
a2bb148a 21 *
5b4602d2 22 * @package qtype
31077627 23 * @subpackage ddimageortext
5b4602d2
TH
24 * @copyright 2009 The Open University
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
a2bb148a
TH
26 */
27
42536280
TH
28defined('MOODLE_INTERNAL') || die();
29
a2bb148a 30/**
e79dad73 31 * Drag-and-drop images onto images editing form definition.
a2bb148a 32 *
5b4602d2
TH
33 * @copyright 2009 The Open University
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
a2bb148a 35 */
d2c112fd 36class qtype_ddimageortext_edit_form extends qtype_ddtoimage_edit_form_base {
e79dad73 37
bc1bcf6e
JP
38 public function qtype() {
39 return 'ddimageortext';
40 }
41
42 public function js_call() {
43 global $PAGE;
44 $maxsizes =new stdClass();
45 $maxsizes->bgimage = new stdClass();
46 $maxsizes->bgimage->width = QTYPE_DDIMAGEORTEXT_BGIMAGE_MAXWIDTH;
47 $maxsizes->bgimage->height = QTYPE_DDIMAGEORTEXT_BGIMAGE_MAXHEIGHT;
48 $maxsizes->dragimage = new stdClass();
49 $maxsizes->dragimage->width = QTYPE_DDIMAGEORTEXT_DRAGIMAGE_MAXWIDTH;
50 $maxsizes->dragimage->height = QTYPE_DDIMAGEORTEXT_DRAGIMAGE_MAXHEIGHT;
51
52 $params = array('maxsizes' => $maxsizes,
53 'topnode' => 'fieldset#previewareaheader');
54
55 $PAGE->requires->yui_module('moodle-qtype_ddimageortext-form',
56 'M.qtype_ddimageortext.init_form',
57 array($params));
58 }
59
60 //drag items
61
62 protected function definition_draggable_items($mform, $itemrepeatsatstart) {
63
64 $this->repeat_elements($this->draggable_item($mform), $itemrepeatsatstart,
65 $this->draggable_items_repeated_options(),
66 'noitems', 'additems', self::ADD_NUM_ITEMS,
67 get_string('addmoreimages', 'qtype_ddimageortext'));
68 }
69
70 protected function draggable_item($mform) {
71 $draggableimageitem = array();
72
73 $draggableimageitem[] = $mform->createElement('header', 'draggableitemheader',
74 get_string('draggableitemheader', 'qtype_ddimageortext', '{no}'));
75 $dragitemtypes = array('image' => get_string('draggableimage', 'qtype_ddimageortext'),
76 'word' => get_string('draggableword', 'qtype_ddimageortext'));
77 $draggableimageitem[] = $mform->createElement('select', 'dragitemtype',
78 get_string('draggableitemtype', 'qtype_ddimageortext'),
79 $dragitemtypes,
80 array('class' => 'dragitemtype'));
81 $draggableimageitem[] = $mform->createElement('filepicker', 'dragitem', '', null,
82 self::file_picker_options());
83
84 $grouparray = array();
85 $grouparray[] = $mform->createElement('text', 'draglabel',
86 get_string('label', 'qtype_ddimageortext'),
87 array('size'=>30, 'class'=>'tweakcss'));
88 $mform->setType('draglabel', PARAM_NOTAGS);
89 $options = array();
90 for ($i = 1; $i <= self::MAX_GROUPS; $i += 1) {
91 $options[$i] = $i;
92 }
93 $grouparray[] = $mform->createElement('static', '', '', ' ' .
94 get_string('group', 'qtype_gapselect').' ');
95 $grouparray[] = $mform->createElement('select', 'draggroup',
96 get_string('group', 'qtype_gapselect'),
97 $options,
98 array('class' => 'draggroup'));
99 $grouparray[] = $mform->createElement('advcheckbox', 'infinite', ' ',
100 get_string('infinite', 'qtype_ddimageortext'));
101 $draggableimageitem[] = $mform->createElement('group', 'drags',
102 get_string('label', 'qtype_ddimageortext'), $grouparray);
103 return $draggableimageitem;
104 }
105
106 protected function draggable_items_repeated_options() {
107 $repeatedoptions = array();
108 $repeatedoptions['draggroup']['default'] = '1';
109 return $repeatedoptions;
110 }
111
112 //drop zones
113
114 protected function drop_zone($mform, $imagerepeats) {
115 $dropzoneitem = array();
116
117 $grouparray = array();
118 $grouparray[] = $mform->createElement('static', 'xleftlabel', '',
119 ' '.get_string('xleft', 'qtype_ddimageortext').' ');
120 $grouparray[] = $mform->createElement('text', 'xleft',
121 get_string('xleft', 'qtype_ddimageortext'),
122 array('size'=>5, 'class'=>'tweakcss'));
123 $mform->setType('xleft', PARAM_NOTAGS);
124 $grouparray[] = $mform->createElement('static', 'ytoplabel', '',
125 ' '.get_string('ytop', 'qtype_ddimageortext').' ');
126 $grouparray[] = $mform->createElement('text', 'ytop',
127 get_string('ytop', 'qtype_ddimageortext'),
128 array('size'=>5, 'class'=>'tweakcss'));
129 $mform->setType('ytop', PARAM_NOTAGS);
130 $options = array();
131
132 $options[0] = '';
133 for ($i = 1; $i <= $imagerepeats; $i += 1) {
134 $options[$i] = $i;
135 }
136 $grouparray[] = $mform->createElement('static', '', '', ' ' .
137 get_string('draggableitem', 'qtype_ddimageortext').' ');
138 $grouparray[] = $mform->createElement('select', 'choice',
139 get_string('draggableitem', 'qtype_ddimageortext'), $options);
140 $grouparray[] = $mform->createElement('static', '', '', ' ' .
141 get_string('label', 'qtype_ddimageortext').' ');
142 $grouparray[] = $mform->createElement('text', 'droplabel',
143 get_string('label', 'qtype_ddimageortext'),
144 array('size'=>10, 'class'=>'tweakcss'));
145 $mform->setType('droplabel', PARAM_NOTAGS);
146 $dropzone = $mform->createElement('group', 'drops',
147 get_string('dropzone', 'qtype_ddimageortext', '{no}'), $grouparray);
148 return array($dropzone);
149 }
150
151 protected function drop_zones_repeated_options() {
152 $repeatedoptions = array();
153 $repeatedoptions['choice']['default'] = '0';
154 return $repeatedoptions;
155 }
a2bb148a 156}