Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
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
 
17
/**
18
 * This file contains form for bulk changing user enrolments.
19
 *
20
 * @package    core_enrol
21
 * @copyright  2011 Sam Hemelryk
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
defined('MOODLE_INTERNAL') || die();
26
 
27
require_once("$CFG->libdir/formslib.php");
28
 
29
/**
30
 * A base class that can be used to easily construct a form for use with bulk operations
31
 *
32
 * @copyright 2011 Sam Hemelryk
33
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 */
35
abstract class enrol_bulk_enrolment_change_form extends moodleform {
36
 
37
    /**
38
     * Defines the standard structure of the form
39
     */
40
    protected function definition() {
41
        $form = $this->_form;
42
        $users = $this->_customdata['users'];
43
 
44
        $statusoptions = $this->get_status_options();
45
        $form->addElement('html', $this->get_users_table($users, $statusoptions));
46
        $form->addElement('select', 'status', get_string('alterstatus', 'enrol_manual'), $statusoptions, array('optional' => true));
47
        $form->addElement('date_time_selector', 'timestart', get_string('altertimestart', 'enrol_manual'), array('optional' => true));
48
        $form->addElement('date_time_selector', 'timeend', get_string('altertimeend', 'enrol_manual'), array('optional' => true));
49
 
50
        $this->add_action_buttons();
51
    }
52
 
53
    /**
54
     * Returns an array of status options
55
     * @return array
56
     */
57
    protected function get_status_options() {
58
        return array(-1                   => get_string('nochange', 'enrol'),
59
                     ENROL_USER_ACTIVE    => get_string('participationactive', 'enrol'),
60
                     ENROL_USER_SUSPENDED => get_string('participationsuspended', 'enrol'));
61
    }
62
 
63
    /**
64
     * Generates an HTML table to display the users being affected by the bulk change.
65
     *
66
     * @param array $users
67
     * @param array $statusoptions
68
     * @return string
69
     */
70
    protected function get_users_table(array $users, array $statusoptions) {
71
        $table = new html_table();
72
        $table->head = array(
73
            get_string('name'),
74
            get_string('participationstatus', 'enrol'),
75
            get_string('enroltimestart', 'enrol'),
76
            get_string('enroltimeend', 'enrol'),
77
        );
78
        $table->data = array();
79
        foreach ($users as $user) {
80
            foreach ($user->enrolments as $enrolment) {
81
                $input = html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'bulkuser[]', 'value' => $user->id));
82
                $table->data[] = array(
83
                    fullname($user).$input,
84
                    $statusoptions[$enrolment->status],
85
                    (!empty($enrolment->timestart))?userdate($enrolment->timestart):'',
86
                    (!empty($enrolment->timeend))?userdate($enrolment->timeend):'',
87
                );
88
            }
89
        }
90
        return html_writer::table($table);
91
    }
92
}
93
 
94
/**
95
 * A convenience class to allow the quick generation of a confirmation form for a bulk operation.
96
 * @copyright 2011 Sam Hemelryk
97
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
98
 */
99
abstract class enrol_bulk_enrolment_confirm_form extends enrol_bulk_enrolment_change_form {
100
 
101
    /**
102
     * Defines the standard structure of the form
103
     */
104
    protected function definition() {
105
        $form = $this->_form;
106
        $users = $this->_customdata['users'];
107
        $title = $this->_customdata['title'];
108
        $message = $this->_customdata['message'];
109
        $button = $this->_customdata['button'];
110
 
111
        $form->addElement('html', $this->get_users_table($users, $this->get_status_options()));
112
        $form->addElement('header', 'ebecf_header', $title);
113
        $form->addElement('html', html_writer::tag('p', $message));
114
        $this->add_action_buttons(true, $button);
115
    }
116
}