OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / admin / analytics / include / container / admin_admin_analyticsWidgetContainer.php
1 <?php
2 /**
3  * コンテナクラス
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: admin_admin_analyticsWidgetContainer.php 5807 2013-03-08 05:18:13Z fishbone $
14  * @link       http://www.magic3.org
15  */
16 require_once($gEnvManager->getContainerPath() . '/baseAdminWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/admin_analyticsDb.php');
18
19 class admin_admin_analyticsWidgetContainer extends BaseAdminWidgetContainer
20 {
21         private $db;    // DB接続オブジェクト
22         private $graphTypeArray;        // グラフタイプ
23         private $termTypeArray;         // 期間タイプ
24         private $graphType;                     // グラフ種別
25         private $path;                          // アクセスパス
26         private $termType;                              // 期間タイプ
27         const DEFAULT_ACCESS_PATH = 'index';            // デフォルトのアクセスパス(PC用アクセスポイント)
28         const ACCESS_PATH_ALL = '_all';                         // アクセスパスすべて選択
29         const DEFAULT_TERM_TYPE = '30day';              // デフォルトの期間タイプ
30         const TERM_TYPE_ALL = '_all';                           // 全データ表示選択
31         const DEFAULT_GRAPH_TYPE = 'pageview';          // デフォルトのグラフ種別
32         const DEFAULT_GRAPH_WIDTH = 800;                // グラフ幅
33         const DEFAULT_GRAPH_HEIGHT = 320;               // グラフ高さ
34         
35         /**
36          * コンストラクタ
37          */
38         function __construct()
39         {
40                 // 親クラスを呼び出す
41                 parent::__construct();
42                 
43                 // DBオブジェクト作成
44                 $this->db = new admin_analyticsDb();
45                 
46                 // グラフタイプ
47                 $this->graphTypeArray = array(  array(  'name' => 'ページビュー', 'value' => 'pageview'),
48                                                                                 array(  'name' => '訪問数',                  'value' => 'visit'),
49                                                                                 array(  'name' => '訪問者数',               'value' => 'visitor'));
50                                                                                 
51                 // 期間タイプ
52                 $this->termTypeArray = array(   array(  'name' => '30日',      'value' => '30day'),
53                                                                                 array(  'name' => '3ヶ月',    'value' => '3month'),
54                                                                                 array(  'name' => '6ヶ月',    'value' => '6month'),
55                                                                                 array(  'name' => '1年',       'value' => '1year'),
56                                                                                 array(  'name' => 'すべて',  'value' => self::TERM_TYPE_ALL));
57         }
58         /**
59          * テンプレートファイルを設定
60          *
61          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
62          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
63          *
64          * @param RequestManager $request               HTTPリクエスト処理クラス
65          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
66          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
67          */
68         function _setTemplate($request, &$param)
69         {       
70                 return 'admin.tmpl.html';
71         }
72         /**
73          * テンプレートにデータ埋め込む
74          *
75          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
76          *
77          * @param RequestManager $request               HTTPリクエスト処理クラス
78          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
79          * @param                                                               なし
80          */
81         function _assign($request, &$param)
82         {
83                 $act = $request->trimValueOf('act');
84                 
85                 // 入力値を取得
86                 $this->path = $request->trimValueOf('item_path');               // アクセスパス
87                 $this->termType = $request->trimValueOf('item_term');                           // 期間タイプ
88                 $graphWidth = $request->trimValueOf('item_graph_width');                // グラフ幅
89                 $graphHeight = $request->trimValueOf('item_graph_height');              // グラフ高さ
90                 
91                 $replaceNew = false;            // データを再取得するかどうか
92                 if ($act == 'update'){          // 設定更新のとき
93                         // 入力チェック
94                         $this->checkNumeric($graphWidth, 'グラフ幅');
95                         $this->checkNumeric($graphHeight, 'グラフ高さ');
96                         
97                         if ($this->getMsgCount() == 0){                 // エラーのないとき
98                                 $paramObj = new stdClass;
99                                 $paramObj->path = $this->path;                          // アクセスパス
100                                 $paramObj->termType = $this->termType;          // 期間タイプ
101                                 $paramObj->graphWidth = $graphWidth;            // グラフ幅
102                                 $paramObj->graphHeight = $graphHeight;          // グラフ高さ
103                                 $ret = $this->updateWidgetParamObj($paramObj);
104                                 if ($ret){
105                                         $this->setMsg(self::MSG_GUIDANCE, 'データを更新しました');
106                                         $replaceNew = true;                     // データ再取得
107                                 } else {
108                                         $this->setMsg(self::MSG_APP_ERR, 'データ更新に失敗しました');
109                                 }
110                                 $this->gPage->updateParentWindow();// 親ウィンドウを更新
111                         }
112                 } else {                // 初期表示の場合
113                         $replaceNew = true;                     // データ再取得
114                 }
115                 
116                 if ($replaceNew){               // データ再取得のとき
117                         $paramObj = $this->getWidgetParamObj();
118                         if (empty($paramObj)){          // 既存データなしのとき
119                                 // デフォルト値設定
120                                 $this->path = self::DEFAULT_ACCESS_PATH;
121                                 $this->termType = self::DEFAULT_TERM_TYPE;
122                                 $graphWidth = self::DEFAULT_GRAPH_WIDTH;                // グラフ幅
123                                 $graphHeight = self::DEFAULT_GRAPH_HEIGHT;              // グラフ高さ
124                         } else {
125                                 $this->path = $paramObj->path;                          // アクセスパス
126                                 $this->termType = $paramObj->termType;          // 期間タイプ
127                                 $graphWidth = $paramObj->graphWidth;            // グラフ幅
128                                 $graphHeight = $paramObj->graphHeight;          // グラフ高さ
129                         }
130                 }
131                 
132                 // アクセスポイントメニュー作成
133                 $this->createPathMenu();
134                 
135                 // 期間メニュー作成
136                 $this->createTermMenu();
137                 
138                 // 値を埋め込む
139                 $this->tmpl->addVar("_widget", "graph_width", $graphWidth);// グラフ幅
140                 $this->tmpl->addVar("_widget", "graph_height", $graphHeight);// グラフ高さ
141         }
142         /**
143          * アクセスパスメニュー作成
144          *
145          * @return                                                              なし
146          */
147         function createPathMenu()
148         {
149                 $selected = '';
150                 if ($this->path == self::ACCESS_PATH_ALL){// アクセスパスすべて選択
151                         $selected = 'selected';
152                 }
153                 $row = array(
154                         'value'    => self::ACCESS_PATH_ALL,                    // アクセスパス
155                         'name'     => 'すべて表示',                        // 表示文字列
156                         'selected' => $selected                                                                                                         // 選択中かどうか
157                 );
158                 $this->tmpl->addVars('path_list', $row);
159                 $this->tmpl->parseTemplate('path_list', 'a');
160                 
161                 $this->db->getPageIdList(array($this, 'pageIdLoop'), 0/*ページID*/);
162         }
163         /**
164          * ページID、取得したデータをテンプレートに設定する
165          *
166          * @param int $index                    行番号(0~)
167          * @param array $fetchedRow             フェッチ取得した行
168          * @param object $param                 未使用
169          * @return bool                                 true=処理続行の場合、false=処理終了の場合
170          */
171         function pageIdLoop($index, $fetchedRow, $param)
172         {
173                 $selected = '';
174                 if ($fetchedRow['pg_path'] == $this->path){
175                         $selected = 'selected';
176                 }
177                 $name = $this->convertToDispString($fetchedRow['pg_path']) . ' - ' . $this->convertToDispString($fetchedRow['pg_name']);                        // ページ名
178                 $row = array(
179                         'value'    => $this->convertToDispString($fetchedRow['pg_path']),                       // アクセスパス
180                         'name'     => $name,                    // ページ名
181                         'selected' => $selected                                                                                                         // 選択中かどうか
182                 );
183                 $this->tmpl->addVars('path_list', $row);
184                 $this->tmpl->parseTemplate('path_list', 'a');
185                 return true;
186         }
187         /**
188          * 期間タイプ選択メニュー作成
189          *
190          * @return なし
191          */
192         function createTermMenu()
193         {
194                 for ($i = 0; $i < count($this->termTypeArray); $i++){
195                         $value = $this->termTypeArray[$i]['value'];
196                         $name = $this->termTypeArray[$i]['name'];
197                         
198                         $selected = '';
199                         if ($value == $this->termType) $selected = 'selected';
200                         
201                         $row = array(
202                                 'value'    => $value,                   // ページID
203                                 'name'     => $name,                    // ページ名
204                                 'selected' => $selected                                                                                                         // 選択中かどうか
205                         );
206                         $this->tmpl->addVars('term_list', $row);
207                         $this->tmpl->parseTemplate('term_list', 'a');
208                 }
209         }
210 }
211 ?>