frontend.php 3.45 KB
Newer Older
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
<?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/>.

/**
 * Front-end class.
 *
 * @package availability_profile
 * @copyright 2014 The Open University
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

namespace availability_profile;

defined('MOODLE_INTERNAL') || die();

/**
 * Front-end class.
 *
 * @package availability_profile
 * @copyright 2014 The Open University
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
class frontend extends \core_availability\frontend {
    protected function get_javascript_strings() {
        return array('op_contains', 'op_doesnotcontain', 'op_endswith', 'op_isempty',
                'op_isequalto', 'op_isnotempty', 'op_startswith', 'conditiontitle',
                'label_operator', 'label_value');
    }

    protected function get_javascript_init_params($course, \cm_info $cm = null,
            \section_info $section = null) {
        // Standard user fields.
        $standardfields = array(
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
            'firstname' => \core\user_fields::get_display_name('firstname'),
            'lastname' => \core\user_fields::get_display_name('lastname'),
            'email' => \core\user_fields::get_display_name('email'),
            'city' => \core\user_fields::get_display_name('city'),
            'country' => \core\user_fields::get_display_name('country'),
            'url' => \core\user_fields::get_display_name('url'),
            'icq' => \core\user_fields::get_display_name('icq'),
            'skype' => \core\user_fields::get_display_name('skype'),
            'aim' => \core\user_fields::get_display_name('aim'),
            'yahoo' => \core\user_fields::get_display_name('yahoo'),
            'msn' => \core\user_fields::get_display_name('msn'),
            'idnumber' => \core\user_fields::get_display_name('idnumber'),
            'institution' => \core\user_fields::get_display_name('institution'),
            'department' => \core\user_fields::get_display_name('department'),
            'phone1' => \core\user_fields::get_display_name('phone1'),
            'phone2' => \core\user_fields::get_display_name('phone2'),
            'address' => \core\user_fields::get_display_name('address')
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
        );
        \core_collator::asort($standardfields);

        // Custom fields.
        $customfields = array();
        $options = array('context' => \context_course::instance($course->id));
        foreach (condition::get_custom_profile_fields() as $field) {
            $customfields[$field->shortname] = format_string($field->name, true, $options);
        }
        \core_collator::asort($customfields);

        // Make arrays into JavaScript format (non-associative, ordered) and return.
        return array(self::convert_associative_array_for_js($standardfields, 'field', 'display'),
                self::convert_associative_array_for_js($customfields, 'field', 'display'));
    }
}