「開発:ブロック/付録B」の版間の差分

提供:MoodleDocs
移動先:案内検索
80行目: 80行目:
# '''weeks''' は、'''course-view-weeks''' になるべきです。
# '''weeks''' は、'''course-view-weeks''' になるべきです。


あなたは、ユーザが活動モジュールに入ったときに表示されるイントロダクションのように、ブロックを他のページでも表示できるようになったことに留意してください。You might therefore need to make the specification for applicable formats more restrictive to keep your block out of pages it is not supposed to be shown in. Also, there are subtle changes to the way that the final decision to allow or disallow a block is made. For the technical details refer to the definition of [[Development:Blocks/Appendix_A#applicable_formats.28.29| applicable_formats()]], and for a more extended example read [[Development:Blocks#Authorized_Personnel_Only|Authorized Personnel Only]], the section dedicated to this subject.
あなたは、ユーザが活動モジュールに入ったときに表示されるイントロダクションのように、ブロックを他のページでも表示できるようになったことに留意してください。そのため、表示されてはいけないブロックをページから遠ざけるため、適用できるフォーマットをさらに制限するようにしてください。You might therefore need to make the specification for applicable formats more restrictive to keep your block out of pages it is not supposed to be shown in. Also, there are subtle changes to the way that the final decision to allow or disallow a block is made. For the technical details refer to the definition of [[Development:Blocks/Appendix_A#applicable_formats.28.29| applicable_formats()]], and for a more extended example read [[Development:Blocks#Authorized_Personnel_Only|Authorized Personnel Only]], the section dedicated to this subject.


That's everything; your block will now be ready for use in Moodle 1.5!
That's everything; your block will now be ready for use in Moodle 1.5!

2009年6月20日 (土) 15:38時点における版

作成中です - Mitsuhiro Yoshida 2009年5月26日 (火) 15:58 (UTC)

Moodle 1.5以前のバージョンとのブロックAPIの違い

この付録では、Moodle 1.5に取り入れられたブロックAPIがどのように変わったのか説明します。また、Moodle 1.5と完全互換性を持つため、開発者がどのようなステップでブロックをアップデートする必要があるのか説明します。残念ですが、これらの変更で下位互換性が壊れてしまいます。これは、Moodle 1.4からのブロックが1.5で動作しないこと、またその逆も同じであることを意味します。

クラス命名規則が変わりました。

Moodle 1.4では、すべてのクラスはCourseBlock_somethingのような名称にする必要がありました。そして、導かれたベースクラスは、MoodleBlockでした。Moodleのオブジェクト指向の側面と一致させるため、これが変わったのがMoodle 1.5です (例えば、クラス enrolment_base、resource_base等があります)。新しいブロッククラスは、代わりにblock_somethingのように命名され、block_baseから導かれます。これは、Moodle 1.5と互換性があるブロックを作成するには、あなたはクラス定義を

class CourseBlock_online_users extends MoodleBlock { ... }

から

class block_online_users extends block_base { ... }

に変更する必要があることを意味します。

上記の例外は、任意のテキストを表示する代わりに、ブロックがアイテム一覧を表示する特別なケースです。この場合、ブロッククラスは、代わりに次のようにblock_listから導かれるべきです:

class block_admin extends block_list { ... }

コンストラクタ VS init()

Moodle 1.4における、それぞれのブロッククラスでは、コースデータを引数として受けるコンストラクタの定義は必須でした (以下の例は、実際のオンラインユーザブロックからです):

function CourseBlock_online_users ($course) {

 $this->title        = get_string('blockname','block_online_users');
 $this->content_type = BLOCK_TYPE_TEXT;
 $this->course       = $course;
 $this->version      = 2004052700;

}

対照的にMoodle 1.5において、コンストラクタは取り除かれ、あなたは、代わりに引数を取得しない init()メソッドを定義する必要があります:

function init() {

 $this->title   = get_string('blockname','block_online_users');
 $this->version = 2004111600;

}

もちろん、これは、あなたが実際に必要とする$courseオブジェクトにアクセスしないままになります。恐らく、 get_content()内部で必要なため、$courseオブジェクトを取得するコードは以下のようになります:

 $course = get_record('course', 'id', $this->instance->pageid);

get_content()に加えて、他のメソッド内部から$courseにアクセスする必要がある場合、同じクエリの複数回実行を避けるため、あなたは、 specialization()メソッド内部から$courseオブジェクトを取得して、後で使用するクラス変数として保存することができます。:

function specialization() {

 $this->course = get_record('course', 'id', $this->instance->pageid);

}

設定付きブロック

Moodle 1.4では、ブロックは、新しい「インスタンス設定 (instance configuration)」と区別するため、現在 (Moodle 1.5) 「グローバル設定 (global configuration)」と呼ばれるオプションのみ持つことができました。あなたのブロックが設定をサポートする場合、あなたは以下の対策を講じる必要があります:

  1. あなたのconfig.htmlファイルをconfig_global.htmlにリネームします。
  2. 新しくリネームしたファイルを編集して、<form>タグを完全に取り除いてください (Moodleは、あなたの設定をフォーム内に自動的に組み込みます)。
  3. HTMLの<input>タグを使用している場合、あなたの設定以外にも影響を及ぼします (例 "sesskey")。ですから、同様に<input>タグも取り除いてください (Moodleは必要に応じて自動的に<input>タグ等を追加します)。
  4. print_configをオーバーライドしている場合、あなたのメソッドをconfig_print()にリネームしてください。
  5. handle_configをオーバーライドしている場合、あなたのメソッドをconfig_save()にリネームしてください。

特別に適用可能なフォーマットのブロック

あなたが許可または許可したくないブロックの存在を指定する正しい方法は、ブロックがコースだけに制限されないことを考慮して、Moodle 1.5のために再開発されました。ブロックに意図された動作を保持するには、あなたのブロックで使用されている場合、以下のフォーマット名 ( applicable_formats() の戻り値の配列キー) を変更する必要があります:

  1. social は、course-view-social になるべきです。
  2. topics は、course-view-topics になるべきです。
  3. weeks は、course-view-weeks になるべきです。

あなたは、ユーザが活動モジュールに入ったときに表示されるイントロダクションのように、ブロックを他のページでも表示できるようになったことに留意してください。そのため、表示されてはいけないブロックをページから遠ざけるため、適用できるフォーマットをさらに制限するようにしてください。You might therefore need to make the specification for applicable formats more restrictive to keep your block out of pages it is not supposed to be shown in. Also, there are subtle changes to the way that the final decision to allow or disallow a block is made. For the technical details refer to the definition of applicable_formats(), and for a more extended example read Authorized Personnel Only, the section dedicated to this subject.

That's everything; your block will now be ready for use in Moodle 1.5!