Newer
Older
Matt Petro
committed
<?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/>.
/**
* course_overview block rendrer
*
* @package block_course_overview
* @copyright 2012 Adam Olley <adam.olley@netspot.com.au>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
/**
* Course_overview block rendrer
*
* @copyright 2012 Adam Olley <adam.olley@netspot.com.au>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_course_overview_uwmoodle_renderer extends plugin_renderer_base {
Matt Petro
committed
/**
* Construct contents of course_overview block
*
* @param array $courses list of courses in sorted order
* @param array $overviews list of course overviews
* @return string html to be displayed in course_overview block
*/
public function course_overview_allterms($terms, $overviews, $selectedterm) {
Matt Petro
committed
$html = '';
$html .= html_writer::start_tag('div', array('class' => 'courselistcontainer', 'id' => 'uwmm_terms_content'));
foreach ($terms as $termcode => $courses) {
if ($termcode != $selectedterm) {
$hidden = 'hidden';
} else {
$hidden = '';
}
$html .= html_writer::start_tag('div', array('class' => 'courselist '.$hidden, 'id' => 'uwmm_term_'.$termcode.'_courses'));
$termstr = block_course_overview_uwmoodle_get_term_name($termcode);
$title = get_string('mycoursesinterm', 'block_course_overview_uwmoodle', $termstr);
$html .= html_writer::start_tag('div', array('class' => 'title'));
$html .= $this->output->heading($title, 2, 'termname');
$html .= html_writer::end_tag('div');
$html .= $this->course_overview($courses, $overviews, $termcode);
$html .= html_writer::end_tag('div');
}
$html .= html_writer::end_tag('div');
$this->page->requires->js_init_call('M.block_course_overview_uwmoodle.termselector');
return $html;
}
public function course_overview($courses, $overviews, $termcode) {
$html = '';
$html .= html_writer::start_tag('div', array('class' => 'courselistcontainer'));
Matt Petro
committed
if (empty($courses)) {
$html .= $this->output->box_start('coursebox');
$html .= $this->output->heading(get_string('nocourses','block_course_overview_uwmoodle'), 3);
Matt Petro
committed
$html .= $this->output->box_end();
} else {
foreach ($courses as $key => $course) {
$html .= $this->output->box_start('coursebox');
Matt Petro
committed
$html .= html_writer::start_tag('div', array('class' => 'course_title'));
// No need to pass title through s() here as it will be done automatically by html_writer.
$attributes = array('title' => $course->fullname);
if (empty($course->visible)) {
$attributes['class'] = 'dimmed';
}
$courseurl = new moodle_url('/course/view.php', array('id' => $course->id));
$coursefullname = format_string($course->fullname, true, $course->id);
$link = html_writer::link($courseurl, $coursefullname, $attributes);
$html .= $this->output->heading($link, 3, 'title');
//$html .= $this->output->box('', 'flush');
Matt Petro
committed
$html .= html_writer::end_tag('div');
if (isset($overviews[$course->id])) {
$html .= $this->activity_display($course->id, $overviews[$course->id], $termcode);
Matt Petro
committed
}
//$html .= $this->output->box('', 'flush');
Matt Petro
committed
$html .= $this->output->box_end();
}
}
$html .= html_writer::end_tag('div');
return $html;
}
public function term_list($termcodes, $selectedterm) {
$thisurl = $this->page->url;
$html = '';
$html .= html_writer::start_tag('div', array('class' => 'termscontainer'));
$html .= html_writer::start_tag('ul', array('class' => 'terms', 'id' => 'uwmm_terms'));
foreach ($termcodes as $termcode) {
$termname = block_course_overview_uwmoodle_get_term_name($termcode);
$attributes = array('id'=>'uwmm_term_'.$termcode);
if ($termcode == $selectedterm) {
$attributes['class'] = 'active';
}
$html .= html_writer::start_tag('li', $attributes);
$html .= html_writer::tag('a', $termname, array('href' => $thisurl->out(false, array('term'=>$termcode))));
$html .= html_writer::end_tag('li');
}
$html .= html_writer::end_tag('ul');
$html .= html_writer::end_tag('div');
return $html;
}
public function begin_course_block($title, $id='', $helpidentifier='') {
$attributes = array('class' => 'courseblock clearfix');
if (!empty($id)) {
$attributes['id'] = $id;
}
$html .= html_writer::start_tag('div', $attributes);
$html .= html_writer::start_tag('div', array('class' => 'cbheader'));
$help = '';
if ($helpidentifier) {
$help = $this->output->help_icon($helpidentifier, 'block_course_overview_uwmoodle');
}
$html .= $this->output->heading($title.$help, 2, 'sectiontitle help');
$html .= html_writer::end_tag('div');
$html .= html_writer::start_tag('div', array('class' => 'cbcontent'));
return $html;
}
public function end_course_block() {
$html = '';
$html .= html_writer::end_tag('div');
$html .= html_writer::end_tag('div');
return $html;
}
public function course_block($terms, $overviews, $selectedterm) {
$html = '';
$html .= $this->begin_course_block(get_string('courses', 'block_course_overview_uwmoodle'), 'uwmm_mycourses_block');
$termcodes = array_keys($terms);
$html .= html_writer::start_tag('div', array('class' => 'lhs'));
$html .= $this->term_list($termcodes, $selectedterm);
$html .= html_writer::end_tag('div');
$html .= html_writer::start_tag('div', array('class' => 'rhs'));
$html .= $this->course_overview_allterms($terms, $overviews, $selectedterm);
$html .= html_writer::end_tag('div');
$html .= $this->end_course_block();
return $html;
}
public function other_course_block($courses, $overviews) {
$html = '';
$html .= $this->begin_course_block(get_string('ongoingcourses', 'block_course_overview_uwmoodle'), 'uwmm_othercourses_block', 'ongoingcourses');
$html .= $this->course_overview($courses, $overviews, block_course_overview_uwmoodle::TERM_OTHER);
$html .= $this->end_course_block();
return $html;
}
/**
* Render term selection box above the list of courses
*
* @param array $terms
* @param string $selectedterm
* @return string html to be displayed in course_overview block
*/
Matt Petro
committed
public function course_header($terms, $selectedterm) {
$output = '';
$thisterm = block_course_overview_uwmoodle_get_term_name($selectedterm);
Matt Petro
committed
$options = array();
$url = new moodle_url('/my/index.php');
$output .= $this->output->box_start('notice');
$output .= html_writer::start_tag('ul', array('class'=>'termlist'));
$output .= html_writer::start_tag('li');
$output .= get_string('selectterm', 'block_course_overview_uwmoodle');
$output .= html_writer::end_tag('li');
// sort by term date, ascending
ksort($terms, SORT_NUMERIC);
$firstitem = true;
Matt Petro
committed
foreach ($terms as $termcode => $courses) {
if ($termcode == block_course_overview_uwmoodle::TERM_OTHER) {
// non-term courses are shown regardless
continue;
}
$termname = block_course_overview_uwmoodle_get_term_name($termcode);
$output .= html_writer::start_tag('li');
if (!$firstitem) {
$output .= ' | ';
} else {
$firstitem = false;
}
if ($termcode == $selectedterm) {
$output .= html_writer::tag('span', $this->rarrow().$termname, array('class'=>'selectedterm'));
} else {
$output .= html_writer::tag('a', $termname, array('href' => $url->out(false, array('term'=>$termcode))));
}
$output .= html_writer::end_tag('li');
//$options[$termcode] = block_course_overview_uwmoodle_get_term_name($termcode);
Matt Petro
committed
}
//ksort($options, SORT_NUMERIC);
Matt Petro
committed
$output .= html_writer::end_tag('ul');
//$output .= $this->output->heading(get_string('mycoursesinterm', 'block_course_overview_uwmoodle', $thisterm), 2, 'sectiontitle');
Matt Petro
committed
$output .= $this->output->box_end();
//$url = new moodle_url('/my/index.php');
//$select = new single_select($url, 'term', $options, '', array('' => 'choosedots'));
//$select->set_label(get_string('selectterm', 'block_course_overview_uwmoodle'));
//$output .= $this->output->render($select);
Matt Petro
committed
return $output;
}
/**
* Render block footer
*
* @return string html to be displayed in course_overview block
*/
public function footer() {
global $CFG;
$output = html_writer::tag('a', get_string("fulllistofcourses"), array('href' => "$CFG->wwwroot/course/index.php"));
$output .= ' ...';
Matt Petro
committed
return $output;
}
/**
* Coustuct activities overview for a course
*
* @param int $cid course id
* @param array $overview overview of activities in course
* @return string html of activities overview
*/
protected function activity_display($cid, $overview, $id) {
Matt Petro
committed
$output = html_writer::start_tag('div', array('class' => 'activity_info'));
foreach (array_keys($overview) as $module) {
$output .= html_writer::start_tag('div', array('class' => 'activity_overview'));
$url = new moodle_url("/mod/$module/index.php", array('id' => $cid));
$modulename = get_string('modulename', $module);
$icontext = html_writer::link($url, $this->output->pix_icon('icon', $modulename, 'mod_'.$module, array('class'=>'iconlarge')));
if (get_string_manager()->string_exists("activityoverview", $module)) {
$icontext .= get_string("activityoverview", $module);
} else {
Matt Petro
committed
$icontext .= get_string("activityoverview", 'block_course_overview_uwmoodle', $modulename);
Matt Petro
committed
}
// Add collapsible region with overview text in it.
$output .= $this->collapsible_region($overview[$module], '', 'uwmm_region_'.$id.'_'.$cid.'_'.$module, $icontext, '', true);
Matt Petro
committed
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
$output .= html_writer::end_tag('div');
}
$output .= html_writer::end_tag('div');
return $output;
}
/**
* Creates collapsable region
*
* @param string $contents existing contents
* @param string $classes class names added to the div that is output.
* @param string $id id added to the div that is output. Must not be blank.
* @param string $caption text displayed at the top. Clicking on this will cause the region to expand or contract.
* @param string $userpref the name of the user preference that stores the user's preferred default state.
* (May be blank if you do not wish the state to be persisted.
* @param bool $default Initial collapsed state to use if the user_preference it not set.
* @return bool if true, return the HTML as a string, rather than printing it.
*/
protected function collapsible_region($contents, $classes, $id, $caption, $userpref = '', $default = false) {
$output = $this->collapsible_region_start($classes, $id, $caption, $userpref, $default);
$output .= $contents;
$output .= $this->collapsible_region_end();
return $output;
}
/**
* Print (or return) the start of a collapsible region, that has a caption that can
* be clicked to expand or collapse the region. If JavaScript is off, then the region
* will always be expanded.
*
* @param string $classes class names added to the div that is output.
* @param string $id id added to the div that is output. Must not be blank.
* @param string $caption text displayed at the top. Clicking on this will cause the region to expand or contract.
* @param string $userpref the name of the user preference that stores the user's preferred default state.
* (May be blank if you do not wish the state to be persisted.
* @param bool $default Initial collapsed state to use if the user_preference it not set.
* @return bool if true, return the HTML as a string, rather than printing it.
*/
protected function collapsible_region_start($classes, $id, $caption, $userpref = '', $default = false) {
// Work out the initial state.
if (!empty($userpref) and is_string($userpref)) {
user_preference_allow_ajax_update($userpref, PARAM_BOOL);
$collapsed = get_user_preferences($userpref, $default);
} else {
$collapsed = $default;
$userpref = false;
}
if ($collapsed) {
$classes .= ' collapsed';
}
$output = '';
$output .= '<div id="' . $id . '" class="collapsibleregion ' . $classes . '">';
$output .= '<div id="' . $id . '_sizer">';
$output .= '<div id="' . $id . '_caption" class="collapsibleregioncaption">';
$output .= $caption . ' ';
$output .= '</div><div id="' . $id . '_inner" class="collapsibleregioninner">';
$this->page->requires->js_init_call('M.block_course_overview_uwmoodle.collapsible', array($id, $userpref, get_string('clicktohideshow')));
return $output;
}
/**
* Close a region started with print_collapsible_region_start.
*
* @return string return the HTML as a string, rather than printing it.
*/
protected function collapsible_region_end() {
$output = '</div></div></div>';
return $output;
}
/**
* Cretes html for welcome area
*
* @param int $msgcount number of messages
* @return string html string for welcome area.
*/
public function welcome_area($msgcount) {
global $USER;
$output = $this->output->box_start('welcome_area');
$picture = $this->output->user_picture($USER, array('size' => 75, 'class' => 'welcome_userpicture'));
$output .= html_writer::tag('div', $picture, array('class' => 'profilepicture'));
$output .= $this->output->box_start('welcome_message');
Matt Petro
committed
$output .= $this->output->heading(get_string('welcome', 'block_course_overview_uwmoodle', $USER->firstname));
Matt Petro
committed
$plural = 's';
if ($msgcount > 0) {
Matt Petro
committed
$output .= get_string('youhavemessages', 'block_course_overview_uwmoodle', $msgcount);
Matt Petro
committed
} else {
Matt Petro
committed
$output .= get_string('youhavenomessages', 'block_course_overview_uwmoodle');
Matt Petro
committed
if ($msgcount == 1) {
$plural = '';
}
}
Matt Petro
committed
$output .= html_writer::link(new moodle_url('/message/index.php'), get_string('message'.$plural, 'block_course_overview_uwmoodle'));
Matt Petro
committed
$output .= $this->output->box_end();
$output .= $this->output->box('', 'flush');
$output .= $this->output->box_end();
return $output;
}
}