「開発:評定表レポートチュートリアル」の版間の差分

提供:MoodleDocs
移動先:案内検索
(done.)
 
(同じ利用者による、間の44版が非表示)
1行目: 1行目:
作成中です - [[利用者:Mitsuhiro Yoshida|Mitsuhiro Yoshida]]
== イントロダクション==
== イントロダクション==
Moodle 1.9で新しく実装された素晴らしい機能のひとつにプラグインレポートのサポートがあります。いくつかのレポートはすでに実装されていますが、様々な種類の新しいレポートを素早く簡単に作成することができます。
Moodle 1.9で新しく実装された素晴らしい機能のひとつにプラグインレポートのサポートがあります。いくつかのレポートはすでに実装されていますが、様々な種類の新しいレポートを素早く簡単に作成することができます。


このページはMoodle評定表に新しいレポートを作成するための簡単なチュートリアルです。最初のセクションはあなたのプラグインが検出され利用可能にするための基本的なセットアップのステップに焦点を合わせています。2番目のセクションでは考えられる実装例を説明しています。しあkし、あなたはこれらの提案を参考にせず自由に開発することができます。
このページはMoodle評定表に新しいレポートを作成するための簡単なチュートリアルです。最初のセクションではあなたのプラグインが検出され利用可能にするための基本的なセットアップのステップに焦点を合わせています。2番目のセクションでは考えられる実装例を説明しています。もちろん、あなたはこれらの提案を参考にせず自由に開発することができます。


このガイドを読む上で、最もシンプルなレポート例は'''grade/report/overview'''です。
このガイドを読む上での最もシンプルなレポート例は'''grade/report/overview'''です。


== 最小限度 ==
== 最小限度 ==
52行目: 50行目:
あなたのレポートに新しいリンクを作成する必要はありません。あなたがすべてのステップに従った場合、レポートは自動的に検出され、評定表プラグインドロップダウンメニュー内に追加されます!
あなたのレポートに新しいリンクを作成する必要はありません。あなたがすべてのステップに従った場合、レポートは自動的に検出され、評定表プラグインドロップダウンメニュー内に追加されます!


あなたが新しいレポートを作成するときに必要なものはこれですべでです! もちろん、あなたは何かをするため、通常データを取得して表示するためのコードを書くことでしょう。次のセクションではflexitableを使用する簡単なアプローチに関して話しましょう。
あなたが新しいレポートを作成するときに必要なものはこれですべてです! もちろん、通常、あなたは何かをするためにデータを取得して表示するためのコードを書くことでしょう。次のセクションではflexitableを使用する簡単なアプローチに関して話しましょう。


== 考え得るステップ 7 ==
== 考え得るステップ 7 ==
60行目: 58行目:
== 考え得るステップ 8 ==
== 考え得るステップ 8 ==


レポートを複数ユーザが利用できる場合、あなたのMoodleの管理セクションに移動して、通常のアップグレードと同じようにテーブルを更新する必要があります。その後、ロールの定義に移動して、あなたの設定が正しいかどうか確認してください。私はMoodle 1.9を使用しています。
レポートを複数ユーザが利用できるようにする場合、あなたのMoodleの管理セクションに移動して、通常のアップグレードと同じようにテーブルを更新する必要があります。その後、ロールの定義に移動して、あなたの設定が正しいかどうか確認してください。私はMoodle 1.9を使用しています。


== grade_reportクラスを拡張する ==  
== grade_reportクラスを拡張する ==  
   
   
You are free to develop that class any way you want, but by using the existing methods set up in grade_report, you can avoid tedious repetition of code. We use flexitable for simple reports, as you can see in the user report (grade_report_user class).    The rest of this tutorial will follow the path of flexitable.
あなたは自由に自分のやりかたでクラスを開発することができます。しかし、grade_repot内に配置されている既存のメソッドを使用することで、退屈なコードの繰り返しを避けることができます。私たちはシンプルなレポートにユーザレポート (grade_report_user class) 内にあるflextitableを使用します。このチュートリアルの残りの部分で、私たちはfulexitableについて取り上げてみます。


=== 新しいファイル ===
=== 新しいファイル ===
#Create a lib.php file (or copy it from other report).
#lib.phpファイルを作成してください (または他のレポートからコピーしてください)
     grade/report/[newreport]/lib.php
     grade/report/[newreport]/lib.php


