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
 * User class utility class
19
 *
20
 * @package   theme_universe
21
 * @copyright 2023 Marcin Czaja (https://rosea.io)
22
 * @license   Commercial https://themeforest.net/licenses
23
 */
24
 
25
namespace theme_universe\util;
26
 
27
use stdClass;
28
use user_picture;
29
 
30
/**
31
 * User class utility class
32
 *
33
 * @package   theme_universe
34
 * @copyright 2023 Marcin Czaja (https://rosea.io)
35
 * @license   Commercial https://themeforest.net/licenses
36
 */
37
class user {
38
    /**
39
     * @var \stdClass $user The user object.
40
     */
41
    protected $user;
42
 
43
    /**
44
     * Class constructor
45
     *
46
     * @param stdClass $user
47
     *
48
     */
49
    public function __construct($user = null) {
50
        global $USER, $DB;
51
 
52
        if (!is_object($user)) {
53
            $user = $DB->get_record('user', ['id' => $user], '*', MUST_EXIST);
54
        }
55
 
56
        if (!$user) {
57
            $user = $USER;
58
        }
59
 
60
        $this->user = $user;
61
    }
62
 
63
    /**
64
     * Returns the user picture
65
     *
66
     * @param int $imgsize
67
     *
68
     * @return \moodle_url
69
     * @throws \coding_exception
70
     */
71
    public function get_user_picture($imgsize = 100) {
72
        global $PAGE;
73
 
74
        $userimg = new user_picture($this->user);
75
 
76
        $userimg->size = $imgsize;
77
 
78
        return $userimg->get_url($PAGE)->out();
79
    }
80
}