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-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
16 require_once($gEnvManager->getContainerPath() . '/baseAdminWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/admin_analyticsDb.php');
19 class admin_admin_analyticsWidgetContainer extends BaseAdminWidgetContainer
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; // グラフ高さ
38 function __construct()
41 parent::__construct();
44 $this->db = new admin_analyticsDb();
47 $this->graphTypeArray = array( array( 'name' => 'ページビュー', 'value' => 'pageview'),
48 array( 'name' => '訪問数', 'value' => 'visit'),
49 array( 'name' => '訪問者数', 'value' => 'visitor'));
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));
61 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
62 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
64 * @param RequestManager $request HTTPリクエスト処理クラス
65 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
66 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
68 function _setTemplate($request, &$param)
70 return 'admin.tmpl.html';
75 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
77 * @param RequestManager $request HTTPリクエスト処理クラス
78 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
81 function _assign($request, &$param)
83 $act = $request->trimValueOf('act');
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'); // グラフ高さ
91 $replaceNew = false; // データを再取得するかどうか
92 if ($act == 'update'){ // 設定更新のとき
94 $this->checkNumeric($graphWidth, 'グラフ幅');
95 $this->checkNumeric($graphHeight, 'グラフ高さ');
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);
105 $this->setMsg(self::MSG_GUIDANCE, 'データを更新しました');
106 $replaceNew = true; // データ再取得
108 $this->setMsg(self::MSG_APP_ERR, 'データ更新に失敗しました');
110 $this->gPage->updateParentWindow();// 親ウィンドウを更新
113 $replaceNew = true; // データ再取得
116 if ($replaceNew){ // データ再取得のとき
117 $paramObj = $this->getWidgetParamObj();
118 if (empty($paramObj)){ // 既存データなしのとき
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; // グラフ高さ
125 $this->path = $paramObj->path; // アクセスパス
126 $this->termType = $paramObj->termType; // 期間タイプ
127 $graphWidth = $paramObj->graphWidth; // グラフ幅
128 $graphHeight = $paramObj->graphHeight; // グラフ高さ
133 $this->createPathMenu();
136 $this->createTermMenu();
139 $this->tmpl->addVar("_widget", "graph_width", $graphWidth);// グラフ幅
140 $this->tmpl->addVar("_widget", "graph_height", $graphHeight);// グラフ高さ
147 function createPathMenu()
150 if ($this->path == self::ACCESS_PATH_ALL){// アクセスパスすべて選択
151 $selected = 'selected';
154 'value' => self::ACCESS_PATH_ALL, // アクセスパス
155 'name' => 'すべて表示', // 表示文字列
156 'selected' => $selected // 選択中かどうか
158 $this->tmpl->addVars('path_list', $row);
159 $this->tmpl->parseTemplate('path_list', 'a');
161 $this->db->getPageIdList(array($this, 'pageIdLoop'), 0/*ページID*/);
164 * ページID、取得したデータをテンプレートに設定する
166 * @param int $index 行番号(0~)
167 * @param array $fetchedRow フェッチ取得した行
168 * @param object $param 未使用
169 * @return bool true=処理続行の場合、false=処理終了の場合
171 function pageIdLoop($index, $fetchedRow, $param)
174 if ($fetchedRow['pg_path'] == $this->path){
175 $selected = 'selected';
177 $name = $this->convertToDispString($fetchedRow['pg_path']) . ' - ' . $this->convertToDispString($fetchedRow['pg_name']); // ページ名
179 'value' => $this->convertToDispString($fetchedRow['pg_path']), // アクセスパス
180 'name' => $name, // ページ名
181 'selected' => $selected // 選択中かどうか
183 $this->tmpl->addVars('path_list', $row);
184 $this->tmpl->parseTemplate('path_list', 'a');
192 function createTermMenu()
194 for ($i = 0; $i < count($this->termTypeArray); $i++){
195 $value = $this->termTypeArray[$i]['value'];
196 $name = $this->termTypeArray[$i]['name'];
199 if ($value == $this->termType) $selected = 'selected';
202 'value' => $value, // ページID
203 'name' => $name, // ページ名
204 'selected' => $selected // 選択中かどうか
206 $this->tmpl->addVars('term_list', $row);
207 $this->tmpl->parseTemplate('term_list', 'a');