Proyectos de Subversion Moodle

Rev

Rev 1 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 836
Línea 33... Línea 33...
33
 *
33
 *
34
 * @package   block_multiblock
34
 * @package   block_multiblock
35
 * @copyright 2019 Peter Spicer <peter.spicer@catalyst-eu.net>
35
 * @copyright 2019 Peter Spicer <peter.spicer@catalyst-eu.net>
36
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 */
37
 */
38
class block_multiblock extends block_base {
38
class block_multiblock extends block_base
-
 
39
{
39
    /** @var object $output Temporary storage of the injected page renderer so we can pass it to child blocks at render time. */
40
    /** @var object $output Temporary storage of the injected page renderer so we can pass it to child blocks at render time. */
40
    private $output;
41
    private $output;
Línea 41... Línea 42...
41
 
42
 
42
    /**
43
    /**
43
     * Core function used to initialize the block.
44
     * Core function used to initialize the block.
44
     */
45
     */
-
 
46
    public function init()
45
    public function init() {
47
    {
46
        $this->title = get_string('pluginname', 'block_multiblock');
48
        $this->title = get_string('pluginname', 'block_multiblock');
Línea 47... Línea 49...
47
    }
49
    }
48
 
50
 
49
    /**
51
    /**
50
     * has_config - denotes whether your block wants to present a configuration interface to site admins or not
52
     * has_config - denotes whether your block wants to present a configuration interface to site admins or not
51
     *
53
     *
52
     * @return boolean
54
     * @return boolean
-
 
55
     */
53
     */
56
    public function has_config()
54
    public function has_config() {
57
    {
Línea 55... Línea 58...
55
        return true;
58
        return true;
56
    }
59
    }
57
 
60
 
58
    /**
61
    /**
59
     * Core function, specifies where the block can be used.
62
     * Core function, specifies where the block can be used.
60
     *
63
     *
-
 
64
     * @return array
61
     * @return array
65
     */
62
     */
66
    public function applicable_formats()
63
    public function applicable_formats() {
67
    {
64
        return [
68
        return [
Línea 65... Línea 69...
65
            'all' => true,
69
            'all' => true,
66
        ];
70
        ];
67
    }
71
    }
68
 
72
 
-
 
73
    /**
69
    /**
74
     * Sets the block's title for a specific instance based on its configuration.
70
     * Sets the block's title for a specific instance based on its configuration.
75
     */
71
     */
76
    public function specialization()
72
    public function specialization() {
77
    {
73
        $defaulttitle = get_config('block_multiblock', 'title');
78
        $defaulttitle = get_config('block_multiblock', 'title');
74
        if (isset($this->config->title)) {
79
        if (isset($this->config->title)) {
75
            $this->title = format_string($this->config->title, true, ['context' => $this->context]);
80
            $this->title = format_string($this->config->title, true, ['context' => $this->context]);
76
        } else if ($defaulttitle) {
81
        } else if ($defaulttitle) {
77
            $this->title = format_string($defaulttitle, true, ['context' => $this->context]);
82
            $this->title = format_string($defaulttitle, true, ['context' => $this->context]);
Línea -... Línea 83...
-
 
83
        } else {
-
 
84
            $this->title = get_string('pluginname', 'block_multiblock');
-
 
85
        }
-
 
86
    }
-
 
87
 
-
 
88
    /* Set block attributes */
-
 
89
    function html_attributes()
-
 
90
    {
-
 
91
        $attributes = array(
-
 
92
            'id' => 'inst' . $this->instance->id,
-
 
93
            'class' => 'block_' . $this->name() . ' block' . 'multiblock-columns-2-parent',
-
 
94
            'role' => $this->get_aria_role()
-
 
95
        );
-
 
96
        if ($this->hide_header()) {
-
 
97
            $attributes['class'] .= ' no-header';
-
 
98
        }
-
 
99
        if ($this->instance_can_be_docked() && get_user_preferences('docked_block_instance_' . $this->instance->id, 0)) {
78
        } else {
100
            $attributes['class'] .= ' dock_on_load';
79
            $this->title = get_string('pluginname', 'block_multiblock');
101
        }
80
        }
102
        return $attributes;
81
    }
103
    }
82
 
104
 
83
    /**
105
    /**
84
     * Loads the child blocks of the current multiblock.
106
     * Loads the child blocks of the current multiblock.
-
 
107
     *
85
     *
108
     * @param int $contextid The multiblock's context instance id.
Línea 86... Línea 109...
86
     * @param int $contextid The multiblock's context instance id.
109
     * @return array An array of child blocks.
87
     * @return array An array of child blocks.
110
     */
88
     */
111
    public function load_multiblocks($contextid)
Línea 105... Línea 128...
105
    }
128
    }
