LoginSignup
1
0

More than 5 years have passed since last update.

Moodleのユーザリストを発音順に表示されるように変更する

Last updated at Posted at 2017-11-19

Moodleの仕様

Moodle 2.6からユーザ情報にfirstnamephonetic、lastnamephoneticなどのフィールドが追加されたが、実際にはほとんど利用されていない。
そのため、実際にはユーザリスト表示時などではユーザ氏名のUnicodeコード順で表示されることが多い。これはアルファベットで氏名を表示する場合には問題ないが、漢字などを用いる場合には意味の無い並び順になってしまう。

修正方法

Moodleの下記の箇所でユーザリストの並び順を決定している。この場所でlastname, firstnameの代わりにlastnamephonetic, firstnamephoneticを利用するよう変更する。

コースへのユーザ登録などの場合@Moodle3.2

lib/datalib.php の $sort を変更する。

lib/datalib.php
function users_order_by_sql($usertablealias = '', $search = null, context $context = null) {
    global $DB, $PAGE;

    if ($usertablealias) {
        $tableprefix = $usertablealias . '.';
    } else {
        $tableprefix = '';
    }

-   $sort = "{$tableprefix}lastname, {$tableprefix}firstname, {$tableprefix}id";
+   $sort = "{$tableprefix}lastnamephonetic, {$tableprefix}firstnamephonetic, {$tableprefix}id";
    $params = array();

    if (!$search) {
        return array($sort, $params);
    }

    if (!$context) {
        $context = $PAGE->context;
    }

クイックメールブロックの場合@v1.5.5

blocks/quickmail/lib.php
    public static function get_non_suspended_users($context, $courseid){
        global $DB, $CFG;
        $everyone = self::get_all_users($context);

        $get_name_string = 'u.firstname, u.lastname';

        if($CFG->version >= 2013111800){
               $get_name_string = get_all_user_name_fields(true, 'u');
        }

        $sql = "SELECT u.id, " . $get_name_string . " , u.email, u.mailformat, u.suspended, u.maildisplay, ue.status  
            FROM {user} u  
                JOIN {user_enrolments} ue                 
                    ON u.id = ue.userid 
                JOIN {enrol} en
                    ON en.id = ue.enrolid                     
                WHERE en.courseid = ?
                    AND ue.status = ?
-               ORDER BY u.lastname, u.firstname"; 
+               ORDER BY u.lastnamephonetic, u.firstnamephonetic"; 

        //let's use a recordset in case the enrollment is huge
        $rs_valids = $DB->get_recordset_sql($sql, array($courseid, 0));

        //container for user_enrolments records
        $valids = array();

以降、必要に応じて追記

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0