| 1 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
| 844 |
liveuser |
6 |
Copyright (C) 2015~2025 Min-Jhin,Chen
|
| 1 |
liveuser |
7 |
|
|
|
8 |
This file is part of QBPWCF.
|
|
|
9 |
|
|
|
10 |
QBPWCF is free software: you can redistribute it and/or modify
|
|
|
11 |
it under the terms of the GNU General Public License as published by
|
|
|
12 |
the Free Software Foundation, either version 3 of the License, or
|
|
|
13 |
(at your option) any later version.
|
|
|
14 |
|
|
|
15 |
QBPWCF is distributed in the hope that it will be useful,
|
|
|
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
18 |
GNU General Public License for more details.
|
|
|
19 |
|
|
|
20 |
You should have received a copy of the GNU General Public License
|
|
|
21 |
along with QBPWCF. If not, see <http://www.gnu.org/licenses/>.
|
|
|
22 |
|
|
|
23 |
*/
|
|
|
24 |
namespace qbpwcf;
|
|
|
25 |
|
| 249 |
liveuser |
26 |
/*
|
|
|
27 |
類別說明:
|
|
|
28 |
應用chartJS繪圖的類別.
|
|
|
29 |
備註:
|
|
|
30 |
無.
|
|
|
31 |
*/
|
| 1 |
liveuser |
32 |
class chartJS{
|
|
|
33 |
|
|
|
34 |
/*
|
|
|
35 |
#函式說明:
|
|
|
36 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
37 |
#回傳結果:
|
|
|
38 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
39 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
40 |
#$result["function"],當前執行的函式名稱.
|
|
|
41 |
#必填參數:
|
|
|
42 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
43 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
44 |
#參考資料:
|
|
|
45 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
46 |
*/
|
|
|
47 |
public function __call($method,$arguments){
|
|
|
48 |
|
|
|
49 |
#取得當前執行的函式
|
|
|
50 |
$result["function"]=__FUNCTION__;
|
|
|
51 |
|
|
|
52 |
#設置執行不正常
|
|
|
53 |
$result["status"]="false";
|
|
|
54 |
|
|
|
55 |
#設置執行錯誤
|
|
|
56 |
$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
|
|
|
57 |
|
|
|
58 |
#設置所丟入的參數
|
|
|
59 |
$result["error"][]=$arguments;
|
|
|
60 |
|
|
|
61 |
#回傳結果
|
|
|
62 |
return $result;
|
|
|
63 |
|
|
|
64 |
}#function __call end
|
|
|
65 |
|
|
|
66 |
/*
|
|
|
67 |
#函式說明:
|
|
|
68 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
69 |
#回傳結果:
|
|
|
70 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
71 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
72 |
#$result["function"],當前執行的函式名稱.
|
|
|
73 |
#必填參數:
|
|
|
74 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
75 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
76 |
#參考資料:
|
|
|
77 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
78 |
*/
|
|
|
79 |
public static function __callStatic($method,$arguments){
|
|
|
80 |
|
|
|
81 |
#取得當前執行的函式
|
|
|
82 |
$result["function"]=__FUNCTION__;
|
|
|
83 |
|
|
|
84 |
#設置執行不正常
|
|
|
85 |
$result["status"]="false";
|
|
|
86 |
|
|
|
87 |
#設置執行錯誤
|
|
|
88 |
$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
|
|
|
89 |
|
|
|
90 |
#設置所丟入的參數
|
|
|
91 |
$result["error"][]=$arguments;
|
|
|
92 |
|
|
|
93 |
#回傳結果
|
|
|
94 |
return $result;
|
|
|
95 |
|
|
|
96 |
}#function __callStatic end
|
|
|
97 |
|
|
|
98 |
/*
|
|
|
99 |
#函式說明:
|
|
|
100 |
#匯入chartJS的函式庫.
|
|
|
101 |
#回傳結果:
|
|
|
102 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
103 |
#$result["error"],錯誤訊息.
|
|
|
104 |
#$result["content"],語法.
|
|
|
105 |
#$result["function"],當前執行的函數名稱.
|
|
|
106 |
#必填參數:
|
|
|
107 |
#$conf["libAddr"],字串,爲ckfEditor套件的網路位置,js附檔名會自動補上.
|
|
|
108 |
$conf["libAddr"]="";
|
|
|
109 |
#可省略參數:
|
|
|
110 |
#$conf["fileArgu"],字串,為當前檔案的路徑,預設為__FILE__.
|
|
|
111 |
#$conf["fileArgu"]=__FILE__;
|
| 176 |
liveuser |
112 |
#參考資料:
|
|
|
113 |
#無.
|
| 1 |
liveuser |
114 |
#備註:
|
|
|
115 |
#無.
|
|
|
116 |
*/
|
|
|
117 |
public static function importLib(&$conf){
|
|
|
118 |
|
|
|
119 |
#初始化要回傳的內容
|
|
|
120 |
$result=array();
|
|
|
121 |
|
|
|
122 |
#取得當前執行的函數名稱
|
|
|
123 |
$result["function"]=__FUNCTION__;
|
|
|
124 |
|
|
|
125 |
#初始化要回傳的語法
|
|
|
126 |
$result["content"]="";
|
|
|
127 |
|
|
|
128 |
#如果沒有參數
|
|
|
129 |
if(func_num_args()==0){
|
|
|
130 |
|
|
|
131 |
#設置執行失敗
|
|
|
132 |
$result["status"]="false";
|
|
|
133 |
|
|
|
134 |
#設置執行錯誤訊息
|
|
|
135 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
136 |
|
|
|
137 |
#回傳結果
|
|
|
138 |
return $result;
|
|
|
139 |
|
|
|
140 |
}#if end
|
|
|
141 |
|
|
|
142 |
#取得參數
|
|
|
143 |
$result["argu"]=$conf;
|
|
|
144 |
|
|
|
145 |
#如果 $conf 不為陣列
|
|
|
146 |
if(gettype($conf)!="array"){
|
|
|
147 |
|
|
|
148 |
#設置執行失敗
|
|
|
149 |
$result["status"]="false";
|
|
|
150 |
|
|
|
151 |
#設置執行錯誤訊息
|
|
|
152 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
153 |
|
|
|
154 |
#如果傳入的參數為 null
|
|
|
155 |
if($conf==null){
|
|
|
156 |
|
|
|
157 |
#設置執行錯誤訊息
|
|
|
158 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
159 |
|
|
|
160 |
}#if end
|
|
|
161 |
|
|
|
162 |
#回傳結果
|
|
|
163 |
return $result;
|
|
|
164 |
|
|
|
165 |
}#if end
|
|
|
166 |
|
|
|
167 |
#檢查參數
|
|
|
168 |
#函式說明:
|
|
|
169 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
170 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
171 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
172 |
#$result["function"],當前執行的函式名稱.
|
|
|
173 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
174 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
175 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
176 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
177 |
#必填寫的參數:
|
|
|
178 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
179 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
180 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
181 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("libAddr");
|
|
|
182 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
183 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
184 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
185 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
186 |
#可以省略的參數:
|
|
|
187 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
188 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
189 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
190 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileArgu");
|
|
|
191 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
192 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
193 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,「null」代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
194 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(__FILE__);
|
|
|
195 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
196 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
197 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
198 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
199 |
|
|
|
200 |
#如果檢查參數失敗
|
|
|
201 |
if($checkResult["status"]=="false"){
|
|
|
202 |
|
|
|
203 |
#設置執行失敗
|
|
|
204 |
$result["status"]="false";
|
|
|
205 |
|
|
|
206 |
#設置錯誤訊息
|
|
|
207 |
$result["error"]=$checkResult;
|
|
|
208 |
|
|
|
209 |
#回傳結果
|
|
|
210 |
return $result;
|
|
|
211 |
|
|
|
212 |
}#if end
|
|
|
213 |
|
|
|
214 |
#如果檢查參數不通過
|
|
|
215 |
if($checkResult["passed"]=="false"){
|
|
|
216 |
|
|
|
217 |
#設置執行失敗
|
|
|
218 |
$result["status"]="false";
|
|
|
219 |
|
|
|
220 |
#設置錯誤訊息
|
|
|
221 |
$result["error"]=$checkResult;
|
|
|
222 |
|
|
|
223 |
#回傳結果
|
|
|
224 |
return $result;
|
|
|
225 |
|
|
|
226 |
}#if end
|
|
|
227 |
|
|
|
228 |
#匯入 $conf["libAddr"] js檔案
|
|
|
229 |
#函式說明:
|
|
|
230 |
#匯入js檔案
|
|
|
231 |
#回傳結果:
|
|
|
232 |
#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
|
|
|
233 |
#$result["functin"],字串,當前函數的名稱.
|
|
|
234 |
#$result["error"],陣列,錯訊訊息.
|
|
|
235 |
#$result["content"],字串,匯入css樣式的語法.
|
|
|
236 |
#必填參數:
|
|
|
237 |
#$conf["jsFileLocation"],陣列字串,多個js檔案的位置與名稱,每個元素代表一個js檔案的位置,js副檔名會自動補上.
|
|
|
238 |
$conf["javaScript::import"]["jsFileLocation"]=array($conf["libAddr"]);
|
|
|
239 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
|
|
|
240 |
$conf["javaScript::import"]["fileArgu"]=$conf["fileArgu"];
|
|
|
241 |
#可省略參數:
|
|
|
242 |
#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,於設為"true".
|
|
|
243 |
#$conf["userDir"]="true";
|
|
|
244 |
#參考資料:
|
|
|
245 |
#php於設常數=>http://php.net/manual/zh/language.constants.predefined.php
|
|
|
246 |
$import=javaScript::import($conf["javaScript::import"]);
|
|
|
247 |
unset($conf["javaScript::import"]);
|
|
|
248 |
|
|
|
249 |
#var_dump($import);
|
|
|
250 |
|
|
|
251 |
#如果建立匯入js檔案的語法失敗
|
|
|
252 |
if($import["status"]=="false"){
|
|
|
253 |
|
|
|
254 |
#設置執行失敗
|
|
|
255 |
$result["status"]="false";
|
|
|
256 |
|
|
|
257 |
#設置錯誤訊息
|
|
|
258 |
$result["error"]=$import;
|
|
|
259 |
|
|
|
260 |
#回傳結果
|
|
|
261 |
return $result;
|
|
|
262 |
|
|
|
263 |
}#if end
|
|
|
264 |
|
|
|
265 |
#取得js語法
|
|
|
266 |
$result["content"]=$import["content"];
|
|
|
267 |
|
|
|
268 |
#設置執行正常
|
|
|
269 |
$result["status"]="true";
|
|
|
270 |
|
|
|
271 |
#回傳結果
|
|
|
272 |
return $result;
|
|
|
273 |
|
|
|
274 |
}#function importLib end
|
|
|
275 |
|
|
|
276 |
/*
|
|
|
277 |
#函式說明:
|
|
|
278 |
#顯示長條圖的demo.
|
|
|
279 |
#回傳結果:
|
|
|
280 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
281 |
#$result["error"],錯誤訊息.
|
|
|
282 |
#$result["content"],語法.
|
|
|
283 |
#$result["function"],當前執行的函數名稱.
|
|
|
284 |
#必填參數:
|
|
|
285 |
#$conf["libAddr"],字串,爲ckfEditor套件的網路位置,js附檔名會自動補上.
|
|
|
286 |
$conf["libAddr"]="";
|
|
|
287 |
#可省略參數:
|
|
|
288 |
#$conf["fileArgu"],字串,為當前檔案的路徑,預設為__FILE__.
|
|
|
289 |
#$conf["fileArgu"]=__FILE__;
|
|
|
290 |
#參考資料:
|
|
|
291 |
#Creating a Chart=>http://www.chartjs.org/docs/latest/
|
|
|
292 |
#備註:
|
|
|
293 |
#無.
|
|
|
294 |
*/
|
|
|
295 |
public static function barDemo(&$conf=array()){
|
|
|
296 |
|
|
|
297 |
#初始化要回傳的內容
|
|
|
298 |
$result=array();
|
|
|
299 |
|
|
|
300 |
#取得當前執行的函數名稱
|
|
|
301 |
$result["function"]=__FUNCTION__;
|
|
|
302 |
|
|
|
303 |
#初始化要回傳的語法
|
|
|
304 |
$result["content"]="";
|
|
|
305 |
|
|
|
306 |
#如果沒有參數
|
|
|
307 |
if(func_num_args()==0){
|
|
|
308 |
|
|
|
309 |
#設置執行失敗
|
|
|
310 |
$result["status"]="false";
|
|
|
311 |
|
|
|
312 |
#設置執行錯誤訊息
|
|
|
313 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
314 |
|
|
|
315 |
#回傳結果
|
|
|
316 |
return $result;
|
|
|
317 |
|
|
|
318 |
}#if end
|
|
|
319 |
|
|
|
320 |
#取得參數
|
|
|
321 |
$result["argu"]=$conf;
|
|
|
322 |
|
|
|
323 |
#如果 $conf 不為陣列
|
|
|
324 |
if(gettype($conf)!="array"){
|
|
|
325 |
|
|
|
326 |
#設置執行失敗
|
|
|
327 |
$result["status"]="false";
|
|
|
328 |
|
|
|
329 |
#設置執行錯誤訊息
|
|
|
330 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
331 |
|
|
|
332 |
#如果傳入的參數為 null
|
|
|
333 |
if($conf==null){
|
|
|
334 |
|
|
|
335 |
#設置執行錯誤訊息
|
|
|
336 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
337 |
|
|
|
338 |
}#if end
|
|
|
339 |
|
|
|
340 |
#回傳結果
|
|
|
341 |
return $result;
|
|
|
342 |
|
|
|
343 |
}#if end
|
|
|
344 |
|
|
|
345 |
#檢查參數
|
|
|
346 |
#函式說明:
|
|
|
347 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
348 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
349 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
350 |
#$result["function"],當前執行的函式名稱.
|
|
|
351 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
352 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
353 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
354 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
355 |
#必填寫的參數:
|
|
|
356 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
357 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
358 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
359 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("libAddr");
|
|
|
360 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
361 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
362 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
363 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
364 |
#可以省略的參數:
|
|
|
365 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
366 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
367 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
368 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileArgu");
|
|
|
369 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
370 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
371 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,「null」代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
372 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(__FILE__);
|
|
|
373 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
374 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
375 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
376 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
377 |
|
|
|
378 |
#如果檢查參數失敗
|
|
|
379 |
if($checkResult["status"]=="false"){
|
|
|
380 |
|
|
|
381 |
#設置執行失敗
|
|
|
382 |
$result["status"]="false";
|
|
|
383 |
|
|
|
384 |
#設置錯誤訊息
|
|
|
385 |
$result["error"]=$checkResult;
|
|
|
386 |
|
|
|
387 |
#回傳結果
|
|
|
388 |
return $result;
|
|
|
389 |
|
|
|
390 |
}#if end
|
|
|
391 |
|
|
|
392 |
#如果檢查參數不通過
|
|
|
393 |
if($checkResult["passed"]=="false"){
|
|
|
394 |
|
|
|
395 |
#設置執行失敗
|
|
|
396 |
$result["status"]="false";
|
|
|
397 |
|
|
|
398 |
#設置錯誤訊息
|
|
|
399 |
$result["error"]=$checkResult;
|
|
|
400 |
|
|
|
401 |
#回傳結果
|
|
|
402 |
return $result;
|
|
|
403 |
|
|
|
404 |
}#if end
|
|
|
405 |
|
|
|
406 |
#demo用的目標
|
|
|
407 |
$demoTarget="<canvas id=\"myChart\" width=\"400\" height=\"400\"></canvas>";
|
|
|
408 |
|
|
|
409 |
#函式說明:
|
|
|
410 |
#匯入chartJS的函式庫.
|
|
|
411 |
#回傳結果:
|
|
|
412 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
413 |
#$result["error"],錯誤訊息.
|
|
|
414 |
#$result["content"],語法.
|
|
|
415 |
#$result["function"],當前執行的函數名稱.
|
|
|
416 |
#必填參數:
|
|
|
417 |
#$conf["libAddr"],字串,爲ckfEditor套件的網路位置,js附檔名會自動補上.
|
|
|
418 |
$conf["chartJS::importLib"]["libAddr"]=$conf["libAddr"];
|
|
|
419 |
#可省略參數:
|
|
|
420 |
#$conf["fileArgu"],字串,為當前檔案的路徑,預設為__FILE__.
|
|
|
421 |
$conf["chartJS::importLib"]["fileArgu"]=$conf["fileArgu"];
|
|
|
422 |
$importLib=chartJS::importLib($conf["chartJS::importLib"]);
|
|
|
423 |
unset($conf["chartJS::importLib"]);
|
|
|
424 |
|
|
|
425 |
#如果建立匯入 chart js lib 的語法失敗
|
|
|
426 |
if($importLib["status"]=="false"){
|
|
|
427 |
|
|
|
428 |
#設置執行失敗
|
|
|
429 |
$result["status"]="false";
|
|
|
430 |
|
|
|
431 |
#設置錯誤訊息
|
|
|
432 |
$result["error"]=$importLib;
|
|
|
433 |
|
|
|
434 |
#回傳結果
|
|
|
435 |
return $result;
|
|
|
436 |
|
|
|
437 |
}#if end
|
|
|
438 |
|
|
|
439 |
#取得匯入chart js的語法
|
|
|
440 |
$result["content"]=$result["content"].$importLib["content"];
|
|
|
441 |
|
|
|
442 |
#涵式說明:
|
|
|
443 |
#將要執行的script語法透過該函式執行
|
|
|
444 |
#回傳結果:
|
|
|
445 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
446 |
#$result["error"],錯誤訊息陣列
|
|
|
447 |
#$result["function"],當前執行的函數名稱
|
|
|
448 |
#$result["content"],要執行的javaScript語法
|
|
|
449 |
#必填的參數:
|
|
|
450 |
#$conf["script"],字串,要執行的javaScript語法,標籤「<script></script>」會自動補上.
|
|
|
451 |
$conf["javaScript::toScript"]["script"]="
|
|
|
452 |
var ctx = document.getElementById(\"myChart\").getContext('2d');
|
|
|
453 |
var myChart = new Chart(ctx,
|
|
|
454 |
{
|
|
|
455 |
type: 'bar',
|
|
|
456 |
data: {
|
|
|
457 |
labels: [\"Red\", \"Blue\", \"Yellow\", \"Green\", \"Purple\", \"Orange\"],
|
|
|
458 |
datasets: [{
|
|
|
459 |
label: '# of Votes',
|
|
|
460 |
data: [12, 19, 3, 5, 2, 3],
|
|
|
461 |
backgroundColor: [
|
|
|
462 |
'rgba(255, 99, 132, 0.2)',
|
|
|
463 |
'rgba(54, 162, 235, 0.2)',
|
|
|
464 |
'rgba(255, 206, 86, 0.2)',
|
|
|
465 |
'rgba(75, 192, 192, 0.2)',
|
|
|
466 |
'rgba(153, 102, 255, 0.2)',
|
|
|
467 |
'rgba(255, 159, 64, 0.2)'
|
|
|
468 |
],
|
|
|
469 |
borderColor: [
|
|
|
470 |
'rgba(255,99,132,1)',
|
|
|
471 |
'rgba(54, 162, 235, 1)',
|
|
|
472 |
'rgba(255, 206, 86, 1)',
|
|
|
473 |
'rgba(75, 192, 192, 1)',
|
|
|
474 |
'rgba(153, 102, 255, 1)',
|
|
|
475 |
'rgba(255, 159, 64, 1)'
|
|
|
476 |
],
|
|
|
477 |
borderWidth: 1
|
|
|
478 |
}]
|
|
|
479 |
},
|
|
|
480 |
options: {
|
|
|
481 |
scales: {
|
|
|
482 |
yAxes: [{
|
|
|
483 |
ticks: {
|
|
|
484 |
beginAtZero:true
|
|
|
485 |
}
|
|
|
486 |
}]
|
|
|
487 |
}
|
|
|
488 |
}
|
|
|
489 |
});
|
|
|
490 |
";
|
|
|
491 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
492 |
unset($conf["javaScript::toScript"]);
|
|
|
493 |
|
|
|
494 |
#如果轉換成js語法失敗
|
|
|
495 |
if($toScript["status"]=="false"){
|
|
|
496 |
|
|
|
497 |
#設置執行失敗
|
|
|
498 |
$result["status"]="false";
|
|
|
499 |
|
|
|
500 |
#設置錯誤訊息
|
|
|
501 |
$result["error"]=$toScript;
|
|
|
502 |
|
|
|
503 |
#回傳結果
|
|
|
504 |
return $result;
|
|
|
505 |
|
|
|
506 |
}#if end
|
|
|
507 |
|
|
|
508 |
#取得使用chart js的語法
|
|
|
509 |
$result["content"]=$result["content"].$demoTarget.$toScript["content"];
|
|
|
510 |
|
|
|
511 |
#設置執行正常
|
|
|
512 |
$result["status"]="true";
|
|
|
513 |
|
|
|
514 |
#回傳結果
|
|
|
515 |
return $result;
|
|
|
516 |
|
|
|
517 |
}#function barDemo end
|
|
|
518 |
|
|
|
519 |
/*
|
|
|
520 |
#函式說明:
|
|
|
521 |
#將數據用長條圖表示.
|
|
|
522 |
#回傳結果:
|
|
|
523 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
524 |
#$result["error"],錯誤訊息.
|
|
|
525 |
#$result["content"],語法.
|
|
|
526 |
#$result["function"],當前執行的函數名稱.
|
|
|
527 |
#必填參數:
|
|
|
528 |
#$conf["libAddr"],字串,爲chartJS的位置,js附檔名會自動補上.
|
|
|
529 |
$conf["libAddr"]="";
|
|
|
530 |
#$conf["data"],字串,要繪製的數據,例如:"2017/07/09 508.25 2017/07/16 1365 2017/07/23 949 2017/07/30 455 2017/08/06 917 2017/08/13 0".
|
|
|
531 |
$conf["data"]="";
|
|
|
532 |
#$conf["canvasId"],字串,為要繪製圖表到哪個canvas元素的id.
|
|
|
533 |
$conf["canvasId"]="";
|
|
|
534 |
#$conf["title"],字串,圖表的標題.
|
|
|
535 |
$conf["title"]="";
|
|
|
536 |
#conf["yTitle"],字串,y軸標題.
|
|
|
537 |
$conf["yTitle"]="";
|
|
|
538 |
#conf["xTitle"],字串,x軸標題.
|
|
|
539 |
$conf["xTitle"]="";
|
|
|
540 |
#可省略參數:
|
|
|
541 |
#$conf["fileArgu"],字串,為當前檔案的路徑,預設為__FILE__.
|
|
|
542 |
#$conf["fileArgu"]=__FILE__;
|
|
|
543 |
#$conf["dataUnit"],字串,數據的單位,預設為"number";
|
|
|
544 |
#$conf["dataUnit"]="number";
|
|
|
545 |
#$conf["yTcolor"],字串,y軸標題顏色與透明度,例如:"0,0,255,0.8"就代表紅光0,綠光0,藍光255,透明度0.2.
|
|
|
546 |
#$conf["yTcolor"]="";
|
|
|
547 |
#$conf["xTcolor"],字串,x軸標題顏色與透明度,例如:"0,0,255,0.8"就代表紅光0,綠光0,藍光255,透明度0.2.
|
|
|
548 |
#$conf["xTcolor"]="";
|
|
|
549 |
#參考資料:
|
|
|
550 |
#Creating a Chart=>http://www.chartjs.org/docs/latest/
|
|
|
551 |
#備註:
|
|
|
552 |
#無.
|
|
|
553 |
*/
|
|
|
554 |
public static function bar(&$conf=array()){
|
|
|
555 |
|
|
|
556 |
#初始化要回傳的內容
|
|
|
557 |
$result=array();
|
|
|
558 |
|
|
|
559 |
#取得當前執行的函數名稱
|
|
|
560 |
$result["function"]=__FUNCTION__;
|
|
|
561 |
|
|
|
562 |
#初始化要回傳的語法
|
|
|
563 |
$result["content"]="";
|
|
|
564 |
|
|
|
565 |
#如果沒有參數
|
|
|
566 |
if(func_num_args()==0){
|
|
|
567 |
|
|
|
568 |
#設置執行失敗
|
|
|
569 |
$result["status"]="false";
|
|
|
570 |
|
|
|
571 |
#設置執行錯誤訊息
|
|
|
572 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
573 |
|
|
|
574 |
#回傳結果
|
|
|
575 |
return $result;
|
|
|
576 |
|
|
|
577 |
}#if end
|
|
|
578 |
|
|
|
579 |
#取得參數
|
|
|
580 |
$result["argu"]=$conf;
|
|
|
581 |
|
|
|
582 |
#如果 $conf 不為陣列
|
|
|
583 |
if(gettype($conf)!="array"){
|
|
|
584 |
|
|
|
585 |
#設置執行失敗
|
|
|
586 |
$result["status"]="false";
|
|
|
587 |
|
|
|
588 |
#設置執行錯誤訊息
|
|
|
589 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
590 |
|
|
|
591 |
#如果傳入的參數為 null
|
|
|
592 |
if($conf==null){
|
|
|
593 |
|
|
|
594 |
#設置執行錯誤訊息
|
|
|
595 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
596 |
|
|
|
597 |
}#if end
|
|
|
598 |
|
|
|
599 |
#回傳結果
|
|
|
600 |
return $result;
|
|
|
601 |
|
|
|
602 |
}#if end
|
|
|
603 |
|
|
|
604 |
#檢查參數
|
|
|
605 |
#函式說明:
|
|
|
606 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
607 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
608 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
609 |
#$result["function"],當前執行的函式名稱.
|
|
|
610 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
611 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
612 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
613 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
614 |
#必填寫的參數:
|
|
|
615 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
616 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
617 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
618 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("libAddr","data","canvasId","title","xTitle","yTitle");
|
|
|
619 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
620 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string","string","string",);
|
|
|
621 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
622 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
623 |
#可以省略的參數:
|
|
|
624 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
625 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
626 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
627 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileArgu","dataUnit","xTcolor","yTcolor");
|
|
|
628 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
629 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
|
|
|
630 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,「null」代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
631 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(__FILE__,"number","0,0,255,0.8","0,0,255,0.8");
|
|
|
632 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
633 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
634 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
635 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
636 |
|
|
|
637 |
#如果檢查參數失敗
|
|
|
638 |
if($checkResult["status"]=="false"){
|
|
|
639 |
|
|
|
640 |
#設置執行失敗
|
|
|
641 |
$result["status"]="false";
|
|
|
642 |
|
|
|
643 |
#設置錯誤訊息
|
|
|
644 |
$result["error"]=$checkResult;
|
|
|
645 |
|
|
|
646 |
#回傳結果
|
|
|
647 |
return $result;
|
|
|
648 |
|
|
|
649 |
}#if end
|
|
|
650 |
|
|
|
651 |
#如果檢查參數不通過
|
|
|
652 |
if($checkResult["passed"]=="false"){
|
|
|
653 |
|
|
|
654 |
#設置執行失敗
|
|
|
655 |
$result["status"]="false";
|
|
|
656 |
|
|
|
657 |
#設置錯誤訊息
|
|
|
658 |
$result["error"]=$checkResult;
|
|
|
659 |
|
|
|
660 |
#回傳結果
|
|
|
661 |
return $result;
|
|
|
662 |
|
|
|
663 |
}#if end
|
|
|
664 |
|
|
|
665 |
#函式說明:
|
|
|
666 |
#匯入chartJS的函式庫.
|
|
|
667 |
#回傳結果:
|
|
|
668 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
669 |
#$result["error"],錯誤訊息.
|
|
|
670 |
#$result["content"],語法.
|
|
|
671 |
#$result["function"],當前執行的函數名稱.
|
|
|
672 |
#必填參數:
|
|
|
673 |
#$conf["libAddr"],字串,爲ckfEditor套件的網路位置,js附檔名會自動補上.
|
|
|
674 |
$conf["chartJS::importLib"]["libAddr"]=$conf["libAddr"];
|
|
|
675 |
#可省略參數:
|
|
|
676 |
#$conf["fileArgu"],字串,為當前檔案的路徑,預設為__FILE__.
|
|
|
677 |
$conf["chartJS::importLib"]["fileArgu"]=$conf["fileArgu"];
|
|
|
678 |
$importLib=chartJS::importLib($conf["chartJS::importLib"]);
|
|
|
679 |
unset($conf["chartJS::importLib"]);
|
|
|
680 |
|
|
|
681 |
#如果建立匯入 chart js lib 的語法失敗
|
|
|
682 |
if($importLib["status"]=="false"){
|
|
|
683 |
|
|
|
684 |
#設置執行失敗
|
|
|
685 |
$result["status"]="false";
|
|
|
686 |
|
|
|
687 |
#設置錯誤訊息
|
|
|
688 |
$result["error"]=$importLib;
|
|
|
689 |
|
|
|
690 |
#回傳結果
|
|
|
691 |
return $result;
|
|
|
692 |
|
|
|
693 |
}#if end
|
|
|
694 |
|
|
|
695 |
#取得匯入chart js的語法
|
|
|
696 |
$result["content"]=$result["content"].$importLib["content"];
|
|
|
697 |
|
|
|
698 |
#用空格分割
|
|
|
699 |
$dataSet=explode(' ',$conf["data"]);
|
|
|
700 |
|
|
|
701 |
#初始化儲存x軸標題的陣列
|
|
|
702 |
$lables=array();
|
|
|
703 |
|
|
|
704 |
#初始化儲存y軸數據的陣列
|
|
|
705 |
$values=array();
|
|
|
706 |
|
|
|
707 |
#兩兩一對
|
|
|
708 |
for($i=0;$i<count($dataSet);$i=$i+2){
|
|
|
709 |
|
|
|
710 |
#取得x軸項目
|
|
|
711 |
$lables[]=$dataSet[$i];
|
|
|
712 |
|
|
|
713 |
#取得y軸項目
|
|
|
714 |
$values[]=$dataSet[$i+1];
|
|
|
715 |
|
|
|
716 |
}#for end
|
|
|
717 |
|
|
|
718 |
#涵式說明:
|
|
|
719 |
#將要執行的script語法透過該函式執行
|
|
|
720 |
#回傳結果:
|
|
|
721 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
722 |
#$result["error"],錯誤訊息陣列
|
|
|
723 |
#$result["function"],當前執行的函數名稱
|
|
|
724 |
#$result["content"],要執行的javaScript語法
|
|
|
725 |
#必填的參數:
|
|
|
726 |
#$conf["script"],字串,要執行的javaScript語法,標籤「<script></script>」會自動補上.
|
|
|
727 |
$conf["javaScript::toScript"]["script"]="
|
|
|
728 |
var ctx = document.getElementById(\"".$conf["canvasId"]."\").getContext('2d');
|
|
|
729 |
var myChart = new Chart(ctx,
|
|
|
730 |
{
|
|
|
731 |
type: 'bar',
|
|
|
732 |
data: {
|
|
|
733 |
labels: ".json_encode($lables).",
|
|
|
734 |
datasets: [{
|
|
|
735 |
label: '# of ".$conf["dataUnit"]."',
|
|
|
736 |
data: ".json_encode($values).",
|
|
|
737 |
backgroundColor: [
|
|
|
738 |
'rgba(255, 99, 132, 0.2)',
|
|
|
739 |
'rgba(54, 162, 235, 0.2)',
|
|
|
740 |
'rgba(255, 206, 86, 0.2)',
|
|
|
741 |
'rgba(75, 192, 192, 0.2)',
|
|
|
742 |
'rgba(153, 102, 255, 0.2)',
|
|
|
743 |
'rgba(255, 159, 64, 0.2)'
|
|
|
744 |
],
|
|
|
745 |
borderColor: [
|
|
|
746 |
'rgba(255,99,132,1)',
|
|
|
747 |
'rgba(54, 162, 235, 1)',
|
|
|
748 |
'rgba(255, 206, 86, 1)',
|
|
|
749 |
'rgba(75, 192, 192, 1)',
|
|
|
750 |
'rgba(153, 102, 255, 1)',
|
|
|
751 |
'rgba(255, 159, 64, 1)'
|
|
|
752 |
],
|
|
|
753 |
borderWidth: 1
|
|
|
754 |
}]
|
|
|
755 |
},
|
|
|
756 |
options:
|
|
|
757 |
{
|
|
|
758 |
scales:
|
|
|
759 |
{
|
|
|
760 |
yAxes:
|
|
|
761 |
[{
|
|
|
762 |
ticks:
|
|
|
763 |
{
|
|
|
764 |
beginAtZero:true
|
|
|
765 |
},
|
|
|
766 |
scaleLabel:
|
|
|
767 |
{
|
|
|
768 |
display: true,
|
|
|
769 |
labelString: '".$conf["yTitle"]."',
|
|
|
770 |
fontColor:'rgba(".$conf["yTcolor"].")',
|
|
|
771 |
}
|
|
|
772 |
}],
|
|
|
773 |
xAxes:
|
|
|
774 |
[{
|
|
|
775 |
scaleLabel:
|
|
|
776 |
{
|
|
|
777 |
display: true,
|
|
|
778 |
labelString: '".$conf["xTitle"]."',
|
|
|
779 |
fontColor:'rgba(".$conf["yTcolor"].")',
|
|
|
780 |
}
|
|
|
781 |
}]
|
|
|
782 |
},
|
|
|
783 |
title:
|
|
|
784 |
{
|
|
|
785 |
display: true,
|
|
|
786 |
text: '".$conf["title"]."'
|
|
|
787 |
},
|
|
|
788 |
legend:
|
|
|
789 |
{
|
|
|
790 |
//disable class label
|
|
|
791 |
display: false
|
|
|
792 |
},
|
|
|
793 |
}
|
|
|
794 |
});
|
|
|
795 |
";
|
|
|
796 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
797 |
unset($conf["javaScript::toScript"]);
|
|
|
798 |
|
|
|
799 |
#如果轉換成js語法失敗
|
|
|
800 |
if($toScript["status"]=="false"){
|
|
|
801 |
|
|
|
802 |
#設置執行失敗
|
|
|
803 |
$result["status"]="false";
|
|
|
804 |
|
|
|
805 |
#設置錯誤訊息
|
|
|
806 |
$result["error"]=$toScript;
|
|
|
807 |
|
|
|
808 |
#回傳結果
|
|
|
809 |
return $result;
|
|
|
810 |
|
|
|
811 |
}#if end
|
|
|
812 |
|
|
|
813 |
#取得使用chart js的語法
|
|
|
814 |
$result["content"]=$result["content"].$toScript["content"];
|
|
|
815 |
|
|
|
816 |
#設置執行正常
|
|
|
817 |
$result["status"]="true";
|
|
|
818 |
|
|
|
819 |
#回傳結果
|
|
|
820 |
return $result;
|
|
|
821 |
|
|
|
822 |
}#function barDemo end
|
|
|
823 |
|
|
|
824 |
}#class chartJS end
|
|
|
825 |
|
|
|
826 |
?>
|