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
 * Contains class used to prepare verification results for display.
19
 *
20
 * @package   mod_customcert
21
 * @copyright 2017 Mark Nelson <markn@moodle.com>
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace mod_customcert\output;
26
 
27
use renderable;
28
use templatable;
29
 
30
/**
31
 * Class to prepare verification results for display.
32
 *
33
 * @package   mod_customcert
34
 * @copyright 2017 Mark Nelson <markn@moodle.com>
35
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36
 */
37
class verify_certificate_results implements templatable, renderable {
38
 
39
    /**
40
     * @var bool Was the code successfully verified?
41
     */
42
    public $success;
43
 
44
    /**
45
     * @var string The message to display.
46
     */
47
    public $message;
48
 
49
    /**
50
     * @var array The certificates issued with the matching code.
51
     */
52
    public $issues;
53
 
54
    /**
55
     * Constructor.
56
     *
57
     * @param \stdClass $result
58
     */
59
    public function __construct($result) {
60
        $this->success = $result->success;
61
        if ($this->success) {
62
            $this->message = get_string('verified', 'customcert');
63
        } else {
64
            $this->message = get_string('notverified', 'customcert');
65
        }
66
        $this->issues = $result->issues;
67
    }
68
 
69
    /**
70
     * Function to export the renderer data in a format that is suitable for a mustache template.
71
     *
72
     * @param \renderer_base $output Used to do a final render of any components that need to be rendered for export.
73
     * @return \stdClass|array
74
     */
75
    public function export_for_template(\renderer_base $output) {
76
        $result = new \stdClass();
77
        $result->success = $this->success;
78
        $result->message = $this->message;
79
        $result->issues = [];
80
        foreach ($this->issues as $issue) {
81
            $resultissue = new verify_certificate_result($issue);
82
            $result->issues[] = $resultissue->export_for_template($output);
83
        }
84
 
85
        return $result;
86
    }
87
}