OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / ec_main / include / iwidgets / lotbuying / include / container / admin_lotbuyingWidgetContainer.php
1 <?php
2 /**
3  * コンテナクラス
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-2012 Magic3 Project.
12  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
13  * @version    SVN: $Id: admin_lotbuyingWidgetContainer.php 5437 2012-12-07 13:14:59Z fishbone $
14  * @link       http://www.magic3.org
15  */
16 require_once($gEnvManager->getContainerPath() . '/baseIWidgetContainer.php');
17 require_once($gEnvManager->getCurrentIWidgetDbPath() . '/lotbuyingDb.php');
18
19 class admin_lotbuyingWidgetContainer extends BaseIWidgetContainer
20 {
21         private $db;    // DB接続オブジェクト
22         private $productClass;          // 商品クラス
23         private $productType;           // 商品タイプ
24         
25         /**
26          * コンストラクタ
27          */
28         function __construct()
29         {
30                 // 親クラスを呼び出す
31                 parent::__construct();
32                 
33                 // DBオブジェクト取得
34                 $this->db = new lotbuyingDb();
35         }
36         /**
37          * テンプレートファイルを設定
38          *
39          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
40          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
41          *
42          * @param RequestManager $request               HTTPリクエスト処理クラス
43          * @param string         $act                   実行処理
44          * @param object         $configObj             定義情報オブジェクト
45          * @param object         $optionObj             可変パラメータオブジェクト
46          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
47          */
48         function _setTemplate($request, $act, $configObj, $optionObj)
49         {       
50                 return 'admin.tmpl.html';
51         }
52         /**
53          * テンプレートにデータ埋め込む
54          *
55          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
56          *
57          * @param RequestManager $request               HTTPリクエスト処理クラス
58          * @param string         $act                   実行処理
59          * @param object         $configObj             定義情報オブジェクト
60          * @param object         $optionObj             可変パラメータオブジェクト
61          * @param                                                               なし
62          */
63         function _assign($request, $act, $configObj, $optionObj)
64         {
65                 $langId = $this->gEnv->getCurrentLanguage();            // 表示言語を取得
66                 
67                 // 基本情報を取得
68                 $id             = $optionObj->id;               // ユニークなID(配送方法ID)
69                 $init   = $optionObj->init;             // データ初期化を行うかどうか
70                 
71                 // 入力値を取得
72                 $this->productClass     = $request->trimValueOf('iw_product_class');            // 商品クラス
73                 $this->productType      = $request->trimValueOf('iw_product_type');             // 商品タイプ
74                 $count                  = $request->trimValueOf('iw_count');                    // 単位数
75                 $discountRate   = $request->trimValueOf('iw_discount_rate');    // 割引率
76
77                 if ($act == 'update'){          // 設定更新のとき
78                         // 入力エラーチェック
79                         $this->checkNumeric($count, '個数');
80                         $this->checkNumeric($discountRate, '割引率');
81                         
82                         if ($this->getMsgCount() == 0){                 // エラーのないとき
83                                 $configObj->productClass        = $this->productClass;          // 商品クラス
84                                 $configObj->productType         = $this->productType;           // 商品タイプ
85                                 $configObj->count                       = $count;                               // 単位数
86                                 $configObj->discountRate        = $discountRate;                // 割引率
87                                 $ret = $this->updateConfigObj($configObj);
88                                 if (!$ret) $this->setMsg(self::MSG_APP_ERR, 'インナーウィジェットデータの更新に失敗しました');
89                                 // ***** 正常に終了した場合はメッセージを残さない *****
90                         }
91                 } else if ($act == 'content'){          // 画面表示のとき
92                         if (!empty($init)){                     // 初期表示のとき
93                                 if (empty($configObj)){         // 定義値がないとき(管理画面なので最初は定義値が存在しない)
94                                         $this->productClass     = '-';          // 商品クラス(選択なし)
95                                         $this->productType      = '-';          // 商品タイプ(選択なし)
96                                         $count                  = 10;           // 単位数
97                                         $discountRate   = 10;           // 割引率
98                                 } else {
99                                         $this->productClass     = $configObj->productClass;             // 商品クラス
100                                         $this->productType      = $configObj->productType;              // 商品タイプ
101                                         $count                  = $configObj->count;                    // 単位数
102                                         $discountRate   = $configObj->discountRate;             // 割引率
103                                 }
104                         }
105
106                         // 画面にデータを埋め込む
107                         $this->tmpl->addVar("_widget", "count", $count);
108                         $this->tmpl->addVar('_widget', 'discount_rate', $discountRate);
109                 }
110
111                 // 商品クラス選択メニュー作成
112                 $this->db->getAllProductClass($langId, array($this, 'productClassLoop'));
113                 
114                 // 商品タイプメニューを作成
115                 $this->db->getAllProductType($this->productClass, $langId, array($this, 'productTypeLoop'));
116         }
117         /**
118          * 商品クラスをテンプレートに設定する
119          *
120          * @param int $index                    行番号(0~)
121          * @param array $fetchedRow             フェッチ取得した行
122          * @param object $param                 未使用
123          * @return bool                                 true=処理続行の場合、false=処理終了の場合
124          */
125         function productClassLoop($index, $fetchedRow, $param)
126         {
127                 $id = $fetchedRow['pu_id'];
128                 $selected = '';
129                 if ($id == $this->productClass) $selected = 'selected';         // 選択中の商品クラス
130
131                 $row = array(
132                         'value'    => $this->convertToDispString($id),                  // ID
133                         'name'     => $this->convertToDispString($fetchedRow['pu_name']),                       // 表示名
134                         'selected' => $selected                                                                                                         // 選択中かどうか
135                 );
136                 $this->tmpl->addVars('product_class_list', $row);
137                 $this->tmpl->parseTemplate('product_class_list', 'a');
138                 return true;
139         }
140         /**
141          * 商品タイプをテンプレートに設定する
142          *
143          * @param int $index                    行番号(0~)
144          * @param array $fetchedRow             フェッチ取得した行
145          * @param object $param                 未使用
146          * @return bool                                 true=処理続行の場合、false=処理終了の場合
147          */
148         function productTypeLoop($index, $fetchedRow, $param)
149         {
150                 $id = $fetchedRow['py_id'];
151                 $selected = '';
152                 if ($id == $this->productType) $selected = 'selected';          // 選択中の商品タイプ
153
154                 $row = array(
155                         'value'    => $this->convertToDispString($id),                  // ID
156                         'name'     => $this->convertToDispString($fetchedRow['py_name']),                       // 表示名
157                         'selected' => $selected                                                                                                         // 選択中かどうか
158                 );
159                 $this->tmpl->addVars('product_type_list', $row);
160                 $this->tmpl->parseTemplate('product_type_list', 'a');
161                 return true;
162         }
163 }
164 ?>