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-2010 Magic3 Project.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
13 * @version SVN: $Id: admin_pretty_photoWidgetContainer.php 3024 2010-04-12 07:32:38Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getContainerPath() . '/baseAdminWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/pretty_photoDb.php');
19 class admin_pretty_photoWidgetContainer extends BaseAdminWidgetContainer
21 private $db; // DB接続オブジェクト
22 private $sysDb; // DB接続オブジェクト
23 private $serialNo; // 選択中の項目のシリアル番号
24 private $serialArray = array(); // 表示中のシリアル番号
26 private $configId; // 定義ID
27 private $paramObj; // パラメータ保存用オブジェクト
28 private $imageInfoArray = array(); // 画像情報
29 private $css; // メニュー用CSS
30 private $cssId; // CSS用ID
31 const DEFAULT_NAME_HEAD = '名称未設定'; // デフォルトの設定名
32 const DEFAULT_IMAGE_SIZE = 60; // デフォルトのサムネールサイズ
37 function __construct()
40 parent::__construct();
43 $this->db = new pretty_photoDb();
44 $this->sysDb = $this->gInstance->getSytemDbObject();
49 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
50 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
52 * @param RequestManager $request HTTPリクエスト処理クラス
53 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
54 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
56 function _setTemplate($request, &$param)
58 $task = $request->trimValueOf('task');
59 if ($task == 'list'){ // 一覧画面
60 return 'admin_list.tmpl.html';
62 return 'admin.tmpl.html';
68 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
70 * @param RequestManager $request HTTPリクエスト処理クラス
71 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
74 function _assign($request, &$param)
76 $task = $request->trimValueOf('task');
77 if ($task == 'list'){ // 一覧画面
78 return $this->createList($request);
80 return $this->createDetail($request);
86 * @param RequestManager $request HTTPリクエスト処理クラス
89 function createDetail($request)
91 // ページ定義IDとページ定義のレコードシリアル番号を取得
92 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
94 $userId = $this->gEnv->getCurrentUserId();
95 $this->langId = $this->gEnv->getCurrentLanguage(); // 表示言語を取得
96 $act = $request->trimValueOf('act');
97 $this->serialNo = $request->trimValueOf('serial'); // 選択項目のシリアル番号
98 $this->configId = $request->trimValueOf('item_id'); // 定義ID
99 if (empty($this->configId)) $this->configId = $defConfigId; // 呼び出しウィンドウから引き継いだ定義ID
102 $name = $request->trimValueOf('item_name'); // 定義名
103 $imageCount = $request->trimValueOf('imagecount'); // 画像情報数
104 $size = $request->trimValueOf('item_size'); // 画像サイズ
105 $urls = $request->trimValueOf('item_url'); // 画像URL
106 $titles = $request->trimValueOf('item_title'); // 画像タイトル
107 $descs = $request->trimValueOf('item_desc'); // 画像説明
108 $this->css = $request->valueOf('item_css'); // メニュー用CSS
109 $this->cssId = $request->trimValueOf('item_css_id'); // CSS用ID
111 $replaceNew = false; // データを再取得するかどうか
112 if ($act == 'add'){// 新規追加
114 $this->checkNumeric($size, '画像サイズ', true);
117 for ($i = 0; $i < count($this->paramObj); $i++){
118 $targetObj = $this->paramObj[$i]->object;
119 if ($name == $targetObj->name){ // 定義名
120 $this->setUserErrorMsg('名前が重複しています');
126 if ($this->getMsgCount() == 0){
128 $newObj = new stdClass;
129 $newObj->name = $name;// 表示名
130 $newObj->size = $size; // 画像サイズ
131 $newObj->imageInfo = array();
132 $newObj->cssId = $this->cssId; // CSS用ID
133 $newObj->css = $this->css; // メニューCSS
135 for ($i = 0; $i < $imageCount; $i++){
138 if (!empty($url)) $url = $this->gEnv->getMacroPath($url);
140 $newInfoObj = new stdClass;
141 $newInfoObj->name = $titles[$i];
142 $newInfoObj->desc = $descs[$i];
143 $newInfoObj->url = $url;
144 $newObj->imageInfo[] = $newInfoObj;
147 $ret = $this->addPageDefParam($defSerial, $defConfigId, $this->paramObj, $newObj);
149 $this->setGuidanceMsg('データを追加しました');
151 $this->configId = $defConfigId; // 定義定義IDを更新
152 $replaceNew = true; // データ再取得
154 $this->setAppErrorMsg('データ追加に失敗しました');
157 } else if ($act == 'update'){ // 設定更新のとき
159 $this->checkNumeric($size, '画像サイズ', true);
161 if ($this->getMsgCount() == 0){ // エラーのないとき
163 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
166 $targetObj->size = $size; // 画像サイズ
167 $targetObj->imageInfo = array();
168 $targetObj->cssId = $this->cssId; // CSS用ID
169 $targetObj->css = $this->css; // メニューCSS
171 for ($i = 0; $i < $imageCount; $i++){
174 if (!empty($url)) $url = $this->gEnv->getMacroPath($url);
176 $newInfoObj = new stdClass;
177 $newInfoObj->name = $titles[$i];
178 $newInfoObj->desc = $descs[$i];
179 $newInfoObj->url = $url;
180 $targetObj->imageInfo[] = $newInfoObj;
185 if ($ret) $ret = $this->updatePageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
187 $this->setMsg(self::MSG_GUIDANCE, 'データを更新しました');
188 $replaceNew = true; // データ再取得
190 $this->setMsg(self::MSG_APP_ERR, 'データ更新に失敗しました');
193 } else if ($act == 'select'){ // 定義IDを変更
194 $replaceNew = true; // データ再取得
195 } else { // 初期起動時、または上記以外の場合
197 $this->configId = $defConfigId; // 呼び出しウィンドウから引き継いだ定義ID
198 $replaceNew = true; // データ再取得
201 $this->createItemMenu();
204 if (empty($this->configId)){ // 新規登録の場合
205 $this->tmpl->setAttribute('item_name_visible', 'visibility', 'visible');// 名前入力フィールド表示
206 if ($replaceNew){ // データ再取得時
207 $name = $this->createDefaultName(); // デフォルト登録項目名
208 $size = self::DEFAULT_IMAGE_SIZE; // 画像サイズ
209 $this->imageInfoArray = array(); // 画像情報
210 $this->cssId = $this->createDefaultCssId(); // CSS用ID
211 $this->css = $this->getParsedTemplateData('default.tmpl.css', array($this, 'makeCss'));// デフォルト用のCSSを取得
215 if ($replaceNew){// データ再取得時
216 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
218 $name = $targetObj->name;// 名前
219 $size = $targetObj->size; // 画像サイズ
220 if (!empty($targetObj->imageInfo)) $this->imageInfoArray = $targetObj->imageInfo; // 画像情報
221 $this->cssId = $targetObj->cssId; // CSS用ID
222 $this->css = $targetObj->css; // メニューCSS
225 $this->serialNo = $this->configId;
227 // 新規作成でないときは、メニューを変更不可にする(画面作成から呼ばれている場合のみ)
228 if (!empty($defConfigId) && !empty($defSerial)) $this->tmpl->addVar("_widget", "id_disabled", 'disabled');
232 $this->createImageList();
233 if (empty($this->imageInfoArray)) $this->tmpl->setAttribute('image_list', 'visibility', 'hidden');// 画像情報一覧
236 if (!empty($this->configId)) $this->tmpl->addVar("_widget", "id", $this->configId); // 定義ID
237 $this->tmpl->addVar("item_name_visible", "name", $name);
238 $this->tmpl->addVar("_widget", "size", $size); // 画像サイズ
239 $this->tmpl->addVar("_widget", "css_id", $this->cssId); // CSS用ID
240 $this->tmpl->addVar("_widget", "css", $this->css);
241 $this->tmpl->addVar("_widget", "serial", $this->serialNo);// 選択中のシリアル番号、IDを設定
244 if (empty($this->serialNo)){ // 新規追加項目を選択しているとき
245 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');// 「新規追加」ボタン
247 $this->tmpl->setAttribute('update_button', 'visibility', 'visible');// 「更新」ボタン
250 $this->convertHelp('update_button');
253 // ページ定義IDとページ定義のレコードシリアル番号を更新
254 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
259 * CSSデータをHTMLのheadタグ内に追加出力する。
260 * _assign()よりも後に実行される。
262 * @param RequestManager $request HTTPリクエスト処理クラス
263 * @param object $param 任意使用パラメータ。
264 * @return string CSS文字列。出力しない場合は空文字列を設定。
266 function _addCssToHead($request, &$param)
275 function createItemMenu()
277 for ($i = 0; $i < count($this->paramObj); $i++){
278 $id = $this->paramObj[$i]->id;// 定義ID
279 $targetObj = $this->paramObj[$i]->object;
280 $name = $targetObj->name;// 定義名
282 if ($this->configId == $id) $selected = 'selected';
285 'name' => $name, // 名前
286 'value' => $id, // 定義ID
287 'selected' => $selected // 選択中の項目かどうか
289 $this->tmpl->addVars('title_list', $row);
290 $this->tmpl->parseTemplate('title_list', 'a');
298 function createImageList()
300 $imageCount = count($this->imageInfoArray);
301 for ($i = 0; $i < $imageCount; $i++){
302 $infoObj = $this->imageInfoArray[$i];
303 $name = $infoObj->name;// タイトル名
304 $desc = $infoObj->desc; // 説明
308 $partArray = explode('/', $infoObj->url);
309 if (count($partArray) > 0) $filename = $partArray[count($partArray)-1];
312 $url = $infoObj->url;
313 if (!empty($url)) $url = str_replace(M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END, $this->gEnv->getRootUrl(), $url);
315 $rootUrl = $this->getUrl($this->gEnv->getRootUrl());
317 'filename' => $this->convertToDispString($filename), // ファイル名
318 'url' => $this->convertToDispString($this->getUrl($url)), // URL
319 'title' => $this->convertToDispString($name), // 名前
320 'desc' => $this->convertToDispString($desc), // 説明
321 'root_url' => $this->convertToDispString($rootUrl)
323 $this->tmpl->addVars('image_list', $row);
324 $this->tmpl->parseTemplate('image_list', 'a');
330 * @return string デフォルト名
332 function createDefaultName()
334 $name = self::DEFAULT_NAME_HEAD;
335 for ($j = 1; $j < 100; $j++){
336 $name = self::DEFAULT_NAME_HEAD . $j;
338 for ($i = 0; $i < count($this->paramObj); $i++){
339 $targetObj = $this->paramObj[$i]->object;
340 if ($name == $targetObj->name){ // 定義名
345 if ($i == count($this->paramObj)) break;
352 * @param RequestManager $request HTTPリクエスト処理クラス
355 function createList($request)
357 // ページ定義IDとページ定義のレコードシリアル番号を取得
358 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
360 $userId = $this->gEnv->getCurrentUserId();
361 $langId = $this->gEnv->getCurrentLanguage(); // 表示言語を取得
362 $act = $request->trimValueOf('act');
364 if ($act == 'delete'){ // メニュー項目の削除
365 $listedItem = explode(',', $request->trimValueOf('seriallist'));
367 for ($i = 0; $i < count($listedItem); $i++){
369 $itemName = 'item' . $i . '_selected';
370 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
372 if ($itemValue){ // チェック項目
373 $delItems[] = $listedItem[$i];
376 if (count($delItems) > 0){
377 $ret = $this->delPageDefParam($defSerial, $defConfigId, $this->paramObj, $delItems);
378 if ($ret){ // データ削除成功のとき
379 $this->setGuidanceMsg('データを削除しました');
381 $this->setAppErrorMsg('データ削除に失敗しました');
386 $this->createItemList();
388 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
390 // ページ定義IDとページ定義のレコードシリアル番号を更新
391 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
398 function createItemList()
400 for ($i = 0; $i < count($this->paramObj); $i++){
401 $id = $this->paramObj[$i]->id;// 定義ID
402 $targetObj = $this->paramObj[$i]->object;
403 $name = $targetObj->name;// 定義名
404 $width = $targetObj->width; // 画像の幅
405 $height = $targetObj->height; // 画像の高さ
406 $widthType = $targetObj->widthType; // 画像の幅単位
407 $heightType = $targetObj->heightType; // 画像の高さ単位
411 $partArray = explode('/', $targetObj->imageUrl);
412 if (count($partArray) > 0) $filename = $partArray[count($partArray)-1];
417 $defCount = $this->sysDb->getPageDefCount($this->gEnv->getCurrentWidgetId(), $id);
419 $operationDisagled = '';
420 if ($defCount > 0) $operationDisagled = 'disabled';
425 if (!empty($width) && $width > 0){
427 if (!empty($widthType)) $imgWidth .= '%';
429 if (!empty($height) && $height > 0){
430 $imgHeight = $height;
431 if (!empty($heightType)) $imgHeight .= '%';
435 $url = $targetObj->imageUrl;
436 if (!empty($url)) $url = str_replace(M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END, $this->gEnv->getRootUrl(), $url);
441 'ope_disabled' => $operationDisagled, // 選択可能かどうか
442 'name' => $this->convertToDispString($name), // 名前
443 'filename' => $this->convertToDispString($filename), // ファイル名
444 'def_count' => $defCount, // 使用数
445 'width' => $imgWidth, // 画像幅
446 'height' => $imgHeight, // 画像高さ
447 'url' => $this->getUrl($url) // URL
449 $this->tmpl->addVars('itemlist', $row);
450 $this->tmpl->parseTemplate('itemlist', 'a');
453 $this->serialArray[] = $id;
461 function createDefaultCssId()
463 return $this->gEnv->getCurrentWidgetId() . '_' . $this->getTempConfigId($this->paramObj);
468 * @param object $tmpl テンプレートオブジェクト
471 function makeCss($tmpl)
473 $tmpl->addVar("_tmpl", "css_id", '#' . $this->cssId); // メニュー用CSS