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
 * Completion enabled set indicator.
19
 *
20
 * @package   core_course
21
 * @copyright 2017 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_course\analytics\indicator;
26
 
27
defined('MOODLE_INTERNAL') || die();
28
 
29
require_once($CFG->dirroot . '/lib/completionlib.php');
30
 
31
/**
32
 * Completion enabled set indicator.
33
 *
34
 * @package   core_course
35
 * @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
36
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 */
38
class completion_enabled extends \core_analytics\local\indicator\binary {
39
 
40
    /**
41
     * get_name
42
     *
43
     * @return new \lang_string
44
     */
45
    public static function get_name(): \lang_string {
46
        return new \lang_string('indicator:completionenabled', 'moodle');
47
    }
48
 
49
    /**
50
     * required_sample_data
51
     *
52
     * @return string[]
53
     */
54
    public static function required_sample_data() {
55
        // Minimum course although it also accepts course_modules.
56
        return array('course');
57
    }
58
 
59
    /**
60
     * Is completion enabled? Work both with courses and activities.
61
     *
62
     * @param int $sampleid
63
     * @param string $sampleorigin
64
     * @param int|false $notusedstarttime
65
     * @param int|false $notusedendtime
66
     * @return float
67
     */
68
    public function calculate_sample($sampleid, $sampleorigin, $notusedstarttime = false, $notusedendtime = false) {
69
 
70
        $course = $this->retrieve('course', $sampleid);
71
 
72
        // It may not be available, but if it is the indicator checks if completion is enabled for the cm.
73
        $cm = $this->retrieve('course_modules', $sampleid);
74
 
75
        $completion = new \completion_info($course);
76
 
77
        if (!$completion->is_enabled($cm)) {
78
            $value = self::get_min_value();
79
        } else if (!$cm && !$completion->has_criteria()) {
80
            // Course completion enabled with no criteria counts as nothing.
81
            $value = self::get_min_value();
82
        } else {
83
            $value = self::get_max_value();
84
        }
85
        return $value;
86
    }
87
}