OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / s / jquery_init / include / container / s_jquery_initWidgetContainer.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: s_jquery_initWidgetContainer.php 4648 2012-02-01 14:23:42Z fishbone $
14  * @link       http://www.magic3.org
15  */
16 require_once($gEnvManager->getContainerPath() . '/baseWidgetContainer.php');
17
18 class s_jquery_initWidgetContainer extends BaseWidgetContainer
19 {
20         private $initScript;    // 初期化用スクリプトファイル
21         private $script;                // 追加スクリプト
22         const DEFAULT_CONFIG_ID = 0;
23         
24         /**
25          * コンストラクタ
26          */
27         function __construct()
28         {
29                 // 親クラスを呼び出す
30                 parent::__construct();
31         }
32         /**
33          * テンプレートファイルを設定
34          *
35          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
36          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
37          *
38          * @param RequestManager $request               HTTPリクエスト処理クラス
39          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
40          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
41          */
42         function _setTemplate($request, &$param)
43         {
44                 return '';
45         }
46         /**
47          * テンプレートにデータ埋め込む
48          *
49          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
50          *
51          * @param RequestManager $request               HTTPリクエスト処理クラス
52          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
53          * @param                                                               なし
54          */
55         function _assign($request, &$param)
56         {
57                 // 定義ID取得
58                 $configId = $this->gEnv->getCurrentWidgetConfigId();
59                 if (empty($configId)) $configId = self::DEFAULT_CONFIG_ID;
60                 
61                 // パラメータオブジェクトを取得
62                 $targetObj = $this->getWidgetParamObjByConfigId($configId);
63                 if (empty($targetObj)){// 定義データが取得できないときは終了
64                         $this->cancelParse();           // テンプレート変換処理中断
65                         return;
66                 } else {
67                         // 値取得
68                         $this->script = $targetObj->script;             // スクリプト
69                                 
70                         $act = $request->trimValueOf('act');
71                         if ($act == 'initscript'){                      // 初期化スクリプト取得のとき
72                                 // 初期化スクリプトを作成
73                                 $initTemplate = $this->getParsedTemplateData('init.tmpl.js', array($this, 'makeInitScript'));// 初期化スクリプト
74                                 
75                                 // 標準のテンプレート変換をキャンセルし、直接出力
76                                 $this->cancelParse();
77                                 $this->gPage->setOutputByHtml(false);   // HTML出力をキャンセル
78                                 echo $initTemplate;
79                         } else {
80                                 // 初期化用スクリプトのURLを作成
81                                 if (!empty($this->script)) $this->initScript = $this->getUrl($this->createCmdUrlToCurrentWidget('act=initscript'));
82                         }
83                 }
84         }
85         /**
86          * JavascriptファイルをHTMLヘッダ部に設定
87          *
88          * JavascriptファイルをHTMLのheadタグ内に追加出力する。
89          * _assign()よりも後に実行される。
90          *
91          * @param RequestManager $request               HTTPリクエスト処理クラス
92          * @param object         $param                 任意使用パラメータ。
93          * @return string                                               Javascriptファイル。出力しない場合は空文字列を設定。
94          */
95         function _addPreMobileScriptFileToHead($request, &$param)
96         {
97                 return $this->initScript;
98         }
99         /**
100          * テンプレートデータ作成処理コールバック
101          *
102          * @param object         $tmpl                  テンプレートオブジェクト
103          * @param                                                               なし
104          */
105         function makeInitScript($tmpl)
106         {
107                 $tmpl->addVar("_tmpl", "script",        $this->script);
108         }
109 }
110 ?>