如何获取moodle中最受欢迎的课程列表

时间:2016-04-18 06:40:02

标签: moodle

有没有办法在moodle中显示最受欢迎的课程和类别列表。是否有任何内置插件,或者它只能通过编写自定义代码来完成。

1 个答案:

答案 0 :(得分:2)

你如何定义最流行的?注册的号码可能是定义最受欢迎的最有用的方式。

SELECT COUNT(*) AS enrolments, c.id, c.fullname
FROM mdl_course c
JOIN (SELECT DISTINCT e.courseid, ue.id AS userid
      FROM mdl_user_enrolments ue
      JOIN mdl_enrol e ON e.id = ue.enrolid) ue ON ue.courseid = c.id
GROUP BY c.id, c.fullname
ORDER BY 1 DESC, c.fullname

更新

在Moodle中使用

$sql = "SELECT c.id, c.fullname, COUNT(*) AS enrolments
        FROM mdl_course c
        JOIN (SELECT DISTINCT e.courseid, ue.id AS userid
              FROM {user_enrolments} ue
              JOIN {enrol} e ON e.id = ue.enrolid) ue ON ue.courseid = c.id
        GROUP BY c.id, c.fullname
        ORDER BY 3 DESC, c.fullname";
$course = $DB->get_record_sql($sql, array(), IGNORE_MULTIPLE);

echo $course->fullname;