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
 * Front-end class.
19
 *
20
 * @package   availability_relativedate
21
 * @copyright 2022 eWallah.net
22
 * @author    Renaat Debleu <info@eWallah.net>
23
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
namespace availability_relativedate;
27
 
28
use cm_info;
29
use section_info;
30
use stdClass;
31
 
32
/**
33
 * Front-end class.
34
 *
35
 * @package   availability_relativedate
36
 * @copyright 2022 eWallah.net
37
 * @author    Renaat Debleu <info@eWallah.net>
38
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39
 */
40
class frontend extends \core_availability\frontend {
41
    /**
42
     * Gets additional parameters for the plugin's initInner function.
43
     *
44
     * Default returns no parameters.
45
     *
46
     * @param stdClass $course Course object
47
     * @param cm_info $cm Course-module currently being edited (null if none)
48
     * @param section_info $section Section currently being edited (null if none)
49
     * @return array Array of parameters for the JavaScript function
50
     */
51
    protected function get_javascript_init_params($course, cm_info $cm = null, section_info $section = null) {
52
        global $DB;
53
        $optionsdwm = self::convert_associative_array_for_js(condition::options_dwm(), 'field', 'display');
54
        $optionsstart = [
55
            ['field' => 1, 'display' => condition::options_start(1)],
56
            ['field' => 6, 'display' => condition::options_start(6)],
57
        ];
58
        if ($course->enddate != 0) {
59
            $optionsstart[] = ['field' => 5, 'display' => condition::options_start(5)];
60
            $optionsstart[] = ['field' => 2, 'display' => condition::options_start(2)];
61
        }
62
        $optionsstart[] = ['field' => 3, 'display' => condition::options_start(3)];
63
        if ($DB->count_records_select('enrol', 'courseid = :courseid AND enrolenddate > 0', ['courseid' => $course->id]) > 0) {
64
            $optionsstart[] = ['field' => 4, 'display' => condition::options_start(4)];
65
        }
66
        $activitysel = [];
67
        if ($course->enablecompletion != 0) {
68
            $currentcmid = $cm ? $cm->id : 0;
69
            $modinfo = get_fast_modinfo($course);
70
            $context = \context_course::instance($course->id);
71
            $str = get_string('section');
72
            $s = [];
73
            $enabled = false;
74
            // Gets only sections with content.
75
            foreach ($modinfo->get_sections() as $sectionnum => $section) {
76
                $name = $modinfo->get_section_info($sectionnum)->name;
77
                if (empty($name)) {
78
                    $name = $str . ' ' . $sectionnum;
79
                }
80
                $s['name'] = format_string($name, true, ['context' => $context]);
81
                $s['coursemodules'] = [];
82
                foreach ($section as $cmid) {
83
                    if ($currentcmid == $cmid) {
84
                        continue;
85
                    }
86
                    $module = $modinfo->get_cm($cmid);
87
                    // Get only course modules which are not being deleted.
88
                    if ($module->deletioninprogress == 0) {
89
                        $compused = $module->completion > 0;
90
                        $s['coursemodules'][] = [
91
                            'id' => $cmid,
92
                            'name' => format_string($module->name, true, ['context' => $context]),
93
                            'completionenabled' => $compused,
94
                        ];
95
                        $enabled = $enabled || $compused;
96
                    }
97
                }
98
                $activitysel[] = $s;
99
            }
100
            if ($enabled) {
101
                $optionsstart[] = ['field' => 7, 'display' => condition::options_start(7)];
102
            }
103
        }
104
        return [$optionsdwm, $optionsstart, is_null($section), [], $activitysel];
105
    }
106
}