D3モジュール用のイベント通知ハンドラ

Date 2008-09-06 06:02:40 | Category: XOOPS

in englishin japanese
D3モジュールの問題点として、イベント通知処理が面倒、というのがあります。
X2のNotificationHandlerは、triggerEvent()する時に、
ROOT/modules/(dirname)/language/(lang)/mail_template/(mail_template).tpl
を読みに行きます。
そこにファイルが無かった時点で、イベント通知は無効だとして処理がスキップされてしまいます。

それを回避するために、d3forumやpicoでは、それぞれ独自のtrigger_event関数を作っていたのですが、それは明らかに工数の無駄です。

D3モジュール用に、イベント処理テンプレートファイルをTRUST_PATHの下からも検索してくれる共通のルーチンを書けば良いだけです。

D3モジュールを使うならaltsys必須

というのも事実上ルール化してますので、D3NotificationHandlerクラスをaltsysに追加しました。
使い方は簡単です。


$notification_handler =& xoops_gethandler( 'notification' ) ;
$notification_handler->triggerEvent($category, $item_id, $event, $extra_tags, $user_list, $module_id, $omit_user_id);

従来は上の書き方だったところを、下のように変更するだけです。

require_once XOOPS_TRUST_PATH.'/libs/altsys/class/D3NotificationHandler.class.php' ;
$notification_handler =& D3NotificationHandler::getInstance();
$notification_handler->triggerEvent($mydirname, $mytrustdirname, $category, $item_id, $event, $extra_tags, $user_list, $omit_user_id);


モジュール指定を $mid ではなく $mydirname で渡すところが違いますが、D3モジュール的にはこの方が使いやすいでしょう。

あまりいろいろテストしてませんが、おそらくXCL2.1でもImpressCMSでも本家2.3でもこのコードで動くでしょう。

すでに手元のpicoやd3forumは、このコードを利用していますので、今後の私のD3モジュールはすべて altsys-0.61以上必須、という形になる予定です。(実際には、altsys本体のバージョンが低くても、class/D3NotificationHandler.class.php ファイルだけ用意すれば事足りますが)

なお、このD3イベント通知ハンドラにおけるメールテンプレートの検索順序は以下の通りです。

ROOT/modules/(mydirname)/language/$language/mail_template/
TRUST/modules/(mydirname)/language/$language/mail_template/
ROOT/modules/(mydirname)/language/english/mail_template/
TRUST/modules/(mydirname)/language/english/mail_template/





You can read more news at PEAK XOOPS.
http://xoops.peak.ne.jp

The URL for this story is:
http://xoops.peak.ne.jp/md/news/index.php?page=article&storyid=460