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
namespace quiz_statistics\tests;
17
 
18
/**
19
 * Test helper functions for statistics
20
 *
21
 * @package   quiz_statistics
22
 * @copyright 2023 onwards Catalyst IT EU {@link https://catalyst-eu.net}
23
 * @author    Mark Johnson <mark.johnson@catalyst-eu.net>
24
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 */
26
class statistics_helper {
27
    /**
28
     * Run any ad-hoc recalculation tasks that have been scheduled.
29
     *
30
     * We need a special function to do this as the tasks are deferred by one hour,
31
     * so we need to pass a custom $timestart argument.
32
     *
33
     * @param bool $discardoutput Capture and discard output from executed tasks?
34
     * @return void
35
     */
36
    public static function run_pending_recalculation_tasks(bool $discardoutput = false): void {
37
        while ($task = \core\task\manager::get_next_adhoc_task(
38
            time() + HOURSECS + 1,
39
            false,
40
            '\quiz_statistics\task\recalculate'
41
        )) {
42
            if ($discardoutput) {
43
                ob_start();
44
            }
45
            $task->execute();
46
            if ($discardoutput) {
47
                ob_end_clean();
48
            }
49
            \core\task\manager::adhoc_task_complete($task);
50
        }
51
    }
52
 
53
}