Factoryモジュール()で自動生成したモジュールとletag,lecatモジュールの連携ですが、
ぶっちゃけ管理画面の一般設定でletag,lecatを選択すればだいたい何とかなります。
カテゴリが表示されなかったり項目のViewActionでタグが表示されなかったりするので、ちょっとだけ手を加えました。
letag連携のタグが表示されない
「タグを使う」にチェックを入れて作成したテーブルのViewActionのテンプレートを見ると、
<!-- tag --> <{if count($object->mTag)>0}> <dt class="tagList"><{$smarty.const._TAG}>: </dt> <dd class="tagList"> <{foreach item=tag from=$object->mTag}> <{assign var=tagurl value=$tag|xoops_escape:url}> <span><a href="<{xoops_cooluri dirname=$dirname dataname=$dataname query="tag=`$tag`"}>"><{$tag|xoops_escape}></a></span> <{/foreach}> <{/if}> |
と、タグ出力用のテンプレートが含まれていることがわかります。しかし、タグを設定したレコードを作成しても、何も表示されません。
そこで、xoops_trust_path/modules/moduleName/class/handler/Table.class.phpに関数を1つ追加します。
diff --git a/xoops_trust_path/modules/moduleName/class/handler/Table.class.php b/xoops_trust_path/modules/moduleName/class/handler/Table.class.php index e76ffc3..58401c9 100644 --- a/xoops_trust_path/modules/moduleName/class/handler/Table.class.php +++ b/xoops_trust_path/modules/moduleName/class/handler/Table.class.php @@ -61,6 +61,26 @@ class ModuleName_TableObject extends Legacy_AbstractObject return 0; } + public function loadTag() + { + $tagDirname = ModuleName_Utils::getModuleConfig($this->getDirname(), 'tag_dirname'); + if ($this->_mIsTagLoaded == false && $tagDirname) { + $tagArr = array(); + if (! $this->isNew()) { + XCube_DelegateUtils::call( + 'Legacy_Tag.'.$tagDirname.'.GetTags', + new XCube_Ref($tagArr), + $tagDirname, + $this->getDirname(), + 'table', + $this->get('table_id') + ); + } + $this->mTag = $tagArr; + $this->_mIsTagLoaded = true; + } + } + } |
この関数をどこかのタイミングで呼び出すことにより、オブジェクトにタグの情報を読みこませることができます。
ちなみに、この関数はXCCKモジュールで利用されていたものを参考に、カラム名等を書き換えたものです。
タグを利用できるようにするために、xoops_trust_path/modules/moduleName/class/AbstractViewAction.class.phpの_setupObject関数に、次のようにして先ほどの関数を呼び出すように記述します。
diff --git a/xoops_trust_path/modules/moduleName/class/AbstractViewAction.class.php b/xoops_trust_path/modules/moduleName/class/AbstractViewAction.class.php index 8ef92f1..0aaa003 100644 --- a/xoops_trust_path/modules/moduleName/class/AbstractViewAction.class.php +++ b/xoops_trust_path/modules/moduleName/class/AbstractViewAction.class.php @@ -71,6 +71,8 @@ abstract class ModuleName_AbstractViewAction extends ModuleName_AbstractAction $this->mObjectHandler =& $this->_getHandler(); $this->mObject =& $this->mObjectHandler->get($id); + + $this->mObject->loadTag(); } /** |
これでオブジェクトのmTagsメンバにタグ情報がセットされます。
あとはViewActionで表示してみれば、タグを設定している項目についてはタグが列挙されるはずです。
カテゴリが表示されない
モジュールをインストールして実際にデータを追加してみると、なぜかカテゴリが表示されない現象に遭遇しました。もちろん事前にlecatモジュールでカテゴリを作成して有ります。対策として、テンプレートを一部変更することで表示できました。こういう時にALTSYSモジュールはとっても便利ですね!
書き換える場所はカテゴリIDを表示しようとしている場所全てです。(e.g. {dirname}_{table}_view.html) IDをそのまま表示すると言うことではなく、カテゴリ名称を表示させます。
- <td><{assign var=catId value=$obj->getShow('category_id')}><{$mainTitleList.$catId|xoops_escape}></td> + <td><{$accessController->getTitle($obj->getVar('category_id'))|xoops_escape}></td>
$accessController
が、lecatモジュール(Legacy_Tag準拠モジュール)よりカテゴリを取得する役割を持っているようで、自動生成されたActionからアサインされています。
これでカテゴリ・タグともに表示できるようになりました。
まだタグを限定したList表示がうまく動作していないので、検証次第またこちらで報告したいと思います。