OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / ec_category_menu / include / container / ec_category_menuWidgetContainer.php
1 <?php
2 /**
3  * index.php用コンテナクラス
4  *
5  * PHP versions 5
6  *
7  * LICENSE: This source file is licensed under the terms of the GNU General Public License.
8  *
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
15  */
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');
19
20 class ec_category_menuWidgetContainer extends BaseWidgetContainer
21 {
22         private $db;                    // DB接続オブジェクト
23         private $levelCount;    // メニュー表示レベル
24         private $imgFilename;           // 画像ファイル名
25         private $color1;
26         private $color2;
27         private $color3;
28         private $color4;
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 = '商品カテゴリー';     // デフォルトメニュータイトル
37                 
38         /**
39          * コンストラクタ
40          */
41         function __construct()
42         {
43                 // 親クラスを呼び出す
44                 parent::__construct();
45                 
46                 // DBオブジェクト作成
47                 $this->db = new ec_category_menuDb();
48         }
49         /**
50          * ウィジェット単位のアクセス制御
51          *
52          * @param RequestManager $request               HTTPリクエスト処理クラス
53          */
54         function _checkAccess($request)
55         {
56                 return true;
57         }
58         /**
59          * テンプレートファイルを設定
60          *
61          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
62          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
63          *
64          * @param RequestManager $request               HTTPリクエスト処理クラス
65          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
66          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
67          */
68         function _setTemplate($request, &$param)
69         {
70                 global $gInstanceManager;
71                 
72                 // メニューの設定を取得
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;                  // メニュータイトル
87                 }
88                 if ($this->imageMenu){// 画像メニューを使用する場合
89                         return 'menu.tmpl.html';
90                 } else {
91                         return 'menu_v_table.tmpl.html';
92                 }
93         }
94         /**
95          * テンプレートにデータ埋め込む
96          *
97          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
98          *
99          * @param RequestManager $request               HTTPリクエスト処理クラス
100          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
101          * @param                                                               なし
102          */
103         function _assign($request, &$param)
104         {
105                 global $gEnvManager;
106                 
107                 // 現在の言語
108                 $currentLang    = $gEnvManager->getCurrentLanguage();
109                 
110                 if ($this->imageMenu){// 画像メニューを使用する場合
111                         // メニュータイトルの設定
112                         if (!empty($this->title)){
113                                 $titleString = '<tr><th>' . $this->title . '</th></tr>';
114                                 $this->tmpl->addVar("_widget", "title", $titleString);
115                         }
116                         
117                         // メニューツリーを作成
118                         $categoryHtml =  $this->createCategoryTreeList($currentLang);
119                         $this->tmpl->addVar("_widget", "category_menu", $categoryHtml);
120                 
121                         // 埋め込みパラメータの設定
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
127                 } else {
128                         // メニューテーブルのパラメータ
129                         $this->tmpl->addVar("_widget", "default_menu_param", $this->gDesign->getDefaultWidgetTableParam());
130                         
131                         // デフォルトメニューのときは1階層のみ作成
132                         // メニュータイトルの設定
133                         if (!empty($this->title)){
134                                 $titleString = '';
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>';
139                                 } else {
140                                 }
141                                 $this->tmpl->addVar("_widget", "title", $titleString);
142                         }
143                         
144                         // メニューを作成
145                         $categoryHtml =  $this->createCategoryList($currentLang);
146                         $this->tmpl->addVar("_widget", "category_menu", $categoryHtml);
147                 }
148         }
149         /**
150          * カテゴリーツリーリスト作成
151          *
152          * @param string        $langId                         言語ID
153          * @return string                                               カテゴリーリスト表示用HTML
154          */
155         function createCategoryTreeList($langId)
156         {
157                 $listHtml = '';
158                 $this->createCategoryTreeListLoop(0, $langId, 0, $listHtml);
159                 return $listHtml;
160         }
161         /**
162          * カテゴリーツリーリスト作成
163          *
164          * @param int       $parentId                   親カテゴリーID
165          * @param string        $langId                         言語ID
166          * @param int       $level                              メニューの階層
167          * @param string                                                カテゴリーリスト表示用HTML
168          * @return なし       
169          */
170         function createCategoryTreeListLoop($parentId, $langId, $level, &$listHtml)
171         {
172                 $arraySize = $this->db->getChildCategoryWithRows($parentId, $langId, $rows);
173                 for ($i = 0; $i < $arraySize; $i++){
174                         $id = $rows[$i]['pc_id'];
175                         
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);
182                         
183                         // 最大階層のときは、サブメニューを生成しない
184                         if ($level + 1 >= $this->levelCount){
185                                 $childCount = 0;
186                         } else {
187                                 $childCount = $this->db->getChildCategoryWithRows($id, $langId, $rows2);
188                         }
189                         if ($childCount <= 0){                  
190                                 $listHtml .= '<li><a href="' . $this->getUrl($url, true) . '">' . $rows[$i]['pc_name'] . '</a></li>' . M3_NL;
191                         } else {
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;
197                         }
198                 }
199         }
200         /**
201          * カテゴリーリスト作成(1階層のみ)
202          *
203          * @param string        $langId                         言語ID
204          * @return string                                               カテゴリーリスト表示用HTML
205          */
206         function createCategoryList($langId)
207         {
208                 $listHtml = '';
209                 $arraySize = $this->db->getChildCategoryWithRows(0, $langId, $rows);
210                 for ($i = 0; $i < $arraySize; $i++){
211                         $id = $rows[$i]['pc_id'];
212                         
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;
220                 }
221                 return $listHtml;
222         }
223 }
224 ?>