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-2009 Magic3 Project.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
13 * @version SVN: $Id: admin_youtube2WidgetContainer.php 2266 2009-08-28 08:25:59Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getContainerPath() . '/baseAdminWidgetContainer.php');
18 class admin_youtube2WidgetContainer extends BaseAdminWidgetContainer
20 private $sysDb; // DB接続オブジェクト
21 private $serialNo; // 選択中の項目のシリアル番号
22 private $serialArray = array(); // 表示中のシリアル番号
24 private $configId; // 定義ID
25 private $paramObj; // パラメータ保存用オブジェクト
26 const DEFAULT_NAME_HEAD = '名称未設定'; // デフォルトの設定名
27 const DEFAULT_WIDTH = 130; // デフォルトの幅
28 const DEFAULT_HEIGHT = 130; // デフォルトの高さ
29 const DEFAULT_MOVIE_ID = 'J_W0_VrUSBU'; // デフォルトの動画
34 function __construct()
37 parent::__construct();
40 $this->sysDb = $this->gInstance->getSytemDbObject();
45 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
46 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
48 * @param RequestManager $request HTTPリクエスト処理クラス
49 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
50 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
52 function _setTemplate($request, &$param)
54 $task = $request->trimValueOf('task');
55 if ($task == 'list'){ // 一覧画面
56 return 'admin_list.tmpl.html';
58 return 'admin.tmpl.html';
64 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
66 * @param RequestManager $request HTTPリクエスト処理クラス
67 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
70 function _assign($request, &$param)
72 $task = $request->trimValueOf('task');
73 if ($task == 'list'){ // 一覧画面
74 return $this->createList($request);
76 return $this->createDetail($request);
82 * @param RequestManager $request HTTPリクエスト処理クラス
85 function createDetail($request)
87 // ページ定義IDとページ定義のレコードシリアル番号を取得
88 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
90 $userId = $this->gEnv->getCurrentUserId();
91 $this->langId = $this->gEnv->getCurrentLanguage(); // 表示言語を取得
92 $act = $request->trimValueOf('act');
93 $this->serialNo = $request->trimValueOf('serial'); // 選択項目のシリアル番号
96 $name = $request->trimValueOf('item_name'); // ヘッダタイトル
97 $width = $request->trimValueOf('item_width'); // ヘッダの幅
98 $height = $request->trimValueOf('item_height'); // ヘッダの高さ
99 $movieId = $request->trimValueOf('item_movie_id'); // YouTubeの動画ID
100 $this->configId = $request->trimValueOf('item_id'); // 定義ID
101 if (empty($this->configId)) $this->configId = $defConfigId; // 呼び出しウィンドウから引き継いだ定義ID
103 $replaceNew = false; // データを再取得するかどうか
104 if (empty($act)){// 初期起動時
106 $this->configId = $defConfigId; // 呼び出しウィンドウから引き継いだ定義ID
107 $replaceNew = true; // データ再取得
108 } else if ($act == 'add'){// 新規追加
110 $this->checkInput($name, '名前');
111 $this->checkInput($movieId, '動画ID');
112 $this->checkNumeric($width, '幅');
113 $this->checkNumeric($height, '高さ');
116 for ($i = 0; $i < count($this->paramObj); $i++){
117 $targetObj = $this->paramObj[$i]->object;
118 if ($name == $targetObj->name){ // 定義名
119 $this->setUserErrorMsg('名前が重複しています');
125 if ($this->getMsgCount() == 0){
127 $newObj = new stdClass;
128 $newObj->name = $name;// 表示名
129 $newObj->width = $width; // 幅
130 $newObj->height = $height; // 高さ
131 $newObj->movieId = $movieId; // YouTubeの動画ID
133 $ret = $this->addPageDefParam($defSerial, $defConfigId, $this->paramObj, $newObj);
135 $this->setGuidanceMsg('データを追加しました');
137 $this->configId = $defConfigId; // 定義定義IDを更新
138 $replaceNew = true; // データ再取得
140 $this->setAppErrorMsg('データ追加に失敗しました');
143 } else if ($act == 'update'){ // 設定更新のとき
145 $this->checkInput($movieId, '動画ID');
146 $this->checkNumeric($width, '幅');
147 $this->checkNumeric($height, '高さ');
149 if ($this->getMsgCount() == 0){ // エラーのないとき
151 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
154 $targetObj->width = $width; // ヘッダの幅
155 $targetObj->height = $height; // ヘッダの高さ
156 $targetObj->movieId = $movieId; // YouTubeの動画ID
160 if ($ret) $ret = $this->updatePageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
162 $this->setMsg(self::MSG_GUIDANCE, 'データを更新しました');
164 $replaceNew = true; // データ再取得
166 $this->setMsg(self::MSG_APP_ERR, 'データ更新に失敗しました');
169 } else if ($act == 'select'){ // 定義IDを変更
170 $replaceNew = true; // データ再取得
174 $this->createItemMenu();
177 if (empty($this->configId)){ // 新規登録の場合
178 $this->tmpl->setAttribute('item_name_visible', 'visibility', 'visible');// 名前入力フィールド表示
179 if ($replaceNew){ // データ再取得時
180 $name = $this->createDefaultName(); // デフォルト登録項目名
181 $width = self::DEFAULT_WIDTH; // 幅
182 $height = self::DEFAULT_HEIGHT; // 高さ
183 $movieId = self::DEFAULT_MOVIE_ID; // YouTubeの動画ID
188 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
190 $name = $targetObj->name;// 名前
191 $width = $targetObj->width; // 幅
192 $height = $targetObj->height; // 高さ
193 $movieId = $targetObj->movieId; // YouTubeの動画ID
196 $this->serialNo = $this->configId;
198 // 新規作成でないときは、メニューを変更不可にする(画面作成から呼ばれている場合のみ)
199 if (!empty($defConfigId) && !empty($defSerial)) $this->tmpl->addVar("_widget", "id_disabled", 'disabled');
203 $this->tmpl->addVar("item_name_visible", "name", $name); // 名前
204 $this->tmpl->addVar("_widget", "width", $width);
205 $this->tmpl->addVar("_widget", "height", $height);
206 $this->tmpl->addVar("_widget", "movie_id", $movieId);
208 $this->tmpl->addVar("_widget", "serial", $this->serialNo);// 選択中のシリアル番号、IDを設定
211 if (empty($this->serialNo)){ // 新規追加項目を選択しているとき
212 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');// 「新規追加」ボタン
214 $this->tmpl->setAttribute('update_button', 'visibility', 'visible');// 「更新」ボタン
216 // ページ定義IDとページ定義のレコードシリアル番号を更新
217 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
224 function createItemMenu()
226 for ($i = 0; $i < count($this->paramObj); $i++){
227 $id = $this->paramObj[$i]->id;// 定義ID
228 $targetObj = $this->paramObj[$i]->object;
229 $name = $targetObj->name;// 定義名
232 if ($this->configId == $id) $selected = 'selected';
234 'name' => $name, // 名前
235 'value' => $id, // 定義ID
236 'selected' => $selected // 選択中の項目かどうか
238 $this->tmpl->addVars('title_list', $row);
239 $this->tmpl->parseTemplate('title_list', 'a');
245 * @return string デフォルト名
247 function createDefaultName()
249 $name = self::DEFAULT_NAME_HEAD;
250 for ($j = 1; $j < 100; $j++){
251 $name = self::DEFAULT_NAME_HEAD . $j;
253 for ($i = 0; $i < count($this->paramObj); $i++){
254 $targetObj = $this->paramObj[$i]->object;
255 if ($name == $targetObj->name){ // 定義名
260 if ($i == count($this->paramObj)) break;
267 * @param RequestManager $request HTTPリクエスト処理クラス
270 function createList($request)
272 // ページ定義IDとページ定義のレコードシリアル番号を取得
273 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
275 $userId = $this->gEnv->getCurrentUserId();
276 $langId = $this->gEnv->getCurrentLanguage(); // 表示言語を取得
277 $act = $request->trimValueOf('act');
279 if ($act == 'delete'){ // メニュー項目の削除
280 $listedItem = explode(',', $request->trimValueOf('seriallist'));
282 for ($i = 0; $i < count($listedItem); $i++){
284 $itemName = 'item' . $i . '_selected';
285 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
287 if ($itemValue){ // チェック項目
288 $delItems[] = $listedItem[$i];
291 if (count($delItems) > 0){
292 $ret = $this->delPageDefParam($defSerial, $defConfigId, $this->paramObj, $delItems);
293 if ($ret){ // データ削除成功のとき
294 $this->setGuidanceMsg('データを削除しました');
296 $this->setAppErrorMsg('データ削除に失敗しました');
301 $this->createItemList();
303 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
305 // ページ定義IDとページ定義のレコードシリアル番号を更新
306 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
313 function createItemList()
315 for ($i = 0; $i < count($this->paramObj); $i++){
316 $id = $this->paramObj[$i]->id;// 定義ID
317 $targetObj = $this->paramObj[$i]->object;
318 $name = $targetObj->name;// 定義名
322 $defCount = $this->sysDb->getPageDefCount($this->gEnv->getCurrentWidgetId(), $id);
324 $operationDisagled = '';
325 if ($defCount > 0) $operationDisagled = 'disabled';
328 'ope_disabled' => $operationDisagled, // 選択可能かどうか
329 'name' => $this->convertToDispString($name), // 名前
330 'movie_id' => $this->convertToDispString($targetObj->movieId), // 動画ID
331 'width' => $targetObj->width, // 動画幅
332 'height' => $targetObj->height, // 動画高さ
333 'def_count' => $defCount // 使用数
335 $this->tmpl->addVars('itemlist', $row);
336 $this->tmpl->parseTemplate('itemlist', 'a');
339 $this->serialArray[] = $id;