Proyectos de Subversion Moodle

Rev

Rev 1295 | Rev 1297 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
256 ariadna 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
 
901 ariadna 17
namespace theme_universe_child\output;
256 ariadna 18
 
19
use html_writer;
20
use stdClass;
21
use moodle_url;
22
use context_course;
23
use context_system;
24
use core_course_list_element;
25
use custom_menu;
26
use action_menu_filler;
27
use action_menu_link_secondary;
28
use action_menu;
29
use action_link;
30
use core_text;
31
use coding_exception;
32
use navigation_node;
33
use context_header;
891 ariadna 34
use core\oauth2\rest;
256 ariadna 35
use pix_icon;
36
use renderer_base;
37
use theme_config;
38
use get_string;
39
use core_course_category;
40
use theme_universe\util\user;
41
use theme_universe\util\course;
901 ariadna 42
use core_completion\progress;
256 ariadna 43
 
44
require_once($CFG->dirroot . '/cesa/statics_blocks.php'); // Incluimos StaticsBlocks
45
 
46
 
47
/**
48
 * Renderers to align Moodle's HTML with that expected by Bootstrap
49
 *
50
 * @package    theme_universe
51
 * @copyright  2023 Marcin Czaja (https://rosea.io)
52
 * @license    Commercial https://themeforest.net/licenses
53
 */