Línea 106... Línea 129...
106
 
129
 
107
    /**
130
    /**
108
     *  Used to add the default blocks to the multiblock.
131
     *  Used to add the default blocks to the multiblock.
109
     */
132
     */
-
 
133
    public function add_default_blocks()
110
    public function add_default_blocks() {
134
    {
Línea 111... Línea 135...
111
        global $DB, $CFG;
135
        global $DB, $CFG;
112
 
136
 
113
        if (empty($this->instance)) {
137
        if (empty($this->instance)) {
Línea 125... Línea 149...
125
 
149
 
Línea 126... Línea 150...
126
            $defaultblocksarray = explode(',', get_config('block_multiblock')->subblock);
150
            $defaultblocksarray = explode(',', get_config('block_multiblock')->subblock);
127
 
151
 
128
            $addblock = new adddefaultblock();
-
 
129
            $addblock->init($blockid, $defaultblocksarray, $this->instance);
152
            $addblock = new adddefaultblock();
130
 
153
            $addblock->init($blockid, $defaultblocksarray, $this->instance);
Línea 131... Línea 154...
131
        }
154
        }
132
    }
155
    }
133
 
156
 
134
    /**
157
    /**
135
     * Used to generate the content for the block.
158
     * Used to generate the content for the block.
136
     *
159
     *
-
 
160
     * @return string
137
     * @return string
161
     */
138
     */
162
    public function get_content()
