OSDN Git Service

バージョン番号更新。
[magic3/magic3.git] / widgets / templateChanger / include / container / templateChangerWidgetContainer.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: templateChangerWidgetContainer.php 2248 2009-08-24 05:22:21Z fishbone $
14  * @link       http://www.magic3.org
15  */
16 require_once($gEnvManager->getContainerPath() . '/baseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/templateChangerDb.php');
18 require_once($gEnvManager->getCommonPath() . '/htmlEdit.php');
19
20 class templateChangerWidgetContainer extends BaseWidgetContainer
21 {
22         private $db;    // DB接続オブジェクト
23         private $selectMenuArray = array();
24         private $currentTemplate;       // 選択中のテンプレート
25         const DEFAULT_TITLE = 'テンプレートチェンジャー';           // デフォルトのウィジェットタイトル
26         
27         /**
28          * コンストラクタ
29          */
30         function __construct()
31         {
32                 // 親クラスを呼び出す
33                 parent::__construct();
34                 
35                 // DB接続オブジェクト作成
36                 $this->db = new templateChangerDb();
37         }
38         /**
39          * テンプレートファイルを設定
40          *
41          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
42          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
43          *
44          * @param RequestManager $request               HTTPリクエスト処理クラス
45          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
46          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
47          */
48         function _setTemplate($request, &$param)
49         {       
50                 return 'index.tmpl.html';
51         }
52         /**
53          * テンプレートにデータ埋め込む
54          *
55          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
56          *
57          * @param RequestManager $request               HTTPリクエスト処理クラス
58          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
59          * @param                                                               なし
60          */
61         function _assign($request, &$param)
62         {
63                 $this->currentTemplate = $this->gEnv->getCurrentTemplateId();// 選択中のテンプレート
64                 
65                 // すべてのテンプレートを取得
66                 $this->db->getAllTemplateList(array($this, 'selectMenuLoop'));
67
68                 // テンプレート選択用メニュー作成
69                 $html = HtmlEdit::createSelectMenu($this->selectMenuArray, M3_SYSTEM_TAG_CHANGE_TEMPLATE, "class=\"button\" onchange=\"showprevimage();\" style=\"width:140px;\"");
70
71                 $imagePath = $this->getUrl($this->gEnv->getCurrentTemplateUrl() . '/template_thumbnail.png');
72                 $this->tmpl->addVar("_widget", "TMPL_IMAGE", $imagePath);                                                       // プレビュー画像
73                 $this->tmpl->addVar("_widget", "CUR_TMPL", $this->gEnv->getCurrentTemplateId());
74                 $this->tmpl->addVar("_widget", "CHANGE_TEMPLATE", M3_REQUEST_CMD_CHANGE_TEMPLATE);      // テンプレート変更処理
75                 $this->tmpl->addVar("_widget", "SEL_BUTTON_LABEL", '選択');                                           // 選択ボタンラベル
76                 $this->tmpl->addVar("_widget", "SEL_LIST", $html);                                                              // テンプレート選択メニュー
77                 $this->tmpl->addVar("_widget", "SEL_TEMPLATE", M3_SYSTEM_TAG_CHANGE_TEMPLATE);          // テンプレート選択タグ
78         }
79         /**
80          * ウィジェットのタイトルを設定
81          *
82          * @param RequestManager $request               HTTPリクエスト処理クラス
83          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
84          * @return string                                               ウィジェットのタイトル名
85          */
86         function _setTitle($request, &$param)
87         {
88                 return self::DEFAULT_TITLE;
89         }
90         /**
91          * メニューを作成
92          *
93          * @param int    $index                 行番号
94          * @param array  $fetchedRow    取得行
95          * @param object $param                 未使用
96          * @return bool                                 trueを返すとループ続行。falseを返すとその時点で終了。
97          */
98         function selectMenuLoop($index, $fetchedRow, $param)
99         {
100                 $menuItems = new SelectMenuItem();
101                 $menuItems->name = strlen($fetchedRow['tm_name']) ? $fetchedRow['tm_name'] : $fetchedRow['tm_id'];
102                 $menuItems->value = $fetchedRow['tm_id'];
103                 if ($menuItems->value == $this->currentTemplate) $menuItems->selected = true;
104                 $this->selectMenuArray[] = $menuItems;
105                 return true;
106         }
107 }
108 ?>