OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / s / photo / include / container / admin_s_photoConfigWidgetContainer.php
1 <?php
2 /**
3  * コンテナクラス
4  *
5  * PHP versions 5
6  *
7  * LICENSE: This source file is licensed under the terms of the GNU General Public License.
8  *
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_s_photoConfigWidgetContainer.php 4716 2012-02-26 02:19:15Z fishbone $
14  * @link       http://www.magic3.org
15  */
16 require_once($gEnvManager->getCurrentWidgetContainerPath() . '/admin_s_photoBaseWidgetContainer.php');
17
18 class admin_s_photoConfigWidgetContainer extends admin_s_photoBaseWidgetContainer
19 {
20         private $sortKeyTypeArray;              // ソートキータイプ
21         private $sortKey;                               // ソートキー
22         
23         /**
24          * コンストラクタ
25          */
26         function __construct()
27         {
28                 // 親クラスを呼び出す
29                 parent::__construct();
30                 
31                 // ソートキー選択用
32                 $this->sortKeyTypeArray = array(        array(  'name' => '画像表示順',            'value' => 'index'),
33                                                                                         array(  'name' => '日付',                     'value' => 'date'),
34                                                                                         array(  'name' => '評価',                     'value' => 'rate'),
35                                                                                         array(  'name' => '参照数',                  'value' => 'ref'));
36         }
37         /**
38          * テンプレートファイルを設定
39          *
40          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
41          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
42          *
43          * @param RequestManager $request               HTTPリクエスト処理クラス
44          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
45          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
46          */
47         function _setTemplate($request, &$param)
48         {
49                 return 'admin_config.tmpl.html';
50         }
51         /**
52          * テンプレートにデータ埋め込む
53          *
54          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
55          *
56          * @param RequestManager $request               HTTPリクエスト処理クラス
57          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
58          * @param                                                               なし
59          */
60         function _assign($request, &$param)
61         {
62                 $act = $request->trimValueOf('act');
63                 $listViewCount = $request->trimValueOf('item_view_count');              // 画像一覧表示数
64                 $listViewOrder = $request->trimValueOf('item_view_order');              // 画像一覧表示順
65                 $this->sortKey = $request->trimValueOf('item_sort_key');                                // ソートキー
66                 $titleLength = $request->trimValueOf('item_title_length');              // 画像タイトル文字数
67                 
68                 $imageSize      = $request->trimValueOf('item_image_size');             // 公開画像サイズ
69                 $thumbnailSize  = $request->trimValueOf('item_thumbnail_size');         // サムネール画像サイズ
70                 $defaultImageSize       = $request->trimValueOf('item_default_image_size');             // デフォルト公開画像サイズ
71                 $defaultThumbnailSize   = $request->trimValueOf('item_default_thumbnail_size');         // デフォルトサムネール画像サイズ
72                 
73                 if ($act == 'update'){          // 設定更新のとき
74                         // 入力値のエラーチェック
75                         $this->checkNumeric($listViewCount, '画像一覧表示数');
76                         $this->checkNumeric($titleLength, '画像タイトル文字数');
77                         $this->checkNumeric($defaultImageSize, 'デフォルト公開画像サイズ');
78                         $this->checkNumeric($defaultThumbnailSize, 'デフォルトサムネール画像サイズ');
79                         
80                         if ($this->getMsgCount() == 0){                 // エラーのないとき
81                                 $isErr = false;
82                                 
83                                 if (!$isErr){
84                                         if (!self::$_mainDb->updateConfig(photoCommonDef::CF_PHOTO_LIST_ITEM_COUNT, $listViewCount)) $isErr = true;// 画像一覧表示数
85                                 }
86                                 if (!$isErr){
87                                         if (!self::$_mainDb->updateConfig(photoCommonDef::CF_PHOTO_LIST_ORDER, $listViewOrder)) $isErr = true;// 画像一覧表示順
88                                 }
89                                 if (!$isErr){
90                                         if (!self::$_mainDb->updateConfig(photoCommonDef::CF_PHOTO_LIST_SORT_KEY, $this->sortKey)) $isErr = true;// 画像一覧ソートキー
91                                 }
92                                 if (!$isErr){
93                                         if (!self::$_mainDb->updateConfig(photoCommonDef::CF_PHOTO_TITLE_SHORT_LENGTH, $titleLength)) $isErr = true;// 画像タイトル文字数
94                                 }
95                                 if (!$isErr){
96                                         if (!self::$_mainDb->updateConfig(photoCommonDef::CF_IMAGE_SIZE, $imageSize)) $isErr = true;    // 公開画像サイズ
97                                 }
98                                 if (!$isErr){
99                                         if (!self::$_mainDb->updateConfig(photoCommonDef::CF_THUMBNAIL_SIZE, $thumbnailSize)) $isErr = true;    // サムネール画像サイズ
100                                 }
101                                 if (!$isErr){
102                                         if (!self::$_mainDb->updateConfig(photoCommonDef::CF_DEFAULT_IMAGE_SIZE, $defaultImageSize)) $isErr = true;     // デフォルト公開画像サイズ
103                                 }
104                                 if (!$isErr){
105                                         if (!self::$_mainDb->updateConfig(photoCommonDef::CF_DEFAULT_THUMBNAIL_SIZE, $defaultThumbnailSize)) $isErr = true;     // デフォルトサムネール画像サイズ
106                                 }
107                                 if ($isErr){
108                                         $this->setMsg(self::MSG_APP_ERR, 'データ更新に失敗しました');
109                                 } else {
110                                         $this->setMsg(self::MSG_GUIDANCE, 'データを更新しました');
111                                 }
112                                 // 値を再取得
113                                 $listViewCount  = self::$_mainDb->getConfig(photoCommonDef::CF_PHOTO_LIST_ITEM_COUNT);          // 画像一覧表示数
114                                 $listViewOrder  = self::$_mainDb->getConfig(photoCommonDef::CF_PHOTO_LIST_ORDER);                       // 画像一覧表示順
115                                 if (!in_array($listViewOrder, array('0', '1'))) $listViewOrder = photoCommonDef::DEFAULT_PHOTO_LIST_ORDER;              // デフォルトの画像一覧並び順(昇順)
116                                 $this->sortKey  = self::$_mainDb->getConfig(photoCommonDef::CF_PHOTO_LIST_SORT_KEY);// 画像一覧ソートキー
117                                 if (empty($this->sortKey)) $this->sortKey = photoCommonDef::DEFAULT_PHOTO_LIST_SORT_KEY;
118                                 $titleLength    = self::$_mainDb->getConfig(photoCommonDef::CF_PHOTO_TITLE_SHORT_LENGTH);// 画像タイトル文字数
119                                 $imageSize                      = self::$_mainDb->getConfig(photoCommonDef::CF_IMAGE_SIZE);     // 公開画像サイズ
120                                 $thumbnailSize          = self::$_mainDb->getConfig(photoCommonDef::CF_THUMBNAIL_SIZE); // サムネール画像サイズ
121                                 $defaultImageSize       = self::$_mainDb->getConfig(photoCommonDef::CF_DEFAULT_IMAGE_SIZE);             // デフォルト公開画像サイズ
122                                 $defaultThumbnailSize   = self::$_mainDb->getConfig(photoCommonDef::CF_DEFAULT_THUMBNAIL_SIZE);         // デフォルトサムネール画像サイズ
123                         }
124                 } else {                // 初期表示の場合
125                         $listViewCount  = self::$_mainDb->getConfig(photoCommonDef::CF_PHOTO_LIST_ITEM_COUNT);// 画像一覧表示数
126                         if (intval($listViewCount) <= 0) $listViewCount = photoCommonDef::DEFAULT_PHOTO_LIST_VIEW_COUNT;
127                         $listViewOrder  = self::$_mainDb->getConfig(photoCommonDef::CF_PHOTO_LIST_ORDER);// 画像一覧表示順
128                         if (!in_array($listViewOrder, array('0', '1'))) $listViewOrder = photoCommonDef::DEFAULT_PHOTO_LIST_ORDER;              // デフォルトの画像一覧並び順(昇順)
129                         $this->sortKey  = self::$_mainDb->getConfig(photoCommonDef::CF_PHOTO_LIST_SORT_KEY);// 画像一覧ソートキー
130                         if (empty($this->sortKey)) $this->sortKey = photoCommonDef::DEFAULT_PHOTO_LIST_SORT_KEY;
131                         $titleLength    = self::$_mainDb->getConfig(photoCommonDef::CF_PHOTO_TITLE_SHORT_LENGTH);// 画像タイトル文字数
132                         if (intval($titleLength) <= 0) $titleLength = photoCommonDef::DEFAULT_PHOTO_TITLE_SHORT_LENGTH;
133                         $imageSize                      = self::$_mainDb->getConfig(photoCommonDef::CF_IMAGE_SIZE);     // 公開画像サイズ
134                         if (empty($imageSize)) $imageSize = photoCommonDef::DEFAULT_IMAGE_SIZE;
135                         $thumbnailSize  = self::$_mainDb->getConfig(photoCommonDef::CF_THUMBNAIL_SIZE); // サムネール画像サイズ
136                         if (empty($thumbnailSize)) $thumbnailSize = photoCommonDef::DEFAULT_THUMBNAIL_SIZE;
137                         $defaultImageSize       = self::$_mainDb->getConfig(photoCommonDef::CF_DEFAULT_IMAGE_SIZE);             // デフォルト公開画像サイズ
138                         if (empty($defaultImageSize)) $defaultImageSize = photoCommonDef::DEFAULT_IMAGE_SIZE;
139                         $defaultThumbnailSize   = self::$_mainDb->getConfig(photoCommonDef::CF_DEFAULT_THUMBNAIL_SIZE);         // デフォルトサムネール画像サイズ
140                         if (empty($defaultThumbnailSize)) $defaultThumbnailSize = photoCommonDef::DEFAULT_THUMBNAIL_SIZE;
141                 }
142                 // ソートキー選択メニュー作成
143                 $this->createSortKeyMenu();
144                 
145                 // 画面に書き戻す
146                 $this->tmpl->addVar("_widget", "view_count", $listViewCount);// 画像一覧表示数
147                 if (empty($listViewOrder)){     // 順方向
148                         $this->tmpl->addVar("_widget", "view_order_dec_selected", 'selected');// 降順
149                 } else {
150                         $this->tmpl->addVar("_widget", "view_order_inc_selected", 'selected');// 昇順
151                 }
152                 $this->tmpl->addVar("_widget", "title_length", $titleLength);// 画像タイトル文字数
153                 $this->tmpl->addVar("_widget", "image_size", $imageSize);// 公開画像サイズ
154                 $this->tmpl->addVar("_widget", "thumbnail_size", $thumbnailSize);// サムネール画像サイズ
155                 $this->tmpl->addVar("_widget", "default_image_size", $defaultImageSize);                        // デフォルト公開画像サイズ
156                 $this->tmpl->addVar("_widget", "default_thumbnail_size", $defaultThumbnailSize);        // デフォルトサムネール画像サイズ
157         }
158         /**
159          * ソートキー選択メニュー作成
160          *
161          * @return なし
162          */
163         function createSortKeyMenu()
164         {
165                 for ($i = 0; $i < count($this->sortKeyTypeArray); $i++){
166                         $value = $this->sortKeyTypeArray[$i]['value'];
167                         $name = $this->sortKeyTypeArray[$i]['name'];
168                         
169                         $selected = '';
170                         if ($value == $this->sortKey) $selected = 'selected';
171                         
172                         $row = array(
173                                 'value'    => $value,                   // ソートキーID
174                                 'name'     => $name,                    // 名前
175                                 'selected' => $selected                 // 選択中かどうか
176                         );
177                         $this->tmpl->addVars('item_sort_key_type_list', $row);
178                         $this->tmpl->parseTemplate('item_sort_key_type_list', 'a');
179                 }
180         }
181 }
182 ?>