成績排序

  1. 問題:成績綜覧查看成績,每門課的排序正確,但課程總數全都以目前瀏覧的課程計算。
  2. 解決
    1. 修改 grade/report/lib.php 中的 get_numusers 函式,增加參數 $context 傳入 course context object,若沒傳入,則使用目前的課程 context。
      [root@dywang report]# diff -uN ../../../moodle23.bak/grade/report/lib.php lib.php 
      --- ../../../moodle23.bak/grade/report/lib.php	2012-06-26 01:14:18.000000000 +0800
      +++ lib.php	2019-06-24 20:29:46.146863831 +0800
      @@ -270,9 +270,12 @@
            * @param boolean $groups include groups limit
            * @return int Count of users
            */
      -    public function get_numusers($groups=true) {
      +    public function get_numusers($groups=true,$context) {
               global $CFG, $DB;
      -
      +		$arr = (array)$context;
      +		if (empty($arr)) {
      +			$context = clone $this->context;
      +		}
               $groupsql      = "";
               $groupwheresql = "";
       
      @@ -280,7 +283,7 @@
               list($gradebookrolessql, $gradebookrolesparams) = $DB->get_in_or_equal(explode(',', $this->gradebookroles), SQL_PARAMS_NAMED, 'grbr0');
       
               //limit to users with an active enrollment
      -        list($enrolledsql, $enrolledparams) = get_enrolled_sql($this->context);
      +        list($enrolledsql, $enrolledparams) = get_enrolled_sql($context);
       
               $params = array_merge($gradebookrolesparams, $enrolledparams);
       
      @@ -300,7 +303,7 @@
                             WHERE ra.roleid $gradebookrolessql
                                   AND u.deleted = 0
                                   $groupwheresql
      -                            AND ra.contextid ".get_related_contexts_string($this->context);
      +                            AND ra.contextid ".get_related_contexts_string($context);
               return $DB->count_records_sql($countsql, $params);
           }
      
    2. 修改 grade/report/overview/lib.php ,在課程迴圈中才呼叫 get_numusers 函式,且傳入課程的 $context
      [root@dywang report]# diff -uN ../../../moodle23.bak/grade/report/overview/lib.php overview/lib.php 
      --- ../../../moodle23.bak/grade/report/overview/lib.php	2012-06-26 01:14:18.000000000 +0800
      +++ overview/lib.php	2019-06-24 20:33:38.035843359 +0800
      @@ -115,7 +115,6 @@
       
               // MDL-11679, only show user's courses instead of all courses
               if ($courses = enrol_get_users_courses($this->user->id, false, 'id, shortname, showgrades')) {
      -            $numusers = $this->get_numusers(false);
       
                   foreach ($courses as $course) {
                       if (!$course->showgrades) {
      @@ -123,6 +122,7 @@
                       }
       
                       $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
      +            $numusers = $this->get_numusers(false, $coursecontext);
       
                       if (!$course->visible && !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
                           // The course is hidden and the user isn't allowed to see it