1291 ariadna 54
class core_renderer extends \theme_universe\output\core_renderer
55
{
56
 
1295 ariadna 57
    public function cesa_navigation_course_menu_lateral_output()
58
    {
59
 
60
 
61
 
62
        global $CFG, $COURSE, $PAGE, $DB, $OUTPUT;
63
 
64
 
65
 
66
 
67
        if (!$COURSE->id) {
68
            return '';
69
        }
70
 
71
        $course_id = $COURSE->id;
72
 
73
        $parent = optional_param('parent', 0, PARAM_INT); // Course module id
74
        if (!$parent) {
75
            $parent = optional_param('amp;parent', 0, PARAM_INT); // Course module id
76
        }
77
 
78
        //$PAGE->requires->js('/theme/edumynew/javascript/menu-lateral.js');
79
 
80
 
81
        if ($parent) {
82
            $sql  = ' SELECT * FROM {subcourse} WHERE course = ' . $parent;
83
            $sql .= ' AND refcourse = ' . $course_id;
84
 
85
            $recordParentRefCourse  = $DB->get_record_sql($sql);
86
            if ($recordParentRefCourse) {
87
                $course_id = $recordParentRefCourse->course;
88
            }
89
        }
90
 
91
 
92
 
93
        $course = get_course($course_id);
94
        $course_context = context_course::instance($course->id);
95
        $completioninfo = new \completion_info($course);
96
 
97
        // $course_context = !empty($PAGE->cm->id)  ? $PAGE->cm : \context_course::instance($COURSE->id);
98
        // First we should check if we want to add navigation.
99
        // Get a list of all the activities in the course.
100
 
101
 
102
 
103
        $menu = [];
104
 
105
        $currentServerLink = strtolower(trim($_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']));
106
        $currentServerLink = html_entity_decode($currentServerLink);
107
        $currentServerLink = htmlentities($currentServerLink);
108
 
109
        $parts = explode('&', $currentServerLink);
110
        if (count($parts) > 1) {
111
            $currentServerLink = $parts[0];
112
        }
113
 
114
 
115
 
116
 
117
        $modules = get_fast_modinfo($course->id)->get_cms();
118
 
119
        $prevmod = null;
120
        $nextmod = null;
121
        $currentmod = new stdClass();
122
        $currentmod->name = "Sin Módulos";
123
        $mods = [];
124
        $menu = [];
125
        $numberOfTemary = 1;
126
        $prevlink = new \StdClass();
127
        $nextlink = new \StdClass();
128
        $prevlink->url = "#";
129
        $nextlink->url = "#";
130
 
131
        $isACoursePage = $course->id !== "1" ? true : false;
132
 
133
 
134
 
135
 
136
        $modules = get_fast_modinfo($COURSE->id)->get_cms();
137
        /*
138
            echo '<pre>';
139
            print_r($modules);
140
            echo '</pre>';
141
            */
142
 
143
        if (!empty($modules)) {
144
            // Put the modules into an array in order by the position they are shown in the course.
145
            foreach ($modules as $module) {
146
                if (!$module->uservisible || $module->is_stealth() || empty($module->url)) {
147
                    continue;
148
                }
149
                $mods[$module->id] = $module;
150
            }
151
 
152
 
153
            $nummods = count($mods);
154
 
155
 
156
            // If there is only one mod then do nothing.
157
            if ($nummods == 1) {
158
            }
159
 
160
            // Get an array of just the course module ids used to get the cmid value based on their position in the course.
161
            $modids = array_keys($mods);
162
 
163
            // Get the position in the array of the course module we are viewing.
164
            $position = array_search($course_context->id, $modids);   //array_search($this->page->cm->id, $modids);
165
 
166
            $currentmod = $mods[$modids[$position]];
167
 
168
 
169
 
170
            // Check if we have a previous mod to show.
171
            if ($position > 0) {
172
                $prevmod = $mods[$modids[$position - 1]];
173
            }
174
 
175
            // Check if we have a next mod to show.
176
            if ($position < ($nummods - 1)) {
177
                $nextmod = $mods[$modids[$position + 1]];
178
            }
179
        }
180
 
181
 
182
        //$sections = $DB->get_records('course_sections', ['course' => $COURSE->id], 'section ASC', 'id,name,section,sequence,visible');
183
 
184
 
185
 
186
 
187
        $modinfo = get_fast_modinfo($course);
188
        $records  =  $modinfo->get_section_info_all();
189
        $sections = [];
190
 
191
        foreach ($records as $record) {
192
            if (!$record->visible) {
193
                continue;
194
            }
195
 
196
            $section = new \stdClass();
197
            $section->id = $record->id;
198
            $section->section = $record->section;
199
            $section->name = $record->name;
200
            $section->parent = $record->parent;
201
            $section->visible = 1;
202
 
203
 
204
            array_push($sections, $section);
205
        }
206
 
207
 
208
 
209
        $openParent = 0;
210
        $maxSections = count($sections);
211
        for ($i = 0; $i < $maxSections; $i++) {
212
 
213
 
214
 
215
            $j = $i + 1;
216
            if ($j < $maxSections) {
217
 
218
                if ($sections[$j]->parent) {
219
                    $openParent = true;
220
                    $sections[$i]->close_section_parent = 0;
221
                    $sections[$i]->close_section = 0;
222
                } else {
223
                    $sections[$i]->close_section_parent = $openParent ? 1 : 0;
224
 
225
                    $sections[$i]->close_section = 1;
226
                }
227
            } else {
228
                $sections[$i]->close_section_parent = $openParent ? 1 : 0;
229
                $sections[$i]->close_section = 1;
230
            }
231
 
232
            // print_r($section);
233
 
234
 
235
        }
236
 
237
        /*
238
             echo '<pre>';
239
           print_r($sections);
240
           echo '</pre>';
241
 
242
      */
243
 
244
 
245
 
246
 
247
        foreach ($sections as $key =>  $section) {
248
 
249
            if (!$section->visible) {
250
                continue;
251
            }
252
 
253
            $activities = [];
254
            $section_active = false;
255
 
256
            foreach ($modules as $module) {
257
 
258
                if ($module->section  != $section->id) {
259
                    continue;
260
                }
261
 
262
                if (!$module->uservisible || $module->is_stealth()) {
263
                    // if (!$module->uservisible || $module->is_stealth() || empty($module->url)) {
264
                    continue;
265
                }
266
 
267
                $mods[$module->id] = $module;
268
 
269
                $duration = '';
270
                $type = '';
271
                $filepath = '';
272
 
273
                $sql = 'SELECT md.name, cm.instance  FROM {modules} md  ' .
274
                    ' JOIN {course_modules} cm ON cm.module = md.id ' .
275
                    ' WHERE cm.id = '  . $module->id . ' LIMIT 1 ';
276
 
277
                $record = $DB->get_record_sql($sql);
278
                if ($record) {
279
 
280
                    /*
281
                        echo '<pre>';
282
                        print_r($record);
283
                        echo '<pre>';
284
                        */
285
 
286
                    $type = $record->name;
287
 
288
                    if ($type == 'hvp') {
289
                        $instance   = $record->instance;
290
 
291
                        $sql = 'SELECT json_content FROM {hvp} WHERE id = ' . $instance . ' LIMIT 1';
292
                        $record = $DB->get_record_sql($sql);
293
 
294
                        if ($record) {
295
                            $json_content = json_decode($record->json_content);
296
 
297
                            if (!empty($json_content->interactiveVideo->video->files[0]->path)) {
298
                                $filepath = trim($json_content->interactiveVideo->video->files[0]->path);
299
                                $filepath = trim(str_replace('#tmp', '', $filepath));
300
 
301
 
302
                                $arr = explode('/', $filepath);
303
                                if (count($arr) > 1) {
304
                                    $filename = $arr[count($arr) - 1];
305
                                } else {
306
                                    $filename = $arr[0];
307
                                }
308
 
309
                                $record = $DB->get_record('files', ['filename' => $filename]);
310
                                if ($record) {
311
                                    $duration = $this->extractDurationFromVideo($record, $filename);
312
                                }
313
                            }
314
                        }
315
                    }
316
                }
317
 
318
                $modname = $module->get_formatted_name();
319
                $modcontent = $module->get_formatted_content();
320
 
321
                if (empty($module->url)) {
322
                    $linkurl = '';
323
                    $currentLink = '';
324
                } else {
325
 
326
                    $linkurl = new moodle_url($module->url, array('forceview' => 1));
327
                    $linkurl = strtolower(trim($linkurl->__toString()));
328
 
329
                    $parts = explode('&', $linkurl);
330
                    if (count($parts) > 1) {
331
                        $currentLink = $parts[0];
332
                    } else {
333
                        $currentLink = $linkurl;
334
                    }
335
                }
336
 
337
                $completiondata = $completioninfo->get_data($module, true);
338
 
339
                if (strcasecmp($currentLink,  $currentServerLink) == 0) {
340
                    $active = true;
341
                    $section_active = true;
342
                } else {
343
                    $active = false;
344
                }
345
 
346
                array_push($activities, [
347
                    'active' => $active,
348
                    'indexElement' => $key,
349
                    'numberOfTemary' => $numberOfTemary,
350
                    'activity' => true,
351
                    'blank' => !empty($section->section),
352
                    'name' => $this->substr_cesa_navigation_course_menu_name($modname),
353
                    'content' => $modcontent,
354
                    'duration' => $duration,
355
                    'type' =>  $type,
356
                    'completed' => $completiondata->completionstate == COMPLETION_COMPLETE || $completiondata->completionstate == COMPLETION_COMPLETE_PASS,
357
                    'failed' => $completiondata->completionstate == COMPLETION_COMPLETE_FAIL,
358
                    'url' => $linkurl
359
                ]);
360
            }
361
 
362
 
363
            if ($activities) {
364
 
365
                if ($section->section) {
366
                    $sectionname = trim($section->name);
367
                    $sectionname = $sectionname ? $sectionname : ' Tema ' . $section->section;
368
                } else {
369
                    $sectionname = 'Recursos';
370
                }
371
 
372
                array_push($menu, [
373
                    'active' => $section_active,
374
                    'indexElement' => $key,
375
                    'id' => $section->id,
376
                    'numberOfTemary' => $numberOfTemary,
377
                    'section' => true,
378
                    'name' => $this->substr_cesa_navigation_course_menu_name($sectionname),
379
                    'close_section_parent' => $section->close_section_parent,
380
                    'close_section' => $section->close_section,
381
                    'completed' => false,
382
                    'url' => false,
383
                    'activities' => $activities,
384
 
385
 
386
                ]);
387
            }
388
 
389
 
390
            $numberOfTemary = ++$numberOfTemary;
391
        }
392
 
393
        // Check if there is a previous module to display.
394
        if ($prevmod) {
395
            $linkurl = new \moodle_url($prevmod->url, array('forceview' => 1));
396
            $attributes = [];
397
            $prevlink = new \action_link($linkurl, $OUTPUT->larrow(), null, $attributes);
398
        }
399
 
400
        // Check if there is a next module to display.
401
        if ($nextmod) {
402
            $linkurl = new \moodle_url($nextmod->url, array('forceview' => 1));
403
            $attributes = [];
404
            $nextlink = new \action_link($linkurl, $OUTPUT->rarrow(), null, $attributes);
405
        }
406
 
407
 
408
        //  echo '<pre>';
409
        // print_r($activities);
410
        // echo '</pre>';
411
        // exit;
412
 
413
 
414
        $progreso = number_format(progress::get_course_progress_percentage($course), 2); // Progreso por curso
415
 
416
        $course_navigation = new \theme_universe_child\output\custom_drawer($prevlink->url, $nextlink->url, $menu, $this->substr_cesa_navigation_course_menu_name($currentmod->name, 10), false, $isACoursePage,  $COURSE->summary, $progreso);
417
        return $course_navigation->export_for_template($OUTPUT);
418
    }
419
 
1296 ariadna 420
    public function render_statics_blocks($userid = null)
1294 ariadna 421
    {
1296 ariadna 422
        global $USER;
1294 ariadna 423
 
1296 ariadna 424
        if (!$userid) {
425
            $userid = $USER->id;
1294 ariadna 426
        }
427
 
1296 ariadna 428
        // Instanciamos StaticsBlocks para renderizar los bloques
429
        $statics_blocks = new \StaticsBlocks(
430
            'side-pre',
431
            ['messageteacher', 'comments', 'cesa_course_rating', 'cesa_notes']
432
        );
1294 ariadna 433
 
1296 ariadna 434
        $blocks = $statics_blocks->renderBlocks();
1294 ariadna 435
 
1296 ariadna 436
        return $blocks;
1294 ariadna 437
    }
1291 ariadna 438
}