Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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
namespace core_grades\output;
18
 
19
use core\output\renderer_base;
20
use core\output\templatable;
21
use core\output\renderable;
22
use grade_grade;
23
 
24
/**
25
 * The base class for the action bar in the gradebook pages.
26
 *
27
 * @package    core_grades
28
 * @copyright  2024 Catalyst IT Australia Pty Ltd
29
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30
 */
31
class penalty_indicator implements renderable, templatable {
32
    /**
33
     * The class constructor.
34
     *
35
     * @param int $decimals the decimal places
36
     * @param grade_grade $grade user grade
37
     * @param bool $showfinalgrade whether to show the final grade (or show icon only)
38
     * @param bool $showgrademax whether to show the max grade
39
     * @param array|null $penaltyicon icon to show if penalty is applied
40
     */
41
    public function __construct(
42
        /** @var int $decimals the decimal places */
43
        protected int $decimals,
44
 
45
        /** @var grade_grade $grade user grade */
46
        protected grade_grade $grade,
47
 
48
        /** @var bool $showfinalgrade whether to show the final grade (or show icon only) */
49
        protected bool $showfinalgrade = false,
50
 
51
        /** @var bool $showgrademax whether to show the max grade */
52
        protected bool $showgrademax = false,
53
 
54
        /** @var array|null $penaltyicon icon to show if penalty is applied */
55
        protected ?array $penaltyicon = null
56
    ) {
57
    }
58
 
59
    /**
60
     * Returns the template for the actions bar.
61
     *
62
     * @return string
63
     */
64
    public function get_template(): string {
65
        return 'core_grades/penalty_indicator';
66
    }
67
 
68
    #[\Override]
69
    public function export_for_template(renderer_base $output): array {
70
        $penalty = format_float($this->grade->deductedmark, $this->decimals);
71
        $finalgrade = $this->showfinalgrade ? format_float($this->grade->finalgrade , $this->decimals) : null;
72
        $grademax = $this->showgrademax ? format_float($this->grade->get_grade_max(), $this->decimals) : null;
73
        $icon = $this->penaltyicon ?: ['name' => 'i/risk_xss', 'component' => 'core'];
74
        $info = get_string('gradepenalty_indicator_info', 'core_grades', $penalty);
75
 
76
        $context = [
77
            'penalty' => $penalty,
78
            'finalgrade' => $finalgrade,
79
            'grademax' => $grademax,
80
            'icon' => $icon,
81
            'info' => $info,
82
        ];
83
 
84
        return $context;
85
    }
86
}