-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathview_action_form_assign.php
executable file
·170 lines (151 loc) · 6.64 KB
/
view_action_form_assign.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
<?php
// This file is part of mod_organizer 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/>.
/**
* view_action_form_assign.php
*
* @package mod_organizer
* @author Thomas Niedermaier (thomas.niedermaier@meduniwien.ac.at)
* @author Andreas Hruska (andreas.hruska@tuwien.ac.at)
* @author Katarzyna Potocka (katarzyna.potocka@tuwien.ac.at)
* @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();
require_once("$CFG->libdir/formslib.php");
require_once(dirname(__FILE__) . '/lib.php');
class organizer_assign_slot_form extends moodleform {
/**
* {@inheritDoc}
* @see moodleform::definition()
*/
protected function definition() {
$this->_sethiddenfields();
}
/**
* {@inheritDoc}
* @see moodleform::definition_after_data()
*/
public function definition_after_data() {
$this->_addslotlist();
$this->add_action_buttons(false, get_string('assign', 'organizer'));
}
/**
* Set the hidden fields in the function
*/
private function _sethiddenfields() {
$mform = $this->_form;
$data = $this->_customdata;
$mform->addElement('hidden', 'id', $data['id']);
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'mode', $data['mode']);
$mform->setType('mode', PARAM_INT);
$mform->addElement('hidden', 'action', 'assign');
$mform->setType('action', PARAM_ALPHANUMEXT);
$mform->addElement('hidden', 'participant', $data['participant']);
$mform->setType('participant', PARAM_INT);
$mform->addElement('hidden', 'group', $data['group']);
$mform->setType('group', PARAM_INT);
$mform->addElement('hidden', 'organizerid', $data['organizerid']);
$mform->setType('organizerid', PARAM_INT);
}
/**
* adds slots to the form
*/
private function _addslotlist() {
global $DB;
$mform = $this->_form;
$data = $this->_customdata;
if ($data['group'] != 0) {
$mform->addElement('header', 'assignheader', get_string('availableslotsfor', 'organizer') .
' <strong>' . $data['groupname'] . '</strong>');
} else {
$mform->addElement('header', 'assignheader', get_string('availableslotsfor', 'organizer') .
' <strong>' . organizer_get_name_link($data['participant']) . '</strong>');
}
$slots = $DB->get_records('organizer_slots', array('organizerid' => $data['organizerid']));
$mform->addElement('html', '<table class="generaltable overview">');
$mform->addElement('html', '<tr>');
$mform->addElement('html',
'<th style="vertical-align: middle;white-space: nowrap; text-align:right; padding-right:50px;" nowrap>' .
get_string('th_datetime', 'organizer') . '</td>');
$mform->addElement('html',
'<th style="vertical-align: middle;white-space: nowrap; text-align:center;" nowrap>' .
get_string('th_location', 'organizer') . '</td>');
$mform->addElement('html',
'<th style="vertical-align: middle;white-space: nowrap; text-align:center;" nowrap>' .
get_string('th_teacher', 'organizer') . '</td>');
$mform->addElement('html', '<th style="vertical-align: middle;white-space: nowrap" nowrap> </td>');
$i = 0;
foreach ($slots as $slot) {
if ($this->_organizer_slot_is_free($slot, $data['participant'])) {
$i++;
$strradio = organizer_date_time($slot);
$mform->addElement('html', '<tr class="free_slot">');
$mform->addElement('html', '<td style="vertical-align: middle;white-space: nowrap" nowrap>');
$mform->addElement('radio', 'selectedslot', '', $strradio, $slot->id);
$mform->addElement('html', '</td>');
$mform->addElement('html',
'<td style="vertical-align: middle;white-space: nowrap" nowrap>' .
organizer_location_link($slot) . '</td>');
$mform->addElement('html',
'<td style="vertical-align: middle;white-space: nowrap" nowrap>' .
organizer_get_name_link($slot->teacherid) . '</td>');
$mform->addElement('html', '<td style="vertical-align: middle;width:100%;"> </td>');
$mform->addElement('html', '</tr>');
if ($i == 1) {
$defaultid = $slot->id;
}
}
}
if ($i == 0) {
$mform->addElement('html',
'<tr class="rcs-course"><td class="cell">'. get_string('nofreeslots', 'organizer') . '</td></tr>');
} else {
$mform->setDefault('selectedslot', $defaultid);
}
$mform->addElement('html', '</table>');
}
/**
* looks if the slot is free for the user
* @param mixed $slot
* @param int $userid
* @return boolean
*/
private function _organizer_slot_is_free($slot, $userid) {
$slotx = new organizer_slot($slot);
if (!$slotx->is_past_due() && !$slotx->is_full() && $slotx->is_available() ) {
$apps = organizer_get_all_user_appointments($slotx->organizerid, $userid);
foreach ($apps as $app) {
if ($app->slotid == $slotx->id) {
return false;
}
}
return true;
}
return false;
}
/**
* Adds Buttons to the form
*/
private function _addbuttons() {
$mform = $this->_form;
$buttonarray = array();
$buttonarray[] = &$mform->createElement('submit', 'assignsubmit', get_string('assign', 'organizer'));
$buttonarray[] = &$mform->createElement('cancel');
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
$mform->closeHeaderBefore('buttonar');
}
}