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
 * Configurable Reports
19
 * A Moodle block for creating customizable reports
20
 * @package blocks
21
 * @author: Juan leyva <http://www.twitter.com/jleyvadelgado>
22
 * @date: 2009
23
 */
24
 
25
class report_timeline extends report_base {
26
 
27
    public function init() {
28
        $this->components = array('timeline', 'columns', 'filters', 'template', 'permissions', 'calcs', 'plot');
29
    }
30
 
31
    public function get_all_elements() {
32
        $elements = array();
33
 
34
        $components = cr_unserialize($this->config->components);
35
 
36
        $config = (isset($components['timeline']['config'])) ? $components['timeline']['config'] : new \stdclass();
37
 
38
        if (isset($config->timemode)) {
39
 
40
            $daysecs = 60 * 60 * 24;
41
 
42
            if ($config->timemode == 'previous') {
43
                $config->starttime = gmmktime() - $config->previousstart * $daysecs;
44
                $config->endtime = gmmktime() - $config->previousend * $daysecs;
45
                if (isset($config->forcemidnight)) {
46
                    $config->starttime = usergetmidnight($config->starttime);
47
                    $config->endtime = usergetmidnight($config->endtime) + ($daysecs - 1);
48
                }
49
            }
50
 
51
            $filterstarttime = optional_param('filter_starttime', 0, PARAM_RAW);
52
            $filterendtime = optional_param('filter_endtime', 0, PARAM_RAW);
53
 
54
            if ($filterstarttime and $filterendtime) {
55
                $filterstarttime = make_timestamp($filterstarttime['year'], $filterstarttime['month'], $filterstarttime['day']);
56
                $filterendtime = make_timestamp($filterendtime['year'], $filterendtime['month'], $filterendtime['day']);
57
 
58
                $config->starttime = usergetmidnight($filterstarttime);
59
                $config->endtime = usergetmidnight($filterendtime) + 24 * 60 * 60;
60
            }
61
 
62
            for ($i = $config->starttime; $i < $config->endtime; $i += $config->interval * $daysecs) {
63
                $row = new stdclass();
64
                $row->id = $i;
65
                $row->starttime = $i;
66
                $row->endtime = $row->starttime + ($config->interval * $daysecs - 1);
67
                if ($row->endtime > $config->endtime) {
68
                    $row->endtime = $config->endtime;
69
                }
70
                $this->timeline[$row->starttime] = $row;
71
                $elements[] = $row->starttime;
72
            }
73
 
74
            if ($config->ordering == 'desc') {
75
                rsort($elements);
76
            }
77
        }
78
 
79
        return $elements;
80
    }
81
 
82
    public function get_rows($elements, $sqlorder = '') {
83
        global $DB, $CFG;
84
 
85
        if (!empty($elements)) {
86
            $finaltimeline = array();
87
            foreach ($elements as $e) {
88
                $finaltimeline[] = $this->timeline[$e];
89
            }
90
            return $finaltimeline;
91
        } else {
92
            return array();
93
        }
94
    }
95
 
96
}