7 * LICENSE: This source file is licensed under the terms of the GNU General Public License.
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
16 require_once($gEnvManager->getContainerPath() . '/baseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/templateChangerDb.php');
18 require_once($gEnvManager->getCommonPath() . '/htmlEdit.php');
20 class templateChangerWidgetContainer extends BaseWidgetContainer
22 private $db; // DB接続オブジェクト
23 private $selectMenuArray = array();
24 private $currentTemplate; // 選択中のテンプレート
25 const DEFAULT_TITLE = 'テンプレートチェンジャー'; // デフォルトのウィジェットタイトル
30 function __construct()
33 parent::__construct();
36 $this->db = new templateChangerDb();
41 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
42 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
44 * @param RequestManager $request HTTPリクエスト処理クラス
45 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
46 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
48 function _setTemplate($request, &$param)
50 return 'index.tmpl.html';
55 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
57 * @param RequestManager $request HTTPリクエスト処理クラス
58 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
61 function _assign($request, &$param)
63 $this->currentTemplate = $this->gEnv->getCurrentTemplateId();// 選択中のテンプレート
66 $this->db->getAllTemplateList(array($this, 'selectMenuLoop'));
69 $html = HtmlEdit::createSelectMenu($this->selectMenuArray, M3_SYSTEM_TAG_CHANGE_TEMPLATE, "class=\"button\" onchange=\"showprevimage();\" style=\"width:140px;\"");
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); // テンプレート選択タグ
82 * @param RequestManager $request HTTPリクエスト処理クラス
83 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
84 * @return string ウィジェットのタイトル名
86 function _setTitle($request, &$param)
88 return self::DEFAULT_TITLE;
93 * @param int $index 行番号
94 * @param array $fetchedRow 取得行
95 * @param object $param 未使用
96 * @return bool trueを返すとループ続行。falseを返すとその時点で終了。
98 function selectMenuLoop($index, $fetchedRow, $param)
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;