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-2011 Magic3 Project.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
13 * @version SVN: $Id: admin_m_contentWidgetContainer.php 4249 2011-08-12 03:43:57Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getContainerPath() . '/baseAdminWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/contentDb.php');
18 require_once($gEnvManager->getCommonPath() . '/valueCheck.php');
20 class admin_m_contentWidgetContainer extends BaseAdminWidgetContainer
22 private $db; // DB接続オブジェクト
23 private $serialNo; // 選択中の項目のシリアル番号
24 private $serialArray = array(); // 表示されているコンテンツシリアル番号
25 const MAIN_MENU_ID = 'mobile_menu'; // メニューID
26 const INC_INDEX = 1; // メニュー項目表示順の増加分
27 const ADMIN_WIDGET_ID = 'admin_main'; // 管理ウィジェットのウィジェットID
28 const CONTENT_TYPE = 'mobile'; // コンテンツタイプ
29 const VIEW_CONTENT_TYPE = 'mc'; // 参照数カウント用
34 function __construct()
37 parent::__construct();
40 $this->db = new contentDb();
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 == 'detail'){ // 詳細画面
56 return 'admin_main_detail.tmpl.html';
58 return 'admin_main.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 == 'detail'){ // 詳細画面
74 return $this->createDetail($request);
76 return $this->createList($request);
82 * @param RequestManager $request HTTPリクエスト処理クラス
85 function createList($request)
88 $userId = $this->gEnv->getCurrentUserId();
89 $langId = $this->gEnv->getDefaultLanguage();
91 $act = $request->trimValueOf('act');
92 if ($act == 'addtomenu'){ // メニューに項目を追加
93 $contentId = $request->trimValueOf('contentid'); // コンテンツID
95 // このウィジェットがマップされているページサブIDを取得
96 $subPageId = $this->gPage->getPageSubIdByWidget($this->gEnv->getDefaultMobilePageId(), $this->gEnv->getCurrentWidgetId());
98 if (!empty($subPageId)) $sub = 'sub=' . $subPageId . '&';
101 $url = M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END . '/m/index.php?' . $sub . 'contentid=' . $contentId;
105 $ret = $this->db->getContentByContentId(self::CONTENT_TYPE, $contentId, $langId, $row);
108 $menutItemName = $row['cn_name']; // 名前
112 $ret = $this->db->addMenuItem(self::MAIN_MENU_ID, $langId, $menutItemName, $url, self::INC_INDEX, $userId);
114 $this->setGuidanceMsg('メインメニューに項目を追加しました');
116 $this->setAppErrorMsg('メインメニューの項目追加に失敗しました');
118 } else if ($act == 'delete'){ // 項目削除の場合
119 $listedItem = explode(',', $request->trimValueOf('seriallist'));
121 for ($i = 0; $i < count($listedItem); $i++){
123 $itemName = 'item' . $i . '_selected';
124 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
126 if ($itemValue){ // チェック項目
127 $delItems[] = $listedItem[$i];
130 if (count($delItems) > 0){
132 for ($i = 0; $i < count($delItems); $i++){
135 $ret = $this->db->getContentBySerial($delItems[$i], $row);
136 if ($ret) $contentId = $row['cn_id']; // コンテンツID
139 if ($ret) $ret = $this->updateWidgetParamObjByConfigId($contentId, null);
142 $ret = $this->db->delContentItem($delItems, $userId);
143 if ($ret){ // データ削除成功のとき
144 $this->setGuidanceMsg('データを削除しました');
146 $this->setAppErrorMsg('データ削除に失敗しました');
149 $this->gPage->updateParentWindow();// 親ウィンドウを更新
151 // コンテンツ項目リストをデフォルト言語で取得
152 $this->db->getAllContentItems(self::CONTENT_TYPE, array($this, 'itemListLoop'), $langId);
153 if (empty($this->serialArray)) $this->tmpl->setAttribute('itemlist', 'visibility', 'hidden');// コンテンツ項目がないときは、一覧を表示しない
154 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
159 * @param RequestManager $request HTTPリクエスト処理クラス
162 function createDetail($request)
165 $userId = $this->gEnv->getCurrentUserId();
166 $langId = $this->gEnv->getDefaultLanguage();
169 $openby = $request->trimValueOf(M3_REQUEST_PARAM_OPEN_BY);
171 $act = $request->trimValueOf('act');
172 $this->serialNo = $request->trimValueOf('serial'); // 選択項目のシリアル番号
173 $name = $request->trimValueOf('item_name');
174 $showTitle = ($request->trimValueOf('show_title') == 'on') ? 1 : 0; // タイトルの表示
175 $titleBgColor = $request->trimValueOf('item_title_bgcolor'); // タイトルバックグランドカラー
176 $html = $request->valueOf('item_html'); // HTMLタグを可能とする
177 $key = $request->valueOf('item_key'); // 外部参照用キー
178 $visible = ($request->trimValueOf('item_visible') == 'on') ? 1 : 0; // チェックボックス
179 $default = ($request->trimValueOf('item_default') == 'on') ? 1 : 0; // チェックボックス
181 $reloadData = false; // データの再読み込み
182 if ($act == 'add'){ // 項目追加の場合
184 $this->checkInput($name, '名前');
187 if ($this->getMsgCount() == 0){
188 $contentId = 0;// コンテンツID初期化
191 // 絵文字画像タグをMagic3内部タグに変換
192 $this->gInstance->getTextConvManager()->convToEmojiTag($html, $html);
194 $ret = $this->db->updateContentItem(self::CONTENT_TYPE, $contentId, $langId, $name, $html, 1/*コンテンツ表示*/, $default, $key, $userId, $newContentId, $newSerial);
196 // 表示属性はコンテンツIDを定義IDにして、ウィジェットパラメータとして保存
198 $paramObj = new stdClass;
199 $paramObj->showTitle = $showTitle; // タイトルの表示
200 $paramObj->titleBgColor = $titleBgColor; // タイトルバックグランドカラー
201 $ret = $this->updateWidgetParamObjByConfigId($newContentId, $paramObj);
204 $this->setGuidanceMsg('データを追加しました');
206 $this->serialNo = $newSerial;
207 $reloadData = true; // データの再読み込み
209 $this->setAppErrorMsg('データ追加に失敗しました');
211 $this->gPage->updateParentWindow();// 親ウィンドウを更新
213 } else if ($act == 'update'){ // 項目更新の場合
215 $this->checkInput($name, '名前');
218 if ($this->getMsgCount() == 0){
219 // 絵文字画像タグをMagic3内部タグに変換
220 $this->gInstance->getTextConvManager()->convToEmojiTag($html, $html);
222 $contentId = $request->trimValueOf('contentid'); // コンテンツID
223 $ret = $this->db->updateContentItem(self::CONTENT_TYPE, $contentId, $langId, $name, $html, 1/*コンテンツ表示*/, $default, $key, $userId, $newContentId, $newSerial);
225 // 表示属性はコンテンツIDを定義IDにして、ウィジェットパラメータとして保存
227 $paramObj = $this->getWidgetParamObjByConfigId($contentId);
228 if (empty($paramObj)) $paramObj = new stdClass;
229 $paramObj->showTitle = $showTitle; // タイトルの表示
230 $paramObj->titleBgColor = $titleBgColor; // タイトルバックグランドカラー
231 $ret = $this->updateWidgetParamObjByConfigId($contentId, $paramObj);
234 $this->setGuidanceMsg('データを更新しました');
236 $this->serialNo = $newSerial;
237 $reloadData = true; // データの再読み込み
239 $this->setAppErrorMsg('データ更新に失敗しました');
241 $this->gPage->updateParentWindow();// 親ウィンドウを更新
243 } else if ($act == 'delete'){ // 項目削除の場合
244 if (empty($this->serialNo)){
245 $this->setUserErrorMsg('削除項目が選択されていません');
248 if ($this->getMsgCount() == 0){
251 $ret = $this->db->getContentBySerial($this->serialNo, $row);
252 if ($ret) $contentId = $row['cn_id']; // コンテンツID
254 $ret = $this->db->delContentItem(array($this->serialNo), $userId);
257 if ($ret) $ret = $this->updateWidgetParamObjByConfigId($contentId, null);
259 if ($ret){ // データ削除成功のとき
260 $this->setGuidanceMsg('データを削除しました');
261 $reloadData = true; // データの再読み込み
263 $this->setAppErrorMsg('データ削除に失敗しました');
265 $this->gPage->updateParentWindow();// 親ウィンドウを更新
268 // コンテンツIDが設定されているとき(他ウィジェットからの表示)は、データを取得
269 $contentId = $request->trimValueOf('contentid'); // コンテンツID
270 if (empty($contentId)){
271 if (empty($this->serialNo)){ // 新規項目追加のとき
272 $visible = 1; // 初期状態は表示
273 // デフォルトの設定項目がないときはデフォルトに設定
274 $contentCount = $this->db->getDefaultContentCount(self::CONTENT_TYPE, $langId);
275 if ($contentCount == 0) $default = 1;
277 $reloadData = true; // データの再読み込み
281 $ret = $this->db->getContentByContentId(self::CONTENT_TYPE, $contentId, $langId, $row);
283 $this->serialNo = $row['cn_serial']; // コンテンツシリアル番号
284 $reloadData = true; // データの再読み込み
290 if ($reloadData){ // データの再読み込み
291 $ret = $this->db->getContentBySerial($this->serialNo, $row);
293 $contentId = $row['cn_id']; // コンテンツID
294 $name = $row['cn_name']; // コンテンツ名前
295 $key = $row['cn_key']; // 外部参照用キー
296 $update_user = $this->convertToDispString($row['lu_name']);// 更新者
297 $update_dt = $this->convertToDispDateTime($row['cn_create_dt']);
299 // 項目表示、デフォルト値チェックボックス
300 $visible = $row['cn_visible'];
301 $default = $row['cn_default'];
304 $html = str_replace(M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END, $this->getUrl($this->gEnv->getRootUrl()), $row['cn_html']); // Magic3ルートURLの変換
305 $this->gInstance->getTextConvManager()->convFromEmojiTag($html, $html);// Magic3内部タグから絵文字画像タグに変換
308 $paramObj = $this->getWidgetParamObjByConfigId($contentId);
309 if (!empty($paramObj)){
310 $showTitle = $paramObj->showTitle; // タイトルの表示
311 $titleBgColor = $paramObj->titleBgColor; // タイトルバックグランドカラー
319 if (!empty($showTitle)) $this->tmpl->addVar("_widget", "show_title", 'checked'); // タイトルの表示
320 $this->tmpl->addVar("_widget", "title_bgcolor", $titleBgColor); // タイトルバックグランドカラー
321 $this->tmpl->addVar("_widget", "sel_item_name", $name); // 名前
322 $this->tmpl->addVar("_widget", "sel_item_html", $html); // HTML
323 $this->tmpl->addVar("_widget", "sel_item_key", $key); // 外部参照用キー
324 $this->tmpl->addVar("_widget", "update_user", $update_user); // 更新者
325 $this->tmpl->addVar("_widget", "update_dt", $update_dt); // 更新日時
327 // 項目表示、項目利用可否チェックボックス
330 $visibleStr = 'checked';
334 $defaultStr = 'checked';
336 $this->tmpl->addVar("_widget", "sel_item_visible", $visibleStr);
337 $this->tmpl->addVar("_widget", "sel_item_default", $defaultStr);
340 $this->tmpl->addVar("_widget", "serial", $this->serialNo);
343 $this->tmpl->addVar('_widget', 'admin_url', $this->getUrl($this->gEnv->getDefaultAdminUrl()));// 管理者URL
344 $this->tmpl->addVar('_widget', 'custom_value_task', 'usercustom'); // ユーザ定義値参照用
345 $this->tmpl->addVar('_widget', 'admin_widget_id', self::ADMIN_WIDGET_ID);// ユーザ定義値参照用(管理ウィジェットのウィジェットID)
348 if (empty($this->serialNo)){ // 新規追加項目を選択しているとき
349 $this->tmpl->addVar("_widget", "sel_item_id", '新規'); // コンテンツID
350 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');// 「新規追加」ボタン
352 $this->tmpl->addVar("_widget", "sel_item_id", $contentId); // コンテンツID
353 $this->tmpl->setAttribute('del_button', 'visibility', 'visible');// 「削除」ボタン
356 if ($openby == 'simple') $this->tmpl->setAttribute('cancel_button', 'visibility', 'hidden'); // 詳細画面のみの表示のときは戻るボタンを隠す
359 * 取得したデータをテンプレートに設定する
361 * @param int $index 行番号(0~)
362 * @param array $fetchedRow フェッチ取得した行
363 * @param object $param 未使用
364 * @return bool true=処理続行の場合、false=処理終了の場合
366 function itemListLoop($index, $fetchedRow, $param)
368 $serial = $this->convertToDispString($fetchedRow['cn_serial']);
372 if ($fetchedRow['cn_visible']){
373 $visible = 'checked';
377 if ($fetchedRow['cn_default']){
378 $default = 'checked';
381 $totalViewCount = $this->gInstance->getAnalyzeManager()->getTotalContentViewCount(self::VIEW_CONTENT_TYPE, $serial);
384 'index' => $index, // 項目番号
385 'serial' => $serial, // シリアル番号
386 'id' => $this->convertToDispString($fetchedRow['cn_id']), // ID
387 'name' => $this->convertToDispString($fetchedRow['cn_name']), // 名前
388 'lang' => $lang, // 対応言語
389 'view_count' => $totalViewCount, // 総参照数
390 'update_user' => $this->convertToDispString($fetchedRow['lu_name']), // 更新者
391 'update_dt' => $this->convertToDispDateTime($fetchedRow['cn_create_dt']), // 更新日時
392 'visible' => $visible, // メニュー項目表示制御
393 'default' => $default // デフォルト項目
395 $this->tmpl->addVars('itemlist', $row);
396 $this->tmpl->parseTemplate('itemlist', 'a');
399 $this->serialArray[] = $fetchedRow['cn_serial'];