OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / news / include / container / newsWidgetContainer.php
1 <?php
2 /**
3  * index.php用コンテナクラス
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-2009 Magic3 Project.
12  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
13  * @version    SVN: $Id: newsWidgetContainer.php 2261 2009-08-28 01:57:12Z fishbone $
14  * @link       http://www.magic3.org
15  */
16 require_once($gEnvManager->getContainerPath() . '/baseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/newsDb.php');
18
19 class newsWidgetContainer extends BaseWidgetContainer
20 {
21         private $db;                    // DB接続オブジェクト
22         private $langId;                // 現在の言語
23         const DEFAULT_CONFIG_ID = 0;
24         const CONTENT_TYPE = 'news';                    // コンテンツタイプ
25                 
26         /**
27          * コンストラクタ
28          */
29         function __construct()
30         {
31                 // 親クラスを呼び出す
32                 parent::__construct();
33                 
34                 // DBオブジェクト作成
35                 $this->db = new newsDb();
36         }
37         /**
38          * テンプレートファイルを設定
39          *
40          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
41          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
42          *
43          * @param RequestManager $request               HTTPリクエスト処理クラス
44          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
45          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
46          */
47         function _setTemplate($request, &$param)
48         {
49                 return 'main.tmpl.html';
50         }
51         /**
52          * テンプレートにデータ埋め込む
53          *
54          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
55          *
56          * @param RequestManager $request               HTTPリクエスト処理クラス
57          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
58          * @param                                                               なし
59          */
60         function _assign($request, &$param)
61         {
62                 $this->langId = $this->gEnv->getCurrentLanguage();
63                 
64                 // 定義ID取得
65                 $configId = $this->gEnv->getCurrentWidgetConfigId();
66                 if (empty($configId)) $configId = self::DEFAULT_CONFIG_ID;
67                 
68                 // パラメータオブジェクトを取得
69                 $paramObj = $this->getWidgetParamObj();
70                 
71                 // コンテンツIDを取得
72                 $contentId = 0;
73                 $name = '';
74                 for ($i = 0; $i < count($paramObj); $i++){
75                         $targetObj = $paramObj[$i];
76                         $id = $targetObj->id;// 定義ID
77                         if ($id == $configId){
78                                 $contentId = $targetObj->contentId;
79                                 $name = $targetObj->name;// 定義名
80                                 break;
81                         }
82                 }
83                 
84                 // コンテンツを取得
85                 $ret = $this->db->getContentByContentId(self::CONTENT_TYPE, $contentId, $this->langId, $row);
86                 if ($ret){
87                         $html = str_replace(M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END, $this->getUrl($this->gEnv->getRootUrl()), $row['cn_html']);// アプリケーションルートを変換
88                 }
89                 
90                 // コンテンツを設定
91                 $this->tmpl->addVar("_widget", "content", $html);
92         }
93 }
94 ?>