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: admin_ec_mainProductcategoryWidgetContainer.php 5440 2012-12-08 09:37:39Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getCurrentWidgetContainerPath() . '/admin_ec_mainBaseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/ec_mainProductCategoryDb.php');
19 class admin_ec_mainProductcategoryWidgetContainer extends admin_ec_mainBaseWidgetContainer
21 private $db; // DB接続オブジェクト
22 private $langId; // 表示言語
23 private $serialNo; // シリアル番号
24 private $serialArray = array(); // 表示されている項目シリアル番号
25 private $parentCategoryId; // 親カテゴリーID
26 private $id; // カテゴリーID
31 function __construct()
34 parent::__construct();
37 $this->db = new ec_mainProductCategoryDb();
42 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
43 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
45 * @param RequestManager $request HTTPリクエスト処理クラス
46 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
47 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
49 function _setTemplate($request, &$param)
51 $task = $request->trimValueOf('task');
52 if ($task == 'productcategory_detail'){ // 詳細画面
53 return 'admin_productcategory_detail.tmpl.html';
55 return 'admin_productcategory.tmpl.html';
61 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
63 * @param RequestManager $request HTTPリクエスト処理クラス
64 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
67 function _assign($request, &$param)
69 $task = $request->trimValueOf('task');
70 if ($task == 'productcategory_detail'){ // 詳細画面
71 return $this->createDetail($request);
73 return $this->createList($request);
79 * @param RequestManager $request HTTPリクエスト処理クラス
82 function createList($request)
84 $this->langId = $this->gEnv->getCurrentLanguage(); // 表示言語を取得
85 $act = $request->trimValueOf('act');
87 if ($act == 'delete'){ // 項目削除の場合
88 $listedItem = explode(',', $request->trimValueOf('seriallist'));
90 for ($i = 0; $i < count($listedItem); $i++){
92 $itemName = 'item' . $i . '_selected';
93 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
95 if ($itemValue){ // チェック項目
96 $delItems[] = $listedItem[$i];
99 if (count($delItems) > 0){
100 $ret = $this->db->delCategoryBySerial($delItems);
101 if ($ret){ // データ削除成功のとき
102 $this->setGuidanceMsg('データを削除しました');
104 $this->setAppErrorMsg('データ削除に失敗しました');
108 // #### カテゴリーリストを作成 ####
109 $this->db->getAllCategory($this->langId, array($this, 'categoryListLoop'));// デフォルト言語で取得
111 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
116 * @param RequestManager $request HTTPリクエスト処理クラス
119 function createDetail($request)
121 $this->langId = $this->gEnv->getCurrentLanguage(); // 表示言語を取得
122 $userId = $this->gEnv->getCurrentUserId();
124 $act = $request->trimValueOf('act');
125 $this->serialNo = $request->trimValueOf('serial'); // 選択項目のシリアル番号
127 $name = $request->trimValueOf('item_name'); // カテゴリー名称
128 $index = $request->trimValueOf('item_index'); // 表示順
129 $visible = ($request->trimValueOf('item_visible') == 'on') ? 1 : 0; // 表示するかどうか
130 $this->parentCategoryId = $request->trimValueOf('item_pcategory'); // 親カテゴリーID
132 $replaceNew = false; // データを再取得するかどうか
133 if ($act == 'add'){ // 項目追加の場合
135 $this->checkInput($name, '名前');
136 $this->checkNumeric($index, '表示順');
139 if ($this->getMsgCount() == 0){
140 $ret = $this->db->addCategory(0, $this->langId, $name, $this->parentCategoryId, $index, $visible, $userId, $newSerial);
142 $this->setGuidanceMsg('データを追加しました');
145 $this->serialNo = $newSerial;
146 $replaceNew = true; // データを再取得
148 $this->setAppErrorMsg('データ追加に失敗しました');
151 } else if ($act == 'update'){ // 項目更新の場合
153 $this->checkInput($name, '名前');
154 $this->checkNumeric($index, '表示順');
157 if ($this->getMsgCount() == 0){
158 $ret = $this->db->updateCategory($this->serialNo, $name, $this->parentCategoryId, $index, $visible, $userId, $newSerial);
160 $this->setGuidanceMsg('データを更新しました');
163 $this->serialNo = $newSerial;
164 $replaceNew = true; // データを再取得
166 $this->setAppErrorMsg('データ更新に失敗しました');
169 } else if ($act == 'delete'){ // 項目削除の場合
170 $ret = $this->db->delCategoryBySerial(array($this->serialNo));
171 if ($ret){ // データ削除成功のとき
172 $this->setGuidanceMsg('データを削除しました');
174 $this->setAppErrorMsg('データ削除に失敗しました');
178 if (empty($this->serialNo)){ // シリアル番号
180 $index = $this->db->getMaxIndex($this->langId) + 1; // 表示順
181 $visible = 1; // 表示状態
182 $this->parentCategoryId = 0; // 親カテゴリーID
184 $replaceNew = true; // データを再取得
189 $ret = $this->db->getCategoryBySerial($this->serialNo, $row);
192 $this->id = $row['pc_id']; // ID
193 $this->langId = $row['pc_language_id']; // 言語ID
194 $name = $row['pc_name']; // 名前
195 $index = $row['pc_sort_order']; // 表示順
196 $visible = $row['pc_visible']; // 表示状態
197 $this->parentCategoryId = $row['pc_parent_id']; // 親カテゴリーID
198 $updateUser = $this->convertToDispString($row['lu_name']); // 更新者
199 $updateDt = $this->convertToDispDateTime($row['pc_create_dt']); // 更新日時
203 $this->db->getAllCategory($this->langId, array($this, 'pcategoryListLoop'));
205 // #### 更新、新規登録部をを作成 ####
206 if (empty($this->serialNo)){ // シリアル番号のときは新規とする
207 $this->tmpl->addVar("_widget", "id", '新規');
208 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');// 「新規追加」ボタン
210 $this->tmpl->addVar("_widget", "id", $this->id);
211 $this->tmpl->setAttribute('update_button', 'visibility', 'visible');
213 $this->tmpl->addVar("_widget", "serial", $this->serialNo);
214 $this->tmpl->addVar("_widget", "name", $name); // 名前
215 $this->tmpl->addVar("_widget", "index", $index); // 表示順
218 if ($visible){ // 項目の表示
219 $visibleStr = 'checked';
221 $this->tmpl->addVar("_widget", "visible", $visibleStr); // 表示状態
222 if (!empty($updateUser)) $this->tmpl->addVar("_widget", "update_user", $updateUser); // 更新者
223 if (!empty($updateDt)) $this->tmpl->addVar("_widget", "update_dt", $updateDt); // 更新日時
226 * 取得したデータをテンプレートに設定する
228 * @param int $index 行番号(0~)
229 * @param array $fetchedRow フェッチ取得した行
230 * @param object $param 未使用
231 * @return bool true=処理続行の場合、false=処理終了の場合
233 function categoryListLoop($index, $fetchedRow, $param)
235 $serial = $fetchedRow['pc_serial'];
236 $id = $this->convertToDispString($fetchedRow['pc_id']);
240 $ret = $this->db->getLangByCategoryId($fetchedRow['pc_id'], $rows);
242 $count = count($rows);
243 for ($i = 0; $i < $count; $i++){
244 if ($this->gEnv->getCurrentLanguage() == 'ja'){ // 日本語の場合
245 $lang .= $rows[$i]['ln_name'];
246 if ($i != $count -1) $lang .= ',';
248 $lang .= $rows[$i]['ln_name_en'];
249 if ($i != $count -1) $lang .= ',';
254 $pcatId = $fetchedRow['pc_parent_id'];
257 $ret = $this->db->getCategoryByCategoryId($pcatId, $this->gEnv->getDefaultLanguage(), $row);
258 if ($ret) $pcategoryName = $this->convertToDispString($row['pc_name']);
261 if ($fetchedRow['pc_visible']){ // 項目の表示
262 $visible = 'checked';
265 'index' => $index, // 行番号
266 'serial' => $serial, // シリアル番号
268 'name' => $this->convertToDispString($fetchedRow['pc_name']), // 名前
269 'pcategory_name' => $pcategoryName, // 親カテゴリー名前
270 'view_index' => $this->convertToDispString($fetchedRow['pc_sort_order']), // 表示順
271 'lang' => $lang, // 対応言語
272 'update_user' => $this->convertToDispString($fetchedRow['lu_name']), // 更新者
273 'update_dt' => $this->convertToDispDateTime($fetchedRow['pc_create_dt']), // 更新日時
274 'visible' => $visible, // メニュー項目表示制御
275 'default' => $default // デフォルト項目
277 $this->tmpl->addVars('itemlist', $row);
278 $this->tmpl->parseTemplate('itemlist', 'a');
281 $this->serialArray[] = $serial;
287 * @param int $index 行番号(0~)
288 * @param array $fetchedRow フェッチ取得した行
289 * @param object $param 未使用
290 * @return bool true=処理続行の場合、false=処理終了の場合
292 function langLoop($index, $fetchedRow, $param)
295 if ($fetchedRow['ln_id'] == $this->langId){
296 $selected = 'selected';
298 if ($this->gEnv->getCurrentLanguage() == 'ja'){ // 日本語表示の場合
299 $name = $this->convertToDispString($fetchedRow['ln_name']);
301 $name = $this->convertToDispString($fetchedRow['ln_name_en']);
305 'value' => $this->convertToDispString($fetchedRow['ln_id']), // 言語ID
306 'name' => $name, // 言語名
307 'selected' => $selected // 選択中かどうか
309 $this->tmpl->addVars('lang_list', $row);
310 $this->tmpl->parseTemplate('lang_list', 'a');
314 * 取得したデータをテンプレートに設定する
316 * @param int $index 行番号(0~)
317 * @param array $fetchedRow フェッチ取得した行
318 * @param object $param 未使用
319 * @return bool true=処理続行の場合、false=処理終了の場合
321 function pcategoryListLoop($index, $fetchedRow, $param)
323 $id = $fetchedRow['pc_id'];// カテゴリ項目ID
324 $name = $fetchedRow['pc_name']; // カテゴリ項目名
326 if ($id == $this->parentCategoryId) $selected = 'selected';
328 // 自分自身は親カテゴリーメニューに加えない
329 if ($this->id == $id) return true;
332 'value' => $this->convertToDispString($id), // カテゴリ項目ID
333 'name' => $this->convertToDispString($name), // カテゴリ項目名
334 'selected' => $selected // 選択中かどうか
336 $this->tmpl->addVars('category_list', $row);
337 $this->tmpl->parseTemplate('category_list', 'a');