Permalink
Browse files

Merge branch 'wip-MDL-37977-master' of git://github.com/marinaglancy/…

…moodle
  • Loading branch information...
dmonllao committed Jun 4, 2018
2 parents b321d23 + dcce357 commit 995457b8cfde7b9c74d41641a9604038714929bf
Showing with 210 additions and 196 deletions.
  1. +202 −0 course/renderer.php
  2. +8 −196 index.php
@@ -2311,6 +2311,208 @@ public function hubinfo($hubinfo) {
return $hubdescription;
}
/**
* Output frontpage summary text and frontpage modules (stored as section 1 in site course)
*
* This may be disabled in settings
*
* @return string
*/
public function frontpage_section1() {
global $SITE, $USER;
$output = '';
$editing = $this->page->user_is_editing();
if ($editing) {
// Make sure section with number 1 exists.
course_create_sections_if_missing($SITE, 1);
}
$modinfo = get_fast_modinfo($SITE);
$section = $modinfo->get_section_info(1);
if (($section && (!empty($modinfo->sections[1]) or !empty($section->summary))) or $editing) {
$output .= $this->box_start('generalbox sitetopic');
// If currently moving a file then show the current clipboard.
if (ismoving($SITE->id)) {
$stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
$output .= '<p><font size="2">';
$cancelcopyurl = new moodle_url('/course/mod.php', ['cancelcopy' => 'true', 'sesskey' => sesskey()]);
$output .= "$stractivityclipboard&nbsp;&nbsp;(" . html_writer::link($cancelcopyurl, get_string('cancel')) .')';
$output .= '</font></p>';
}
$context = context_course::instance(SITEID);
// If the section name is set we show it.
if (trim($section->name) !== '') {
$output .= $this->heading(
format_string($section->name, true, array('context' => $context)),
2,
'sectionname'
);
}
$summarytext = file_rewrite_pluginfile_urls($section->summary,
'pluginfile.php',
$context->id,
'course',
'section',
$section->id);
$summaryformatoptions = new stdClass();
$summaryformatoptions->noclean = true;
$summaryformatoptions->overflowdiv = true;
$output .= format_text($summarytext, $section->summaryformat, $summaryformatoptions);
if ($editing && has_capability('moodle/course:update', $context)) {
$streditsummary = get_string('editsummary');
$editsectionurl = new moodle_url('/course/editsection.php', ['id' => $section->id]);
$output .= html_writer::link($editsectionurl, $this->pix_icon('t/edit', $streditsummary)) .
"<br /><br />";
}
$output .= $this->course_section_cm_list($SITE, $section);
$output .= $this->course_section_add_cm_control($SITE, $section->section);
$output .= $this->box_end();
}
return $output;
}
/**
* Output news for the frontpage (extract from site-wide news forum)
*
* @param stdClass $newsforum record from db table 'forum' that represents the site news forum
* @return string
*/
protected function frontpage_news($newsforum) {
global $CFG, $SITE, $SESSION, $USER;
require_once($CFG->dirroot .'/mod/forum/lib.php');
$output = '';
if (isloggedin()) {
$SESSION->fromdiscussion = $CFG->wwwroot;
$subtext = '';
if (\mod_forum\subscriptions::is_subscribed($USER->id, $newsforum)) {
if (!\mod_forum\subscriptions::is_forcesubscribed($newsforum)) {
$subtext = get_string('unsubscribe', 'forum');
}
} else {
$subtext = get_string('subscribe', 'forum');
}
$suburl = new moodle_url('/mod/forum/subscribe.php', array('id' => $newsforum->id, 'sesskey' => sesskey()));
$output .= html_writer::tag('div', html_writer::link($suburl, $subtext), array('class' => 'subscribelink'));
}
ob_start();
forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems, 'plain', 'p.modified DESC');
$output .= ob_get_contents();
ob_end_clean();
return $output;
}
/**
* Renders part of frontpage with a skip link (i.e. "My courses", "Site news", etc.)
*
* @param string $skipdivid
* @param string $contentsdivid
* @param string $header Header of the part
* @param string $contents Contents of the part
* @return string
*/
protected function frontpage_part($skipdivid, $contentsdivid, $header, $contents) {
$output = html_writer::link('#' . $skipdivid,
get_string('skipa', 'access', core_text::strtolower(strip_tags($header))),
array('class' => 'skip-block skip'));
// Wrap frontpage part in div container.
$output .= html_writer::start_tag('div', array('id' => $contentsdivid));
$output .= $this->heading($header);
$output .= $contents;
// End frontpage part div container.
$output .= html_writer::end_tag('div');
$output .= html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => $skipdivid));
return $output;
}
/**
* Outputs contents for frontpage as configured in $CFG->frontpage or $CFG->frontpageloggedin
*
* @return string
*/
public function frontpage() {
global $CFG, $SITE;
$output = '';
if (isloggedin() and !isguestuser() and isset($CFG->frontpageloggedin)) {
$frontpagelayout = $CFG->frontpageloggedin;
} else {
$frontpagelayout = $CFG->frontpage;
}
foreach (explode(',', $frontpagelayout) as $v) {
switch ($v) {
// Display the main part of the front page.
case FRONTPAGENEWS:
if ($SITE->newsitems) {
// Print forums only when needed.
require_once($CFG->dirroot .'/mod/forum/lib.php');
if (($newsforum = forum_get_course_forum($SITE->id, 'news')) &&
($forumcontents = $this->frontpage_news($newsforum))) {
$newsforumcm = get_fast_modinfo($SITE)->instances['forum'][$newsforum->id];
$output .= $this->frontpage_part('skipsitenews', 'site-news-forum',
$newsforumcm->get_formatted_name(), $forumcontents);
}
}
break;
case FRONTPAGEENROLLEDCOURSELIST:
$mycourseshtml = $this->frontpage_my_courses();
if (!empty($mycourseshtml)) {
$output .= $this->frontpage_part('skipmycourses', 'frontpage-course-list',
get_string('mycourses'), $mycourseshtml);
break;
}
// No "break" here. If there are no enrolled courses - continue to 'Available courses'.
case FRONTPAGEALLCOURSELIST:
$availablecourseshtml = $this->frontpage_available_courses();
if (!empty($availablecourseshtml)) {
$output .= $this->frontpage_part('skipavailablecourses', 'frontpage-available-course-list',
get_string('availablecourses'), $availablecourseshtml);
}
break;
case FRONTPAGECATEGORYNAMES:
$output .= $this->frontpage_part('skipcategories', 'frontpage-category-names',
get_string('categories'), $this->frontpage_categories_list());
break;
case FRONTPAGECATEGORYCOMBO:
$output .= $this->frontpage_part('skipcourses', 'frontpage-category-combo',
get_string('courses'), $this->frontpage_combo_list());
break;
case FRONTPAGECOURSESEARCH:
$output .= $this->box($this->course_search_form('', 'short'), 'mdl-align');
break;
}
$output .= '<br />';
}
return $output;
}
}
/**
Oops, something went wrong.

0 comments on commit 995457b

Please sign in to comment.