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-2013 Magic3 Project.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
13 * @version SVN: $Id: admin_featured_contentWidgetContainer.php 5544 2013-01-14 04:57:24Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getContainerPath() . '/baseAdminWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/featured_contentDb.php');
19 class admin_featured_contentWidgetContainer extends BaseAdminWidgetContainer
21 private $db; // DB接続オブジェクト
22 private $serialNo; // 選択中の項目のシリアル番号
23 private $serialArray = array(); // 表示中のシリアル番号
25 private $configId; // 定義ID
26 private $paramObj; // パラメータ保存用オブジェクト
27 private $fieldInfoArray = array(); // フィールド情報
28 const DEFAULT_NAME_HEAD = '名称未設定'; // デフォルトの設定名
29 const CONTENT_WIDGET_ID_PC = 'default_content'; // コンテンツ編集ウィジェット(PC用)
30 const CONTENT_TYPE = ''; // コンテンツタイプ
31 const DEFAULT_COLUMN_COUNT = 2; // カラム数
32 const DEFAULT_LEAD_CONTENT_COUNT = 1; // 先頭のコンテンツ数
33 const DEFAULT_COLUMN_CONTENT_COUNT = 2; // カラム部のコンテンツ数
38 function __construct()
41 parent::__construct();
44 $this->db = new featured_contentDb();
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 $defName = $request->trimValueOf('item_def_name'); // 定義名
103 $fieldCount = $request->trimValueOf('fieldcount'); // 表示項目数
104 // $names = $request->trimValueOf('item_name'); // 表示項目、名前
105 $contentIds = $request->trimValueOf('item_contentid'); // 表示項目、コンテンツID
106 $showReadMore = ($request->trimValueOf('item_show_read_more') == 'on') ? 1 : 0; // 「続きを読む」ボタンを表示
107 $readMoreTitle = $request->trimValueOf('item_read_more_title'); // 「続きを読む」ボタンタイトル
108 $leadContentCount = $request->trimValueOf('item_lead_content_count'); // 先頭のコンテンツ数
109 $columnContentCount = $request->trimValueOf('item_column_content_count'); // カラム部のコンテンツ数
110 $columnCount = $request->trimValueOf('item_column_count'); // カラム数
111 $showCreateDate = ($request->trimValueOf('item_show_created_date') == 'on') ? 1 : 0; // 表示項目(作成日)
112 $showModifiedDate = ($request->trimValueOf('item_show_modified_date') == 'on') ? 1 : 0; // 表示項目(更新日)
113 $showPublishedDate = ($request->trimValueOf('item_show_published_date') == 'on') ? 1 : 0; // 表示項目(公開日)
115 $replaceNew = false; // データを再取得するかどうか
116 if ($act == 'add'){// 新規追加
118 $this->checkNumeric($leadContentCount, '先頭部のコンテンツ数');
119 $this->checkNumeric($columnContentCount, 'カラム部のコンテンツ数');
120 $this->checkNumeric($columnCount, 'カラム数');
123 for ($i = 0; $i < count($this->paramObj); $i++){
124 $targetObj = $this->paramObj[$i]->object;
125 if ($defName == $targetObj->name){ // 定義名
126 $this->setUserErrorMsg('名前が重複しています');
132 if ($this->getMsgCount() == 0){
134 $newObj = new stdClass;
135 $newObj->name = $defName;// 表示名
136 $newObj->showReadMore = $showReadMore; // 「続きを読む」ボタンを表示
137 $newObj->readMoreTitle = $readMoreTitle; // 「続きを読む」ボタンタイトル
138 $newObj->leadContentCount = $leadContentCount; // 先頭のコンテンツ数
139 $newObj->columnContentCount = $columnContentCount; // カラム部のコンテンツ数
140 $newObj->columnCount = $columnCount; // カラム数
141 $newObj->showCreateDate = $showCreateDate; // 表示項目(作成日)
142 $newObj->showModifiedDate = $showModifiedDate; // 表示項目(更新日)
143 $newObj->showPublishedDate = $showPublishedDate; // 表示項目(公開日)
145 $newObj->fieldInfo = array();
147 for ($i = 0; $i < $fieldCount; $i++){
148 $newInfoObj = new stdClass;
149 // $newInfoObj->name = $names[$i];
150 $newInfoObj->contentId = $contentIds[$i];
151 $newObj->fieldInfo[] = $newInfoObj;
154 $ret = $this->addPageDefParam($defSerial, $defConfigId, $this->paramObj, $newObj);
156 $this->setGuidanceMsg('データを追加しました');
158 $this->configId = $defConfigId; // 定義定義IDを更新
159 $replaceNew = true; // データ再取得
161 $this->setAppErrorMsg('データ追加に失敗しました');
164 } else if ($act == 'update'){ // 設定更新のとき
166 $this->checkNumeric($leadContentCount, '先頭部のコンテンツ数');
167 $this->checkNumeric($columnContentCount, 'カラム部のコンテンツ数');
168 $this->checkNumeric($columnCount, 'カラム数');
170 if ($this->getMsgCount() == 0){ // エラーのないとき
172 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
175 $targetObj->showReadMore = $showReadMore; // 「続きを読む」ボタンを表示
176 $targetObj->readMoreTitle = $readMoreTitle; // 「続きを読む」ボタンタイトル
177 $targetObj->leadContentCount = $leadContentCount; // 先頭のコンテンツ数
178 $targetObj->columnContentCount = $columnContentCount; // カラム部のコンテンツ数
179 $targetObj->columnCount = $columnCount; // カラム数
180 $targetObj->showCreateDate = $showCreateDate; // 表示項目(作成日)
181 $targetObj->showModifiedDate = $showModifiedDate; // 表示項目(更新日)
182 $targetObj->showPublishedDate = $showPublishedDate; // 表示項目(公開日)
183 $targetObj->fieldInfo = array();
185 for ($i = 0; $i < $fieldCount; $i++){
186 $newInfoObj = new stdClass;
187 // $newInfoObj->name = $names[$i];
188 $newInfoObj->contentId = $contentIds[$i];
189 $targetObj->fieldInfo[] = $newInfoObj;
194 if ($ret) $ret = $this->updatePageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
196 $this->setMsg(self::MSG_GUIDANCE, 'データを更新しました');
197 $replaceNew = true; // データ再取得
199 $this->setMsg(self::MSG_APP_ERR, 'データ更新に失敗しました');
202 } else if ($act == 'select'){ // 定義IDを変更
203 $replaceNew = true; // データ再取得
204 } else { // 初期起動時、または上記以外の場合
206 $this->configId = $defConfigId; // 呼び出しウィンドウから引き継いだ定義ID
207 $replaceNew = true; // データ再取得
210 $this->createItemMenu();
213 if (empty($this->configId)){ // 新規登録の場合
214 $this->tmpl->setAttribute('item_def_name_visible', 'visibility', 'visible');// 名前入力フィールド表示
215 if ($replaceNew){ // データ再取得時
216 $defName = $this->createDefaultName(); // デフォルト登録項目名
217 $showReadMore = 0; // 「続きを読む」ボタンを表示
218 $readMoreTitle = ''; // 「続きを読む」ボタンタイトル
219 $leadContentCount = self::DEFAULT_LEAD_CONTENT_COUNT; // 先頭のコンテンツ数
220 $columnContentCount = self::DEFAULT_COLUMN_CONTENT_COUNT; // カラム部のコンテンツ数
221 $columnCount = self::DEFAULT_COLUMN_COUNT; // カラム数
222 $showCreateDate = 0; // 表示項目(作成日)
223 $showModifiedDate = 0; // 表示項目(更新日)
224 $showPublishedDate = 0; // 表示項目(公開日)
225 $this->fieldInfoArray = array(); // フィールド情報
229 if ($replaceNew){// データ再取得時
230 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
232 $defName = $targetObj->name;// 名前
233 $showReadMore = $targetObj->showReadMore; // 「続きを読む」ボタンを表示
234 $readMoreTitle = $targetObj->readMoreTitle; // 「続きを読む」ボタンタイトル
235 $leadContentCount = $targetObj->leadContentCount; // 先頭のコンテンツ数
236 $columnContentCount = $targetObj->columnContentCount; // カラム部のコンテンツ数
237 $columnCount = $targetObj->columnCount; // カラム数
238 $showCreateDate = $targetObj->showCreateDate; // 表示項目(作成日)
239 $showModifiedDate = $targetObj->showModifiedDate; // 表示項目(更新日)
240 $showPublishedDate = $targetObj->showPublishedDate; // 表示項目(公開日)
241 if (!empty($targetObj->fieldInfo)) $this->fieldInfoArray = $targetObj->fieldInfo; // フィールド情報
244 $this->serialNo = $this->configId;
246 // 新規作成でないときは、メニューを変更不可にする(画面作成から呼ばれている場合のみ)
247 if (!empty($defConfigId) && !empty($defSerial)) $this->tmpl->addVar("_widget", "id_disabled", 'disabled');
251 $this->createFieldList();
252 if (empty($this->fieldInfoArray)) $this->tmpl->setAttribute('field_list', 'visibility', 'hidden');// 表示項目一覧を表示
254 // 画面にデータを埋め込む(ウィジェット共通部)
255 if (!empty($this->configId)) $this->tmpl->addVar("_widget", "id", $this->configId); // 定義ID
256 $this->tmpl->addVar("item_def_name_visible", "def_name", $defName);
257 $this->tmpl->addVar("_widget", "serial", $this->serialNo);// 選択中のシリアル番号、IDを設定
261 if ($showReadMore) $checked = 'checked';
262 $this->tmpl->addVar("_widget", "show_read_more", $checked); // 「続きを読む」ボタンを表示
263 $this->tmpl->addVar("_widget", "read_more_title", $readMoreTitle); // 「続きを読む」ボタンタイトル
264 $this->tmpl->addVar("_widget", "lead_content_count", $leadContentCount); // 先頭のコンテンツ数
265 $this->tmpl->addVar("_widget", "column_content_count", $columnContentCount); // カラム部のコンテンツ数
266 $this->tmpl->addVar("_widget", "column_count", $columnCount); // カラム数
268 if ($showCreateDate) $checked = 'checked';
269 $this->tmpl->addVar("_widget", "show_created_date", $checked); // 表示項目(作成日)
271 if ($showModifiedDate) $checked = 'checked';
272 $this->tmpl->addVar("_widget", "show_modified_date", $checked); // 表示項目(更新日)
274 if ($showPublishedDate) $checked = 'checked';
275 $this->tmpl->addVar("_widget", "show_published_date", $checked); // 表示項目(公開日)
277 $this->tmpl->addVar('_widget', 'content_widget_id', self::CONTENT_WIDGET_ID_PC);// コンテンツ表示ウィジェット
278 $this->tmpl->addVar('_widget', 'admin_url', $this->getUrl($this->gEnv->getDefaultAdminUrl()));// 管理者URL
281 if (empty($this->serialNo)){ // 新規追加項目を選択しているとき
282 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');// 「新規追加」ボタン
285 $this->tmpl->addVar("_widget", "preview_disabled", 'disabled ');// 「プレビュー」ボタン
287 $this->tmpl->setAttribute('update_button', 'visibility', 'visible');// 「更新」ボタン
289 // このウィジェットがマップされているページサブIDを取得
290 $subPageId = $this->gPage->getPageSubIdByWidget($this->gEnv->getDefaultPageId(), $this->gEnv->getCurrentWidgetId(), $defConfigId);
291 $previewUrl = $this->gEnv->getDefaultUrl();
292 if (!empty($subPageId)) $previewUrl .= '?sub=' . $subPageId;
293 $this->tmpl->addVar("_widget", "preview_url", $this->getUrl($previewUrl));
296 // ページ定義IDとページ定義のレコードシリアル番号を更新
297 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
304 function createItemMenu()
306 for ($i = 0; $i < count($this->paramObj); $i++){
307 $id = $this->paramObj[$i]->id;// 定義ID
308 $targetObj = $this->paramObj[$i]->object;
309 $defName = $targetObj->name;// 定義名
311 if ($this->configId == $id) $selected = 'selected';
314 'name' => $defName, // 名前
315 'value' => $id, // 定義ID
316 'selected' => $selected // 選択中の項目かどうか
318 $this->tmpl->addVars('title_list', $row);
319 $this->tmpl->parseTemplate('title_list', 'a');
327 function createFieldList()
329 $fieldCount = count($this->fieldInfoArray);
330 for ($i = 0; $i < $fieldCount; $i++){
331 $infoObj = $this->fieldInfoArray[$i];
332 // $name = $infoObj->name;// 名前
333 $contentId = $infoObj->contentId; // コンテンツID
336 $ret = $this->db->getContentByContentId(self::CONTENT_TYPE, $contentId, $this->langId, $row);
338 $contentName = $row['cn_name'];
342 // 'name' => $this->convertToDispString($name), // 名前
343 'name' => $this->convertToDispString($contentName), // コンテンツ名
344 'content_id' => $this->convertToDispString($contentId), // コンテンツID
345 'root_url' => $this->convertToDispString($this->getUrl($this->gEnv->getRootUrl()))
347 $this->tmpl->addVars('field_list', $row);
348 $this->tmpl->parseTemplate('field_list', 'a');
354 * @return string デフォルト名
356 function createDefaultName()
358 $name = self::DEFAULT_NAME_HEAD;
359 for ($j = 1; $j < 100; $j++){
360 $name = self::DEFAULT_NAME_HEAD . $j;
362 for ($i = 0; $i < count($this->paramObj); $i++){
363 $targetObj = $this->paramObj[$i]->object;
364 if ($name == $targetObj->name){ // 定義名
369 if ($i == count($this->paramObj)) break;
376 * @param RequestManager $request HTTPリクエスト処理クラス
379 function createList($request)
381 // ページ定義IDとページ定義のレコードシリアル番号を取得
382 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
384 $userId = $this->gEnv->getCurrentUserId();
385 $langId = $this->gEnv->getCurrentLanguage(); // 表示言語を取得
386 $act = $request->trimValueOf('act');
388 if ($act == 'delete'){ // メニュー項目の削除
389 $listedItem = explode(',', $request->trimValueOf('seriallist'));
391 for ($i = 0; $i < count($listedItem); $i++){
393 $itemName = 'item' . $i . '_selected';
394 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
396 if ($itemValue){ // チェック項目
397 $delItems[] = $listedItem[$i];
400 if (count($delItems) > 0){
401 $ret = $this->delPageDefParam($defSerial, $defConfigId, $this->paramObj, $delItems);
402 if ($ret){ // データ削除成功のとき
403 $this->setGuidanceMsg('データを削除しました');
405 $this->setAppErrorMsg('データ削除に失敗しました');
410 $this->createItemList();
412 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
414 // ページ定義IDとページ定義のレコードシリアル番号を更新
415 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
422 function createItemList()
424 for ($i = 0; $i < count($this->paramObj); $i++){
425 $id = $this->paramObj[$i]->id;// 定義ID
426 $targetObj = $this->paramObj[$i]->object;
427 $defName = $targetObj->name;// 定義名
432 $defCount = $this->_db->getPageDefCount($this->gEnv->getCurrentWidgetId(), $id);
434 $operationDisagled = '';
435 if ($defCount > 0) $operationDisagled = 'disabled';
440 'ope_disabled' => $operationDisagled, // 選択可能かどうか
441 'name' => $this->convertToDispString($defName), // 名前
442 'def_count' => $defCount // 使用数
444 $this->tmpl->addVars('itemlist', $row);
445 $this->tmpl->parseTemplate('itemlist', 'a');
448 $this->serialArray[] = $id;