OSDN Git Service

DB更新スクリプト更新。
[magic3/magic3.git] / widgets / m / bbs_2ch / include / container / m_bbs_2chSubjectWidgetContainer.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-2011 Magic3 Project.
12  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
13  * @version    SVN: $Id: m_bbs_2chSubjectWidgetContainer.php 4033 2011-03-18 01:43:53Z fishbone $
14  * @link       http://www.magic3.org
15  */
16 require_once($gEnvManager->getCurrentWidgetContainerPath() .    '/m_bbs_2chBaseWidgetContainer.php');
17
18 class m_bbs_2chSubjectWidgetContainer extends m_bbs_2chBaseWidgetContainer
19 {
20         private $isExistsThread;        // スレッドが存在するかどうか
21                 
22         /**
23          * コンストラクタ
24          */
25         function __construct()
26         {
27                 // 親クラスを呼び出す
28                 parent::__construct();
29         }
30         /**
31          * テンプレートファイルを設定
32          *
33          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
34          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
35          *
36          * @param RequestManager $request               HTTPリクエスト処理クラス
37          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
38          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
39          */
40         function _setTemplate($request, &$param)
41         {
42                 return 'subject.tmpl.html';
43         }
44         /**
45          * テンプレートにデータ埋め込む
46          *
47          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
48          *
49          * @param RequestManager $request               HTTPリクエスト処理クラス
50          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
51          * @param                                                               なし
52          */
53         function _assign($request, &$param)
54         {
55                 // 検索キーワードを取得
56                 $keyword = $request->trimValueOf(M3_REQUEST_PARAM_KEYWORD);
57                         
58                 // スレッドメニュー作成
59                 if (empty($keyword)){
60                         $this->_db->getThread(array($this, 'itemsLoop'), $this->_boardId, -1/*すべて取得*/);
61                 } else {
62                         $this->_db->getThreadByKeyword(array($this, 'itemsLoop'), $this->_boardId, -1/*すべて取得*/, $keyword);
63                 }
64                 
65                 // スレッドが存在しないときはタグを非表示にする
66                 if (!$this->isExistsThread) $this->tmpl->setAttribute('itemlist', 'visibility', 'hidden');
67         }
68         /**
69          * 取得したコンテンツ項目をテンプレートに設定する
70          *
71          * @param int           $index                  行番号
72          * @param array         $fetchedRow             取得行
73          * @param object        $param                  任意使用パラメータ
74          * @return bool                                         trueを返すとループ続行。falseを返すとその時点で終了。
75          */
76         function itemsLoop($index, $fetchedRow)
77         {
78                 // トップ画面に表示するスレッド最大数
79                 $threadId = $fetchedRow['th_id'];
80                 $no = $index + 1;
81                 $subject = $fetchedRow['th_subject'] . '(' . $fetchedRow['th_message_count'] . ')';
82                 $url = $this->_currentPageUrl . '&' . M3_REQUEST_PARAM_BBS_THREAD_ID . '=' . $threadId;
83                 
84                 $row = array(
85                         'no' => $no,                                                                                    // インデックス番号
86                         'url' => $this->convertUrlToHtmlEntity($this->getUrl($url, true)),                                                                                      // スレッド画面へのリンク
87                         'subject' => $this->convertToDispString($subject)               // スレッド件名
88                 );
89                 $this->tmpl->addVars('itemlist', $row);
90                 $this->tmpl->parseTemplate('itemlist', 'a');
91                 
92                 $this->isExistsThread = true;   // スレッドが存在するかどうか
93                 return true;
94         }
95 }
96 ?>