Improved category and course list display on front page- see bug Bug #5965 - Frontpage Category List also showing courses; new Combo List(categories + courses), fixed categories list and separate settings for not logged in / logged in users; merged from MOODLE_16_STABLE

This commit is contained in:
skodak 2006-07-19 12:10:07 +00:00
parent fa145ae1af
commit 6f24e48e1f
6 changed files with 76 additions and 25 deletions

View file

@ -33,26 +33,46 @@
<table width="100%" cellpadding="0" cellspacing="0" border="0"> <table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr> <tr>
<?php <?php
$coursecount = (count_records('course') <= FRONTPAGECOURSELIMIT);
$options = array(FRONTPAGENEWS => get_string("frontpagenews"), $options = array(FRONTPAGENEWS => get_string("frontpagenews"),
FRONTPAGECOURSELIST => get_string("frontpagecourselist"), FRONTPAGECOURSELIST => get_string("frontpagecourselist"),
FRONTPAGECATEGORYNAMES => get_string("frontpagecategorynames"), FRONTPAGECATEGORYNAMES => get_string("frontpagecategorynames"),
FRONTPAGECATEGORYCOMBO => get_string("frontpagecategorycombo"),
); );
$values = array(get_string('hide'), get_string('order1', 'admin'), get_string('order2', 'admin')); $values = array(get_string('hide'), get_string('order1', 'admin'), get_string('order2', 'admin'), get_string('order3', 'admin'), get_string('order4', 'admin'));
$seq = array_flip(explode(',',$form->frontpage)); $seq = array_flip(explode(',',$form->frontpage));
foreach ($seq as $k => $s) { foreach ($seq as $k => $s) {
$seq[$k]++; $seq[$k]++;
} }
if (count_records("course") > 200) { if (!$coursecount and isset($seq[FRONTPAGECOURSELIST])) {
unset($options[FRONTPAGECOURSELIST]); unset($seq[FRONTPAGECOURSELIST]); //disable course list option when too many course present
if (isset($seq[FRONTPAGECOURSELIST])) {
$form->frontpage = 2;
}
} else {
$values[] = get_string('order3', 'admin');
} }
foreach ($options as $key => $option) {
$disabled = (!$coursecount and ($key == FRONTPAGECOURSELIST));
echo "<td>$option<br />";
choose_from_menu ($values, "frontpage[$key]", isset($seq[$key])?$seq[$key]:0, '', '', 0, false, $disabled);
echo '</td>';
}
?>
</tr>
</table>
</td>
</tr>
<tr valign="top">
<td align="right"><?php print_string("frontpageformatloggedin") ?>:</td>
<td>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<?php
$seq = array_flip(explode(',',$form->frontpageloggedin));
foreach ($seq as $k => $s) {
$seq[$k]++;
}
foreach ($options as $key => $option) { foreach ($options as $key => $option) {
echo "<td>$option<br />"; echo "<td>$option<br />";
choose_from_menu ($values, "frontpage[$key]", isset($seq[$key])?$seq[$key]:0, ""); choose_from_menu ($values, "frontpageloggedin[$key]", isset($seq[$key])?$seq[$key]:0, '');
echo '</td>'; echo '</td>';
} }
?> ?>

View file

