Skip to content

a few fixes and improvements for your very nice block, 1.9 branch only for now #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Nov 28, 2011
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ first one will be used. If the summary is empty, a customizable text "Unit X"
content of the first non-empty HTML DOM node from the section summary is used
as the summary title.

This block requires PHP 5.

Maintainer
----------

Expand All @@ -22,5 +24,5 @@ The block has been written and is currently maintained by David Mudrak.
Documentation
-------------

See [the page at Moodle wiki](http://docs.moodle.org/en/Course_contents_block)
See [the page at Moodle wiki](http://docs.moodle.org/19/en/Course_contents_block)
for more details.
69 changes: 32 additions & 37 deletions block_course_contents.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?PHP //$Id$
<?PHP

/**
* Block course_contents - generates a course contents based on the section descriptions
*
*
* @uses block_base
* @package block_course_contents
* @version $Id$
* @copyright 2009
* @author David Mudrak <david.mudrak@gmail.com>
* @author David Mudrak <david.mudrak@gmail.com>
* @license GNU Public License {@link http://www.gnu.org/copyleft/gpl.html}
*/
class block_course_contents extends block_base {
Expand All @@ -30,45 +29,44 @@ function get_content() {
return $this->content;
}

$this->content = new stdClass;
$this->content = new stdClass();
$this->content->footer = '';
$this->content->text = '';

if (empty($this->instance->pageid)) { // sticky
if (!empty($COURSE)) {
$this->instance->pageid = $COURSE->id;
}
}

if (empty($this->instance)) {
if ($COURSE->id == SITEID) {
// there are no sections on the front page course
return $this->content;
}

if ($this->instance->pageid == $COURSE->id) {
$course = $COURSE;
} else {
$course = get_record('course', 'id', $this->instance->pageid);
}
$course = $COURSE;
$context = get_context_instance(CONTEXT_COURSE, $course->id);

if ($course->format == 'weeks' or $course->format == 'weekscss') {
$highlight = ceil((time()-$course->startdate)/604800);
$linktext = get_string('jumptocurrentweek', 'block_course_contents');
$sectionname = 'week';
}
else if ($course->format == 'topics') {

} else if ($course->format == 'scorm' or $course->format == 'social') {
// this formats do not have sections at all, no need for this block there
return $this->content;

} else {
// anything else defaults to 'topics'
$highlight = $course->marker;
$linktext = get_string('jumptocurrenttopic', 'block_course_contents');
$sectionname = 'topic';
}

if (!empty($USER->id)) {
$display = get_field('course_display', 'display', 'course', $this->instance->pageid, 'userid', $USER->id);
if (isset($USER->display[$course->id])) {
$displaysection = $USER->display[$course->id];
} else {
$displaysection = course_set_display($course->id, 0);
}
if (!empty($display)) {
$link = $CFG->wwwroot.'/course/view.php?id='.$this->instance->pageid.'&amp;'.$sectionname.'=';

if ($displaysection) {
$link = $CFG->wwwroot.'/course/view.php?id='.$course->id.'&amp;'.$sectionname.'=';
} else {
$link = $CFG->wwwroot.'/course/view.php?id='.$this->instance->pageid.'#sectionblock-';
$link = $CFG->wwwroot.'/course/view.php?id='.$course->id.'#sectionblock-';
}

$sql = "SELECT section, summary, visible
Expand Down Expand Up @@ -99,10 +97,14 @@ function get_content() {
} else {
$text .= "<li class=\"section-item r$odd\">";
}
$text .= "<a href=\"$link$i\"$style>";
if (!$displaysection or $displaysection != $i) {
$text .= "<a href=\"$link$i\"$style>";
}
$text .= "<span class=\"section-number\">$i </span>";
$text .= "<span class=\"section-title\">$title</span>";
$text .= "</a>";
if (!$displaysection or $displaysection != $i) {
$text .= "</a>";
}
$text .= "</li>\n";
}
$text .= '</ul>';
Expand All @@ -119,11 +121,9 @@ function get_content() {
return $this->content;
}



/**
* Given a section summary, exctract a text suitable as a section title
*
* Given a section summary, extract a text suitable as a section title
*
* @param string $summary Section summary as returned from database (no slashes)
* @return string Section title
*/
Expand All @@ -136,15 +136,14 @@ function extract_title($summary) {
return $this->_node_plain_text($node);
}


/**
* Recursively find the first suitable plaintext from the HTML DOM.
*
* Internal private function called only from {@link extract_title()}
*
*
* @param mixed $node Current root node
* @access private
* @return void str
* @return void str
*/
private function _node_plain_text($node) {
if ($node->nodetype == HDOM_TYPE_TEXT) {
Expand All @@ -162,9 +161,5 @@ private function _node_plain_text($node) {
}
return $t;
}



}

?>
9 changes: 0 additions & 9 deletions styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,3 @@

.block_course_contents {
}

.block_course_contents {
}

.block_course_contents {
}

.block_course_contents {
}