OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / portal_updateinfo / include / container / admin_portal_updateinfoNewsWidgetContainer.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    ポータル用コンテンツ更新情報
10  * @author     株式会社 毎日メディアサービス
11  * @copyright  Copyright 2009 株式会社 毎日メディアサービス.
12  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
13  * @version    SVN: $Id: admin_portal_updateinfoNewsWidgetContainer.php 2724 2009-12-21 07:41:16Z fishbone $
14  * @link       http://www.m-media.co.jp
15  */
16 require_once($gEnvManager->getCurrentWidgetContainerPath() . '/admin_portal_updateinfoBaseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/portal_updateinfoDb.php');
18
19 class admin_portal_updateinfoNewsWidgetContainer extends admin_portal_updateinfoBaseWidgetContainer
20 {
21         private $db;    // DB接続オブジェクト
22         private $sysDb;         // システムDBオブジェクト
23         private $serialNo;              // 選択中の項目のシリアル番号
24         private $lang;          // 現在の選択言語
25         private $serialArray = array();         // 表示されている項目シリアル番号
26         private $isExistsList;          // リスト項目が存在するかどうか
27         const CONTENT_TYPE = 'content';         // 取得コンテンツタイプ
28         const DEFAULT_ITEM_COUNT = 10;          // デフォルトの表示項目数
29         
30         /**
31          * コンストラクタ
32          */
33         function __construct()
34         {
35                 // 親クラスを呼び出す
36                 parent::__construct();
37                 
38                 // DBオブジェクト作成
39                 $this->db = new portal_updateinfoDb();
40                 $this->sysDb = $this->gInstance->getSytemDbObject();
41         }
42         /**
43          * テンプレートファイルを設定
44          *
45          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
46          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
47          *
48          * @param RequestManager $request               HTTPリクエスト処理クラス
49          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
50          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
51          */
52         function _setTemplate($request, &$param)
53         {
54                 $task = $request->trimValueOf('task');
55                 if ($task == 'news_detail'){            // 詳細画面
56                         return 'admin_news_detail.tmpl.html';
57                 } else {                        // 一覧画面
58                         return 'admin_news.tmpl.html';
59                 }
60         }
61         /**
62          * テンプレートにデータ埋め込む
63          *
64          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
65          *
66          * @param RequestManager $request               HTTPリクエスト処理クラス
67          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
68          * @param                                                               なし
69          */
70         function _assign($request, &$param)
71         {
72                 $task = $request->trimValueOf('task');
73                 if ($task == 'news_detail'){    // 詳細画面
74                         return $this->createDetail($request);
75                 } else {                        // 一覧画面
76                         return $this->createList($request);
77                 }
78         }
79         /**
80          * 一覧画面作成
81          *
82          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
83          *
84          * @param RequestManager $request               HTTPリクエスト処理クラス
85          * @param                                                               なし
86          */
87         function createList($request)
88         {
89                 // ユーザ情報、表示言語
90                 $this->langId = $this->gEnv->getDefaultLanguage();
91                 $this->itemCount = self::DEFAULT_ITEM_COUNT;    // 表示項目数
92                 $paramObj = $this->getWidgetParamObj();
93                 if (!empty($paramObj)){
94                         $this->itemCount        = $paramObj->itemCount;
95                 }
96                 
97                 $act = $request->trimValueOf('act');
98                 if ($act == 'delete'){          // 項目削除の場合
99                         $listedItem = explode(',', $request->trimValueOf('seriallist'));
100                         $delItems = array();
101                         for ($i = 0; $i < count($listedItem); $i++){
102                                 // 項目がチェックされているかを取得
103                                 $itemName = 'item' . $i . '_selected';
104                                 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
105                                 
106                                 if ($itemValue){                // チェック項目
107                                         $delItems[] = $listedItem[$i];
108                                 }
109                         }
110                         if (count($delItems) > 0){
111                                 $ret = $this->db->delUpdateInfoItem($delItems);
112                                 if ($ret){              // データ削除成功のとき
113                                         $this->setGuidanceMsg('データを削除しました');
114                                 } else {
115                                         $this->setAppErrorMsg('データ削除に失敗しました');
116                                 }
117                         }
118                 } else if ($act == 'selpage'){                  // ページ選択
119                 }
120                 // 一覧を作成
121                 $this->db->getUpdateInfoList(self::CONTENT_TYPE, intval($this->itemCount), array($this, 'itemsLoop'));
122
123                 // 非表示項目を設定
124                 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
125                 
126                 // 一覧項目がないときは、一覧を表示しない
127                 if (!$this->isExistsList) $this->tmpl->setAttribute('itemlist', 'visibility', 'hidden');
128         }
129         /**
130          * 詳細画面作成
131          *
132          * @param RequestManager $request               HTTPリクエスト処理クラス
133          * @param                                                               なし
134          */
135         function createDetail($request)
136         {
137         }
138         /**
139          * 取得したメニュー項目をテンプレートに設定する
140          *
141          * @param int           $index                  行番号
142          * @param array         $fetchedRow             取得行
143          * @param object        $param                  任意使用パラメータ
144          * @return bool                                         trueを返すとループ続行。falseを返すとその時点で終了。
145          */
146         function itemsLoop($index, $fetchedRow)
147         {
148                 $name = $fetchedRow['nw_name'];
149                 $linkUrl = $fetchedRow['nw_link'];              // コンテンツへのリンク
150                 $message = $fetchedRow['nw_message'];
151                 $siteLink = $fetchedRow['nw_site_link'];
152                 $siteName = $fetchedRow['nw_site_name'];
153                 
154                 if (!empty($name)){
155                         $row = array(
156                                 'index' => $index,                                                                              // 項目番号
157                                 'link_url' => $this->convertUrlToHtmlEntity($linkUrl),          // リンク
158                                 'name' => $this->convertToDispString($name),                    // タイトル
159                                 'message' => $this->convertToDispString($message),              // メッセージ
160                                 'site_link' => $this->convertUrlToHtmlEntity($siteLink),        // サイトへのリンク
161                                 'site_name' => $this->convertToDispString($siteName),           // サイト名
162                                 'reg_date' => $this->convertToDispDateTime($fetchedRow['nw_regist_dt'])         // 登録日時
163                         );
164                         $this->tmpl->addVars('itemlist', $row);
165                         $this->tmpl->parseTemplate('itemlist', 'a');
166                 
167                         // 表示中の項目のシリアル番号を保存
168                         $this->serialArray[] = $fetchedRow['nw_serial'];
169                 
170                         $this->isExistsList = true;             // リスト項目が存在するかどうか
171                 }
172                 return true;
173         }
174 }
175 ?>