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_m_pc_contentWidgetContainer.php 2568 2009-11-18 13:05:26Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getContainerPath() . '/baseAdminWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/pc_contentDb.php');
19 class admin_m_pc_contentWidgetContainer extends BaseAdminWidgetContainer
21 private $db; // DB接続オブジェクト
22 private $serialNo; // 選択中の項目のシリアル番号
23 private $serialArray = array(); // 表示されているコンテンツシリアル番号
24 private $_menuId = 'mobile_menu'; // メインメニューID
25 private $isExistsContent; // コンテンツ項目が存在するかどうか
26 const INC_INDEX = 1; // メニュー項目表示順の増加分
27 const ADMIN_WIDGET_ID = 'admin_main'; // 管理ウィジェットのウィジェットID
28 const CONTENT_TYPE = 'ct'; // 参照数カウント用
33 function __construct()
36 parent::__construct();
39 $this->db = new pc_contentDb();
44 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
45 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
47 * @param RequestManager $request HTTPリクエスト処理クラス
48 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
49 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
51 function _setTemplate($request, &$param)
53 $task = $request->trimValueOf('task');
54 if ($task == 'detail'){ // 詳細画面
55 return 'admin_main_detail.tmpl.html';
57 return 'admin_main.tmpl.html';
63 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
65 * @param RequestManager $request HTTPリクエスト処理クラス
66 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
69 function _assign($request, &$param)
71 $task = $request->trimValueOf('task');
72 if ($task == 'detail'){ // 詳細画面
73 return $this->createDetail($request);
75 return $this->createList($request);
81 * @param RequestManager $request HTTPリクエスト処理クラス
84 function createList($request)
87 $userId = $this->gEnv->getCurrentUserId();
88 $langId = $this->gEnv->getDefaultLanguage();
90 $act = $request->trimValueOf('act');
91 if ($act == 'addtomenu'){ // メニューに項目を追加
92 $contentId = $request->trimValueOf('contentid'); // コンテンツID
95 // このウィジェットがマップされているページサブIDを取得
96 $subPageId = $this->gPage->getPageSubIdByWidget($this->gEnv->getDefaultPageId(), $this->gEnv->getCurrentWidgetId());
98 if (!empty($subPageId)) $sub = 'sub=' . $subPageId . '&';
101 $url = M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END . '/index.php?' . $sub . 'contentid=' . $contentId;*/
102 // このウィジェットがマップされているページサブIDを取得
103 $subPageId = $this->gPage->getPageSubIdByWidget($this->gEnv->getDefaultMobilePageId(), $this->gEnv->getCurrentWidgetId());
105 if (!empty($subPageId)) $sub = 'sub=' . $subPageId . '&';
108 $url = M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END . '/m/index.php?' . $sub . 'contentid=' . $contentId;
112 $ret = $this->db->getContentByContentId($contentId, $langId, $row);
115 $menutItemName = $row['cn_name']; // 名前
119 $ret = $this->db->addMenuItem($this->_menuId, $langId, $menutItemName, $url, self::INC_INDEX, $userId);
121 $this->setGuidanceMsg('メインメニューに項目を追加しました');
123 $this->setAppErrorMsg('メインメニューの項目追加に失敗しました');
125 } else if ($act == 'delete'){ // 項目削除の場合
126 $listedItem = explode(',', $request->trimValueOf('seriallist'));
128 for ($i = 0; $i < count($listedItem); $i++){
130 $itemName = 'item' . $i . '_selected';
131 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
133 if ($itemValue){ // チェック項目
134 $delItems[] = $listedItem[$i];
137 if (count($delItems) > 0){
138 $ret = $this->db->delContentItem($delItems);
139 if ($ret){ // データ削除成功のとき
140 $this->setGuidanceMsg('データを削除しました');
142 $this->setAppErrorMsg('データ削除に失敗しました');
147 // コンテンツ項目リストをデフォルト言語で取得
148 $this->db->getAllContentItems(array($this, 'itemListLoop'), $langId);
149 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
150 // コンテンツ項目がないときは、一覧を表示しない
151 if (!$this->isExistsContent) $this->tmpl->setAttribute('itemlist', 'visibility', 'hidden');
156 * @param RequestManager $request HTTPリクエスト処理クラス
159 function createDetail($request)
162 $langId = $this->gEnv->getDefaultLanguage();
165 $openby = $request->trimValueOf(M3_REQUEST_PARAM_OPEN_BY);
167 $act = $request->trimValueOf('act');
168 $this->serialNo = $request->trimValueOf('serial'); // 選択項目のシリアル番号
169 $name = $request->trimValueOf('item_name');
170 $showTitle = ($request->trimValueOf('show_title') == 'on') ? 1 : 0; // タイトルの表示
171 $titleBgColor = $request->trimValueOf('item_title_bgcolor'); // タイトルバックグランドカラー
172 $html = $request->valueOf('item_html'); // HTMLタグを可能とする
173 $key = $request->valueOf('item_key'); // 外部参照用キー
174 $visible = ($request->trimValueOf('item_visible') == 'on') ? 1 : 0; // チェックボックス
175 $limited = ($request->trimValueOf('item_limited') == 'on') ? 1 : 0; // チェックボックス
176 $default = ($request->trimValueOf('item_default') == 'on') ? 1 : 0; // チェックボックス
178 $reloadData = false; // データの再読み込み
179 if ($act == 'add'){ // 項目追加の場合
181 $this->checkInput($name, '名前');
184 if ($this->getMsgCount() == 0){
185 $ret = $this->db->addContentItem(0, $langId, $name, ''/*説明*/, $html, $visible, $default, $limited, $key, $newSerial);
187 // 表示属性はコンテンツIDを定義IDにして、ウィジェットパラメータとして保存
189 $paramObj = new stdClass;
190 $paramObj->showTitle = $showTitle; // タイトルの表示
191 $paramObj->titleBgColor = $titleBgColor; // タイトルバックグランドカラー
192 $ret = $this->updateWidgetParamObjByConfigId($newContentId, $paramObj);
195 $this->setGuidanceMsg('データを追加しました');
197 $this->serialNo = $newSerial;
198 $reloadData = true; // データの再読み込み
200 $this->setAppErrorMsg('データ追加に失敗しました');
203 } else if ($act == 'update'){ // 項目更新の場合
205 $this->checkInput($name, '名前');
208 if ($this->getMsgCount() == 0){
209 $ret = $this->db->updateContentItem($this->serialNo, $name, $html, $visible, $default, $limited, $key, $newSerial);
211 $this->setGuidanceMsg('データを更新しました');
213 $this->serialNo = $newSerial;
214 $reloadData = true; // データの再読み込み
216 $this->setAppErrorMsg('データ更新に失敗しました');
219 } else if ($act == 'delete'){ // 項目削除の場合
220 if (empty($this->serialNo)){
221 $this->setUserErrorMsg('削除項目が選択されていません');
224 if ($this->getMsgCount() == 0){
225 $ret = $this->db->delContentItem(array($this->serialNo));
226 if ($ret){ // データ削除成功のとき
227 $this->setGuidanceMsg('データを削除しました');
228 $reloadData = true; // データの再読み込み
230 $this->setAppErrorMsg('データ削除に失敗しました');
234 // コンテンツIDが設定されているとき(他ウィジェットからの表示)は、データを取得
235 $contentId = $request->trimValueOf('contentid'); // コンテンツID
236 if (empty($contentId)){
237 if (empty($this->serialNo)){ // 新規項目追加のとき
238 $visible = 1; // 初期状態は表示
240 $reloadData = true; // データの再読み込み
244 $ret = $this->db->getContentByContentId($contentId, $langId, $row);
246 $this->serialNo = $row['cn_serial']; // コンテンツシリアル番号
247 $reloadData = true; // データの再読み込み
253 if ($reloadData){ // データの再読み込み
254 $ret = $this->db->getContentBySerial($this->serialNo, $row);
256 $contentId = $row['cn_id']; // コンテンツID
257 $name = $row['cn_name']; // コンテンツ名前
258 $html = str_replace(M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END, $this->gEnv->getRootUrl(), $row['cn_html']); // HTML
259 $key = $row['cn_key']; // 外部参照用キー
260 $update_user = $this->convertToDispString($row['lu_name']);// 更新者
261 $update_dt = $this->convertToDispDateTime($row['cn_create_dt']);
263 // 項目表示、デフォルト値チェックボックス
264 $visible = $row['cn_visible'];
265 $default = $row['cn_default'];
266 $limited = $row['cn_user_limited']; // ユーザ制限
273 $this->tmpl->addVar("_widget", "sel_item_name", $name); // 名前
274 $this->tmpl->addVar("_widget", "sel_item_html", $html); // HTML
275 $this->tmpl->addVar("_widget", "sel_item_key", $key); // 外部参照用キー
276 $this->tmpl->addVar("_widget", "update_user", $update_user); // 更新者
277 $this->tmpl->addVar("_widget", "update_dt", $update_dt); // 更新日時
279 // 項目表示、項目利用可否チェックボックス
281 if ($visible) $visibleStr = 'checked';
282 $this->tmpl->addVar("_widget", "sel_item_visible", $visibleStr);
284 if ($default) $defaultStr = 'checked';
285 $this->tmpl->addVar("_widget", "sel_item_default", $defaultStr);
287 if ($limited) $limitedStr = 'checked';
288 $this->tmpl->addVar("_widget", "sel_item_limited", $limitedStr);
291 $this->tmpl->addVar("_widget", "serial", $this->serialNo);
294 $this->tmpl->addVar('_widget', 'admin_url', $this->getUrl($this->gEnv->getDefaultAdminUrl()));// 管理者URL
295 $this->tmpl->addVar('_widget', 'custom_value_task', 'usercustom'); // ユーザ定義値参照用
296 $this->tmpl->addVar('_widget', 'admin_widget_id', self::ADMIN_WIDGET_ID);// ユーザ定義値参照用(管理ウィジェットのウィジェットID)
299 if (empty($this->serialNo)){ // 新規追加項目を選択しているとき
300 $this->tmpl->addVar("_widget", "sel_item_id", '新規'); // コンテンツID
301 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');// 「新規追加」ボタン
303 $this->tmpl->addVar("_widget", "sel_item_id", $contentId); // コンテンツID
304 $this->tmpl->setAttribute('del_button', 'visibility', 'visible');// 「削除」ボタン
307 if ($openby == 'simple') $this->tmpl->setAttribute('cancel_button', 'visibility', 'hidden'); // 詳細画面のみの表示のときは戻るボタンを隠す
310 * 取得したデータをテンプレートに設定する
312 * @param int $index 行番号(0~)
313 * @param array $fetchedRow フェッチ取得した行
314 * @param object $param 未使用
315 * @return bool true=処理続行の場合、false=処理終了の場合
317 function itemListLoop($index, $fetchedRow, $param)
319 $serial = $this->convertToDispString($fetchedRow['cn_serial']);
323 if ($fetchedRow['cn_visible']) $visible = 'checked';
327 if ($fetchedRow['cn_user_limited']) $limited = 'checked';
331 if ($fetchedRow['cn_default']) $default = 'checked';
335 $ret = $this->db->getLangByContentId($fetchedRow['cn_id'], $rows);
337 $count = count($rows);
338 for ($i = 0; $i < $count; $i++){
339 if ($this->gEnv->getCurrentLanguage() == 'ja'){ // 日本語の場合
340 $lang .= $rows[$i]['ln_name'];
341 if ($i != $count -1) $lang .= ',';
343 $lang .= $rows[$i]['ln_name_en'];
344 if ($i != $count -1) $lang .= ',';
349 $totalViewCount = $this->gInstance->getAnalyzeManager()->getTotalContentViewCount(self::CONTENT_TYPE, $serial);
352 'index' => $index, // 項目番号
353 'serial' => $serial, // シリアル番号
354 'id' => $this->convertToDispString($fetchedRow['cn_id']), // ID
355 'name' => $this->convertToDispString($fetchedRow['cn_name']), // 名前
356 'lang' => $lang, // 対応言語
357 'view_count' => $totalViewCount, // 総参照数
358 'update_user' => $this->convertToDispString($fetchedRow['lu_name']), // 更新者
359 'update_dt' => $this->convertToDispDateTime($fetchedRow['cn_create_dt']), // 更新日時
360 'visible' => $visible, // メニュー項目表示制御
361 'limited' => $limited, // ユーザ制限
362 'default' => $default // デフォルト項目
364 $this->tmpl->addVars('itemlist', $row);
365 $this->tmpl->parseTemplate('itemlist', 'a');
368 $this->serialArray[] = $fetchedRow['cn_serial'];
370 $this->isExistsContent = true; // コンテンツ項目が存在するかどうか