7 * LICENSE: This source file is licensed under the terms of the GNU General Public License.
9 * @package Magic3 Framework
10 * @author 平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
11 * @copyright Copyright 2006-2012 Magic3 Project.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
13 * @version SVN: $Id: accordion_menuWidgetContainer.php 4943 2012-06-07 23:21:43Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getContainerPath() . '/baseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/accordion_menuDb.php');
19 class accordion_menuWidgetContainer extends BaseWidgetContainer
21 private $db; // DB接続オブジェクト
22 private $langId; // 現在の言語
23 private $paramObj; // 定義取得用
24 private $headCss; // ヘッダ出力用CSS
25 const DEFAULT_CONFIG_ID = 0;
26 const MAX_MENU_TREE_LEVEL = 5; // メニュー階層最大数
31 function __construct()
34 parent::__construct();
37 $this->db = new accordion_menuDb();
42 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
43 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
45 * @param RequestManager $request HTTPリクエスト処理クラス
46 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
47 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
49 function _setTemplate($request, &$param)
51 return 'index.tmpl.html';
56 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
58 * @param RequestManager $request HTTPリクエスト処理クラス
59 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
62 function _assign($request, &$param)
64 $this->langId = $this->gEnv->getCurrentLanguage();
67 $configId = $this->gEnv->getCurrentWidgetConfigId();
68 if (empty($configId)) $configId = self::DEFAULT_CONFIG_ID;
71 $targetObj = $this->getWidgetParamObjByConfigId($configId);
72 if (!empty($targetObj)){ // 定義データが取得できたとき
73 $menuId = $targetObj->menuId; // メニューID
74 $name = $targetObj->name;// 定義名
75 $css = $targetObj->css; // メニューCSS
76 $cssId = $targetObj->cssId; // メニューCSSのID
78 $this->tmpl->setAttribute('_widget', 'visibility', 'visible');
81 $menuHtml = $this->createMenu($menuId, 0);
82 $this->tmpl->addVar("_widget", "menu_html", $menuHtml);
83 $this->tmpl->addVar("_widget", "css_id", $cssId); // CSS用ID
86 $this->headCss = str_replace(M3_TAG_START . M3_TAG_MACRO_WIDGET_URL . M3_TAG_END, $this->gEnv->getCurrentWidgetRootUrl(), $css);
92 * CSSデータをHTMLのheadタグ内に追加出力する。
93 * _assign()よりも後に実行される。
95 * @param RequestManager $request HTTPリクエスト処理クラス
96 * @param object $param 任意使用パラメータ。
97 * @return string CSS文字列。出力しない場合は空文字列を設定。
99 function _addCssToHead($request, &$param)
101 return $this->headCss;
106 * @param string $menuId メニューID
107 * @param int $parantId 親メニュー項目ID
108 * @param int $level 階層数
109 * @return string ツリーメニュータグ
111 function createMenu($menuId, $parantId, $level = 0)
114 if ($level >= self::MAX_MENU_TREE_LEVEL) return '';
117 if ($this->db->getChildMenuItems($menuId, $parantId, $rows)){
118 $itemCount = count($rows);
119 for ($i = 0; $i < $itemCount; $i++){
123 if (!$row['md_visible']) continue;
126 $linkUrl = $row['md_link_url'];
127 $linkUrl = str_replace(M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END, $this->gEnv->getRootUrl(), $linkUrl);
128 if (empty($linkUrl)) $linkUrl = '#';
129 $linkUrl = $this->convertUrlToHtmlEntity($linkUrl);
133 switch ($row['md_link_type']){
134 case 0: // 同ウィンドウで開くリンク
136 case 1: // 別ウィンドウで開くリンク
137 $option = 'target="_blank"';
142 $name = $this->getCurrentLangString($row['md_name']);
143 if (empty($name)) continue;
145 // ##### ツリーメニュー作成 #####
146 if ($row['md_type'] == 0){ // リンク項目のとき
147 $treeHtml .= '<li><a href="' . $linkUrl . '" ' . $option . '>' . $this->convertToDispString($name) . '</a></li>' . M3_NL;
148 } else if ($row['md_type'] == 1){ // フォルダのとき
150 $treeHtml .= '<li><a class="head" href="#">' . $this->convertToDispString($name) . '</a>' . M3_NL;
151 $treeHtml .= '<ul>' . M3_NL;
152 $treeHtml .= $this->createMenu($menuId, $row['md_id'], $level + 1);
153 $treeHtml .= '</ul>' . M3_NL;
154 $treeHtml .= '</li>' . M3_NL;
155 } else if ($row['md_type'] == 2){ // テキストのとき
156 //$treeHtml .= '<li><span>' . $this->convertToDispString($row['md_name']) . '</span></li>' . M3_NL;
157 } else if ($row['md_type'] == 3){ // セパレータのとき
158 //$treeHtml .= '<li><span>' . '-----' . '</span></li>' . M3_NL;