@ -37,6 +37,13 @@
$form->numsections = 1; // Force the topic display for this format $form->numsections = 1; // Force the topic display for this format
} }
$form->frontpageloggedin = array_flip($form->frontpageloggedin);
unset($form->frontpageloggedin[0]);
$form->frontpageloggedin = array_flip($form->frontpageloggedin);
asort($form->frontpageloggedin);
$form->frontpageloggedin = implode(',',array_flip($form->frontpageloggedin));
set_config("frontpageloggedin", $form->frontpageloggedin);
$form->timemodified = time(); $form->timemodified = time();
if ($form->id) { if ($form->id) {
@ -98,12 +105,18 @@
if (isset($CFG->frontpage)) { if (isset($CFG->frontpage)) {
$form->frontpage = $CFG->frontpage; $form->frontpage = $CFG->frontpage;
} else { } else {
$form->frontpage = FRONTPAGECOURSELIST; // Show course list by default $form->frontpage = FRONTPAGECOURSELIST; // Show course list by default
set_config("frontpage", $form->frontpage); set_config("frontpage", $form->frontpage);
} }
if (isset($CFG->frontpageloggedin)) {
$form->frontpageloggedin = $CFG->frontpageloggedin;
} else {
$form->frontpageloggedin = $form->frontpage;
set_config("frontpageloggedin", $form->frontpageloggedin);
}
$stradmin = get_string("administration"); $stradmin = get_string("administration");
$strconfiguration = get_string("configuration"); $strconfiguration = get_string("configuration");
$strsitesettings = get_string("sitesettings"); $strsitesettings = get_string("sitesettings");

View file

@ -14,11 +14,13 @@ define('COURSE_MAX_SUMMARIES_PER_PAGE', 10); // courses
define('COURSE_MAX_COURSES_PER_DROPDOWN',1000); // max courses in log dropdown before switching to optional define('COURSE_MAX_COURSES_PER_DROPDOWN',1000); // max courses in log dropdown before switching to optional
define('COURSE_MAX_USERS_PER_DROPDOWN',1000); // max users in log dropdown before switching to optional define('COURSE_MAX_USERS_PER_DROPDOWN',1000); // max users in log dropdown before switching to optional
define('FRONTPAGENEWS', 0); define('FRONTPAGENEWS', 0);
define('FRONTPAGECOURSELIST', 1); define('FRONTPAGECOURSELIST', 1);
define('FRONTPAGECATEGORYNAMES', 2); define('FRONTPAGECATEGORYNAMES', 2);
define('FRONTPAGETOPICONLY', 3); define('FRONTPAGETOPICONLY', 3);
define("EXCELROWS", 65535); define('FRONTPAGECATEGORYCOMBO', 4);
define("FIRSTUSEDEXCELROW", 3); define('FRONTPAGECOURSELIMIT', 200); // maximum number of courses displayed on the frontpage
define('EXCELROWS', 65535);
define('FIRSTUSEDEXCELROW', 3);
function print_recent_selector_form($course, $advancedfilter=0, $selecteduser=0, $selecteddate="lastlogin", function print_recent_selector_form($course, $advancedfilter=0, $selecteduser=0, $selecteddate="lastlogin",
@ -1314,7 +1316,7 @@ function make_categories_list(&$list, &$parents, $category=NULL, $path="") {
} }
function print_whole_category_list($category=NULL, $displaylist=NULL, $parentslist=NULL, $depth=-1) { function print_whole_category_list($category=NULL, $displaylist=NULL, $parentslist=NULL, $depth=-1, $files = false) {
/// Recursive function to print out all the categories in a nice format /// Recursive function to print out all the categories in a nice format
/// with or without courses included /// with or without courses included
global $CFG; global $CFG;
@ -1329,7 +1331,7 @@ function print_whole_category_list($category=NULL, $displaylist=NULL, $parentsli
if ($category) { if ($category) {
if ($category->visible or iscreator()) { if ($category->visible or iscreator()) {
print_category_info($category, $depth); print_category_info($category, $depth, $files);
} else { } else {
return; // Don't bother printing children of invisible categories return; // Don't bother printing children of invisible categories
} }
@ -1352,7 +1354,7 @@ function print_whole_category_list($category=NULL, $displaylist=NULL, $parentsli
$down = $last ? false : true; $down = $last ? false : true;
$first = false; $first = false;
print_whole_category_list($cat, $displaylist, $parentslist, $depth + 1); print_whole_category_list($cat, $displaylist, $parentslist, $depth + 1, $files);
} }
} }
} }
@ -1373,7 +1375,7 @@ function make_categories_options() {
return $cats; return $cats;
} }
function print_category_info($category, $depth) { function print_category_info($category, $depth, $files = false) {
/// Prints the category info in indented fashion /// Prints the category info in indented fashion
/// This function is only used by print_whole_category_list() above /// This function is only used by print_whole_category_list() above
@ -1388,10 +1390,8 @@ function print_category_info($category, $depth) {
$catlinkcss = $category->visible ? '' : ' class="dimmed" '; $catlinkcss = $category->visible ? '' : ' class="dimmed" ';
$frontpage = explode(',', $CFG->frontpage); $coursecount = count_records('course') <= FRONTPAGECOURSELIMIT;
$frontpage = $frontpage?array_flip($frontpage):array(); if ($files and $coursecount) {
$coursecount = count_records('course') <= 200;
if (isset($frontpage[FRONTPAGECATEGORYNAMES]) && !isset($frontpage[FRONTPAGECOURSELIST]) && $coursecount) {
$catimage = '<img src="'.$CFG->pixpath.'/i/course.gif" width="16" height="16" border="0" alt="" />'; $catimage = '<img src="'.$CFG->pixpath.'/i/course.gif" width="16" height="16" border="0" alt="" />';
} else { } else {
$catimage = "&nbsp;"; $catimage = "&nbsp;";
@ -1399,7 +1399,7 @@ function print_category_info($category, $depth) {
echo "\n\n".'<table border="0" cellpadding="3" cellspacing="0" width="100%">'; echo "\n\n".'<table border="0" cellpadding="3" cellspacing="0" width="100%">';
if (isset($frontpage[FRONTPAGECATEGORYNAMES]) && !isset($frontpage[FRONTPAGECOURSELIST]) && $coursecount) { if ($files and $coursecount) {
$courses = get_courses($category->id, 'c.sortorder ASC', 'c.id,c.sortorder,c.visible,c.fullname,c.shortname,c.password,c.summary,c.guest,c.cost,c.currency'); $courses = get_courses($category->id, 'c.sortorder ASC', 'c.id,c.sortorder,c.visible,c.fullname,c.shortname,c.password,c.summary,c.guest,c.cost,c.currency');
echo "<tr>"; echo "<tr>";

View file

@ -119,7 +119,13 @@
} }
} }
foreach (explode(',',$CFG->frontpage) as $v) { if (isloggedin() and !isguest() 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. switch ($v) { /// Display the main part of the front page.
case strval(FRONTPAGENEWS): case strval(FRONTPAGENEWS):
if ($SITE->newsitems) { // Print forums only when needed if ($SITE->newsitems) { // Print forums only when needed
@ -169,6 +175,15 @@
print_course_search('', false, 'short'); print_course_search('', false, 'short');
break; break;
case FRONTPAGECATEGORYCOMBO:
print_heading_block(get_string('categories'));
print_simple_box_start('center', '100%', '', 5, 'categorybox');
print_whole_category_list(NULL, NULL, NULL, -1, true);
print_simple_box_end();
print_course_search('', false, 'short');
break;
case FRONTPAGETOPICONLY: // Do nothing!! :-) case FRONTPAGETOPICONLY: // Do nothing!! :-)
break; break;

View file

@ -202,6 +202,7 @@ $string['optionalmaintenancemessage'] = 'Optional maintenance messsage';
$string['order1'] = 'First'; $string['order1'] = 'First';
$string['order2'] = 'Second'; $string['order2'] = 'Second';
$string['order3'] = 'Third'; $string['order3'] = 'Third';
$string['order4'] = 'Forth';
$string['pathdvips'] = 'Path of <i>dvips</i> binary'; $string['pathdvips'] = 'Path of <i>dvips</i> binary';
$string['pathconvert'] = 'Path of <i>convert</i> binary'; $string['pathconvert'] = 'Path of <i>convert</i> binary';
$string['pathlatex'] = 'Path of <i>latex</i> binary'; $string['pathlatex'] = 'Path of <i>latex</i> binary';

View file

@ -552,10 +552,12 @@ $string['formatweeks'] = 'Weekly format';
$string['formatweekscss'] = 'Weekly format - CSS/No tables'; $string['formatweekscss'] = 'Weekly format - CSS/No tables';
$string['formatwiki'] = 'Wiki-like format'; $string['formatwiki'] = 'Wiki-like format';
$string['from'] = 'From'; $string['from'] = 'From';
$string['frontpagecategorycombo'] = 'Combo list';
$string['frontpagecategorynames'] = 'List of categories'; $string['frontpagecategorynames'] = 'List of categories';
$string['frontpagecourselist'] = 'List of courses'; $string['frontpagecourselist'] = 'List of courses';
$string['frontpagedescription'] = 'Front Page Description'; $string['frontpagedescription'] = 'Front Page Description';
$string['frontpageformat'] = 'Front page format'; $string['frontpageformat'] = 'Front page format';
$string['frontpageformatloggedin'] = 'Front page format when logged in';
$string['frontpagenews'] = 'News items'; $string['frontpagenews'] = 'News items';
$string['frontpagetopiconly'] = 'Topic section'; $string['frontpagetopiconly'] = 'Topic section';
$string['fulllistofcourses'] = 'All courses'; $string['fulllistofcourses'] = 'All courses';