#The lib.php contains an extension of the grade_report class, and should be named
#lib.phpはgrade_reportクラスのエクステンションを含み、下記のような名称となります。
     grade_report_[newreport]
     grade_report_[newreport]


=== Grade_report class variables ===
=== Grade_reportクラス変数 ===
The grade_report class makes the following variables available to your new class, if you use its constructor in your child class' constructor:
あなたの子クラスのコンストラクタがgrade_reportのコンストラクタを使用する場合、grade_reportはあなたのクラスで使用できる下記の変数を作成します :
      
      
; courseid      : Required by constructor
; courseid      : コンストラクタにより必要
; gpr            : Grade plugin return tracking object, required by constructor
; gpr            : オブジェクトをトラッキングする評定プラグイン戻り値 (Grade plugin return)、コンストラクタにより必要
; context        : Required by constructor
; context        : コンストラクタにより必要
; gtree          : The grade_tree must be instantiated in child classes: not all reports need the whole tree
; gtree          : grade_treeは子クラスに生成する必要があります: ツリー全体にすべてのレポートが必要というわけではありません。
; prefs          : Array of user preferences related to this report. Methods are given to get and set these easily
; prefs          : このレポートに関係するユーザプリファレンスの配列です。これらを容易に取得および設定できるよう、メソッドが提供されます。
; gradebookroles : The roles for this report, pulled out of $CFG->gradebookroles
; gradebookroles : このレポートのロールです。$CFG->gradebookrolesから取得されます。
; baseurl        : Base url for sorting by first/last name (not needed by all reports)
; baseurl        : 姓名をソートするためのベースURIです (すべてのレポートで必要というわけではありません)
; pbarurl        : Base url for paging
; pbarurl        : ページングのベースURIです。
; page          : Current page (for paging). Must be given to constructor if paging is required.
; page          : ページングのための現在のページです。ページングが必要な場合、コンストラクタを与える必要があります。
; lang_strings  : Array of cached language strings (using get_string() all the time                          takes a long time!). A method is provided to replace get_string() and use this cache   
; lang_strings  : 言語ストリングをキャッシュするための配列です (常にget_string() を使用すると長い時間を要します!)。このキャッシュをget_string() の代わりに使用するためのメソッドが提供されます。
; currentgroup  : The current group being displayed.
; currentgroup  : 表示されている現在のグループです。
; group_selector : A HTML select element used to select the current group.
; group_selector : 現在のグループを選択するためのHTML選択エレメントです。
; groupsql      : An SQL fragment used to add linking information to the group tables.
; groupsql      : グループテーブルにリンク情報を追加するときに使用されるSQLフラグメントです。
; groupwheresql  : An SQL constraint to append to the queries used by this object to build the report.
; groupwheresql  : レポートを構築するため、このオブジェクトが使用するクエリに追加されるSQL制約 (constraint) です。


=== Grade_report class methods ===  
=== Grade_reportクラスメソッド ===  


