]> git.mjollnir.org Git - moodle.git/commitdiff
replacing legacy calls
authortoyomoyo <toyomoyo>
Thu, 14 Sep 2006 03:18:55 +0000 (03:18 +0000)
committertoyomoyo <toyomoyo>
Thu, 14 Sep 2006 03:18:55 +0000 (03:18 +0000)
file.php
lib/datalib.php

index 190208cced7c420ddbc0a380623bbcbafbd82fe3..29e114e1e1ffb5f3c7719b155d01c558a968d9c6 100644 (file)
--- a/file.php
+++ b/file.php
     // warning: it may break backwards compatibility
     if ((!empty($CFG->preventaccesstohiddenfiles)) 
         and (count($args) >= 2)
-        and (!isteacher($course->id))) {
+        and (!has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_COURSE, $course->id))) {
 
         $reference = ltrim($relativepath, "/{$args[0]}/");
 
index 6f800d6001e6fa6163582e3b53a260f94ed2592f..ce1932b0b222361856c3006cfb9010c31e876031 100644 (file)
@@ -584,14 +584,29 @@ function get_courses_page($categoryid="all", $sort="c.sortorder ASC", $fields="c
  * @param int $userid The user of interest
  * @param string $sort ?
  * @return object {@link $COURSE} records
- * @todo XXX Convert to Roles
  */
 function get_my_courses($userid, $sort='visible DESC,sortorder ASC') {
 
     global $CFG, $USER;
 
-    $course = array();
+    $mycourses = array();
+    $SQL = "SELECT * from {$CFG->prefix}course WHERE 1 ORDER BY $sort";
+    $courses = get_records_sql($SQL);
+    
+    foreach ($courses as $course) {
+        if ($course->id != SITEID) {
+            // users with moodle/course:view are considered course participants
+            // the course needs to be visible, or user must have moodle/course:viewhiddencourses capability set to view
+            // hidden courses  
+            if (has_capability('moodle/course:view', get_context_instance(CONTEXT_COURSE, $course->id), $userid)
+                && ($course->visible || has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course->id), $userid))) {
+                $mycourses[] = $course;
+            }
+        }
+    }
 
+    return $mycourses;
+/*
     if ($students = get_records('user_students', 'userid', $userid, '', 'id, course')) {
         foreach ($students as $student) {
             $course[$student->course] = $student->course;
@@ -620,7 +635,7 @@ function get_my_courses($userid, $sort='visible DESC,sortorder ASC') {
     $courseids = implode(',', $course);
 
     return get_records_list('course', 'id', $courseids, $sort);
-
+*/
 //  The following is correct but VERY slow with large datasets
 //
 //    return get_records_sql("SELECT c.*