139
    public function get_content() {
163
    {
140
        global $DB, $CFG;
164
        global $DB, $CFG;
141
        if ($this->content !== null) {
165
        if ($this->content !== null) {
Línea 208... Línea 232...
208
     * This internally calls ->get_content(), and then adds the editing controls etc.
232
     * This internally calls ->get_content(), and then adds the editing controls etc.
209
     *
233
     *
210
     * @param object $output The output renderer from the parent context (e.g. page renderer)
234
     * @param object $output The output renderer from the parent context (e.g. page renderer)
211
     * @return block_contents a representation of the block, for rendering.
235
     * @return block_contents a representation of the block, for rendering.
212
     */
236
     */
213
    public function get_content_for_output($output) {
237
    public function get_content_for_output($output)
-
 
238
    {
214
        $this->output = $output;
239
        $this->output = $output;
215
        $bc = parent::get_content_for_output($output);
240
        $bc = parent::get_content_for_output($output);
Línea 216... Línea 241...
216
 
241
 
217
        if (empty($bc->controls)) {
242
        if (empty($bc->controls)) {
Línea 233... Línea 258...
233
                );
258
                );
234
            }
259
            }
235
        }
260
        }
236
        // Append a delete+split item on the end.
261
        // Append a delete+split item on the end.
237
        $newcontrols[] = new action_menu_link_secondary(
262
        $newcontrols[] = new action_menu_link_secondary(
238
            new moodle_url('/blocks/multiblock/manage.php', ['id' => $this->instance->id, 'sesskey' => sesskey(),
263
            new moodle_url('/blocks/multiblock/manage.php', [
-
 
264
                'id' => $this->instance->id,
-
 
265
                'sesskey' => sesskey(),
239
                    'action' => 'splitdelete']),
266
                'action' => 'splitdelete'
-
 
267
            ]),
240
            icon_helper::delete($str),
268
            icon_helper::delete($str),
241
            get_string('splitanddelete', 'block_multiblock', $this->title),
269
            get_string('splitanddelete', 'block_multiblock', $this->title),
242
            ['class' => 'editing_manage']
270
            ['class' => 'editing_manage']
243
        );
271
        );
244
        $bc->controls = $newcontrols;
272
        $bc->controls = $newcontrols;
Línea 247... Línea 275...
247
 
275
 
248
    /**
276
    /**
249
     * Allows the block to be added multiple times to a single page
277
     * Allows the block to be added multiple times to a single page
250
     * @return boolean
278
     * @return boolean
251
     */
279
     */
-
 
280
    public function instance_allow_multiple()
252
    public function instance_allow_multiple() {
281
    {
253
        return true;
282
        return true;
Línea 254... Línea 283...
254
    }
283
    }
255
 
284
 
256
    /**
285
    /**
257
     * Copy all the children when copying to a new block instance.
286
     * Copy all the children when copying to a new block instance.
258
     *
287
     *
259
     * @param int $fromid The id number of the block instance to copy from
288
     * @param int $fromid The id number of the block instance to copy from
260
     * @return bool
289
     * @return bool
-
 
290
     */
261
     */
291
    public function instance_copy($fromid)
Línea 262... Línea 292...
262
    public function instance_copy($fromid) {
292
    {
Línea 263... Línea 293...
263
        global $DB;
293
        global $DB;
Línea 289... Línea 319...
289
    /**
319
    /**
290
     * Callback for when this block instance is being deleted, to clean up child blocks.
320
     * Callback for when this block instance is being deleted, to clean up child blocks.
291
     *
321
     *
292
     * @return bool
322
     * @return bool
293
     */
323
     */
294
    public function instance_delete() {
324
    public function instance_delete()
-
 
325
    {
295
        global $DB;
326
        global $DB;
Línea 296... Línea 327...
296
 
327
 
297
        // Find all the things that relate to this block.
328
        // Find all the things that relate to this block.
298
        foreach ($DB->get_records('block_instances', ['parentcontextid' => $this->context->id]) as $subblock) {
329
        foreach ($DB->get_records('block_instances', ['parentcontextid' => $this->context->id]) as $subblock) {
Línea 304... Línea 335...
304
    /**
335
    /**
305
     * Lists all the known presentation types that exist in the block.
336
     * Lists all the known presentation types that exist in the block.
306
     *
337
     *
307
     * @return array An array of presentations for block rendering.
338
     * @return array An array of presentations for block rendering.
308
     */
339
     */
309
    public static function get_valid_presentations(): array {
340
    public static function get_valid_presentations(): array
-
 
341
    {
310
        static $presentations = null;
342
        static $presentations = null;
Línea 311... Línea 343...
311
 
343
 
Línea 312... Línea 344...
312
        if ($presentations === null) {
344
        if ($presentations === null) {
Línea 332... Línea 364...
332
    /**
364
    /**
333
     * Returns the default presentation for the multiblock.
365
     * Returns the default presentation for the multiblock.
334
     *
366
     *
335
     * @return string The default presentation's identifier.
367
     * @return string The default presentation's identifier.
336
     */
368
     */
337
    public static function get_default_presentation(): string {
369
    public static function get_default_presentation(): string
-
 
370
    {
338
        $presentations = static::get_valid_presentations();
371
        $presentations = static::get_valid_presentations();
339
        $multiblockpresentationoptions = [];
372
        $multiblockpresentationoptions = [];
340
        $configuredpresentation = get_config('block_multiblock', 'presentation');
373
        $configuredpresentation = get_config('block_multiblock', 'presentation');
341
        foreach ($presentations as $presentationid => $presentation) {
374
        foreach ($presentations as $presentationid => $presentation) {
342
            array_push($multiblockpresentationoptions, $presentationid);
375
            array_push($multiblockpresentationoptions, $presentationid);