7 * LICENSE: This source file is licensed under the terms of the GNU General Public License.
10 * @author 株式会社 毎日メディアサービス
11 * @copyright Copyright 2010 株式会社 毎日メディアサービス.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
13 * @version SVN: $Id: admin_user_contentRoomWidgetContainer.php 3026 2010-04-13 05:14:43Z fishbone $
14 * @link http://www.m-media.co.jp
16 require_once($gEnvManager->getCurrentWidgetContainerPath() . '/admin_user_contentBaseWidgetContainer.php');
18 class admin_user_contentRoomWidgetContainer extends admin_user_contentBaseWidgetContainer
20 private $langId; // 言語ID
21 private $serialNo; // 選択中の項目のシリアル番号
22 private $serialArray = array(); // 表示されている項目シリアル番号
23 private $categoryArray = array(); // 表示されている所属カテゴリのID
24 private $categoryValues = array(); // 選択されているカテゴリの項目値
25 const CONTENT_TYPE = 'uc'; // 参照数カウント用
30 function __construct()
33 parent::__construct();
38 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
39 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
41 * @param RequestManager $request HTTPリクエスト処理クラス
42 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
43 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
45 function _setTemplate($request, &$param)
47 $task = $request->trimValueOf('task');
48 if ($task == 'room_detail'){ // 詳細画面
49 return 'admin_room_detail.tmpl.html';
51 return 'admin_room.tmpl.html';
57 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
59 * @param RequestManager $request HTTPリクエスト処理クラス
60 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
63 function _assign($request, &$param)
65 $task = $request->trimValueOf('task');
66 if ($task == 'room_detail'){ // 詳細画面
67 return $this->createDetail($request);
69 return $this->createList($request);
75 * @param RequestManager $request HTTPリクエスト処理クラス
78 function createList($request)
80 $this->langId = $this->gEnv->getDefaultLanguage(); // デフォルト言語
81 $act = $request->trimValueOf('act');
83 if ($act == 'delete'){ // 項目削除の場合
84 $listedItem = explode(',', $request->trimValueOf('seriallist'));
86 for ($i = 0; $i < count($listedItem); $i++){
88 $itemName = 'item' . $i . '_selected';
89 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
91 if ($itemValue){ // チェック項目
92 $delItems[] = $listedItem[$i];
95 if (count($delItems) > 0){
98 for ($i = 0; $i < count($delItems); $i++){
100 $ret = $this->_localDb->getRoomBySerial($delItems[$i], $row);
101 if ($ret) $roomArray[] = $row['ur_id']; // ルーム識別ID
105 $ret = $this->_localDb->delRoom($delItems);
107 // 削除するルームに対応したカテゴリを削除
109 for ($i = 0; $i < count($roomArray); $i++){
110 $ret = $this->_localDb->delRoomCategory($roomArray[$i]);
114 if ($ret){ // データ削除成功のとき
115 $this->setGuidanceMsg('データを削除しました');
117 $this->setAppErrorMsg('データ削除に失敗しました');
123 $this->_localDb->getAllRooms(array($this, 'itemLoop'));
125 if (count($this->serialArray) > 0){
126 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
129 $this->tmpl->setAttribute('itemlist', 'visibility', 'hidden');
135 * @param RequestManager $request HTTPリクエスト処理クラス
138 function createDetail($request)
140 $this->langId = $this->gEnv->getDefaultLanguage(); // デフォルト言語
142 $act = $request->trimValueOf('act');
143 $this->serialNo = $request->trimValueOf('serial'); // 選択項目のシリアル番号
144 $name = $request->trimValueOf('item_name'); // 名前
145 $id = $request->trimValueOf('item_id'); // ルーム識別ID
146 $groupId = $request->trimValueOf('item_group_id'); // 所属グループID
147 $visible = ($request->trimValueOf('item_visible') == 'on') ? 1 : 0; // 表示するかどうか
148 $categoryList = $request->trimValueOf('category_list'); // カテゴリIDのリスト
149 if (!empty($categoryList)) $this->categoryArray = explode(',', $categoryList);
152 for ($i = 0; $i < count($this->categoryArray); $i++){
153 $itemName = 'item_category' . $i;
154 $itemValue = $request->trimValueOf($itemName);
155 $categoryId = $this->categoryArray[$i];
158 if (!empty($itemValue)) $this->categoryValues[$categoryId] = $itemValue;
161 $replaceNew = false; // データを再取得するかどうか
162 if ($act == 'add'){ // 新規追加のとき
164 //$this->checkInput($name, '表示名');
165 $this->checkSingleByte($id, '識別ID');
166 $this->checkNumeric($groupId, '所属グループID'); // 所属グループID
169 if ($this->_localDb->getRoomById($id, $row)) $this->setMsg(self::MSG_USER_ERR, '識別IDが重複しています');
172 if ($this->getMsgCount() == 0){
173 $ret = $this->_localDb->updateRoom(0/*新規*/, $id, $name, $groupId, $visible, $newSerial);
176 if ($ret) $ret = $this->_localDb->updateRoomCategory($id, $this->categoryValues);
178 if ($ret){ // データ追加成功のとき
179 $this->setMsg(self::MSG_GUIDANCE, 'データを追加しました');
181 $this->serialNo = $newSerial; // シリアル番号を更新
182 $replaceNew = true; // データを再取得
184 $this->setMsg(self::MSG_APP_ERR, 'データ追加に失敗しました');
187 } else if ($act == 'update'){ // 行更新のとき
189 //$this->checkInput($name, '表示名');
190 $this->checkNumeric($groupId, '所属グループID'); // 所属グループID
193 if ($this->getMsgCount() == 0){
194 $ret = $this->_localDb->updateRoom($this->serialNo, $id, $name, $groupId, $visible, $newSerial);
197 if ($ret) $ret = $this->_localDb->updateRoomCategory($id, $this->categoryValues);
199 if ($ret){ // データ追加成功のとき
200 $this->setMsg(self::MSG_GUIDANCE, 'データを更新しました');
202 $this->serialNo = $newSerial; // シリアル番号を更新
203 $replaceNew = true; // データを再取得
205 $this->setMsg(self::MSG_APP_ERR, 'データ更新に失敗しました');
210 $ret = $this->_localDb->getRoomBySerial($this->serialNo, $row);
211 if ($ret) $id = $row['ur_id']; // ルーム識別ID
213 if (empty($id)){ // タブ識別IDが空のときは新規とする
217 $groupId = 0; // 所属グループID
220 $replaceNew = true; // データを再取得
226 $ret = $this->_localDb->getRoomById($id, $row);
228 $this->serialNo = $row['ur_serial'];
229 $name = $row['ur_name'];
230 $groupId = $row['ur_group_id']; // 所属グループID
231 $visible = $row['ur_visible']; // 公開
234 $ret = $this->_localDb->getRoomCategory($id, $rows);
236 $this->categoryValues = array();
237 for ($i = 0; $i < count($rows); $i++){
238 $key = $rows[$i][um_category_id];
239 $value = $rows[$i][um_category_item_id];
240 $this->categoryValues[$key] = $value;
247 $this->categoryArray = array(); // 表示カテゴリを一旦初期化
248 $this->_localDb->getAllCategoryForMenu($this->langId, array($this, 'menuLoop'));
250 // 項目がないときは、カテゴリメニューを表示しない
251 if (empty($this->categoryArray)){
252 $this->tmpl->setAttribute('category', 'visibility', 'hidden');
253 } else { // カテゴリが設定されているとき
254 $this->tmpl->addVar("_widget", "category_list", implode($this->categoryArray, ',')); // 表示中のカテゴリIDのリスト
257 if (empty($this->serialNo)){ // シリアル番号が空のときは新規とする
258 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');// 新規登録ボタン表示
259 $this->tmpl->setAttribute('new_id_field', 'visibility', 'visible');// 新規ID入力フィールド表示
261 $this->tmpl->addVar("new_id_field", "id", $id); // 識別キー
263 $this->tmpl->setAttribute('update_button', 'visibility', 'visible');// 更新ボタン表示
264 $this->tmpl->setAttribute('id_field', 'visibility', 'visible');// 固定IDフィールド表示
266 $this->tmpl->addVar("id_field", "id", $id); // 識別キー
270 $this->tmpl->addVar("_widget", "name", $name); // 名前
271 $this->tmpl->addVar("_widget", "group_id", $groupId); // 所属グループID
273 // 項目表示、項目利用可否チェックボックス
275 if ($visible) $checked = 'checked';
276 $this->tmpl->addVar("_widget", "visible", $checked);
279 $this->tmpl->addVar("_widget", "serial", $this->serialNo);
282 * 取得したルーム情報をテンプレートに設定する
284 * @param int $index 行番号(0~)
285 * @param array $fetchedRow フェッチ取得した行
286 * @param object $param 未使用
287 * @return bool true=処理続行の場合、false=処理終了の場合
289 function itemLoop($index, $fetchedRow, $param)
291 $id = $fetchedRow['ur_id']; // ルームID
293 if ($fetchedRow['ur_visible']){ // 項目の表示
294 $visible = 'checked';
298 $contentId = $id; // コンテンツID
299 $totalViewCount = $this->gInstance->getAnalyzeManager()->getTotalContentViewCount(self::CONTENT_TYPE, 0/*コンテンツID指定*/, $contentId);
303 'serial' => $fetchedRow['ur_serial'],
304 'id' => $this->convertToDispString($id), // 識別ID
305 'name' => $this->convertToDispString($fetchedRow['ur_name']), // 表示名
306 'group' => $this->convertToDispString($fetchedRow['ur_group_id']), // 所属グループID
307 'visible' => $visible, // 公開状況
308 'view_count' => $totalViewCount // 総参照数
310 $this->tmpl->addVars('itemlist', $row);
311 $this->tmpl->parseTemplate('itemlist', 'a');
314 $this->serialArray[] = $fetchedRow['ur_serial'];
318 * 取得したタブ定義をテンプレートに設定する
320 * @param int $index 行番号(0~)
321 * @param array $fetchedRow フェッチ取得した行
322 * @param object $param 未使用
323 * @return bool true=処理続行の場合、false=処理終了の場合
325 function menuLoop($index, $fetchedRow, $param)
327 static $categoryIndex = 0; // カテゴリ表示順
328 static $isFirst = true; // 最初の項目かどうか
330 $id = $fetchedRow['ua_id'];
331 $itemId = $fetchedRow['ua_item_id'];
332 if (empty($itemId)){ // カテゴリタイトルのとき
334 'index' => $categoryIndex, // 項目番号
335 'title' => $this->convertToDispString($fetchedRow['ua_name']) // 表示名
337 $this->tmpl->addVars('category', $itemRow);
338 $this->tmpl->parseTemplate('category', 'a');
340 $categoryIndex++; // カテゴリ表示順を更新
341 $isFirst = true; // 最初の項目かどうか
342 $this->categoryArray[] = $fetchedRow['ua_id'];// カテゴリIDを保存
344 if ($isFirst){ // 最初の項目のとき
345 $this->tmpl->clearTemplate('category_list');
350 if ($this->categoryValues[$id] == $itemId) $selected = 'selected';
353 'value' => $this->convertToDispString($itemId), // カテゴリー項目ID
354 'name' => $this->convertToDispString($fetchedRow['ua_name']), // カテゴリー項目名
355 'selected' => $selected // 選択中かどうか
357 $this->tmpl->addVars('category_list', $menurow);
358 $this->tmpl->parseTemplate('category_list', 'a');