Hi all,
I use Moodle 1.9.5 with Anomaly and the automatic menu bar from Chen ZhongWei. In the Moodlelike theme, I saw “my courses” and I tried to adapt the code. Until now I was unable to produce the list of my courses with the automatic menu. Only the tab appears in the menu bar. We don’t use “my Moodle” at our site.
Can somebody help me to get a list of my courses into the menu bar? Any help is greatly appreciated.
With kind regards,
Hartmut
回复Hartmut Scherer
Re: How can I see a list of my courses in the menu bar in Anomaly?
Hi all,
I am still looking for help. Can somebody advise me how to get a list of my courses into the menu bar without using "my Moodle"? I inserted the code that needs to revised.
With kind regards,
Hartmut
<div style="width:100%;margin-top: 0px;">
<table cellpadding=0 cellspacing=0 style="width:100%; ">
<td style="width:100%; " >
<ul id="qm0" class="qmmc">
<?php
echo '<li><span class="qmdivider qmdividery" ></span></li>';
$text ='<li><a class="qmparent" href="'.$CFG->wwwroot.'/">Home</a>';
$text .= '</li>';
echo $text;
print_whole_category_list_menu();
if (isloggedin()) {
echo '<li><span class="qmdivider qmdividery" ></span></li>';
$text ='<li><a class="qmparent" href=" '.$CFG->wwwroot.'/">My Courses</a>';
$text .='<ul>';
$text .='<li><a href=\' '.$CFG->wwwroot.'/course/\'>All Courses...</a></li>';
$text .= '</ul></li>';
echo $text;
//Get my courses
$courses_my = get_my_courses($USER->id, 'visible DESC,sortorder ASC', '*', false, 21);
//
foreach ($courses_my as $c) {
if (isset($USER->lastcourseaccess[$c->id])) {
$courses_my[$c->id]->lastaccess = $USER->lastcourseaccess[$c->id];
} else {
$courses_my[$c->id]->lastaccess = 0;
}
}
//
//
if (empty($courses_my)) {
//Do nothing
} else {
foreach ($courses_my as $c) {
$content .= '<a href=\' '.$CFG->wwwroot.'/course/view.php?id='.$c->id.'\'>'.$c->fullname.'</a>';
}
}
//
echo $content;
echo '<a href=\' '.$CFG->wwwroot.'/course/\'>All Courses...</a>';
}
function print_whole_category_list_menu($category=NULL, $displaylist=NULL, $parentslist=NULL, $depth=-1, $files = true) {
/// Recursive function to print out all the categories in a nice format
/// with or without courses included
//global $CFG;
if (isset($CFG->max_category_depth) && ($depth >= $CFG->max_category_depth)) {
return;
}
if ($category) {
if ($category->visible or has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM))) {
print_category_info_menu($category, $depth, $files, $left);
} else {
return; // Don't bother printing children of invisible categories
}
} else {
$category->id = "0";
}
if ($categories = get_child_categories($category->id)) { // Print all the children recursively
$countcats = count($categories);
$count = 0;
$first = true;
$last = false;
foreach ($categories as $cat) {
$count++;
if ($count == $countcats) {
$last = true;
}
$up = $first ? false : true;
$down = $last ? false : true;
$first = false;
print_whole_category_list_menu($cat, $displaylist, $parentslist, $depth + 1, $files);
echo '</ul></li>';
}
}
}
function print_category_info_menu($category, $depth, $files = false) {
/// Prints the category info in indented fashion
/// This function is only used by print_whole_category_list() above
//global $CFG;
$coursecount = count_records('course') <= FRONTPAGECOURSELIMIT;
$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');
if ($depth) {
echo '<li><span class="qmdivider qmdividerx" ></span></li>';
if ($category->visible) {
echo '<li><a class="qmparent" href="'.$CFG->wwwroot.'/course/category.php?id='.$category->id.'">'.format_string($category->name).'</a>';
} else {
echo '<li><a class="invisiblecategory" href="'.$CFG->wwwroot.'/course/category.php?id='.$category->id.'">'.format_string($category->name).'</a>';
}
} else {
echo '<li><span class="qmdivider qmdividery" ></span></li>';
if ($category->visible) {
echo '<li><a class="qmparent" href="'.$CFG->wwwroot.'/course/category.php?id='.$category->id.'">'.format_string($category->name).'</a>';
} else {
echo '<li><a class="invisiblecategory" href="'.$CFG->wwwroot.'/course/category.php?id='.$category->id.'">'.format_string($category->name).'</a>';
}
}
if ($files and $coursecount) {
echo '<ul>';
if ($courses && !(isset($CFG->max_category_depth)&& ($depth>=$CFG->max_category_depth - 1))) {
foreach ($courses as $course) {
if ($course->visible) {
echo '<li><a href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.format_string($course->fullname).'</a></li>';
} else {
echo '<li><a class="invisiblecourse" href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.format_string($course->fullname).'</a></li>';
}
}
}
}
}
?>
<li class="qmclear"> </li></ul>
</td></tr></table>
</div>
<!-- Create Menu Settings: (Menu ID, Is Vertical, Show Timer, Hide Timer, On Click ('all', 'main' or 'lev2'), Right to Left, Horizontal Subs, Flush Left, Flush Top) -->
<script type="text/javascript">qm_create(0,false,100,300,false,false,false,false,false);</script>
I am still looking for help. Can somebody advise me how to get a list of my courses into the menu bar without using "my Moodle"? I inserted the code that needs to revised.
With kind regards,
Hartmut
<div style="width:100%;margin-top: 0px;">
<table cellpadding=0 cellspacing=0 style="width:100%; ">
<td style="width:100%; " >
<ul id="qm0" class="qmmc">
<?php
echo '<li><span class="qmdivider qmdividery" ></span></li>';
$text ='<li><a class="qmparent" href="'.$CFG->wwwroot.'/">Home</a>';
$text .= '</li>';
echo $text;
print_whole_category_list_menu();
if (isloggedin()) {
echo '<li><span class="qmdivider qmdividery" ></span></li>';
$text ='<li><a class="qmparent" href=" '.$CFG->wwwroot.'/">My Courses</a>';
$text .='<ul>';
$text .='<li><a href=\' '.$CFG->wwwroot.'/course/\'>All Courses...</a></li>';
$text .= '</ul></li>';
echo $text;
//Get my courses
$courses_my = get_my_courses($USER->id, 'visible DESC,sortorder ASC', '*', false, 21);
//
foreach ($courses_my as $c) {
if (isset($USER->lastcourseaccess[$c->id])) {
$courses_my[$c->id]->lastaccess = $USER->lastcourseaccess[$c->id];
} else {
$courses_my[$c->id]->lastaccess = 0;
}
}
//
//
if (empty($courses_my)) {
//Do nothing
} else {
foreach ($courses_my as $c) {
$content .= '<a href=\' '.$CFG->wwwroot.'/course/view.php?id='.$c->id.'\'>'.$c->fullname.'</a>';
}
}
//
echo $content;
echo '<a href=\' '.$CFG->wwwroot.'/course/\'>All Courses...</a>';
}
function print_whole_category_list_menu($category=NULL, $displaylist=NULL, $parentslist=NULL, $depth=-1, $files = true) {
/// Recursive function to print out all the categories in a nice format
/// with or without courses included
//global $CFG;
if (isset($CFG->max_category_depth) && ($depth >= $CFG->max_category_depth)) {
return;
}
if ($category) {
if ($category->visible or has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM))) {
print_category_info_menu($category, $depth, $files, $left);
} else {
return; // Don't bother printing children of invisible categories
}
} else {
$category->id = "0";
}
if ($categories = get_child_categories($category->id)) { // Print all the children recursively
$countcats = count($categories);
$count = 0;
$first = true;
$last = false;
foreach ($categories as $cat) {
$count++;
if ($count == $countcats) {
$last = true;
}
$up = $first ? false : true;
$down = $last ? false : true;
$first = false;
print_whole_category_list_menu($cat, $displaylist, $parentslist, $depth + 1, $files);
echo '</ul></li>';
}
}
}
function print_category_info_menu($category, $depth, $files = false) {
/// Prints the category info in indented fashion
/// This function is only used by print_whole_category_list() above
//global $CFG;
$coursecount = count_records('course') <= FRONTPAGECOURSELIMIT;
$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');
if ($depth) {
echo '<li><span class="qmdivider qmdividerx" ></span></li>';
if ($category->visible) {
echo '<li><a class="qmparent" href="'.$CFG->wwwroot.'/course/category.php?id='.$category->id.'">'.format_string($category->name).'</a>';
} else {
echo '<li><a class="invisiblecategory" href="'.$CFG->wwwroot.'/course/category.php?id='.$category->id.'">'.format_string($category->name).'</a>';
}
} else {
echo '<li><span class="qmdivider qmdividery" ></span></li>';
if ($category->visible) {
echo '<li><a class="qmparent" href="'.$CFG->wwwroot.'/course/category.php?id='.$category->id.'">'.format_string($category->name).'</a>';
} else {
echo '<li><a class="invisiblecategory" href="'.$CFG->wwwroot.'/course/category.php?id='.$category->id.'">'.format_string($category->name).'</a>';
}
}
if ($files and $coursecount) {
echo '<ul>';
if ($courses && !(isset($CFG->max_category_depth)&& ($depth>=$CFG->max_category_depth - 1))) {
foreach ($courses as $course) {
if ($course->visible) {
echo '<li><a href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.format_string($course->fullname).'</a></li>';
} else {
echo '<li><a class="invisiblecourse" href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.format_string($course->fullname).'</a></li>';
}
}
}
}
}
?>
<li class="qmclear"> </li></ul>
</td></tr></table>
</div>
<!-- Create Menu Settings: (Menu ID, Is Vertical, Show Timer, Hide Timer, On Click ('all', 'main' or 'lev2'), Right to Left, Horizontal Subs, Flush Left, Flush Top) -->
<script type="text/javascript">qm_create(0,false,100,300,false,false,false,false,false);</script>
回复Hartmut Scherer
Re: How can I see a list of my courses in the menu bar in Anomaly?
回复Patrick Malley