Rev 1371 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace theme_universe_child\output;
use html_writer;
use stdClass;
use moodle_url;
use context_course;
use context_system;
use core_course_list_element;
use custom_menu;
use action_menu_filler;
use action_menu_link_secondary;
use action_menu;
use action_link;
use core_text;
use coding_exception;
use navigation_node;
use context_header;
use core\oauth2\rest;
use pix_icon;
use renderer_base;
use theme_config;
use get_string;
use core_course_category;
use theme_universe\util\user;
use theme_universe\util\course;
use core_completion\progress;
require_once($CFG->dirroot . '/cesa/statics_blocks.php');
/**
* Renderers to align Moodle's HTML with that expected by Bootstrap
*
* @package theme_universe_child
* @copyright 2023 Marcin Czaja (https://rosea.io)
* @license Commercial https://themeforest.net/licenses
*/
class core_renderer extends \core_renderer
{
/**
* Renderiza los bloques estáticos
*/
public function render_statics_blocks($userid = null)
{
global $USER;
if (!$userid) {
$userid = $USER->id;
}
// Instanciamos StaticsBlocks para renderizar los bloques
$statics_blocks = new \StaticsBlocks(
'side-pre',
['messageteacher', 'comments', 'cesa_course_rating', 'cesa_notes']
);
$blocks = $statics_blocks->renderBlocks();
return $blocks;
}
/**
* Navegación de completitud del curso
*/
public function cesa_navigation_course_completion()
{
global $COURSE, $PAGE, $USER, $CFG;
if (empty($PAGE->cm->id) || empty($COURSE->enablecompletion)) {
return '';
}
$course_context = context_course::instance($COURSE->id);
$roles = get_user_roles($course_context, $USER->id, true);
$completion_visible = true;
foreach ($roles as $role) {
if ($role->shortname != 'student') {
$completion_visible = false;
}
}
if (!$completion_visible) {
return '';
}
$PAGE->requires->js(new \moodle_url($CFG->wwwroot . '/local/cesanavigation/javascript/terminacion.js'));
$page_context = $PAGE->cm;
$modules = get_fast_modinfo($COURSE->id)->get_cms();
$mods = [];
foreach ($modules as $module) {
if (!$module->uservisible || $module->is_stealth() || empty($module->url)) {
continue;
}
$mods[$module->id] = $module;
}
$nummods = count($mods);
if ($nummods == 1) {
return '';
}
$modids = array_keys($mods);
$position = array_search($page_context->id, $modids);
$currentmod = $mods[$modids[$position]];
$completioninfo = new \completion_info($COURSE);
$completiondata = $completioninfo->get_data($currentmod, true);
if ($completiondata->completionstate != COMPLETION_COMPLETE && $completiondata->completionstate != COMPLETION_COMPLETE_PASS) {
$url = new \moodle_url($CFG->wwwroot . '/local/cesanavigation/terminacion.php', ['courseid' => $COURSE->id, 'modid' => $currentmod->id]);
return '<div class="containerr">
<input type="button" class="btn btn-primary d-block mx-auto btn-cesa-course-completion button-cesa vertical-center center" data-url="' . $url . '" value="Completar y continuar">
</div>';
}
return '';
}
/**
* Menú lateral del curso
*/
public function cesa_navigation_course_menu_lateral_output()
{
global $CFG, $COURSE, $PAGE, $DB, $OUTPUT;
if (!$COURSE->id) {
return '';
}
$course_id = $COURSE->id;
$parent = optional_param('parent', 0, PARAM_INT);
if (!$parent) {
$parent = optional_param('amp;parent', 0, PARAM_INT);
}
if ($parent) {
$sql = ' SELECT * FROM {subcourse} WHERE course = ' . $parent;
$sql .= ' AND refcourse = ' . $course_id;
$recordParentRefCourse = $DB->get_record_sql($sql);
if ($recordParentRefCourse) {
$course_id = $recordParentRefCourse->course;
}
}
$course = get_course($course_id);
$course_context = context_course::instance($course->id);
$completioninfo = new \completion_info($course);
$menu = [];
$currentServerLink = strtolower(trim($_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']));
$currentServerLink = html_entity_decode($currentServerLink);
$currentServerLink = htmlentities($currentServerLink);
$parts = explode('&', $currentServerLink);
if (count($parts) > 1) {
$currentServerLink = $parts[0];
}
$modules = get_fast_modinfo($course->id)->get_cms();
$prevmod = null;
$nextmod = null;
$currentmod = new stdClass();
$currentmod->name = "Sin Módulos";
$mods = [];
$menu = [];
$numberOfTemary = 1;
$prevlink = new \StdClass();
$nextlink = new \StdClass();
$prevlink->url = "#";
$nextlink->url = "#";
$isACoursePage = $course->id !== "1" ? true : false;
$modules = get_fast_modinfo($COURSE->id)->get_cms();
if (!empty($modules)) {
foreach ($modules as $module) {
if (!$module->uservisible || $module->is_stealth() || empty($module->url)) {
continue;
}
$mods[$module->id] = $module;
}
$nummods = count($mods);
if ($nummods == 1) {
return '';
}
$modids = array_keys($mods);
$position = array_search($course_context->id, $modids);
$currentmod = $mods[$modids[$position]];
if ($position > 0) {
$prevmod = $mods[$modids[$position - 1]];
}
if ($position < ($nummods - 1)) {
$nextmod = $mods[$modids[$position + 1]];
}
}
$modinfo = get_fast_modinfo($course);
$records = $modinfo->get_section_info_all();
$sections = [];
foreach ($records as $record) {
if (!$record->visible) {
continue;
}
$section = new \stdClass();
$section->id = $record->id;
$section->section = $record->section;
$section->name = $record->name;
$section->parent = $record->parent;
$section->visible = 1;
array_push($sections, $section);
}
$openParent = 0;
$maxSections = count($sections);
for ($i = 0; $i < $maxSections; $i++) {
$j = $i + 1;
if ($j < $maxSections) {
if ($sections[$j]->parent) {
$openParent = true;
$sections[$i]->close_section_parent = 0;
$sections[$i]->close_section = 0;
} else {
$sections[$i]->close_section_parent = $openParent ? 1 : 0;
$sections[$i]->close_section = 1;
}
} else {
$sections[$i]->close_section_parent = $openParent ? 1 : 0;
$sections[$i]->close_section = 1;
}
}
foreach ($sections as $key => $section) {
if (!$section->visible) {
continue;
}
$activities = [];
$section_active = false;
foreach ($modules as $module) {
if ($module->section != $section->id) {
continue;
}
if (!$module->uservisible || $module->is_stealth()) {
continue;
}
$mods[$module->id] = $module;
$duration = '';
$type = '';
$filepath = '';
$sql = 'SELECT md.name, cm.instance FROM {modules} md ' .
'JOIN {course_modules} cm ON cm.module = md.id ' .
'WHERE cm.id = ' . $module->id . ' LIMIT 1';
$record = $DB->get_record_sql($sql);
if ($record) {
$type = $record->name;
if ($type == 'hvp') {
$instance = $record->instance;
$sql = 'SELECT json_content FROM {hvp} WHERE id = ' . $instance . ' LIMIT 1';
$record = $DB->get_record_sql($sql);
if ($record) {
$json_content = json_decode($record->json_content);
if (!empty($json_content->interactiveVideo->video->files[0]->path)) {
$filepath = trim($json_content->interactiveVideo->video->files[0]->path);
$filepath = trim(str_replace('#tmp', '', $filepath));
$arr = explode('/', $filepath);
if (count($arr) > 1) {
$filename = $arr[count($arr) - 1];
} else {
$filename = $arr[0];
}
$duration = $this->extractDurationFromVideo($record, $filename);
}
}
}
$activity = new \stdClass();
$activity->id = $module->id;
$activity->name = $this->substr_cesa_navigation_course_menu_name($module->name);
$activity->url = $module->url;
$activity->type = $type;
$activity->duration = $duration;
$activity->active = ($currentmod->id == $module->id);
array_push($activities, $activity);
}
}
$section->activities = $activities;
array_push($menu, $section);
}
$data = new \stdClass();
$data->sections = $menu;
$data->currentmod = $currentmod;
$data->prevmod = $prevmod;
$data->nextmod = $nextmod;
return $this->render_from_template('theme_universe_child/course_menu_lateral', $data);
}
/**
* Drawer del curso
*/
public function universe_child_course_drawer(): string
{
global $COURSE, $PAGE, $OUTPUT;
if (!$COURSE->id) {
return '';
}
$course = get_course($COURSE->id);
$course_context = context_course::instance($course->id);
$drawer = new \stdClass();
$drawer->course = $course;
$drawer->context = $course_context;
$drawer->output = $OUTPUT;
return $this->render_from_template('theme_universe_child/course_drawer', $drawer);
}
/**
* Funciones de imágenes de la barra de navegación
*/
public function get_navbar_image_courses()
{
global $CFG;
if (!empty($this->page->theme->settings->navbar_icon_courses)) {
$url = $this->page->theme->setting_file_url('navbar_icon_courses', 'navbar_icon_courses');
$relativebaseurl = preg_replace('|^https?://|i', '//', $CFG->wwwroot);
$url = str_replace($relativebaseurl, '', $url);
return new moodle_url($url);
}
return $CFG->wwwroot . '/theme/universe_child/pix/icon-catalog-white.png';
}
public function get_navbar_image_progress()
{
global $CFG;
if (!empty($this->page->theme->settings->navbar_icon_progress)) {
$url = $this->page->theme->setting_file_url('navbar_icon_progress', 'navbar_icon_progress');
$relativebaseurl = preg_replace('|^https?://|i', '//', $CFG->wwwroot);
$url = str_replace($relativebaseurl, '', $url);
return new moodle_url($url);
}
return $CFG->wwwroot . '/theme/universe_child/pix/icon-progress-white.png';
}
public function get_navbar_image_forums()
{
global $CFG;
if (!empty($this->page->theme->settings->navbar_icon_forums)) {
$url = $this->page->theme->setting_file_url('navbar_icon_forums', 'navbar_icon_forums');
$relativebaseurl = preg_replace('|^https?://|i', '//', $CFG->wwwroot);
$url = str_replace($relativebaseurl, '', $url);
return new moodle_url($url);
}
return $CFG->wwwroot . '/theme/universe_child/pix/icon-forum-white.png';
}
public function get_navbar_image_calendar()
{
global $CFG;
if (!empty($this->page->theme->settings->navbar_icon_calendar)) {
$url = $this->page->theme->setting_file_url('navbar_icon_calendar', 'navbar_icon_calendar');
$relativebaseurl = preg_replace('|^https?://|i', '//', $CFG->wwwroot);
$url = str_replace($relativebaseurl, '', $url);
return new moodle_url($url);
}
return $CFG->wwwroot . '/theme/universe_child/pix/icon-calendar-white.png';
}
public function get_navbar_image_personal_area()
{
global $CFG;
if (!empty($this->page->theme->settings->navbar_icon_personal_area)) {
$url = $this->page->theme->setting_file_url('navbar_icon_personal_area', 'navbar_icon_personal_area');
$relativebaseurl = preg_replace('|^https?://|i', '//', $CFG->wwwroot);
$url = str_replace($relativebaseurl, '', $url);
return new moodle_url($url);
}
return $CFG->wwwroot . '/theme/universe_child/pix/icon-personal-area-white.png';
}
public function get_navbar_image_messages()
{
global $CFG;
if (!empty($this->page->theme->settings->navbar_icon_messages)) {
$url = $this->page->theme->setting_file_url('navbar_icon_messages', 'navbar_icon_messages');
$relativebaseurl = preg_replace('|^https?://|i', '//', $CFG->wwwroot);
$url = str_replace($relativebaseurl, '', $url);
return new moodle_url($url);
}
return $CFG->wwwroot . '/theme/universe_child/pix/icon-messages-white.png';
}
/**
* Funciones de utilidad
*/
private function extractDurationFromVideo($record, $filename)
{
global $DB;
$sql = 'SELECT * FROM {files} WHERE filename = "' . $filename . '" AND component = "mod_hvp" AND filearea = "content" LIMIT 1';
$file = $DB->get_record_sql($sql);
if ($file) {
$sql = 'SELECT * FROM {files} WHERE filename = "' . $filename . '" AND component = "mod_hvp" AND filearea = "content" AND id != ' . $file->id . ' LIMIT 1';
$file2 = $DB->get_record_sql($sql);
if ($file2) {
$sql = 'SELECT * FROM {files} WHERE filename = "' . $filename . '" AND component = "mod_hvp" AND filearea = "content" AND id != ' . $file->id . ' AND id != ' . $file2->id . ' LIMIT 1';
$file3 = $DB->get_record_sql($sql);
if ($file3) {
return $file3->duration;
}
}
}
return '';
}
private function substr_cesa_navigation_course_menu_name($s, $l = 50)
{
return core_text::substr($s, 0, $l);
}
/**
* Sobrescribe la función de acceso de invitados del tema padre
*/
public function theme_universe_get_course_guest_access_hint($courseid)
{
return $this->theme_universe_child_get_course_guest_access_hint($courseid);
}
/**
* Implementación específica del tema hijo para el acceso de invitados
*/
public function theme_universe_child_get_course_guest_access_hint($courseid)
{
global $DB, $CFG;
$html = '';
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
$context = context_course::instance($course->id);
if (isguestuser() || !isloggedin()) {
$html .= html_writer::start_tag('div', array('class' => 'courseguestaccess'));
$html .= html_writer::tag('p', get_string('guestaccess', 'theme_universe_child'));
$html .= html_writer::end_tag('div');
}
return $html;
}
}