Skip to content

Commit

Permalink
MDL-20459 - convert $OUTPUT->spacer to use CSS. eliminate echo '<div>…
Browse files Browse the repository at this point in the history
…' to use html_writer::tag
  • Loading branch information
rwijaya committed Jul 26, 2010
1 parent 93ad2d4 commit ea831ce
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 29 deletions.
63 changes: 36 additions & 27 deletions course/lib.php
Expand Up @@ -2009,8 +2009,10 @@ function print_category_info($category, $depth, $showcourses = false) {


$strsummary = get_string('summary'); $strsummary = get_string('summary');


$catlinkcss = $category->visible ? '' : ' class="dimmed" '; $catlinkcss = null;

if (!$category->visible) {
$catlinkcss = array('class'=>'dimmed');
}
static $coursecount = null; static $coursecount = null;
if (null === $coursecount) { if (null === $coursecount) {
// only need to check this once // only need to check this once
Expand All @@ -2025,36 +2027,36 @@ function print_category_info($category, $depth, $showcourses = false) {


$courses = get_courses($category->id, 'c.sortorder ASC', 'c.id,c.sortorder,c.visible,c.fullname,c.shortname,c.summary'); $courses = get_courses($category->id, 'c.sortorder ASC', 'c.id,c.sortorder,c.visible,c.fullname,c.shortname,c.summary');
if ($showcourses and $coursecount) { if ($showcourses and $coursecount) {
echo '<div class="categorylist clearfix">'; echo '<div class="categorylist clearfix">';
echo '<div class="category">';
$cat = ''; $cat = '';
$cat .= html_writer::tag('div', $catimage, array('class'=>'image')); $cat .= html_writer::tag('div', $catimage, array('class'=>'image'));
$catlink = '<a '.$catlinkcss.' href="'.$CFG->wwwroot.'/course/category.php?id='.$category->id.'">'. format_string($category->name).'</a>'; $catlink = html_writer::link(new moodle_url('/course/category.php', array('id'=>$category->id)), format_string($category->name), $catlinkcss);
$cat .= html_writer::tag('div', $catlink, array('class'=>'name')); $cat .= html_writer::tag('div', $catlink, array('class'=>'name'));


$indent = ''; $html = '';
if ($depth > 0) { if ($depth > 0) {
for ($i=0; $i< $depth; $i++) { for ($i=0; $i< $depth; $i++) {
$indent = html_writer::tag('div', $indent .$cat, array('class'=>'indentation')); $html = html_writer::tag('div', $html . $cat, array('class'=>'indentation'));
$cat = ''; $cat = '';
} }
} else { } else {
$indent = $cat; $html = $cat;
} }
echo $indent; echo html_writer::tag('div', $html, array('class'=>'category'));
echo '</div>';

echo html_writer::tag('div', '', array('class'=>'clearfloat')); echo html_writer::tag('div', '', array('class'=>'clearfloat'));


// does the depth exceed maxcategorydepth // does the depth exceed maxcategorydepth
// maxcategorydepth == 0 or unset meant no limit // maxcategorydepth == 0 or unset meant no limit
$limit = !(isset($CFG->maxcategorydepth) && ($depth >= $CFG->maxcategorydepth-1)); $limit = !(isset($CFG->maxcategorydepth) && ($depth >= $CFG->maxcategorydepth-1));
if ($courses && ($limit || $CFG->maxcategorydepth == 0)) { if ($courses && ($limit || $CFG->maxcategorydepth == 0)) {
foreach ($courses as $course) { foreach ($courses as $course) {
$linkcss = $course->visible ? '' : ' class="dimmed" '; $linkcss = null;

if (!$course->visible) {
$linkcss = array('class'=>'dimmed');
}

$coursecontent = ''; $coursecontent = '';
$courselink = '<a '.$linkcss.' href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'. format_string($course->fullname).'</a>'; $courselink = html_writer::link(new moodle_url('/course/view.php', array('id'=>$course->id)), format_string($course->fullname), $linkcss);
$coursecontent .= html_writer::tag('div', $courselink, array('class'=>'name')); $coursecontent .= html_writer::tag('div', $courselink, array('class'=>'name'));


//TODO: add some guest, pay icons //TODO: add some guest, pay icons
Expand All @@ -2067,25 +2069,32 @@ function print_category_info($category, $depth, $showcourses = false) {
$coursecontent .= html_writer::tag('div', $actionlink, array('class'=>'info')); $coursecontent .= html_writer::tag('div', $actionlink, array('class'=>'info'));
} }


$indent = ''; $html = '';
for ($i=1; $i <= $depth; $i++) { for ($i=1; $i <= $depth; $i++) {
$indent = html_writer::tag('div', $indent . $coursecontent , array('class'=>'indentation')); $html = html_writer::tag('div', $html . $coursecontent , array('class'=>'indentation'));
$coursecontent = ''; $coursecontent = '';
} }
echo html_writer::tag('div', $indent, array('class'=>'course clearfloat')); echo html_writer::tag('div', $html, array('class'=>'course clearfloat'));
} }
} }
echo '</div>'; echo '</div>';
} else { } else {
echo '<div class="categorylist">'; echo '<div class="categorylist">';
echo '<div class="category">'; $html = '';
if ($depth) { $cat = html_writer::link(new moodle_url('/course/category.php', array('id'=>$category->id)), format_string($category->name), $catlinkcss);
$indent = $depth*20; $cat .= html_writer::tag('span', '('.count($courses).')', array('title'=>get_string('numberofcourses'), 'class'=>'numberofcourse'));
echo $OUTPUT->spacer(array('height'=>10, 'width'=>$indent, 'br'=>true)); // should be done with CSS instead
} if ($depth > 0) {
echo '<a '.$catlinkcss.' href="'.$CFG->wwwroot.'/course/category.php?id='.$category->id.'">'. format_string($category->name).'</a>'; for ($i=0; $i< $depth; $i++) {
echo '<span class="numberofcourse" title="' .get_string('numberofcourses') . '"> ('.count($courses).')</span>'; $html = html_writer::tag('div', $html .$cat, array('class'=>'indentation'));
echo '</div>'; $cat = '';
}
} else {
$html = $cat;
}

echo html_writer::tag('div', $html, array('class'=>'category'));
echo html_writer::tag('div', '', array('class'=>'clearfloat'));
echo '</div>'; echo '</div>';
} }
} }
Expand Down
4 changes: 2 additions & 2 deletions theme/base/style/course.css
Expand Up @@ -83,8 +83,8 @@
.categorylist .course .info {float:left;text-align: left;} .categorylist .course .info {float:left;text-align: left;}
.categorylist .course {padding-left:18px;} .categorylist .course {padding-left:18px;}


#page-course-index .indentation {padding-left: 30px;} .categorylist .indentation {padding-left: 20px;}
#page-course-index .category .image {padding-right: 5px;} #page-course-index .category .image {padding-right: 2px;}


.path-course-report-outline td.numviews {text-align:right;} .path-course-report-outline td.numviews {text-align:right;}
.path-course-report-outline tr.section {text-align: center;} .path-course-report-outline tr.section {text-align: center;}
Expand Down

0 comments on commit ea831ce

Please sign in to comment.