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
 * Task that generates session duration data for reports.
19
 * @package block_dedication
20
 * @copyright 2022 University of Canterbury
21
 * @author Pramith Dayananda <pramithd@catalyst.net.nz>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
namespace block_dedication\task;
25
 
26
use block_dedication\lib\utils;
27
 
28
/**
29
 * Dedication data generator task.
30
 */
31
class dedication_collector extends \core\task\scheduled_task {
32
 
33
    /**
34
     * Return the task's name as shown in admin screens.
35
     *
36
     * @return string
37
     */
38
    public function get_name() {
39
        return get_string('collect_dedication', 'block_dedication');
40
    }
41
 
42
    /**
43
     * Execute the task.
44
     */
45
    public function execute() {
46
        $lastruntime = get_config('block_dedication', 'lastcalculated');
47
        if (empty($lastruntime)) {
48
            mtrace("This is the first time this task has been run, calculate data for last 12 weeks");
49
            // First time this task has been run - lets pull in last 12 weeks of time calculations.
50
            $lastruntime = time() - WEEKSECS * 12;
51
        } else if ($lastruntime > time() - (2 * HOURSECS)) {
52
            mtrace("This task can only be triggered every 2 hours");
53
            return;
54
        }
55
        utils::generate_stats($lastruntime, time());
56
    }
57
}