利用停止アカウントが手動登録に表示される

利用停止アカウントが手動登録に表示される

- Yuuki Murakami の投稿
返信数: 8

いつもお世話になっております。村上です。

Moodle3.8.1 でMoodleを利用しております。
ユーザから利用停止にしたアカウントも手動登録の
受講未登録ユーザに表示される仕様になっていると思いますが
利用停止にしたユーザを一覧に表示されない方法はありますでしょうか?


Yuuki Murakami への返信

Re: 利用停止アカウントが手動登録に表示される

- Mitsuhiro Yoshida の投稿
画像 Developers 画像 Particularly helpful Moodlers 画像 Translators

大変お手数ですが、ご質問内容に関しまして、以下の手順をお教え頂けませんでしょうか。

  • ユーザが自分のアカウントを利用停止にする方法
  • 受講未登録ユーザにユーザを表示する方法
Mitsuhiro Yoshida への返信

Re: 利用停止アカウントが手動登録に表示される

- Yuuki Murakami の投稿
恐れ入ります。村上です。
書き方が悪かったですので、再度書き直します。

管理者ユーザにて大学を退学などして、対象ユーザではなくなったため、
アナウンスメントの強制購読でのUser Unknownを避けるためにも
プロフィール内の「利用停止アカウント」にチェックを入れるか、
下の目のアイコンを閉じて利用停止にしています。

 

この状態で手動登録したところ、利用停止しているstudent02とteacher02 ユーザが一覧で表示されるが
利用停止(退学)になっているので、一覧には表示しないで欲しいという問い合わせになります。

 
※訳あって、利用停止アカウントを削除が出来ない状態です。物理削除をすれば受講未登録ユーザには
 表示されない状態であるのはわかりますが、現状、削除が出来ない状態である事はご了承くださいませ。


 問い合わせとしては「利用停止アカウントしたstudent02とteacher02が受験未登録ユーザの
 一覧に表示されているが、停止アカウントは一覧には表示されないようにする事は可能か」
 になります。

 宜しくお願い致します。
Yuuki Murakami への返信

Re: 利用停止アカウントが手動登録に表示される

- Mitsuhiro Yoshida の投稿
画像 Developers 画像 Particularly helpful Moodlers 画像 Translators

ありがとうございます。

Moodle Trackerでも以下のように利用停止ユーザを表示しないオプションが提案されているようですね。

[[MDL-35731] Hide (or option to hide) users with suspended enrolments in multiple areas - Moodle Tracker]
https://tracker.moodle.org/browse/MDL-35731

恐らく、以下のプログラム修正でご希望の動くに近くなるかと思います。

修正対象プログラム:
user/lib.php

修正箇所:
1477行目

[ 修正前 ]
    if (!empty($additionalwhere)) {
        $wheres[] = $additionalwhere;
        $params = array_merge($params, $additionalparams);
    }

    $from = implode("\n", $joins);
    if ($wheres) {
        $where = 'WHERE ' . implode(' AND ', $wheres);
    } else {
        $where = '';
    }

[ 修正後 ]
    if (!empty($additionalwhere)) {
        $wheres[] = $additionalwhere;
        $params = array_merge($params, $additionalparams);
    }

    // exclude suspended users
    $wheres[] = "u.suspended = 0";

    $from = implode("\n", $joins);
    if ($wheres) {
        $where = 'WHERE ' . implode(' AND ', $wheres);
    } else {
        $where = '';
    }
Mitsuhiro Yoshida への返信

Re: 利用停止アカウントが手動登録に表示される

- Yuuki Murakami の投稿

ありがとうございます。

早速修正を行いましたが、表示は変わらないですね。
教えていただいた箇所以外に修正する場所はありますでしょうか?

Yuuki Murakami への返信

Re: 利用停止アカウントが手動登録に表示される

- Mitsuhiro Yoshida の投稿
画像 Developers 画像 Particularly helpful Moodlers 画像 Translators

大変失礼しました。

以下のプログラム修正ではいかがでしょうか。

修正対象プログラム:
enrol/manual/locallib.php

修正箇所:
120行目

