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 the customcert module for 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
 * Provides helper functionality.
19
 *
20
 * @package    mod_customcert
21
 * @copyright  2021 Mark Nelson <mdjnelson@gmail.com>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace mod_customcert;
26
 
27
use core_user\fields;
28
 
29
/**
30
 * Class helper.
31
 *
32
 * Helper functionality for this module.
33
 *
34
 * @package    mod_customcert
35
 * @copyright  2021 Mark Nelson <mdjnelson@gmail.com>
36
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 */
38
class helper {
39
 
40
    /**
41
     * A centralised location for the all name fields.
42
     *
43
     * Returns a sql string snippet.
44
     *
45
     * @param string $tableprefix table query prefix to use in front of each field.
46
     * @return string All name fields.
47
     */
48
    public static function get_all_user_name_fields(string $tableprefix = ''): string {
49
        $alternatenames = [];
50
        foreach (fields::get_name_fields() as $field) {
51
            $alternatenames[$field] = $field;
52
        }
53
 
54
        if ($tableprefix) {
55
            foreach ($alternatenames as $key => $altname) {
56
                $alternatenames[$key] = $tableprefix . '.' . $altname;
57
            }
58
        }
59
 
60
        return implode(',', $alternatenames);
61
    }
62
}