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 |
* Keeps track of the analysis results by storing the results in an array.
|
|
|
19 |
*
|
|
|
20 |
* @package core_analytics
|
|
|
21 |
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
namespace core_analytics\local\analysis;
|
|
|
26 |
|
|
|
27 |
defined('MOODLE_INTERNAL') || die();
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* Keeps track of the analysis results by storing the results in an array.
|
|
|
31 |
*
|
|
|
32 |
* @package core_analytics
|
|
|
33 |
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
|
|
|
34 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
35 |
*/
|
|
|
36 |
class result_array extends result {
|
|
|
37 |
|
|
|
38 |
/**
|
|
|
39 |
* Stores the analysis results by time-splitting method.
|
|
|
40 |
* @var array
|
|
|
41 |
*/
|
|
|
42 |
private $resultsbytimesplitting = [];
|
|
|
43 |
|
|
|
44 |
/**
|
|
|
45 |
* Stores the analysis results.
|
|
|
46 |
* @param array $results
|
|
|
47 |
* @return bool True if anything was successfully analysed
|
|
|
48 |
*/
|
|
|
49 |
public function add_analysable_results(array $results): bool {
|
|
|
50 |
|
|
|
51 |
$any = false;
|
|
|
52 |
|
|
|
53 |
// Process all provided time splitting methods.
|
|
|
54 |
foreach ($results as $timesplittingid => $result) {
|
|
|
55 |
if (!empty($result->result)) {
|
|
|
56 |
if (empty($this->resultsbytimesplitting[$timesplittingid])) {
|
|
|
57 |
$this->resultsbytimesplitting[$timesplittingid] = [];
|
|
|
58 |
}
|
|
|
59 |
$this->resultsbytimesplitting[$timesplittingid] += $result->result;
|
|
|
60 |
$any = true;
|
|
|
61 |
}
|
|
|
62 |
}
|
|
|
63 |
if (empty($any)) {
|
|
|
64 |
return false;
|
|
|
65 |
}
|
|
|
66 |
return true;
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
/**
|
|
|
70 |
* Formats the result.
|
|
|
71 |
*
|
|
|
72 |
* @param array $data
|
|
|
73 |
* @param \core_analytics\local\target\base $target
|
|
|
74 |
* @param \core_analytics\local\time_splitting\base $timesplitting
|
|
|
75 |
* @param \core_analytics\analysable $analysable
|
|
|
76 |
* @return mixed The data as it comes
|
|
|
77 |
*/
|
|
|
78 |
public function format_result(array $data, \core_analytics\local\target\base $target,
|
|
|
79 |
\core_analytics\local\time_splitting\base $timesplitting, \core_analytics\analysable $analysable) {
|
|
|
80 |
return $data;
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
/**
|
|
|
84 |
* Returns the results of the analysis.
|
|
|
85 |
* @return array
|
|
|
86 |
*/
|
|
|
87 |
public function get(): array {
|
|
|
88 |
|
|
|
89 |
// We join the datasets by time splitting method.
|
|
|
90 |
$timesplittingresults = array();
|
|
|
91 |
foreach ($this->resultsbytimesplitting as $timesplittingid => $results) {
|
|
|
92 |
if (empty($timesplittingresults[$timesplittingid])) {
|
|
|
93 |
$timesplittingresults[$timesplittingid] = [];
|
|
|
94 |
}
|
|
|
95 |
$timesplittingresults[$timesplittingid] += $results;
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
return $timesplittingresults;
|
|
|
99 |
}
|
|
|
100 |
}
|