The grade_report class has the following methods which you can use, provided the right steps have been taken to initialise the object first:
最初にオブジェクトを初期化する正しいステップが実行されるという条件で、grade_reportクラスには私たちが使用できる以下のメソッドがあります:
; get_pref()            : Given the name of a user preference (without grade_report_ prefix), locally saves then returns the value of that preference. If the preference has already been fetched before, the saved value is returned. If the preference is not set at the User level, the $CFG equivalent is given (site default).
; get_pref()            : ユーザプリファレンス名を (grade_report_ prefixなしに) 取得します。ローカルに保存した後、プリファレンス値を返します。前にプリファレンスが取得されている場合、保存された値が返されます。プリファレンスがユーザユーザレベルで保存されていない場合、$CFGと等しい値 (サイトデフォルト) が渡されます。
; set_pref()            : Uses set_user_preferences() to update the value of a user preference. If 'default' is given as the value, the preference will be removed in favour of a higher-level preference ($CFG->$pref_name usually)
; set_pref()            : ユーザプリファレンスの値を更新するため、set_user_preferences() を使用します。値に「default」が設定された場合、高いレベルのプリファレンス (通常、$CFG->$pref_name) を使用するため削除されます。
; process_data()        : Abstract method, needs to be implemented by child classes if they want to handle user form submissions on the report they want to handle user actions on the report                                 
; process_data()        : 抽象メソッドです。レポートでユーザフォームによる送信を処理したい場合、子クラスから実装される必要があります。
; process_action()      : Abstract method, needs to be implemented by child classes if they want to handle user actions on the report
; process_action()      : 抽象メソッドです。レポートでユーザの操作を処理したい場合、子クラスから実装される必要があります。
; get_grade_clean()    : format grade using lang specific decimal point and thousand separator the result is suitable for printing on html page
; get_grade_clean()    : 言語特有の小数点および3桁区切り (thousand separator) を使用して評点をHTMLページに適した形でフォーマットします。
; format_grade()        : Given a user input grade, format it to standard format i.e. no thousand separator, and . as decimal point
; format_grade()        : ユーザが入力した評点を標準書式でフォーマットします。例) 小数点に「.」を使用して、3桁区切り (thousand separator) に「,」を使用する。
; get_lang_string()    : First checks the cached language strings, then returns match if found, or uses get_string(). Use this for any lang_strings in the grades.php file.
; get_lang_string()    : 最初にキャッシュされた言語ストリングを探します。合致する言語ストリングが見つかった場合、その言語ストリングを返します。または、get_string() を使用してください。これをgrades.phpファイル内のlang_stringsすべてに使用してください。
; grade_to_percentage() : Computes then returns the percentage value of the grade value within the given range.
; grade_to_percentage() : 計算した後、与えられた範囲内における評定値のパーセンテージ値を返します。
; get_grade_letters()  : Fetches and returns an array of grade letters indexed by their grade boundaries, as stored in preferences.
; get_grade_letters()  : プリファレンスに保存されている、評定境界によりインデックス付けされた評定文字の配列を取得して返します。
; get_numusers()        : Fetches and returns a count of all the users that will be shown on this page.
; get_numusers()        : このページに表示されるユーザすべてをカウントして、カウント数を返します。
; setup_groups()        : Sets up this object's group variables, mainly to restrict the selection of users to display.
; setup_groups()        : 表示するユーザの選択を制限することを主目的として、このオブジェクトのグループ変数をセットします。
; get_sort_arrow()      : Returns an arrow icon inside an <a> tag, for the purpose of sorting a column.
; get_sort_arrow()      : カラムのソートを目的として、<a>タグの中の矢印アイコンを返します。
; get_module_link()    : Builds and returns a HTML link to the grade or view page of the module given. If no itemmodule is given, only the name of the category/item is returned, no link.
; get_module_link()    : 評定へのリンクまたはモジュールの閲覧ページを構築した後、HTMLを返します。itemmoduleが与えられない場合、カテゴリ名/アイテムのみが返され、リンクは返されません。


=== Report child class ===
=== レポート子クラス ===


Assuming you are using flexitable, your child class needs the following variable and methods:
あなたがFlexiTableを使用している場合、子クラスでは下記の変数およびメソッドが必要です:
     $table : The flexitable that will hold the data
     $table : データを保持するFlexiTable
      
      
*grade_report_[newreport]() : Constructor. You can set up anything here, but you must call the parent constructor with the 3 required params:
*grade_report_[newreport]() : コンスタラクタです。あなたはどのようなものでもここに設定できますが、3個の必須パラメータを使って親コンストラクタをコールする必要があります:
         parent::grade_report($COURSE->id, $gpr, $context);
         parent::grade_report($COURSE->id, $gpr, $context);
         The $gpr and $context variables are normally set up in grade/report/[newreport]/index.php
         通常、$gprおよび$context変数はgrade/report/[newreport]/index.phpにて設定されます。
      
      
*setup_table() : Prepares the headers and attributes of the flexitable. Example used for the very simple overview report:
*setup_table() : FlexiTableのヘッダおよび属性を準備します。例では非常に簡単なオーバービューレポートに使用されます:
         // setting up table headers
         // setting up table headers
         $tablecolumns = array('coursename', 'grade', 'rank');
         $tablecolumns = array('coursename', 'grade', 'rank');
136行目: 134行目:
         $this->table->setup();
         $this->table->setup();
      
      
