OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / blog_archive_menu / include / container / blog_archive_menuWidgetContainer.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-2012 Magic3 Project.
12  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
13  * @version    SVN: $Id: blog_archive_menuWidgetContainer.php 5270 2012-10-04 12:19:21Z fishbone $
14  * @link       http://www.magic3.org
15  */
16 require_once($gEnvManager->getContainerPath() . '/baseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/blog_archive_menuDb.php');
18
19 class blog_archive_menuWidgetContainer extends BaseWidgetContainer
20 {
21         private $db;                    // DB接続オブジェクト
22         private $langId;                // 言語
23         const TARGET_WIDGET = 'blog_main';              // 呼び出しウィジェットID
24         const DEFAULT_TITLE = 'ブログアーカイブ';               // デフォルトのウィジェットタイトル名
25                 
26         /**
27          * コンストラクタ
28          */
29         function __construct()
30         {
31                 // 親クラスを呼び出す
32                 parent::__construct();
33                 
34                 // DBオブジェクト作成
35                 $this->db = new blog_archive_menuDb();
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 'menu.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                 // #### カテゴリーリストを作成 ####
65                 $ret = $this->db->getAllEntry($this->langId, $rows);// デフォルト言語で取得
66                 if ($ret){
67                         $foreYear = 0;
68                         $foreMonth = 0;
69                         $entryCount = 0;                // 記事数
70                         $rowCount = count($rows);
71                         for ($i = 0; $i < $rowCount; $i++){
72                                 // 記事の投稿日を取得
73                                 $this->timestampToYearMonthDay($rows[$i]['be_regist_dt'], $year, $month, $day);
74                 
75                                 if ($year == $foreYear && $month == $foreMonth){                // 年月が変わらないとき
76                                         $entryCount++;          // 記事数
77                                 } else {                // 年月が変更のとき
78                                         // メニュー項目を作成
79                                         if ($entryCount > 0){           // 記事数が0以上のとき
80                                                 $name = $foreYear . '年' . $foreMonth . '月(' . $entryCount . ')';
81                                                 $linkUrl = $this->createCmdUrlToWidget(self::TARGET_WIDGET, 'act=view&year=' . $foreYear . '&month=' . $foreMonth);
82                                                 $row = array(
83                                                         'link_url' => $this->convertUrlToHtmlEntity($this->getUrl($linkUrl, true/*リンク用*/)),             // リンク
84                                                         'name' => $this->convertToDispString($name)                     // タイトル
85                                                 );
86                                                 $this->tmpl->addVars('itemlist', $row);
87                                                 $this->tmpl->parseTemplate('itemlist', 'a');
88                                         }
89                                         
90                                         // データを初期化
91                                         $foreYear = $year;
92                                         $foreMonth = $month;
93                                         $entryCount = 1;        // 記事数
94                                 }
95                         }
96                         // メニュー項目を作成
97                         if ($entryCount > 0){           // 記事数が0以上のとき
98                                 $name = $foreYear . '年' . $foreMonth . '月(' . $entryCount . ')';
99                                 $linkUrl = $this->createCmdUrlToWidget(self::TARGET_WIDGET, 'act=view&year=' . $foreYear . '&month=' . $foreMonth);
100                                 $row = array(
101                                         'link_url' => $this->convertUrlToHtmlEntity($this->getUrl($linkUrl, true/*リンク用*/)),             // リンク
102                                         'name' => $this->convertToDispString($name)                     // タイトル
103                                 );
104                                 $this->tmpl->addVars('itemlist', $row);
105                                 $this->tmpl->parseTemplate('itemlist', 'a');
106                         }
107                 }
108         }
109         /**
110          * ウィジェットのタイトルを設定
111          *
112          * @param RequestManager $request               HTTPリクエスト処理クラス
113          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
114          * @return string                                               ウィジェットのタイトル名
115          */
116         function _setTitle($request, &$param)
117         {
118                 return self::DEFAULT_TITLE;
119         }
120 }
121 ?>