]> git.mjollnir.org Git - moodle.git/commitdiff
Upgrading print_course to use roles properly
authormoodler <moodler>
Sat, 16 Sep 2006 15:23:41 +0000 (15:23 +0000)
committermoodler <moodler>
Sat, 16 Sep 2006 15:23:41 +0000 (15:23 +0000)
Added list for the teacher names for better XHTML

course/lib.php

index 561e28259557590cac427ae89597a10dbf02883f..34d265deee38a4bc0958288e896768dcd9de1901 100644 (file)
@@ -1510,33 +1510,40 @@ function print_course($course, $width="100%") {
 
     global $CFG, $USER;
 
-    require_once("$CFG->dirroot/enrol/enrol.class.php");
-
-    $enrol = enrolment_factory::factory($course->enrol);
+    $context = get_context_instance(CONTEXT_COURSE, $course->id);
 
-    print_simple_box_start("center", "$width", '', 5, "coursebox");
+    print_simple_box_start('center', $width, '', 5, 'coursebox');
 
-    $linkcss = $course->visible ? "" : " class=\"dimmed\" ";
+    $linkcss = $course->visible ? '' : ' class="dimmed" ';
 
-    echo "<table width=\"100%\">";
+    echo '<table width="100%">';
     echo '<tr valign="top">';
     echo '<td valign="top" width="50%" class="info">';
     echo '<b><a title="'.get_string('entercourse').'"'.
          $linkcss.' href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.
          $course->fullname.'</a></b><br />';
-    if ($teachers = get_course_teachers($course->id)) {
-        echo "<span class=\"teachers\">\n";
+
+    if ($teachers = get_users_by_capability($context, 'moodle/course:update')) {
+        $canseehidden = has_capability('moodle/role:viewhiddenassigns', $context);
+        $namesarray = array();
         foreach ($teachers as $teacher) {
-            if (empty($teacher->role)) {
-                $teacher->role = $course->teacher;
+            if (!$teacher->hidden || $canseehidden) {
+                $roles = get_user_roles($context, $teacher->id);
+                $role = array_shift($roles);  // First one
+                $fullname = fullname($teacher, has_capability('moodle/site:viewfullnames', $context));
+                $namesarray[] = format_string($role->name).': <a href="'.$CFG->wwwroot.'/user/view.php?id='.
+                                  $teacher->id.'&amp;course='.SITEID.'">'.$fullname.'</a>';
             }
-            $fullname = fullname($teacher, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id))); // is the USER a teacher of that course
-            echo $teacher->role.': <a href="'.$CFG->wwwroot.'/user/view.php?id='.$teacher->id.
-                '&amp;course='.SITEID.'">'.$fullname.'</a><br />';
         }
-        echo "</span>\n";
+        if ($namesarray) {
+            echo "<ul class=\"teachers\">\n<li>";
+            echo implode('</li><li>', $namesarray);
+            echo "</li></ul>";
+        }
     }
 
+    require_once("$CFG->dirroot/enrol/enrol.class.php");
+    $enrol = enrolment_factory::factory($course->enrol);
     echo $enrol->get_access_icons($course);
 
     echo '</td><td valign="top" width="50%" class="summary">';