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-2011 Magic3 Project.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
13 * @version SVN: $Id: admin_event_mainCategoryWidgetContainer.php 3976 2011-02-03 13:58:42Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getCurrentWidgetContainerPath() . '/admin_event_mainBaseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/event_categoryDb.php');
19 class admin_event_mainCategoryWidgetContainer extends admin_event_mainBaseWidgetContainer
21 private $langId; // 言語ID
22 private $serialNo; // 選択中の項目のシリアル番号
23 private $serialArray = array(); // 表示されている項目シリアル番号
24 private $categoryItemArray = array(); // カテゴリ項目情報
29 function __construct()
32 parent::__construct();
35 $this->db = new event_categoryDb();
40 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
41 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
43 * @param RequestManager $request HTTPリクエスト処理クラス
44 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
45 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
47 function _setTemplate($request, &$param)
49 $task = $request->trimValueOf('task');
50 if ($task == 'category_detail'){ // 詳細画面
51 return 'admin_category_detail.tmpl.html';
53 return 'admin_category.tmpl.html';
59 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
61 * @param RequestManager $request HTTPリクエスト処理クラス
62 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
65 function _assign($request, &$param)
67 $task = $request->trimValueOf('task');
68 if ($task == 'category_detail'){ // 詳細画面
69 return $this->createDetail($request);
71 return $this->createList($request);
77 * @param RequestManager $request HTTPリクエスト処理クラス
80 function createList($request)
82 $this->langId = $this->gEnv->getDefaultLanguage(); // デフォルト言語
83 $act = $request->trimValueOf('act');
85 if ($act == 'delete'){ // 項目削除の場合
86 $listedItem = explode(',', $request->trimValueOf('seriallist'));
88 for ($i = 0; $i < count($listedItem); $i++){
90 $itemName = 'item' . $i . '_selected';
91 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
93 if ($itemValue){ // チェック項目
94 $delItems[] = $listedItem[$i];
97 if (count($delItems) > 0){
98 $ret = $this->db->delCategory($delItems);
99 if ($ret){ // データ削除成功のとき
100 $this->setGuidanceMsg('データを削除しました');
102 $this->setAppErrorMsg('データ削除に失敗しました');
108 $this->db->getAllCategory($this->langId, array($this, 'itemLoop'));
110 if (count($this->serialArray) > 0){
111 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
114 $this->tmpl->setAttribute('itemlist', 'visibility', 'hidden');
120 * @param RequestManager $request HTTPリクエスト処理クラス
123 function createDetail($request)
125 $this->langId = $this->gEnv->getDefaultLanguage(); // デフォルト言語
127 $act = $request->trimValueOf('act');
128 $this->serialNo = $request->trimValueOf('serial'); // 選択項目のシリアル番号
129 $name = $request->trimValueOf('item_name'); // 名前
130 $id = $request->trimValueOf('item_id'); // 識別ID
131 $index = $request->trimValueOf('item_index'); // 表示順
132 $itemCount = intval($request->trimValueOf('itemcount')); // カテゴリ項目数
133 $lineIds = $request->trimValueOf('item_lineid'); // 行カテゴリID
134 $lineNames = $request->trimValueOf('item_linename'); // 行カテゴリ名前
137 for ($i = 0; $i < $itemCount; $i++){
139 $line['ec_item_id'] = $lineIds[$i];
140 $line['ec_name'] = $lineNames[$i];
141 $line['ec_index'] = $i + 1;
142 $this->categoryItemArray[] = $line;
145 $replaceNew = false; // データを再取得するかどうか
146 if ($act == 'add'){ // 新規追加のとき
148 $this->checkInput($name, '表示名');
149 $this->checkSingleByte($id, 'カテゴリ識別ID');
150 $this->checkNumeric($index, '表示順'); // 表示順
151 for ($i = 0; $i < $itemCount; $i++){
153 $this->checkInput($this->categoryItemArray[$i]['ec_name'], 'カテゴリ項目名(No.' . $no . ')');
154 $this->checkSingleByte($this->categoryItemArray[$i]['ec_item_id'], 'カテゴリ項目ID(No.' . $no . ')');
158 if ($this->db->getCategoryById($id, $this->langId, $row)) $this->setMsg(self::MSG_USER_ERR, 'カテゴリ識別IDが重複しています');
161 if ($this->getMsgCount() == 0){
162 $ret = $this->db->updateCategory(0/*新規*/, $id, $this->langId, $name, $index, $this->categoryItemArray, $newSerial);
163 if ($ret){ // データ追加成功のとき
164 $this->setMsg(self::MSG_GUIDANCE, 'データを追加しました');
166 $this->serialNo = $newSerial; // シリアル番号を更新
167 $replaceNew = true; // データを再取得
169 $this->setMsg(self::MSG_APP_ERR, 'データ追加に失敗しました');
172 } else if ($act == 'update'){ // 行更新のとき
174 $this->checkInput($name, '表示名');
175 $this->checkSingleByte($id, 'カテゴリ識別ID');
176 $this->checkNumeric($index, '表示順'); // 表示順
177 for ($i = 0; $i < $itemCount; $i++){
179 $this->checkInput($this->categoryItemArray[$i]['ec_name'], 'カテゴリ項目名(No.' . $no . ')');
180 $this->checkSingleByte($this->categoryItemArray[$i]['ec_item_id'], 'カテゴリ項目ID(No.' . $no . ')');
184 if ($this->getMsgCount() == 0){
185 $ret = $this->db->updateCategory($this->serialNo, $id, $this->langId, $name, $index, $this->categoryItemArray, $newSerial);
186 if ($ret){ // データ追加成功のとき
187 $this->setMsg(self::MSG_GUIDANCE, 'データを更新しました');
189 $this->serialNo = $newSerial; // シリアル番号を更新
190 $replaceNew = true; // データを再取得
192 $this->setMsg(self::MSG_APP_ERR, 'データ更新に失敗しました');
197 $ret = $this->db->getCategoryBySerial($this->serialNo, $row);
198 if ($ret) $id = $row['ec_id']; // カテゴリ識別ID
200 if (empty($id)){ // カテゴリIDが空のときは新規とする
206 $replaceNew = true; // データを再取得
212 $ret = $this->db->getCategoryById($id, $this->langId, $row);
214 $this->serialNo = $row['ec_serial'];
215 $name = $row['ec_name'];
216 $index = $row['ec_index']; // 表示順
219 $ret = $this->db->getAllCategoryItemsById($id, $this->langId, $this->categoryItemArray);
224 $this->createCategoryItemList();
225 if (empty($this->categoryItemArray)) $this->tmpl->setAttribute('item_list', 'visibility', 'hidden');// カテゴリ項目情報一覧
227 if (empty($this->serialNo)){ // シリアル番号が空のときは新規とする
228 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');// 新規登録ボタン表示
229 $this->tmpl->setAttribute('new_id_field', 'visibility', 'visible');// 新規ID入力フィールド表示
231 $this->tmpl->addVar("new_id_field", "id", $id); // 識別キー
233 $this->tmpl->setAttribute('update_button', 'visibility', 'visible');// 更新ボタン表示
234 $this->tmpl->setAttribute('id_field', 'visibility', 'visible');// 固定IDフィールド表示
236 $this->tmpl->addVar("id_field", "id", $id); // 識別キー
240 $this->tmpl->addVar("_widget", "name", $name); // 名前
241 $this->tmpl->addVar("_widget", "index", $index); // 表示順
244 $this->tmpl->addVar("_widget", "serial", $this->serialNo);
247 * 取得したタブ定義をテンプレートに設定する
249 * @param int $index 行番号(0~)
250 * @param array $fetchedRow フェッチ取得した行
251 * @param object $param 未使用
252 * @return bool true=処理続行の場合、false=処理終了の場合
254 function itemLoop($index, $fetchedRow, $param)
258 'serial' => $fetchedRow['ec_serial'],
259 'id' => $this->convertToDispString($fetchedRow['ec_id']), // 識別ID
260 'name' => $this->convertToDispString($fetchedRow['ec_name']), // 表示名
261 'item_index' => $fetchedRow['ec_index'] // 表示順
263 $this->tmpl->addVars('itemlist', $row);
264 $this->tmpl->parseTemplate('itemlist', 'a');
267 $this->serialArray[] = $fetchedRow['ec_serial'];
275 function createCategoryItemList()
277 $itemCount = count($this->categoryItemArray);
278 for ($i = 0; $i < $itemCount; $i++){
279 $id = $this->categoryItemArray[$i]['ec_item_id'];// カテゴリ項目ID
280 $name = $this->categoryItemArray[$i]['ec_name']; // カテゴリ項目名
283 'id' => $this->convertToDispString($id), // カテゴリ項目ID
284 'name' => $this->convertToDispString($name), // カテゴリ項目名
285 'root_url' => $this->convertToDispString($this->getUrl($this->gEnv->getRootUrl()))
287 $this->tmpl->addVars('item_list', $row);
288 $this->tmpl->parseTemplate('item_list', 'a');