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
namespace bbbext_simple\bigbluebuttonbn;
17
 
18
use stdClass;
19
 
20
/**
21
 * A class for the main mod form extension
22
 *
23
 * @package   mod_bigbluebuttonbn
24
 * @copyright 2023 onwards, Blindside Networks Inc
25
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
 * @author    Laurent David (laurent@call-learning.fr)
27
 */
28
class mod_form_addons extends \mod_bigbluebuttonbn\local\extension\mod_form_addons {
29
    /**
30
     * Allows modules to modify the data returned by form get_data().
31
     * This method is also called in the bulk activity completion form.
32
     *
33
     * Only available on moodleform_mod.
34
     *
35
     * @param stdClass $data passed by reference
36
     */
37
    public function data_postprocessing(\stdClass &$data): void {
38
        // Nothing for now.
39
    }
40
 
41
    /**
42
     * Allow module to modify  the data at the pre-processing stage.
43
     *
44
     * This method is also called in the bulk activity completion form.
45
     *
46
     * @param array|null $defaultvalues
47
     */
48
    public function data_preprocessing(?array &$defaultvalues): void {
49
        // This is where we can add the data from the flexurl table to the data provided.
50
        if (!empty($defaultvalues['id'])) {
51
            global $DB;
52
            $flexurlrecord = $DB->get_record('bbbext_simple', [
53
                'bigbluebuttonbnid' => $defaultvalues['id'],
54
            ]);
55
            if ($flexurlrecord) {
56
                $defaultvalues['newfield'] = $flexurlrecord->newfield;
57
            }
58
        }
59
    }
60
 
61
    /**
62
     * Can be overridden to add custom completion rules if the module wishes
63
     * them. If overriding this, you should also override completion_rule_enabled.
64
     * <p>
65
     * Just add elements to the form as needed and return the list of IDs. The
66
     * system will call disabledIf and handle other behaviour for each returned
67
     * ID.
68
     *
69
     * @return array Array of string IDs of added items, empty array if none
70
     */
71
    public function add_completion_rules(): array {
72
        $this->mform->addElement('advcheckbox', 'completionextraisehandtwice',
73
            get_string('completionextraisehandtwice', 'bbbext_simple'),
74
            get_string('completionextraisehandtwice_desc', 'bbbext_simple'));
75
 
76
        $this->mform->addHelpButton('completionextraisehandtwice', 'completionextraisehandtwice',
77
            'bbbext_simple');
78
        $this->mform->disabledIf('completionextraisehandtwice', 'completion', 'neq', COMPLETION_AGGREGATION_ANY);
79
        return ['completionextraisehandtwice' . $this->suffix];
80
    }
81
 
82
    /**
83
     * Called during validation. Override to indicate, based on the data, whether
84
     * a custom completion rule is enabled (selected).
85
     *
86
     * @param array $data Input data (not yet validated)
87
     * @return bool True if one or more rules is enabled, false if none are;
88
     *   default returns false
89
     */
90
    public function completion_rule_enabled(array $data): bool {
91
        return !empty($data['completionextraisehandtwice' . $this->suffix]);
92
    }
93
 
94
    /**
95
     * Form adjustments after setting data
96
     *
97
     * @return void
98
     */
99
    public function definition_after_data() {
100
        // Nothing for now.
101
    }
102
 
103
    /**
104
     * Add new form field definition
105
     */
106
    public function add_fields(): void {
107
        $this->mform->addElement('header', 'simple', get_string('pluginname', 'bbbext_simple'));
108
        $this->mform->addElement('text', 'newfield', get_string('newfield', 'bbbext_simple'));
109
        $this->mform->setType('newfield', PARAM_TEXT);
110
    }
111
 
112
    /**
113
     * Validate form and returns an array of errors indexed by field name
114
     *
115
     * @param array $data
116
     * @param array $files
117
     * @return array
118
     */
119
    public function validation(array $data, array $files): array {
120
        $errors = [];
121
        if (empty($data['newfield' . $this->suffix])) {
122
            $errors['newfield'] = get_string('newfielderror', 'bbbext_simple');
123
        }
124
        return $errors;
125
    }
126
}