*fill_table() : After setup_table(), gathers and enters the data in the table. Again, from the overview report:
*fill_table() : setup_table()の後、データを収集してテーブルに入力します。再度、オーバービューレポートより:
         global $CFG;
         global $CFG;
         $numusers = $this->get_numusers();
         $numusers = $this->get_numusers();
173行目: 171行目:
             return false;
             return false;
         }
         }
*print_table() : Just does what its name says...
*print_table() : 名称通りのことが実行されます ...
         ob_start();
         ob_start();
         $this->table->print_html();
         $this->table->print_html();
183行目: 181行目:
         }
         }
          
          
*process_data() and process_action() : You can implement these two methods if you need to handle data and actions.
*process_data() および process_action() : あなたがデータおよび操作を処理したい場合、これら2つのメソッドを実装することができます。


=== Set up the index.php file ===
=== index.phpファイルをセットアップする ===
Here is the simple example from the overview report (grade/report/overview).
以下、オーバービューレポート (grade/report/overview) からのシンプルな例です。
      
      
     require_once '../../../config.php';
     require_once '../../../config.php';
271行目: 269行目:


== 結論 ==
== 結論 ==
This short tutorial doesn't explain how to actually create a ''useful'' report. That part is essentially up to you, and there are no hard rules about how to do it. Instead, this tutorial explains how to setup a "stub" report, a basic framework with a set of tools and variables you can use to create a fully functional and essential report for your Moodle needs. Please share your report-building experiences and tribulations with the Moodle community through the forum.
この短いチュートリアルでは「有益な」レポートの作成方法を説明しているわけではありません。その部分は基本的にあなた次第であり、レポートを作成するための難しいルールはありません。代わりにこのチュートリアルでは、あなたのMoodleでの必要性に応じて作成する、完全に機能的かつ重要なレポートを作成するための基本的なフレームワーク、つまり「スタブ」レポートに関する設定方法を説明しています。あなたのレポート開発および経験した困難を、フォーラムを通してMoodleコミュニティと共有してください。


== 関連情報 ==
== 関連情報 ==


