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_event_mainCommentWidgetContainer.php 3982 2011-02-07 03:00:55Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getCurrentWidgetContainerPath() . '/admin_event_mainBaseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/event_mainDb.php');
18 require_once($gEnvManager->getCurrentWidgetDbPath() . '/event_commentDb.php');
20 class admin_event_mainCommentWidgetContainer extends admin_event_mainBaseWidgetContainer
22 private $db; // DB接続オブジェクト
23 private $mainDb; // DB接続オブジェクト
24 private $sysDb; // システムDBオブジェクト
25 private $serialNo; // 選択中の項目のシリアル番号
27 private $lang; // 現在の選択言語
28 private $serialArray = array(); // 表示されている項目シリアル番号
29 private $entryArray = array(); // 表示されている項目の記事ID
30 const CONTENT_TYPE = 'bg'; // 記事参照数取得用
31 const DEFAULT_LIST_COUNT = 20; // 最大リスト表示数
32 const CATEGORY_COUNT = 2; // 記事カテゴリーの選択可能数
33 const COMMENT_SIZE = 40; // コメント内容の最大文字列長
38 function __construct()
41 parent::__construct();
44 $this->db = new event_commentDb();
45 $this->mainDb = new event_mainDb();
46 $this->sysDb = $this->gInstance->getSytemDbObject();
51 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
52 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
54 * @param RequestManager $request HTTPリクエスト処理クラス
55 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
56 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
58 function _setTemplate($request, &$param)
60 $task = $request->trimValueOf('task');
61 if ($task == 'comment_detail'){ // 詳細画面
62 return 'admin_comment_detail.tmpl.html';
64 return 'admin_comment.tmpl.html';
70 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
72 * @param RequestManager $request HTTPリクエスト処理クラス
73 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
76 function _assign($request, &$param)
78 $task = $request->trimValueOf('task');
79 if ($task == 'comment_detail'){ // 詳細画面
80 return $this->createDetail($request);
82 return $this->createList($request);
86 * JavascriptファイルをHTMLヘッダ部に設定
88 * JavascriptファイルをHTMLのheadタグ内に追加出力する。
89 * _assign()よりも後に実行される。
91 * @param RequestManager $request HTTPリクエスト処理クラス
92 * @param object $param 任意使用パラメータ。
93 * @return string Javascriptファイル。出力しない場合は空文字列を設定。
95 function _addScriptFileToHead($request, &$param)
97 $scriptArray = array($this->getUrl($this->gEnv->getScriptsUrl() . self::CALENDAR_SCRIPT_FILE), // カレンダースクリプトファイル
98 $this->getUrl($this->gEnv->getScriptsUrl() . self::CALENDAR_LANG_FILE), // カレンダー言語ファイル
99 $this->getUrl($this->gEnv->getScriptsUrl() . self::CALENDAR_SETUP_FILE)); // カレンダーセットアップファイル
104 * CSSファイルをHTMLヘッダ部に設定
106 * CSSファイルをHTMLのheadタグ内に追加出力する。
107 * _assign()よりも後に実行される。
109 * @param RequestManager $request HTTPリクエスト処理クラス
110 * @param object $param 任意使用パラメータ。
111 * @return string CSS文字列。出力しない場合は空文字列を設定。
113 function _addCssFileToHead($request, &$param)
115 return $this->getUrl($this->gEnv->getScriptsUrl() . self::CALENDAR_CSS_FILE);
120 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
122 * @param RequestManager $request HTTPリクエスト処理クラス
125 function createList($request)
128 $defaultLangId = $this->gEnv->getDefaultLanguage();
130 $act = $request->trimValueOf('act');
131 $this->langId = $request->trimValueOf('item_lang'); // 現在メニューで選択中の言語
132 if (empty($this->langId)) $this->langId = $defaultLangId; // 言語が選択されていないときは、デフォルト言語を設定
135 $pageNo = $request->trimValueOf('page'); // ページ番号
136 if (empty($pageNo)) $pageNo = 1;
139 $maxListCount = self::DEFAULT_LIST_COUNT;
140 $serializedParam = $this->sysDb->getWidgetParam($this->gEnv->getCurrentWidgetId());
141 if (!empty($serializedParam)){
142 $dispInfo = unserialize($serializedParam);
143 $maxListCount = $dispInfo->maxMemberListCountByAdmin; // 会員リスト最大表示数
146 $search_startDt = $request->trimValueOf('search_start'); // 検索範囲開始日付
147 if (!empty($search_startDt)) $search_startDt = $this->convertToProperDate($search_startDt);
148 $search_endDt = $request->trimValueOf('search_end'); // 検索範囲終了日付
149 if (!empty($search_endDt)) $search_endDt = $this->convertToProperDate($search_endDt);
150 $search_keyword = $request->trimValueOf('search_keyword'); // 検索キーワード
152 if ($act == 'delete'){ // 項目削除の場合
153 $listedItem = explode(',', $request->trimValueOf('seriallist'));
155 for ($i = 0; $i < count($listedItem); $i++){
157 $itemName = 'item' . $i . '_selected';
158 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
160 if ($itemValue){ // チェック項目
161 $delItems[] = $listedItem[$i];
164 if (count($delItems) > 0){
165 $ret = $this->db->delCommentItem($delItems);
166 if ($ret){ // データ削除成功のとき
167 $this->setGuidanceMsg('データを削除しました');
169 $this->setAppErrorMsg('データ削除に失敗しました');
172 } else if ($act == 'search'){ // 検索のとき
173 if (!empty($search_startDt) && !empty($search_endDt) && $search_startDt > $search_endDt){
174 $this->setUserErrorMsg('期間の指定範囲にエラーがあります。');
176 $pageNo = 1; // ページ番号初期化
177 } else if ($act == 'selpage'){ // ページ選択
179 // ###### 一覧の取得条件を作成 ######
180 if (!empty($search_endDt)) $endDt = $this->getNextDay($search_endDt);
183 $totalCount = $this->db->getCommentItemCount($search_startDt, $endDt, $search_keyword, $this->langId);
186 $pageCount = (int)(($totalCount -1) / $maxListCount) + 1; // 総ページ数
187 if ($pageNo < 1) $pageNo = 1;
188 if ($pageNo > $pageCount) $pageNo = $pageCount;
189 $this->firstNo = ($pageNo -1) * $maxListCount + 1; // 先頭番号
193 if ($pageCount > 1){ // ページが2ページ以上のときリンクを作成
194 for ($i = 1; $i <= $pageCount; $i++){
196 $link = ' ' . $i;
198 $link = ' <a href="#" onclick="selpage(\'' . $i . '\');return false;">' . $i . '</a>';
205 $this->db->searchCommentItems($maxListCount, $pageNo, $search_startDt, $endDt, $search_keyword, $this->langId, array($this, 'itemListLoop'));
206 if (count($this->serialArray) <= 0) $this->tmpl->setAttribute('itemlist', 'visibility', 'hidden');// 投稿記事がないときは、一覧を表示しない
209 $this->tmpl->addVar("_widget", "page_link", $pageLink);
210 $this->tmpl->addVar("_widget", "total_count", $totalCount);
213 $this->tmpl->addVar("_widget", "search_start", $search_startDt); // 開始日付
214 $this->tmpl->addVar("_widget", "search_end", $search_endDt); // 終了日付
215 $this->tmpl->addVar("_widget", "search_keyword", $search_keyword); // 検索キーワード
218 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
219 $this->tmpl->addVar("_widget", "entry_list", implode($this->entryArray, ','));// 表示項目の記事IDを設定
220 $this->tmpl->addVar("_widget", "page", $pageNo); // ページ番号
221 $this->tmpl->addVar("_widget", "list_count", $maxListCount); // 一覧表示項目数
226 * @param RequestManager $request HTTPリクエスト処理クラス
229 function createDetail($request)
232 $defaultLangId = $this->gEnv->getDefaultLanguage();
233 $regUserId = $this->gEnv->getCurrentUserId(); // 記事投稿ユーザ
234 $regDt = date("Y/m/d H:i:s"); // 投稿日時
236 $act = $request->trimValueOf('act');
237 $this->langId = $request->trimValueOf('item_lang'); // 現在メニューで選択中の言語
238 if (empty($this->langId)) $this->langId = $defaultLangId; // 言語が選択されていないときは、デフォルト言語を設定
239 $this->entryId = $request->trimValueOf('entry'); // 記事エントリーID
240 $this->serialNo = $request->trimValueOf('serial'); // 選択項目のシリアル番号
241 if (empty($this->serialNo)) $this->serialNo = 0;
242 $name = $request->trimValueOf('item_name');
243 $html = $request->valueOf('item_html');
244 $url = $request->valueOf('item_url');
245 $email = $request->valueOf('item_email');
246 $reg_user = $request->valueOf('item_reg_user');
247 $status = $request->trimValueOf('item_status'); // エントリー状態(0=未設定、1=編集中、2=公開、3=非公開)
249 $dataReload = false; // データの再ロード
250 if ($act == 'add'){ // 項目追加の場合
253 $this->checkInput($name, 'タイトル');
256 if ($this->getMsgCount() == 0){
257 $ret = $this->db->addEntryItem(0, $this->langId, $name, $html, $status, $this->categoryArray, $regUserId, $regDt, $newSerial);
259 $this->setGuidanceMsg('データを追加しました');
261 $this->serialNo = $newSerial;
262 $dataReload = true; // データの再ロード
264 $this->setAppErrorMsg('データ追加に失敗しました');
267 } else if ($act == 'update'){ // 項目更新の場合
269 if ($this->getMsgCount() == 0){
270 $ret = $this->db->updateCommentItem($this->serialNo, $name, $html, $url, $reg_user, $email);
273 $this->setGuidanceMsg('データを更新しました');
274 $dataReload = true; // データの再ロード
276 $this->setAppErrorMsg('データ更新に失敗しました');
279 } else if ($act == 'delete'){ // 項目削除の場合
280 if (empty($this->serialNo)){
281 $this->setUserErrorMsg('削除項目が選択されていません');
284 if ($this->getMsgCount() == 0){
285 $ret = $this->db->delCommentItem(array($this->serialNo));
286 if ($ret){ // データ削除成功のとき
287 $this->setGuidanceMsg('データを削除しました');
289 $this->setAppErrorMsg('データ削除に失敗しました');
292 } else if ($act == 'deleteid'){ // ID項目削除の場合
293 } else { // 初期画面表示のとき
294 $dataReload = true; // データの再ロード
298 if ($dataReload){ // データの再ロード
299 $ret = $this->db->getCommentBySerial($this->serialNo, $row);
301 $this->entryId = $row['ee_id']; // エントリーID
302 $entryTitle = $row['ee_name']; // 記事タイトル
303 $name = $row['eo_name']; // コメントタイトル
304 $html = $row['eo_html']; // HTML
305 $email = $row['eo_email']; // eメール
306 $url = $row['eo_url']; // URL
307 $reg_user = $row['eo_user_name']; // 投稿者
308 $reg_dt = $this->convertToDispDateTime($row['eo_regist_dt']); // 投稿日時
309 $update_user = $row['update_user_name']; // 更新者
310 $update_dt = $this->convertToDispDateTime($row['eo_update_dt']); // 更新日時
315 $this->tmpl->addVar("_widget", "serial", $this->serialNo); // シリアル番号
317 // 入力フィールドの設定、共通項目のデータ設定
318 if ($this->entryId == 0){ // 記事IDが0のときは、新規追加モードにする
319 $this->tmpl->addVar('_widget', 'id', '新規');
321 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');
323 $this->tmpl->addVar('_widget', 'id', $this->entryId);
325 if ($this->serialNo == 0){ // 未登録データのとき
327 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');
330 $this->tmpl->setAttribute('delete_button', 'visibility', 'visible');// デフォルト言語以外はデータ削除
331 $this->tmpl->setAttribute('update_button', 'visibility', 'visible');
335 $this->tmpl->addVar("_widget", "entry_title", $this->convertToDispString($entryTitle)); // 記事タイトル
336 $this->tmpl->addVar("_widget", "name", $this->convertToDispString($name)); // コメントタイトル
337 $this->tmpl->addVar("_widget", "html", $this->convertToDispString($html)); // HTML
338 $this->tmpl->addVar("_widget", "email", $this->convertToDispString($email)); // Eメール
339 $this->tmpl->addVar("_widget", "url", $this->convertToDispString($url)); // URL
340 $this->tmpl->addVar("_widget", "reg_user", $this->convertToDispString($reg_user)); // 投稿者
341 $this->tmpl->addVar("_widget", "entry_dt", $reg_dt); // 投稿日時
342 $this->tmpl->addVar("_widget", "update_user", $this->convertToDispString($update_user)); // 更新者
343 $this->tmpl->addVar("_widget", "update_dt", $update_dt); // 更新日時
346 * 取得したデータをテンプレートに設定する
348 * @param int $index 行番号(0~)
349 * @param array $fetchedRow フェッチ取得した行
350 * @param object $param 未使用
351 * @return bool true=処理続行の場合、false=処理終了の場合
353 function itemListLoop($index, $fetchedRow, $param)
356 $serial = $fetchedRow['eo_serial'];
359 $entryId = $fetchedRow['ee_id'];
362 /*switch ($fetchedRow['eo_status']){
363 case 1: $status = '<font color="green">公開</font>'; break;
364 case 2: $status = '非公開'; break;
368 if (function_exists('mb_strimwidth')){
369 $comment = mb_strimwidth($fetchedRow['eo_html'], 0, self::COMMENT_SIZE, '…');
371 $comment = substr($fetchedRow['eo_html'], 0, self::COMMENT_SIZE) . '...';
374 'index' => $index, // 項目番号
375 'no' => $index + 1, // 行番号
376 'serial' => $serial, // シリアル番号
377 'entry_name' => $this->convertToDispString($fetchedRow['ee_name']), // 記事タイトル
378 'name' => $this->convertToDispString($fetchedRow['eo_name']), // コメントタイトル
379 'content' => $this->convertToDispString($comment), // コメント内容
380 'lang' => $lang, // 対応言語
381 'status' => $status, // 公開状況
382 'reg_user' => $this->convertToDispString($fetchedRow['eo_user_name']), // 投稿者
383 'reg_date' => $this->convertToDispDateTime($fetchedRow['eo_regist_dt']) // 投稿日時
385 $this->tmpl->addVars('itemlist', $row);
386 $this->tmpl->parseTemplate('itemlist', 'a');
389 $this->serialArray[] = $serial;
390 if (!in_array($entryId, $this->entryArray)) $this->entryArray[] = $entryId; // 存在しない場合は追加
396 * @param int $index 行番号(0~)
397 * @param array $fetchedRow フェッチ取得した行
398 * @param object $param 未使用
399 * @return bool true=処理続行の場合、false=処理終了の場合
401 function langLoop($index, $fetchedRow, $param)
404 if ($fetchedRow['ln_id'] == $this->langId){
405 $selected = 'selected';
407 if ($this->gEnv->getCurrentLanguage() == 'ja'){ // 日本語表示の場合
408 $name = $this->convertToDispString($fetchedRow['ln_name']);
410 $name = $this->convertToDispString($fetchedRow['ln_name_en']);
414 'value' => $this->convertToDispString($fetchedRow['ln_id']), // 言語ID
415 'name' => $name, // 言語名
416 'selected' => $selected // 選択中かどうか
418 $this->tmpl->addVars('lang_list', $row);
419 $this->tmpl->parseTemplate('lang_list', 'a');