Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | 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
 * This file contains main class for the course format Social
19
 *
20
 * @since     Moodle 2.0
21
 * @package   format_social
22
 * @copyright 2009 Sam Hemelryk
23
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
defined('MOODLE_INTERNAL') || die();
27
require_once($CFG->dirroot. '/course/format/lib.php');
28
 
29
/**
30
 * Main class for the Social course format
31
 *
32
 * @package    format_social
33
 * @copyright  2012 Marina Glancy
34
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35
 */
36
class format_social extends core_courseformat\base {
37
 
38
    /**
39
     * The URL to use for the specified course
40
     *
41
     * @param int|stdClass $section Section object from database or just field course_sections.section
42
     *     if null the course view page is returned
43
     * @param array $options options for view URL. At the moment core uses:
44
     *     'navigation' (bool) ignored by this format
45
     *     'sr' (int) ignored by this format
46
     * @return null|moodle_url
47
     */
48
    public function get_view_url($section, $options = array()) {
49
        return new moodle_url('/course/view.php', ['id' => $this->courseid]);
50
    }
51
 
52
    /**
53
     * Loads all of the course sections into the navigation
54
     *
55
     * @param global_navigation $navigation
56
     * @param navigation_node $node The course node within the navigation
57
     */
58
    public function extend_course_navigation($navigation, navigation_node $node) {
59
        // Social course format does not extend navigation, it uses social_activities block instead
60
    }
61
 
62
    /**
63
     * Returns the list of blocks to be automatically added for the newly created course
64
     *
65
     * @return array of default blocks, must contain two keys BLOCK_POS_LEFT and BLOCK_POS_RIGHT
66
     *     each of values is an array of block names (for left and right side columns)
67
     */
68
    public function get_default_blocks() {
69
        return array(
70
            BLOCK_POS_LEFT => array(),
71
            BLOCK_POS_RIGHT => array('social_activities')
72
        );
73
    }
74
 
75
    /**
76
     * Definitions of the additional options that this course format uses for course
77
     *
78
     * social format uses the following options:
79
     * - numdiscussions
80
     *
81
     * @param bool $foreditform
82
     * @return array of options
83
     */
84
    public function course_format_options($foreditform = false) {
85
        static $courseformatoptions = false;
86
        if ($courseformatoptions === false) {
87
            $courseformatoptions = array(
88
                'numdiscussions' => array(
89
                    'default' => 10,
90
                    'type' => PARAM_INT,
91
                )
92
            );
93
        }
94
 
95
        if ($foreditform && !isset($courseformatoptions['numdiscussions']['label'])) {
96
            $courseformatoptionsedit = array(
97
                'numdiscussions' => array(
98
                    'label' => new lang_string('numberdiscussions', 'format_social'),
99
                    'help' => 'numberdiscussions',
100
                    'help_component' => 'format_social',
101
                    'element_type' => 'text',
102
                )
103
            );
104
            $courseformatoptions = array_merge_recursive($courseformatoptions, $courseformatoptionsedit);
105
        }
106
        return $courseformatoptions;
107
    }
108
 
109
    /**
110
     * Returns whether this course format allows the activity to
111
     * have "triple visibility state" - visible always, hidden on course page but available, hidden.
112
     *
113
     * @param stdClass|cm_info $cm course module (may be null if we are displaying a form for adding a module)
114
     * @param stdClass|section_info $section section where this module is located or will be added to
115
     * @return bool
116
     */
117
    public function allow_stealth_module_visibility($cm, $section) {
118
        return true;
119
    }
120
 
121
    /**
122
     * Return the plugin configs for external functions.
123
     *
124
     * @return array the list of configuration settings
125
     * @since Moodle 3.5
126
     */
127
    public function get_config_for_external() {
128
        // Return everything (nothing to hide).
129
        return $this->get_format_options();
130
    }
131
 
1441 ariadna 132
    #[\Override]
133
    public function supports_ajax() {
134
        // All home page is rendered in the backend, we only need an ajax editor components in edit mode.
135
        // This will also prevent redirectng to the login page when a guest tries to access the site,
136
        // and will make the home page loading faster.
137
        $ajaxsupport = new stdClass();
138
        $ajaxsupport->capable = $this->show_editor();
139
        return $ajaxsupport;
140
    }
141
 
142
    #[\Override]
143
    public function supports_components() {
144
        return true;
145
    }
146
 
147
    #[\Override]
148
    public function uses_sections() {
149
        return true;
150
    }
151
 
152
    #[\Override]
153
    public function get_section_name($section) {
154
        $section = $this->get_section($section);
155
        if ($section->is_delegated()) {
156
            return $section->name;
157
        }
158
        // Social format only uses one section inside the social activities block.
159
        return get_string('socialactivities', 'format_social');
160
    }
161
 
1 efrain 162
    /**
1441 ariadna 163
     * Social format uses only section 0.
1 efrain 164
     *
1441 ariadna 165
     * @return int
166
     */
167
    #[\Override]
168
    public function get_sectionnum(): int {
169
        return 0;
170
    }
171
 
172
    /**
173
     * Returns if a specific section is visible to the current user.
1 efrain 174
     *
1441 ariadna 175
     * Formats can override this method to implement any special section logic.
176
     * Social format does not use any other sections than section 0 and
177
     * used this method to hide all other sections from the Move section activity.
178
     *
179
     * @param section_info $section the section modinfo
180
     * @return bool;
1 efrain 181
     */
1441 ariadna 182
    #[\Override]
183
    public function is_section_visible(section_info $section): bool {
184
        $visible = parent::is_section_visible($section);
185
        // Social format does only use section 0 as a normal section.
186
        // Any other included section should be a delegated one (subsections).
187
        return $visible && ($section->sectionnum == 0 || $section->is_delegated());
1 efrain 188
    }
189
}