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
use block_dedication\lib\utils;
18
/**
19
 * Dedication block definition.
20
 *
21
 * @package    block_dedication
22
 * @copyright  2008 CICEI http://http://www.cicei.com
23
 * @author     2008 Borja Rubio Reyes
24
 *             2011 Aday Talavera Hierro (update to Moodle 2.x)
25
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
 */
27
class block_dedication extends block_base {
28
 
29
    /**
30
     * Initialise.
31
     *
32
     * @return void
33
     */
34
    public function init() {
35
        $this->title = get_string('pluginname', 'block_dedication');
36
    }
37
 
38
    /** Block level config. */
39
    public function specialization() {
40
        // Previous block versions didn't have config settings.
41
        if ($this->config === null) {
42
            $this->config = new stdClass();
43
        }
44
        // Set always show_dedication config settings to avoid errors.
45
        if (!isset($this->config->show_dedication)) {
46
            $this->config->show_dedication = 1;
47
        }
48
    }
49
 
50
    /**
51
     * Output block.
52
     *
53
     * @return stdclass
54
     */
55
    public function get_content() {
56
        global $USER, $COURSE;
57
 
58
        if ($this->content !== null) {
59
            return $this->content;
60
        }
61
 
62
        $this->content = new stdClass();
63
        $this->content->text = '';
64
        $this->content->footer = '';
65
 
66
        $lastruntime = get_config('block_dedication', 'lastcalculated');
67
        if (empty($lastruntime)) {
68
            $this->content->text = html_writer::tag('p', get_string('timespenttasknotrunning', 'block_dedication'),
69
                                                    ['class' => 'warning']);
70
            return $this->content;
71
        }
72
        $showtimespent = empty($this->config->show_dedication) ? false : true;
73
        if ($showtimespent) {
74
            $timespent = utils::timespent($COURSE->id, $USER->id);
75
            $this->content->text .= html_writer::tag('p', get_string('timespent_estimation', 'block_dedication'));
76
            $this->content->text .= html_writer::tag('p', $timespent);
77
 
78
            $lastupdated = get_config('block_dedication', 'lastcalculated');
79
            if (!empty($lastupdated)) {
80
                $this->content->footer .= html_writer::span(get_string('lastupdated', 'block_dedication',
81
                    userdate($lastupdated, get_string('strftimedatetimeshort', 'core_langconfig'))), 'dimmed_text');
82
            }
83
        }
84
        if (has_capability('block/dedication:viewreports', context_course::instance($COURSE->id))) {
85
            $url = new moodle_url('/blocks/dedication/index.php', ['id' => $COURSE->id]);
86
            $this->content->footer .= html_writer::tag('p', html_writer::link($url,
87
                                                       get_string('timespentreport', 'block_dedication')));
88
        } else if ($showtimespent) {
89
            $url = new moodle_url('/blocks/dedication/user.php', ['id' => $COURSE->id, 'userid' => $USER->id]);
90
            $this->content->footer .= html_writer::tag('p', html_writer::link($url,
91
                                                       get_string('timespentreport', 'block_dedication')));
92
        }
93
 
94
        return $this->content;
95
    }
96
 
97
    /**
98
     * Page types that can add this block.
99
     *
100
     * @return array
101
     */
102
    public function applicable_formats() {
103
        return ['admin' => false,
104
                'site-index' => true,
105
                'course-view' => true,
106
                'mod' => false,
107
                'my' => false];
108
    }
109
 
110
    /**
111
     * Controls global configurability of block.
112
     *
113
     * @return bool
114
     */
115
    public function has_config(): bool {
116
        return true;
117
    }
118
 
119
}