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-2007 Magic3 Project.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
13 * @version SVN: $Id: ec_category_menuWidgetContainer.php 2363 2009-09-26 14:45:44Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getContainerPath() . '/baseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetContainerPath() . '/ec_category_menuInfo.php');
18 require_once($gEnvManager->getCurrentWidgetDbPath() . '/ec_category_menuDb.php');
20 class ec_category_menuWidgetContainer extends BaseWidgetContainer
22 private $db; // DB接続オブジェクト
23 private $levelCount; // メニュー表示レベル
24 private $imgFilename; // 画像ファイル名
29 private $imageMenu; // 画像メニューを使用するかどうか
30 private $title; // メニュータイトル
31 private $menuType = 0; // デフォルトメニューのメニュータイプ(0=テーブル、1=リスト)
32 const TARGET_WIDGET = 'ec_main'; // 呼び出しウィジェットID
33 const THIS_WIDGET_ID = 'ec_category_menu'; // ウィジェットID
34 const DEFAULT_IMG_FILENAME = 'menu1.png'; // デフォルトファイル名
35 const DEFAULT_LEVEL_COUNT = 3; // デフォルト表示階層
36 const DEFAULT_MENU_TITLE = '商品カテゴリー'; // デフォルトメニュータイトル
41 function __construct()
44 parent::__construct();
47 $this->db = new ec_category_menuDb();
52 * @param RequestManager $request HTTPリクエスト処理クラス
54 function _checkAccess($request)
61 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
62 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
64 * @param RequestManager $request HTTPリクエスト処理クラス
65 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
66 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
68 function _setTemplate($request, &$param)
70 global $gInstanceManager;
73 $this->imgFilename = self::DEFAULT_IMG_FILENAME; // メニュー画像
74 $this->levelCount = self::DEFAULT_LEVEL_COUNT; // デフォルト表示階層
75 $this->title = self::DEFAULT_MENU_TITLE; // メニュータイトル
76 $serializedParam = $gInstanceManager->getSytemDbObject()->getWidgetParam(self::THIS_WIDGET_ID);
77 if (!empty($serializedParam)){
78 $menuInfo = unserialize($serializedParam);
79 if (!empty($menuInfo->imageFilename)) $this->imgFilename = $menuInfo->imageFilename;
80 if (!empty($menuInfo->levelCount)) $this->levelCount = $menuInfo->levelCount;
81 if (!empty($menuInfo->fontColor1)) $this->color1 = $menuInfo->fontColor1;
82 if (!empty($menuInfo->fontColor2)) $this->color2 = $menuInfo->fontColor2;
83 if (!empty($menuInfo->fontColor3)) $this->color3 = $menuInfo->fontColor3;
84 if (!empty($menuInfo->fontColor4)) $this->color4 = $menuInfo->fontColor4;
85 if (!empty($menuInfo->useImageMenu)) $this->imageMenu = $menuInfo->useImageMenu; // 画像メニューを使用するかどうか
86 if (!empty($menuInfo->title)) $this->title = $menuInfo->title; // メニュータイトル
88 if ($this->imageMenu){// 画像メニューを使用する場合
89 return 'menu.tmpl.html';
91 return 'menu_v_table.tmpl.html';
97 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
99 * @param RequestManager $request HTTPリクエスト処理クラス
100 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
103 function _assign($request, &$param)
108 $currentLang = $gEnvManager->getCurrentLanguage();
110 if ($this->imageMenu){// 画像メニューを使用する場合
112 if (!empty($this->title)){
113 $titleString = '<tr><th>' . $this->title . '</th></tr>';
114 $this->tmpl->addVar("_widget", "title", $titleString);
118 $categoryHtml = $this->createCategoryTreeList($currentLang);
119 $this->tmpl->addVar("_widget", "category_menu", $categoryHtml);
122 $this->tmpl->addVar("_widget", "image_filename", $this->imgFilename); // 画像ファイル名
123 $this->tmpl->addVar("_widget", "color1", $this->color1); // 文字色1
124 $this->tmpl->addVar("_widget", "color2", $this->color2); // 文字色2
125 $this->tmpl->addVar("_widget", "color3", $this->color3); // 文字色3
126 $this->tmpl->addVar("_widget", "color4", $this->color4); // 文字色4
129 $this->tmpl->addVar("_widget", "default_menu_param", $this->gDesign->getDefaultWidgetTableParam());
131 // デフォルトメニューのときは1階層のみ作成
133 if (!empty($this->title)){
135 if ($this->menuType == 0){ // テーブルタイプのとき
136 $titleString .= '<tr><th>' . $this->title . '</th></tr>';
137 } else if ($this->_menuType == 1){ // リストタイプのとき
138 $titleString .= '<lh>' . $this->title . '</lh>';
141 $this->tmpl->addVar("_widget", "title", $titleString);
145 $categoryHtml = $this->createCategoryList($currentLang);
146 $this->tmpl->addVar("_widget", "category_menu", $categoryHtml);
152 * @param string $langId 言語ID
153 * @return string カテゴリーリスト表示用HTML
155 function createCategoryTreeList($langId)
158 $this->createCategoryTreeListLoop(0, $langId, 0, $listHtml);
164 * @param int $parentId 親カテゴリーID
165 * @param string $langId 言語ID
166 * @param int $level メニューの階層
167 * @param string カテゴリーリスト表示用HTML
170 function createCategoryTreeListLoop($parentId, $langId, $level, &$listHtml)
172 $arraySize = $this->db->getChildCategoryWithRows($parentId, $langId, $rows);
173 for ($i = 0; $i < $arraySize; $i++){
174 $id = $rows[$i]['pc_id'];
176 $url = '?' . M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_FIND_WIDGET;
177 $url .= '&' . M3_REQUEST_PARAM_WIDGET_ID . '=' . self::TARGET_WIDGET;
178 $url .= '&' . M3_REQUEST_PARAM_FROM . '=' . self::THIS_WIDGET_ID; // 送信元
179 // $url .= '&' . M3_REQUEST_PARAM_OPERATION_TODO . '=category';
180 // $url .= '&id=' . $id;
181 $url .= '&' . M3_REQUEST_PARAM_OPERATION_TODO . '=' . urlencode('category=' . $id);
183 // 最大階層のときは、サブメニューを生成しない
184 if ($level + 1 >= $this->levelCount){
187 $childCount = $this->db->getChildCategoryWithRows($id, $langId, $rows2);
189 if ($childCount <= 0){
190 $listHtml .= '<li><a href="' . $this->getUrl($url, true) . '">' . $rows[$i]['pc_name'] . '</a></li>' . M3_NL;
192 $listHtml .= '<li><a href="' . $this->getUrl($url, true) . '">' . $rows[$i]['pc_name'] . '</a>' . M3_NL;
193 $listHtml .= '<ul>' . M3_NL;
194 $this->createCategoryTreeListLoop($id, $langId, $level+1, $listHtml);
195 $listHtml .= '</ul>' . M3_NL;
196 $listHtml .= '</li>' . M3_NL;
203 * @param string $langId 言語ID
204 * @return string カテゴリーリスト表示用HTML
206 function createCategoryList($langId)
209 $arraySize = $this->db->getChildCategoryWithRows(0, $langId, $rows);
210 for ($i = 0; $i < $arraySize; $i++){
211 $id = $rows[$i]['pc_id'];
213 $url = '?' . M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_FIND_WIDGET;
214 $url .= '&' . M3_REQUEST_PARAM_WIDGET_ID . '=' . self::TARGET_WIDGET;
215 $url .= '&' . M3_REQUEST_PARAM_FROM . '=' . self::THIS_WIDGET_ID; // 送信元
216 // $url .= '&' . M3_REQUEST_PARAM_OPERATION_TODO . '=category';
217 // $url .= '&id=' . $id;
218 $url .= '&' . M3_REQUEST_PARAM_OPERATION_TODO . '=' . urlencode('category=' . $id);
219 $listHtml .= '<tr><td><a href="' . $this->getUrl($url, true) . '" class="mainlevel">' . $rows[$i]['pc_name'] . '</a></td></tr>' . M3_NL;