OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / event_main / include / container / admin_event_mainCommentWidgetContainer.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-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
15  */
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');
19
20 class admin_event_mainCommentWidgetContainer extends admin_event_mainBaseWidgetContainer
21 {
22         private $db;    // DB接続オブジェクト
23         private $mainDb;        // DB接続オブジェクト
24         private $sysDb;         // システムDBオブジェクト
25         private $serialNo;              // 選択中の項目のシリアル番号
26         private $entryId;
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;                        // コメント内容の最大文字列長
34         
35         /**
36          * コンストラクタ
37          */
38         function __construct()
39         {
40                 // 親クラスを呼び出す
41                 parent::__construct();
42                 
43                 // DBオブジェクト作成
44                 $this->db = new event_commentDb();
45                 $this->mainDb = new event_mainDb();
46                 $this->sysDb = $this->gInstance->getSytemDbObject();
47         }
48         /**
49          * テンプレートファイルを設定
50          *
51          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
52          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
53          *
54          * @param RequestManager $request               HTTPリクエスト処理クラス
55          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
56          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
57          */
58         function _setTemplate($request, &$param)
59         {
60                 $task = $request->trimValueOf('task');
61                 if ($task == 'comment_detail'){         // 詳細画面
62                         return 'admin_comment_detail.tmpl.html';
63                 } else {                        // 一覧画面
64                         return 'admin_comment.tmpl.html';
65                 }
66         }
67         /**
68          * テンプレートにデータ埋め込む
69          *
70          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
71          *
72          * @param RequestManager $request               HTTPリクエスト処理クラス
73          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
74          * @param                                                               なし
75          */
76         function _assign($request, &$param)
77         {
78                 $task = $request->trimValueOf('task');
79                 if ($task == 'comment_detail'){ // 詳細画面
80                         return $this->createDetail($request);
81                 } else {                        // 一覧画面
82                         return $this->createList($request);
83                 }
84         }
85         /**
86          * JavascriptファイルをHTMLヘッダ部に設定
87          *
88          * JavascriptファイルをHTMLのheadタグ内に追加出力する。
89          * _assign()よりも後に実行される。
90          *
91          * @param RequestManager $request               HTTPリクエスト処理クラス
92          * @param object         $param                 任意使用パラメータ。
93          * @return string                                               Javascriptファイル。出力しない場合は空文字列を設定。
94          */
95         function _addScriptFileToHead($request, &$param)
96         {
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));       // カレンダーセットアップファイル
100                 return $scriptArray;
101
102         }
103         /**
104          * CSSファイルをHTMLヘッダ部に設定
105          *
106          * CSSファイルをHTMLのheadタグ内に追加出力する。
107          * _assign()よりも後に実行される。
108          *
109          * @param RequestManager $request               HTTPリクエスト処理クラス
110          * @param object         $param                 任意使用パラメータ。
111          * @return string                                               CSS文字列。出力しない場合は空文字列を設定。
112          */
113         function _addCssFileToHead($request, &$param)
114         {
115                 return $this->getUrl($this->gEnv->getScriptsUrl() . self::CALENDAR_CSS_FILE);
116         }
117         /**
118          * 一覧画面作成
119          *
120          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
121          *
122          * @param RequestManager $request               HTTPリクエスト処理クラス
123          * @param                                                               なし
124          */
125         function createList($request)
126         {
127                 // ユーザ情報、表示言語
128                 $defaultLangId = $this->gEnv->getDefaultLanguage();
129                 
130                 $act = $request->trimValueOf('act');
131                 $this->langId = $request->trimValueOf('item_lang');                             // 現在メニューで選択中の言語
132                 if (empty($this->langId)) $this->langId = $defaultLangId;                       // 言語が選択されていないときは、デフォルト言語を設定  
133                 
134                 // ##### 検索条件 #####
135                 $pageNo = $request->trimValueOf('page');                                // ページ番号
136                 if (empty($pageNo)) $pageNo = 1;
137                 
138                 // DBの保存設定値を取得
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;           // 会員リスト最大表示数
144                 }
145
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');                      // 検索キーワード
151
152                 if ($act == 'delete'){          // 項目削除の場合
153                         $listedItem = explode(',', $request->trimValueOf('seriallist'));
154                         $delItems = array();
155                         for ($i = 0; $i < count($listedItem); $i++){
156                                 // 項目がチェックされているかを取得
157                                 $itemName = 'item' . $i . '_selected';
158                                 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
159                                 
160                                 if ($itemValue){                // チェック項目
161                                         $delItems[] = $listedItem[$i];
162                                 }
163                         }
164                         if (count($delItems) > 0){
165                                 $ret = $this->db->delCommentItem($delItems);
166                                 if ($ret){              // データ削除成功のとき
167                                         $this->setGuidanceMsg('データを削除しました');
168                                 } else {
169                                         $this->setAppErrorMsg('データ削除に失敗しました');
170                                 }
171                         }
172                 } else if ($act == 'search'){           // 検索のとき
173                         if (!empty($search_startDt) && !empty($search_endDt) && $search_startDt > $search_endDt){
174                                 $this->setUserErrorMsg('期間の指定範囲にエラーがあります。');
175                         }
176                         $pageNo = 1;            // ページ番号初期化
177                 } else if ($act == 'selpage'){                  // ページ選択
178                 }
179                 // ###### 一覧の取得条件を作成 ######
180                 if (!empty($search_endDt)) $endDt = $this->getNextDay($search_endDt);
181                 
182                 // 総数を取得
183                 $totalCount = $this->db->getCommentItemCount($search_startDt, $endDt, $search_keyword, $this->langId);
184
185                 // 表示するページ番号の修正
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;              // 先頭番号
190                 
191                 // ページング用リンク作成
192                 $pageLink = '';
193                 if ($pageCount > 1){    // ページが2ページ以上のときリンクを作成
194                         for ($i = 1; $i <= $pageCount; $i++){
195                                 if ($i == $pageNo){
196                                         $link = '&nbsp;' . $i;
197                                 } else {
198                                         $link = '&nbsp;<a href="#" onclick="selpage(\'' . $i . '\');return false;">' . $i . '</a>';
199                                 }
200                                 $pageLink .= $link;
201                         }
202                 }
203                 
204                 // 記事項目リストを取得
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');// 投稿記事がないときは、一覧を表示しない
207                 
208                 // 検索結果
209                 $this->tmpl->addVar("_widget", "page_link", $pageLink);
210                 $this->tmpl->addVar("_widget", "total_count", $totalCount);
211                 
212                 // 検索条件
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);      // 検索キーワード
216
217                 // 非表示項目を設定
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);    // 一覧表示項目数
222         }
223         /**
224          * 詳細画面作成
225          *
226          * @param RequestManager $request               HTTPリクエスト処理クラス
227          * @param                                                               なし
228          */
229         function createDetail($request)
230         {
231                 // デフォルト値
232                 $defaultLangId  = $this->gEnv->getDefaultLanguage();
233                 $regUserId              = $this->gEnv->getCurrentUserId();                      // 記事投稿ユーザ
234                 $regDt                  = date("Y/m/d H:i:s");                                          // 投稿日時
235
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=非公開)
248
249                 $dataReload = false;            // データの再ロード
250                 if ($act == 'add'){             // 項目追加の場合
251                 /*
252                         // 入力チェック
253                         $this->checkInput($name, 'タイトル');
254                                         
255                         // エラーなしの場合は、データを登録
256                         if ($this->getMsgCount() == 0){
257                                 $ret = $this->db->addEntryItem(0, $this->langId, $name, $html, $status, $this->categoryArray, $regUserId, $regDt, $newSerial);
258                                 if ($ret){
259                                         $this->setGuidanceMsg('データを追加しました');
260                                         // シリアル番号更新
261                                         $this->serialNo = $newSerial;
262                                         $dataReload = true;             // データの再ロード
263                                 } else {
264                                         $this->setAppErrorMsg('データ追加に失敗しました');
265                                 }
266                         }*/
267                 } else if ($act == 'update'){           // 項目更新の場合
268                         // エラーなしの場合は、データを更新
269                         if ($this->getMsgCount() == 0){
270                                 $ret = $this->db->updateCommentItem($this->serialNo, $name, $html, $url, $reg_user, $email);
271                                 
272                                 if ($ret){
273                                         $this->setGuidanceMsg('データを更新しました');
274                                         $dataReload = true;             // データの再ロード
275                                 } else {
276                                         $this->setAppErrorMsg('データ更新に失敗しました');
277                                 }
278                         }
279                 } else if ($act == 'delete'){           // 項目削除の場合
280                         if (empty($this->serialNo)){
281                                 $this->setUserErrorMsg('削除項目が選択されていません');
282                         }
283                         // エラーなしの場合は、データを削除
284                         if ($this->getMsgCount() == 0){
285                                 $ret = $this->db->delCommentItem(array($this->serialNo));
286                                 if ($ret){              // データ削除成功のとき
287                                         $this->setGuidanceMsg('データを削除しました');
288                                 } else {
289                                         $this->setAppErrorMsg('データ削除に失敗しました');
290                                 }
291                         }
292                 } else if ($act == 'deleteid'){         // ID項目削除の場合
293                 } else {        // 初期画面表示のとき
294                         $dataReload = true;             // データの再ロード
295                 }
296                 
297                 // 設定データを再取得
298                 if ($dataReload){               // データの再ロード
299                         $ret = $this->db->getCommentBySerial($this->serialNo, $row);
300                         if ($ret){
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']);                // 更新日時
311                         }
312                 }
313                 
314                 // 非表示項目を設定
315                 $this->tmpl->addVar("_widget", "serial", $this->serialNo);      // シリアル番号
316
317                 // 入力フィールドの設定、共通項目のデータ設定
318                 if ($this->entryId == 0){               // 記事IDが0のときは、新規追加モードにする
319                         $this->tmpl->addVar('_widget', 'id', '新規');
320                         
321                         $this->tmpl->setAttribute('add_button', 'visibility', 'visible');
322                 } else {
323                         $this->tmpl->addVar('_widget', 'id', $this->entryId);
324                         
325                         if ($this->serialNo == 0){              // 未登録データのとき
326                                 // データ追加ボタン表示
327                                 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');
328                         } else {
329                                 // データ更新、削除ボタン表示
330                                 $this->tmpl->setAttribute('delete_button', 'visibility', 'visible');// デフォルト言語以外はデータ削除
331                                 $this->tmpl->setAttribute('update_button', 'visibility', 'visible');
332                         }
333                 }
334                 // ### 入力値を再設定 ###
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);        // 更新日時
344         }
345         /**
346          * 取得したデータをテンプレートに設定する
347          *
348          * @param int $index                    行番号(0~)
349          * @param array $fetchedRow             フェッチ取得した行
350          * @param object $param                 未使用
351          * @return bool                                 true=処理続行の場合、false=処理終了の場合
352          */
353         function itemListLoop($index, $fetchedRow, $param)
354         {
355                 // シリアル番号
356                 $serial = $fetchedRow['eo_serial'];
357                 
358                 // 記事ID
359                 $entryId = $fetchedRow['ee_id'];
360                 
361                 // 公開状態
362                 /*switch ($fetchedRow['eo_status']){
363                         case 1: $status = '<font color="green">公開</font>';  break;
364                         case 2: $status = '非公開';  break;
365                 }*/
366                 
367                 // コメント内容
368                 if (function_exists('mb_strimwidth')){
369                         $comment = mb_strimwidth($fetchedRow['eo_html'], 0, self::COMMENT_SIZE, '…');
370                 } else {
371                         $comment = substr($fetchedRow['eo_html'], 0, self::COMMENT_SIZE) . '...';
372                 }
373                 $row = array(
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']) // 投稿日時
384                 );
385                 $this->tmpl->addVars('itemlist', $row);
386                 $this->tmpl->parseTemplate('itemlist', 'a');
387                 
388                 // 表示中項目のシリアル番号を保存
389                 $this->serialArray[] = $serial;
390                 if (!in_array($entryId, $this->entryArray)) $this->entryArray[] = $entryId;             // 存在しない場合は追加
391                 return true;
392         }
393         /**
394          * 取得した言語をテンプレートに設定する
395          *
396          * @param int $index                    行番号(0~)
397          * @param array $fetchedRow             フェッチ取得した行
398          * @param object $param                 未使用
399          * @return bool                                 true=処理続行の場合、false=処理終了の場合
400          */
401         function langLoop($index, $fetchedRow, $param)
402         {
403                 $selected = '';
404                 if ($fetchedRow['ln_id'] == $this->langId){
405                         $selected = 'selected';
406                 }
407                 if ($this->gEnv->getCurrentLanguage() == 'ja'){         // 日本語表示の場合
408                         $name = $this->convertToDispString($fetchedRow['ln_name']);
409                 } else {
410                         $name = $this->convertToDispString($fetchedRow['ln_name_en']);
411                 }
412
413                 $row = array(
414                         'value'    => $this->convertToDispString($fetchedRow['ln_id']),                 // 言語ID
415                         'name'     => $name,                    // 言語名
416                         'selected' => $selected                                                                                                         // 選択中かどうか
417                 );
418                 $this->tmpl->addVars('lang_list', $row);
419                 $this->tmpl->parseTemplate('lang_list', 'a');
420                 return true;
421         }
422 }
423 ?>