* [http://moodle.org/mod/forum/discuss.php?d=69223&mode=3 Gradebook Development ideas] forum discussion
* [http://moodle.org/mod/forum/discuss.php?d=69223&mode=3 評定表開発アイデア] フォーラムディスカッション - 英語
* Using Moodle [http://moodle.org/mod/forum/discuss.php?d=51107 New gradebook for Moodle] forum discussion
* Using Moodle [http://moodle.org/mod/forum/discuss.php?d=51107 Moodleの新しい評定表] フォーラムディスカッション - 英語
* [[Development:Grades]]
* [[開発: 評定]]


[[Category:開発者|評定]]
[[Category:開発者|評定]]

2010年11月11日 (木) 16:58時点における最新版

イントロダクション

Moodle 1.9で新しく実装された素晴らしい機能のひとつにプラグインレポートのサポートがあります。いくつかのレポートはすでに実装されていますが、様々な種類の新しいレポートを素早く簡単に作成することができます。

このページはMoodle評定表に新しいレポートを作成するための簡単なチュートリアルです。最初のセクションではあなたのプラグインが検出され利用可能にするための基本的なセットアップのステップに焦点を合わせています。2番目のセクションでは考えられる実装例を説明しています。もちろん、あなたはこれらの提案を参考にせず自由に開発することができます。

このガイドを読む上での最もシンプルなレポート例はgrade/report/overviewです。

最小限度

これらすべてのステップには新しいファイルの作成が含まれますが、あなたの人生を楽にするため、すべてのケースにおいて既存のレポートをコピー&ペーストすることができます。

1. grade/report配下に新しいフォルダを作成してください。

   grade/report/[newreport]

2. 新しいレポートフォルダ配下に /dbサブフォルダを作成してください。

   grade/report/[newreport]/db

3. dbフォルダ内に下記のコンテンツを含むaccess.phpファイルを作成してください。必要に応じてケイパビリティを変更してください。

   grade/report/[newreport]/db/access.php
 
   <?php
   $gradereport_[newreport]_capabilities = array(
       'gradereport/[newreport]:view' => array(
           'riskbitmask' => RISK_PERSONAL,
           'captype' => 'read',
           'contextlevel' => CONTEXT_COURSE,
           'legacy' => array(
               'student' => CAP_ALLOW,
               'teacher' => CAP_ALLOW,
               'editingteacher' => CAP_ALLOW,
               'admin' => CAP_ALLOW
           )
       ),
   );
   ?>

4. 現在日付のversion.phpファイルを作成してください:

   grade/report/[newreport]/version.php
   <?php
   $plugin->version  = 2007081000;
   $plugin->requires = 2007081000;
   ?>

5. index.phpファイルを作成してください:

   grade/report/[newreport]/index.php

6. あなたのレポートの言語ファイルを作成してください。少なくともモジュール名、そして任意でケイパビリティのストリングを含んでください。

   grade/report/[newreport]/lang/en_utf8/gradereport_[newreport].php
   
   以下、ユーザレポートの言語ファイル例です:
   
   $string['modulename'] = 'ユーザレポート';
   $string['user:view'] = 'あなたオリジナルの評定レポートを表示します。';

あなたのレポートに新しいリンクを作成する必要はありません。あなたがすべてのステップに従った場合、レポートは自動的に検出され、評定表プラグインドロップダウンメニュー内に追加されます!

あなたが新しいレポートを作成するときに必要なものはこれですべてです! もちろん、通常、あなたは何かをするためにデータを取得して表示するためのコードを書くことでしょう。次のセクションではflexitableを使用する簡単なアプローチに関して話しましょう。

考え得るステップ 7

私はsettings.phpファイルを新しい「grade\report\[directory name]」ディレクトリに入れる必要もありました。このファイルが存在しないため、私には「Section Error!」というエラーメッセージが表示されていました。ファイルを「grade\report\[directory name]」ディレクトリに入れた後、エラーメッセージは表示されないようになりました。settings.phpファイルは空です。私はMoodle 1.9を使用しています。

考え得るステップ 8

レポートを複数ユーザが利用できるようにする場合、あなたのMoodleの管理セクションに移動して、通常のアップグレードと同じようにテーブルを更新する必要があります。その後、ロールの定義に移動して、あなたの設定が正しいかどうか確認してください。私はMoodle 1.9を使用しています。

grade_reportクラスを拡張する

あなたは自由に自分のやりかたでクラスを開発することができます。しかし、grade_repot内に配置されている既存のメソッドを使用することで、退屈なコードの繰り返しを避けることができます。私たちはシンプルなレポートにユーザレポート (grade_report_user class) 内にあるflextitableを使用します。このチュートリアルの残りの部分で、私たちはfulexitableについて取り上げてみます。

新しいファイル

  1. lib.phpファイルを作成してください (または他のレポートからコピーしてください)。
   grade/report/[newreport]/lib.php
  1. lib.phpはgrade_reportクラスのエクステンションを含み、下記のような名称となります。
   grade_report_[newreport]

Grade_reportクラス変数

あなたの子クラスのコンストラクタがgrade_reportのコンストラクタを使用する場合、grade_reportはあなたのクラスで使用できる下記の変数を作成します :

courseid
コンストラクタにより必要
gpr
オブジェクトをトラッキングする評定プラグイン戻り値 (Grade plugin return)、コンストラクタにより必要
context
コンストラクタにより必要
gtree
grade_treeは子クラスに生成する必要があります: ツリー全体にすべてのレポートが必要というわけではありません。
prefs
このレポートに関係するユーザプリファレンスの配列です。これらを容易に取得および設定できるよう、メソッドが提供されます。
gradebookroles
このレポートのロールです。$CFG->gradebookrolesから取得されます。
baseurl
姓名をソートするためのベースURIです (すべてのレポートで必要というわけではありません)。
pbarurl
ページングのベースURIです。
page
ページングのための現在のページです。ページングが必要な場合、コンストラクタを与える必要があります。
lang_strings
言語ストリングをキャッシュするための配列です (常にget_string() を使用すると長い時間を要します!)。このキャッシュをget_string() の代わりに使用するためのメソッドが提供されます。
currentgroup
表示されている現在のグループです。
group_selector
現在のグループを選択するためのHTML選択エレメントです。
groupsql
グループテーブルにリンク情報を追加するときに使用されるSQLフラグメントです。
groupwheresql
レポートを構築するため、このオブジェクトが使用するクエリに追加されるSQL制約 (constraint) です。

Grade_reportクラスメソッド

最初にオブジェクトを初期化する正しいステップが実行されるという条件で、grade_reportクラスには私たちが使用できる以下のメソッドがあります:

get_pref()
ユーザプリファレンス名を (grade_report_ prefixなしに) 取得します。ローカルに保存した後、プリファレンス値を返します。前にプリファレンスが取得されている場合、保存された値が返されます。プリファレンスがユーザユーザレベルで保存されていない場合、$CFGと等しい値 (サイトデフォルト) が渡されます。
set_pref()
ユーザプリファレンスの値を更新するため、set_user_preferences() を使用します。値に「default」が設定された場合、高いレベルのプリファレンス (通常、$CFG->$pref_name) を使用するため削除されます。
process_data()
抽象メソッドです。レポートでユーザフォームによる送信を処理したい場合、子クラスから実装される必要があります。
process_action()
抽象メソッドです。レポートでユーザの操作を処理したい場合、子クラスから実装される必要があります。
get_grade_clean()
言語特有の小数点および3桁区切り (thousand separator) を使用して評点をHTMLページに適した形でフォーマットします。
format_grade()
ユーザが入力した評点を標準書式でフォーマットします。例) 小数点に「.」を使用して、3桁区切り (thousand separator) に「,」を使用する。
get_lang_string()
最初にキャッシュされた言語ストリングを探します。合致する言語ストリングが見つかった場合、その言語ストリングを返します。または、get_string() を使用してください。これをgrades.phpファイル内のlang_stringsすべてに使用してください。
grade_to_percentage()
計算した後、与えられた範囲内における評定値のパーセンテージ値を返します。
get_grade_letters()
プリファレンスに保存されている、評定境界によりインデックス付けされた評定文字の配列を取得して返します。
get_numusers()
このページに表示されるユーザすべてをカウントして、カウント数を返します。
setup_groups()
表示するユーザの選択を制限することを主目的として、このオブジェクトのグループ変数をセットします。
get_sort_arrow()
カラムのソートを目的として、<a>タグの中の矢印アイコンを返します。
get_module_link()
評定へのリンクまたはモジュールの閲覧ページを構築した後、HTMLを返します。itemmoduleが与えられない場合、カテゴリ名/アイテムのみが返され、リンクは返されません。

レポート子クラス

あなたがFlexiTableを使用している場合、子クラスでは下記の変数およびメソッドが必要です:

   $table : データを保持するFlexiTable
   
  • grade_report_[newreport]() : コンスタラクタです。あなたはどのようなものでもここに設定できますが、3個の必須パラメータを使って親コンストラクタをコールする必要があります:
       parent::grade_report($COURSE->id, $gpr, $context);
       通常、$gprおよび$context変数はgrade/report/[newreport]/index.phpにて設定されます。
   
  • setup_table() : FlexiTableのヘッダおよび属性を準備します。例では非常に簡単なオーバービューレポートに使用されます:
       // setting up table headers
       $tablecolumns = array('coursename', 'grade', 'rank');
       $tableheaders = array($this->get_lang_string('coursename', 'grades'),
                             $this->get_lang_string('grade'),
                             $this->get_lang_string('rank', 'grades'));

       $this->table = new flexible_table('grade-report-overview-'.$this->user->id);

       $this->table->define_columns($tablecolumns);
       $this->table->define_headers($tableheaders);
       $this->table->define_baseurl($this->baseurl);

       $this->table->set_attribute('cellspacing', '0');
       $this->table->set_attribute('id', 'overview-grade');
       $this->table->set_attribute('class', 'boxaligncenter generaltable');

       $this->table->setup();
    
  • fill_table() : setup_table()の後、データを収集してテーブルに入力します。再度、オーバービューレポートより:
       global $CFG;
       $numusers = $this->get_numusers();

       if ($courses = get_courses('all', null, 'c.id, c.shortname')) {
           foreach ($courses as $course) {
               // Get course grade_item
               $grade_item_id = get_field('grade_items', 'id', 'itemtype', 
                                          'course', 'courseid', $course->id);

               // Get the grade
               $finalgrade = get_field('grade_grades', 'finalgrade', 'itemid', 
                                       $grade_item_id, 'userid', $this->user->id);

               /// prints rank
               if ($finalgrade) {
                   /// find the number of users with a higher grade
                   $sql = "SELECT COUNT(DISTINCT(userid))
                           FROM {$CFG->prefix}grade_grades
                           WHERE finalgrade > $finalgrade
                           AND itemid = $grade_item_id";
                   $rank = count_records_sql($sql) + 1;

                   $rankdata = "$rank/$numusers";
               } else {
                   // no grade, no rank
                   $rankdata = "-";
               }

               $this->table->add_data(array($course->shortname, $finalgrade, $rankdata));
           }

           return true;
       } else {
           notify(get_string('nocourses', 'grades'));
           return false;
       }
  • print_table() : 名称通りのことが実行されます ...
       ob_start();
       $this->table->print_html();
       $html = ob_get_clean();
       if ($return) {
           return $html;
       } else {
           echo $html;
       }
       
  • process_data() および process_action() : あなたがデータおよび操作を処理したい場合、これら2つのメソッドを実装することができます。

index.phpファイルをセットアップする

以下、オーバービューレポート (grade/report/overview) からのシンプルな例です。

   require_once '../../../config.php';
   require_once $CFG->libdir.'/gradelib.php';
   require_once $CFG->dirroot.'/grade/lib.php';
   require_once $CFG->dirroot.'/grade/report/overview/lib.php';

   $courseid = optional_param('id', $COURSE->id, PARAM_INT);
   $userid   = optional_param('userid', $USER->id, PARAM_INT);

   /// basic access checks
   if (!$course = get_record('course', 'id', $courseid)) {
       print_error('nocourseid');
   }
   require_login($course);

   if (!$user = get_complete_user_data('id', $userid)) {
       error("Incorrect userid");
   }

   $context     = get_context_instance(CONTEXT_COURSE, $course->id);
   $usercontext = get_context_instance(CONTEXT_USER, $user->id);
   require_capability('gradereport/overview:view', $context);

   $access = true;
   if (has_capability('moodle/grade:viewall', $context)) {
       //ok - can view all course grades

   } else if ($user->id == $USER->id and has_capability('moodle/grade:view', $context) and $course->showgrades) {
       //ok - can view own grades

   } else if (has_capability('moodle/grade:viewall', $usercontext) and $course->showgrades) {
       // ok - can view grades of this user- parent most probably

   } else {
       $acces = false;
   }

   /// return tracking object
   $gpr = new grade_plugin_return(array('type'=>'report', 'plugin'=>'overview', 'courseid'=>$course->id, 'userid'=>$userid));

   /// last selected report session tracking
   if (!isset($USER->grade_last_report)) {
       $USER->grade_last_report = array();
   }
   $USER->grade_last_report[$course->id] = 'overview';

   /// Build navigation
   $strgrades  = get_string('grades');
   $reportname = get_string('modulename', 'gradereport_overview');

   $navigation = grade_build_nav(__FILE__, $reportname, $course->id);

   /// Print header
   print_header_simple($strgrades.': '.$reportname, ': '.$strgrades, $navigation,
                       , , true, , navmenu($course));

   /// Print the plugin selector at the top
   print_grade_plugin_selector($course->id, 'report', 'overview');

   if ($access) {

       //first make sure we have proper final grades - this must be done before constructing of the grade tree
       grade_regrade_final_grades($course->id);

       // Create a report instance
       $report = new grade_report_overview($userid, $gpr, $context);

       $gradetotal = 0;
       $gradesum = 0;

       // print the page
       print_heading(get_string('modulename', 'gradereport_overview'). ' - '.fullname($report->user));

       if ($report->fill_table()) {
           echo $report->print_table(true);
       }

   } else {
       // no access to grades!
       echo "Can not view grades."; //TODO: localize
   }
   print_footer($course);

結論

この短いチュートリアルでは「有益な」レポートの作成方法を説明しているわけではありません。その部分は基本的にあなた次第であり、レポートを作成するための難しいルールはありません。代わりにこのチュートリアルでは、あなたのMoodleでの必要性に応じて作成する、完全に機能的かつ重要なレポートを作成するための基本的なフレームワーク、つまり「スタブ」レポートに関する設定方法を説明しています。あなたのレポート開発および経験した困難を、フォーラムを通してMoodleコミュニティと共有してください。

関連情報