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
declare(strict_types=1);
18
 
19
use core_reportbuilder\local\models\report;
20
 
21
/**
22
 * Behat data generator for Report builder
23
 *
24
 * @package     core_reportbuilder
25
 * @copyright   2021 Paul Holden <paulh@moodle.com>
26
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 */
28
class behat_core_reportbuilder_generator extends behat_generator_base {
29
 
30
    /**
31
     * Get a list of the entities that can be created for this component
32
     *
33
     * @return array[]
34
     */
35
    protected function get_creatable_entities(): array {
36
        return [
37
            'Reports' => [
38
                'singular' => 'Report',
39
                'datagenerator' => 'report',
40
                'required' => [
41
                    'name',
42
                    'source',
43
                ],
44
            ],
45
            'Columns' => [
46
                'singular' => 'Column',
47
                'datagenerator' => 'column',
48
                'required' => [
49
                    'report',
50
                    'uniqueidentifier',
51
                ],
52
                'switchids' => [
53
                    'report' => 'reportid',
54
                ],
55
            ],
56
            'Conditions' => [
57
                'singular' => 'Condition',
58
                'datagenerator' => 'condition',
59
                'required' => [
60
                    'report',
61
                    'uniqueidentifier',
62
                ],
63
                'switchids' => [
64
                    'report' => 'reportid',
65
                ],
66
            ],
67
            'Filters' => [
68
                'singular' => 'Filter',
69
                'datagenerator' => 'filter',
70
                'required' => [
71
                    'report',
72
                    'uniqueidentifier',
73
                ],
74
                'switchids' => [
75
                    'report' => 'reportid',
76
                ],
77
            ],
78
            'Audiences' => [
79
                'singular' => 'Audience',
80
                'datagenerator' => 'audience',
81
                'required' => [
82
                    'report',
83
                    'configdata',
84
                ],
85
                'switchids' => [
86
                    'report' => 'reportid',
87
                ],
88
            ],
89
            'Schedules' => [
90
                'singular' => 'Schedule',
91
                'datagenerator' => 'schedule',
92
                'required' => [
93
                    'report',
94
                    'name',
95
                ],
96
                'switchids' => [
97
                    'report' => 'reportid',
98
                ],
99
            ],
100
        ];
101
    }
102
 
103
    /**
104
     * Look up report ID from given name
105
     *
106
     * @param string $name
107
     * @return int
108
     */
109
    protected function get_report_id(string $name): int {
110
        global $DB;
111
 
112
        return (int) $DB->get_field(report::TABLE, 'id', ['name' => $name], MUST_EXIST);
113
    }
114
 
115
    /**
116
     * Pre-process audience entity, generate correct config structure
117
     *
118
     * @param array $audience
119
     * @return array
120
     */
121
    protected function preprocess_audience(array $audience): array {
122
        $audience['configdata'] = (array) json_decode($audience['configdata']);
123
 
124
        return $audience;
125
    }
126
}