[ 修正前 ]
    public function find_users($search) {
        global $DB;
        // By default wherecondition retrieves all users except the deleted, not confirmed and guest.
        list($wherecondition, $params) = $this->search_sql($search, 'u');
        $params['enrolid'] = $this->enrolid;

        $fields      = 'SELECT ' . $this->required_fields_sql('u');
        $countfields = 'SELECT COUNT(1)';

        $sql = " FROM {user} u
                 JOIN {user_enrolments} ue ON (ue.userid = u.id AND ue.enrolid = :enrolid)
                WHERE $wherecondition";

[ 修正後 ]
    public function find_users($search) {
        global $DB;
        // By default wherecondition retrieves all users except the deleted, not confirmed and guest.
        list($wherecondition, $params) = $this->search_sql($search, 'u');
        $params['enrolid'] = $this->enrolid;

        $fields      = 'SELECT ' . $this->required_fields_sql('u');
        $countfields = 'SELECT COUNT(1)';

        $wherecondition = "$wherecondition AND u.suspended = 0";

        $sql = " FROM {user} u
                 JOIN {user_enrolments} ue ON (ue.userid = u.id AND ue.enrolid = :enrolid)
                WHERE $wherecondition";
Mitsuhiro Yoshida への返信

Re: 利用停止アカウントが手動登録に表示される

- Yuuki Murakami の投稿

Yoshida様、ありがとうございます。

ソースを修正していました。
結果は以下の通りになりました。

1. student02とteacher02は利用停止にしているユーザですが、表示されています。

    画面の4名を全員追加すると

 

2. 利用停止にしているstudent02とteacher02は表示されなくなりました。

 

動きとしては問題ないと思いますが、1.の時点で「受験未登録ユーザ」の段階で
利用停止ユーザを表示させないようにする事は難しいでしょうか?

具体的には退学・除籍などで既に学校にいないユーザになるため、既に学校にいない
ユーザがなぜ表示されているかという問い合わせが質問させていただいた発端となります。

可能であれば1の段階で表示されないようにするのは難しいでしょうか?

質問ばかりして申し訳ありませんが、宜しくお願い致します。


Yuuki Murakami への返信

Re: 利用停止アカウントが手動登録に表示される

- Mitsuhiro Yoshida の投稿
画像 Developers 画像 Particularly helpful Moodlers 画像 Translators

大変失礼しました。ユーザ検索の関数 (find_users()) が未登録ユーザ用 (Enrol candidates) と登録済みユーザ用 (Enrolled users) の2箇所にありました。

大変お手数ですが、以下のプログラム修正をお試しください。

修正対象プログラム:
enrol/manual/locallib.php

修正箇所:
55行目

[ 修正前 ]
    public function find_users($search) {
        global $DB;
        // By default wherecondition retrieves all users except the deleted, not confirmed and guest.
        list($wherecondition, $params) = $this->search_sql($search, 'u');
        $params['enrolid'] = $this->enrolid;

        $fields      = 'SELECT ' . $this->required_fields_sql('u');
        $countfields = 'SELECT COUNT(1)';

        $sql = " FROM {user} u
            LEFT JOIN {user_enrolments} ue ON (ue.userid = u.id AND ue.enrolid = :enrolid)
                WHERE $wherecondition
                      AND ue.id IS NULL";

[ 修正後 ]
    public function find_users($search) {
        global $DB;
        // By default wherecondition retrieves all users except the deleted, not confirmed and guest.
        list($wherecondition, $params) = $this->search_sql($search, 'u');
        $params['enrolid'] = $this->enrolid;

        $fields      = 'SELECT ' . $this->required_fields_sql('u');
        $countfields = 'SELECT COUNT(1)';

        $wherecondition = "$wherecondition AND u.suspended = 0";
 
        $sql = " FROM {user} u
            LEFT JOIN {user_enrolments} ue ON (ue.userid = u.id AND ue.enrolid = :enrolid)
                WHERE $wherecondition
                      AND ue.id IS NULL";

------------------------------------------

修正箇所:
120行目

[ 修正前 ]
    public function find_users($search) {
        global $DB;
        // By default wherecondition retrieves all users except the deleted, not confirmed and guest.
        list($wherecondition, $params) = $this->search_sql($search, 'u');
        $params['enrolid'] = $this->enrolid;

        $fields      = 'SELECT ' . $this->required_fields_sql('u');
        $countfields = 'SELECT COUNT(1)';

        $sql = " FROM {user} u
                 JOIN {user_enrolments} ue ON (ue.userid = u.id AND ue.enrolid = :enrolid)
                WHERE $wherecondition";

[ 修正後 ]
    public function find_users($search) {
        global $DB;
        // By default wherecondition retrieves all users except the deleted, not confirmed and guest.
        list($wherecondition, $params) = $this->search_sql($search, 'u');
        $params['enrolid'] = $this->enrolid;

        $fields      = 'SELECT ' . $this->required_fields_sql('u');
        $countfields = 'SELECT COUNT(1)';

        $wherecondition = "$wherecondition AND u.suspended = 0";

        $sql = " FROM {user} u
                 JOIN {user_enrolments} ue ON (ue.userid = u.id AND ue.enrolid = :enrolid)
                WHERE $wherecondition";
Mitsuhiro Yoshida への返信

Re: 利用停止アカウントが手動登録に表示される

- Yuuki Murakami の投稿

Yoshida様、ありがとうございます。

今回の修正で受講未登録ユーザの方も利用停止アカウントは
非表示になりました。

本番サーバでも修正を行いたいと思います。

何度も対応していただき、ありがとうございました。

以上、宜しくお願い致します。