Initial commit
This commit is contained in:
188
renderers/core_renderer.php
Normal file
188
renderers/core_renderer.php
Normal file
@@ -0,0 +1,188 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* renderers/core_renderer.php
|
||||
* @package theme_qualisaude
|
||||
* @copyright 2015 onwards LMSACE Dev Team (http://www.lmsace.com)
|
||||
* @author LMSACE Dev Team
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* qualisaude core renderer renderer from the moodle core renderer
|
||||
* @copyright 2015 onwards LMSACE Dev Team (http://www.lmsace.com)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class theme_qualisaude_core_renderer extends theme_boost\output\core_renderer {
|
||||
/**
|
||||
* Custom menu in header.
|
||||
* @param custom_menu $menu
|
||||
* @return type
|
||||
*/
|
||||
public function custom_menu_render(custom_menu $menu) {
|
||||
global $CFG;
|
||||
|
||||
$langs = get_string_manager()->get_list_of_translations();
|
||||
$haslangmenu = $this->lang_menu() != '';
|
||||
|
||||
if (!$menu->has_children() && !$haslangmenu) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$content = '';
|
||||
foreach ($menu->get_children() as $item) {
|
||||
$context = $item->export_for_template($this);
|
||||
$content .= $this->render_from_template('theme_qualisaude/custom_menu_item', $context);
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract first image from html
|
||||
*
|
||||
* @param string $html (must be well formed)
|
||||
* @return array | bool (false)
|
||||
*/
|
||||
public static function extract_first_image($html) {
|
||||
$doc = new \DOMDocument();
|
||||
libxml_use_internal_errors(true); // Required for HTML5.
|
||||
$doc->loadHTML($html);
|
||||
libxml_clear_errors(); // Required for HTML5.
|
||||
$imagetags = $doc->getElementsByTagName('img');
|
||||
if ($imagetags->item(0)) {
|
||||
$src = $imagetags->item(0)->getAttribute('src');
|
||||
$alt = $imagetags->item(0)->getAttribute('alt');
|
||||
return array('src' => $src, 'alt' => $alt);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Alternative rendering of front page news, called from layout/faux_site_index.php which
|
||||
* replaces the standard news output with this.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function site_frontpage_news() {
|
||||
global $CFG, $SITE;
|
||||
|
||||
require_once($CFG->dirroot.'/mod/forum/lib.php');
|
||||
|
||||
if (!$forum = forum_get_course_forum($SITE->id, 'news')) {
|
||||
print_error('cannotfindorcreateforum', 'forum');
|
||||
}
|
||||
|
||||
$cm = get_coursemodule_from_instance('forum', $forum->id, $SITE->id, false, MUST_EXIST);
|
||||
$context = \context_module::instance($cm->id, MUST_EXIST);
|
||||
|
||||
$output = html_writer::start_tag('div', array('id' => 'site-news-forum', 'class' => 'clearfix'));
|
||||
$output .= $this->heading(format_string('Notícias', true, array('context' => $context)));
|
||||
|
||||
$groupmode = groups_get_activity_groupmode($cm, $SITE);
|
||||
$currentgroup = groups_get_activity_group($cm);
|
||||
|
||||
if (!$discussions = forum_get_discussions($cm,
|
||||
'p.modified DESC', true, null, $SITE->newsitems, false, -1, $SITE->newsitems)) {
|
||||
$output .= html_writer::tag('div', '('.get_string('nonews', 'forum').')', array('class' => 'forumnodiscuss'));
|
||||
|
||||
if (forum_user_can_post_discussion($forum, $currentgroup, $groupmode, $cm, $context)) {
|
||||
$output .= html_writer::link(
|
||||
new moodle_url('/mod/forum/post.php', array('forum' => $forum->id)),
|
||||
'Adicionar notícia',
|
||||
array('class' => 'btn btn-primary')
|
||||
);
|
||||
} else {
|
||||
// No news and user cannot edit, so return nothing.
|
||||
return 'Nenhuma notícia cadastrada';
|
||||
}
|
||||
|
||||
return $output.'</div>';
|
||||
}
|
||||
|
||||
$output .= html_writer::start_div('', array('id' => 'news-articles'));
|
||||
foreach ($discussions as $discussion) {
|
||||
if (!forum_user_can_see_discussion($forum, $discussion, $context)) {
|
||||
continue;
|
||||
}
|
||||
$message = file_rewrite_pluginfile_urls($discussion->message,
|
||||
'pluginfile.php', $context->id, 'mod_forum', 'post', $discussion->id);
|
||||
|
||||
$imagestyle = '';
|
||||
|
||||
$imgarr = $this->extract_first_image($message);
|
||||
if ($imgarr) {
|
||||
$imageurl = s($imgarr['src']);
|
||||
$imagestyle = " style=\"background-image:url('$imageurl')\"";
|
||||
}
|
||||
|
||||
$name = format_string($discussion->name, true, array('context' => $context));
|
||||
$date = userdate($discussion->timemodified, get_string('strftimedatetime', 'langconfig'));
|
||||
|
||||
$message = format_text($message, $discussion->messageformat, ['context' => $context]);
|
||||
|
||||
$readmorebtn = "<a class='btn btn-secondary toggle' href='".
|
||||
$CFG->wwwroot."/mod/forum/discuss.php?d=".$discussion->discussion."'>Saiba mais</a>";
|
||||
|
||||
$preview = '';
|
||||
$newsimage = '';
|
||||
if (!$imagestyle) {
|
||||
$preview = html_to_text($message, 0, false);
|
||||
$preview = "<div class='news-article-preview'><p>".shorten_text($preview, 200)."</p>";
|
||||
// $preview .= "<p class='text-right'>".$readmorebtn."</p>";
|
||||
$preview .= "</div>";
|
||||
} else {
|
||||
$newsimage = '<div class="news-article-image toggle"'.$imagestyle.' title="Saiba mais"></div>';
|
||||
}
|
||||
$close = get_string('closebuttontitle', 'moodle');
|
||||
$output .= <<<HTML
|
||||
<div class="news-article clearfix">
|
||||
<div class="news-article-inner">
|
||||
<div class="news-article-content">
|
||||
<h3 class='toggle'><a href="$CFG->wwwroot/mod/forum/discuss.php?d=$discussion->discussion">{$name}</a></h3>
|
||||
</div>
|
||||
</div>
|
||||
{$preview}
|
||||
|
||||
</div>
|
||||
HTML;
|
||||
}
|
||||
// $actionlinks = html_writer::link(
|
||||
// new moodle_url('/mod/forum/view.php', array('id' => $cm->id)),
|
||||
// 'Mais notícias',
|
||||
// array('class' => 'btn btn-secondary')
|
||||
// );
|
||||
// if (forum_user_can_post_discussion($forum, $currentgroup, $groupmode, $cm, $context)) {
|
||||
// $actionlinks .= html_writer::link(
|
||||
// new moodle_url('/mod/forum/post.php', array('forum' => $forum->id)),
|
||||
// 'Nova notícia',
|
||||
// array('class' => 'btn btn-primary')
|
||||
// );
|
||||
// }
|
||||
$output .= html_writer::end_div();
|
||||
// $output .= "<br><div class='text-center'>$actionlinks</div>";
|
||||
$output .= html_writer::end_tag('div');
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
153
renderers/course_renderer.php
Normal file
153
renderers/course_renderer.php
Normal file
@@ -0,0 +1,153 @@
|
||||
<?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/>.
|
||||
|
||||
|
||||
/**
|
||||
* renderers/course_renderer.php
|
||||
* @package theme_qualisaude
|
||||
* @copyright 2015 onwards LMSACE Dev Team (http://www.lmsace.com)
|
||||
* @author LMSACE Dev Team
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . "/course/renderer.php");
|
||||
|
||||
use core_completion\progress;
|
||||
|
||||
/**
|
||||
* qualisaude core course renderer renderer from the moodle core course renderer
|
||||
* @copyright 2015 onwards LMSACE Dev Team (http://www.lmsace.com)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class theme_qualisaude_core_course_renderer extends core_course_renderer {
|
||||
|
||||
public function getProgress($course){
|
||||
global $USER;
|
||||
|
||||
if (empty($userid)) {
|
||||
$userid = $USER->id;
|
||||
}
|
||||
|
||||
$percentage = progress::get_course_progress_percentage($course);
|
||||
if(!$percentage){
|
||||
$percentage=0;
|
||||
}
|
||||
|
||||
$completion = new \completion_info($course);
|
||||
$modules = $completion->get_activities();
|
||||
$count = count($modules);
|
||||
if (!$count) {
|
||||
$count=0;
|
||||
}
|
||||
|
||||
$completed = 0;
|
||||
foreach ($modules as $module) {
|
||||
$data = $completion->get_data($module, false, $userid);
|
||||
$completed += $data->completionstate == COMPLETION_INCOMPLETE ? 0 : 1;
|
||||
}
|
||||
|
||||
$content = "<div class='barra_progresso'>";
|
||||
$content .= " <label>$completed atividades completas de $count</label>";
|
||||
$content .= " <div class='progresso'>";
|
||||
$content .= " <div class='andamento' style='width:$percentage%;'><label style='color:#fff; float: right; font-weight: 300; margin-right:10px; font-size: 14px;'>$percentage%</label></div>";
|
||||
$content .= " </div>";
|
||||
$content .= "</div>";
|
||||
|
||||
return $content;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrite the course box.
|
||||
* @param coursecat_helper $chelper
|
||||
* @param type|array $course
|
||||
* @param type|string $additionalclasses
|
||||
* @return type
|
||||
*/
|
||||
protected function coursecat_coursebox(coursecat_helper $chelper, $course, $additionalclasses = '') {
|
||||
global $CFG;
|
||||
if (!isset($this->strings->summary)) {
|
||||
$this->strings->summary = get_string('summary');
|
||||
}
|
||||
if ($chelper->get_show_courses() <= self::COURSECAT_SHOW_COURSES_COUNT) {
|
||||
return '';
|
||||
}
|
||||
if ($course instanceof stdClass) {
|
||||
require_once($CFG->libdir. '/coursecatlib.php');
|
||||
$course = new course_in_list($course);
|
||||
}
|
||||
$content = '';
|
||||
$classes = trim('coursebox clearfix '. $additionalclasses);
|
||||
if ($chelper->get_show_courses() >= self::COURSECAT_SHOW_COURSES_EXPANDED) {
|
||||
$nametag = 'h3';
|
||||
} else {
|
||||
$classes .= ' collapsed';
|
||||
$nametag = 'div';
|
||||
}
|
||||
|
||||
// Coursebox.
|
||||
$content .= html_writer::start_tag('div', array(
|
||||
'class' => $classes,
|
||||
'data-courseid' => $course->id,
|
||||
'data-type' => self::COURSECAT_TYPE_COURSE,
|
||||
));
|
||||
|
||||
$content .= html_writer::start_tag('div', array('class' => 'info'));
|
||||
|
||||
// Course name.
|
||||
$coursename = $chelper->get_course_formatted_name($course);
|
||||
$coursenamelink = html_writer::link(new moodle_url('/course/view.php', array('id' => $course->id)),
|
||||
$coursename, array('class' => $course->visible ? '' : 'dimmed'));
|
||||
$content .= html_writer::tag($nametag, $coursenamelink, array('class' => 'coursename'));
|
||||
// If we display course in collapsed form but the course has summary or course contacts, display the link to the info page.
|
||||
$content .= html_writer::start_tag('div', array('class' => 'moreinfo'));
|
||||
if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) {
|
||||
if ($course->has_summary() || $course->has_course_contacts() || $course->has_course_overviewfiles()) {
|
||||
$url = new moodle_url('/course/info.php', array('id' => $course->id));
|
||||
$image = html_writer::empty_tag('img', array('src' => $this->output->image_url('i/info'),
|
||||
'alt' => $this->strings->summary));
|
||||
$content .= html_writer::link($url, $image, array('title' => $this->strings->summary));
|
||||
// Make sure JS file to expand course content is included.
|
||||
$this->coursecat_include_js();
|
||||
}
|
||||
}
|
||||
$content .= html_writer::end_tag('div'); // Moreinfo.
|
||||
|
||||
// Print enrolmenticons.
|
||||
if ($icons = enrol_get_course_info_icons($course)) {
|
||||
$content .= html_writer::start_tag('div', array('class' => 'enrolmenticons'));
|
||||
foreach ($icons as $pixicon) {
|
||||
$content .= $this->render($pixicon);
|
||||
}
|
||||
$content .= html_writer::end_tag('div'); // Enrolmenticons.
|
||||
}
|
||||
|
||||
$content .= html_writer::end_tag('div'); // Info.
|
||||
|
||||
if (empty($course->get_course_overviewfiles())) {
|
||||
$class = "content-block";
|
||||
} else {
|
||||
$class = "";
|
||||
}
|
||||
$content .= html_writer::start_tag('div', array('class' => 'content '.$class));
|
||||
$content .= $this->coursecat_coursebox_content($chelper, $course);
|
||||
$content .= html_writer::end_tag('div'); // Content.
|
||||
$content .= html_writer::end_tag('div'); // Coursebox.
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user