| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
| 226 |
liveuser |
6 |
Copyright (C) 2014~2025 MIN ZHI, CHEN
|
| 3 |
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;
|
| 226 |
liveuser |
25 |
|
| 3 |
liveuser |
26 |
/*
|
|
|
27 |
類別說明:
|
|
|
28 |
用於處理csv格式檔案的類別.
|
|
|
29 |
備註:
|
|
|
30 |
無.
|
|
|
31 |
*/
|
|
|
32 |
class csv{
|
|
|
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){
|
| 226 |
liveuser |
48 |
|
| 3 |
liveuser |
49 |
#取得當前執行的函式
|
|
|
50 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
51 |
|
| 3 |
liveuser |
52 |
#設置執行不正常
|
|
|
53 |
$result["status"]="false";
|
| 226 |
liveuser |
54 |
|
| 3 |
liveuser |
55 |
#設置執行錯誤
|
|
|
56 |
$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
|
| 226 |
liveuser |
57 |
|
| 3 |
liveuser |
58 |
#設置所丟入的參數
|
|
|
59 |
$result["error"][]=$arguments;
|
| 226 |
liveuser |
60 |
|
| 3 |
liveuser |
61 |
#回傳結果
|
|
|
62 |
return $result;
|
| 226 |
liveuser |
63 |
|
| 3 |
liveuser |
64 |
}#function __call end
|
| 226 |
liveuser |
65 |
|
| 3 |
liveuser |
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){
|
| 226 |
liveuser |
80 |
|
| 3 |
liveuser |
81 |
#取得當前執行的函式
|
|
|
82 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
83 |
|
| 3 |
liveuser |
84 |
#設置執行不正常
|
|
|
85 |
$result["status"]="false";
|
| 226 |
liveuser |
86 |
|
| 3 |
liveuser |
87 |
#設置執行錯誤
|
|
|
88 |
$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
|
| 226 |
liveuser |
89 |
|
| 3 |
liveuser |
90 |
#設置所丟入的參數
|
|
|
91 |
$result["error"][]=$arguments;
|
| 226 |
liveuser |
92 |
|
| 3 |
liveuser |
93 |
#回傳結果
|
|
|
94 |
return $result;
|
| 226 |
liveuser |
95 |
|
| 3 |
liveuser |
96 |
}#function __callStatic end
|
|
|
97 |
|
|
|
98 |
/*
|
|
|
99 |
#函式說明:
|
|
|
100 |
#快速建立一個csv檔案,並且要求使用者下載。
|
|
|
101 |
#回傳結果:
|
|
|
102 |
#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
|
|
|
103 |
#$result["error"],錯誤訊息陣列.
|
|
|
104 |
#$result["function"],取得當前執行的函數名稱
|
|
|
105 |
#$result["content"],輸出的csv檔案位置.
|
|
|
106 |
#如果有設置$conf["noDownload"]爲"true"的話,則會回傳檔案的位置
|
|
|
107 |
#必填參數:
|
|
|
108 |
#$conf["dataArray"],字串陣列,要寫入的文字.$conf["dataArray"][$i],代表第 $i 行的內容,$conf["dataArray"][$i][$j],代表第 $i 第 $j個欄位的內容.
|
|
|
109 |
$conf["dataArray"]=array();
|
|
|
110 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
111 |
$conf["fileArgu"]=__FILE__;
|
|
|
112 |
#可省略參數:
|
|
|
113 |
#$conf["csvFilePathAndName"]="";#輸出的csv檔案路徑與名稱,預設爲系統時間,副檔名"csv"會自動加上.
|
|
|
114 |
#$conf["noDownload"]="true";#如果爲"true"則代表不要讓使用者下載,但會回傳檔案的相對位置,預設為"true".
|
|
|
115 |
#參考資料:
|
|
|
116 |
#http://php.net/manual/en/function.str-split.php
|
|
|
117 |
#http://php.net/manual/en/function.fputcsv.php
|
|
|
118 |
#備註:
|
|
|
119 |
#可用fputcsv涵式替代
|
|
|
120 |
#建議增加自動判斷是否要建立csv檔路徑所需的資料夾
|
|
|
121 |
*/
|
|
|
122 |
public static function create(&$conf){
|
| 226 |
liveuser |
123 |
|
| 3 |
liveuser |
124 |
#初始化要回傳的變數
|
|
|
125 |
$result=array();
|
| 226 |
liveuser |
126 |
|
| 3 |
liveuser |
127 |
#初始化當前執行的函數名稱
|
|
|
128 |
$result["funciton"]=__FUNCTION__;
|
| 226 |
liveuser |
129 |
|
| 3 |
liveuser |
130 |
#如果 $conf 不為陣列
|
|
|
131 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
132 |
|
| 3 |
liveuser |
133 |
#設置執行失敗
|
|
|
134 |
$result["status"]="false";
|
| 226 |
liveuser |
135 |
|
| 3 |
liveuser |
136 |
#設置執行錯誤訊息
|
|
|
137 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
138 |
|
|
|
139 |
#如果傳入的參數為 null
|
|
|
140 |
if($conf==null){
|
| 226 |
liveuser |
141 |
|
| 3 |
liveuser |
142 |
#設置執行錯誤訊息
|
|
|
143 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
144 |
|
| 3 |
liveuser |
145 |
}#if end
|
|
|
146 |
|
|
|
147 |
#回傳結果
|
|
|
148 |
return $result;
|
| 226 |
liveuser |
149 |
|
| 3 |
liveuser |
150 |
}#if end
|
| 226 |
liveuser |
151 |
|
| 3 |
liveuser |
152 |
#檢查參數
|
|
|
153 |
#函式說明:
|
|
|
154 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
155 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
156 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
157 |
#$result["function"],當前執行的函式名稱.
|
|
|
158 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
159 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
160 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
161 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
162 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
163 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
164 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
165 |
#必填寫的參數:
|
|
|
166 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
167 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
168 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
169 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dataArray","fileArgu");
|
| 226 |
liveuser |
170 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
171 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
|
|
|
172 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
173 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
174 |
#可以省略的參數:
|
|
|
175 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
176 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
177 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
178 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("csvFilePathAndName","noDownload");
|
| 226 |
liveuser |
179 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
180 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
181 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
182 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"true");
|
|
|
183 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
184 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
185 |
#參考資料來源:
|
|
|
186 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
187 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
188 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
189 |
|
| 3 |
liveuser |
190 |
#如果檢查失敗
|
|
|
191 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
192 |
|
| 3 |
liveuser |
193 |
#設置執行不正常
|
|
|
194 |
$result["status"]="false";
|
| 226 |
liveuser |
195 |
|
| 3 |
liveuser |
196 |
#設置錯誤訊息
|
|
|
197 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
198 |
|
| 3 |
liveuser |
199 |
#回傳結果
|
|
|
200 |
return $result;
|
| 226 |
liveuser |
201 |
|
|
|
202 |
}#if end
|
|
|
203 |
|
| 3 |
liveuser |
204 |
#如果檢查不通過
|
|
|
205 |
if($checkResult["passed"]=="false"){
|
|
|
206 |
|
|
|
207 |
#設置執行不正常
|
|
|
208 |
$result["status"]="false";
|
| 226 |
liveuser |
209 |
|
| 3 |
liveuser |
210 |
#設置錯誤訊息
|
|
|
211 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
212 |
|
| 3 |
liveuser |
213 |
#回傳結果
|
|
|
214 |
return $result;
|
|
|
215 |
|
|
|
216 |
}#if end
|
| 226 |
liveuser |
217 |
|
| 3 |
liveuser |
218 |
#如果 $conf["csvFilePathAndName"] 沒有設置
|
|
|
219 |
if(!isset($conf["csvFilePathAndName"])){
|
| 226 |
liveuser |
220 |
|
| 3 |
liveuser |
221 |
#預設爲系統時間
|
|
|
222 |
#涵式說明:
|
|
|
223 |
#回傳RFC822格式的當前時間,格式會像這種 「Wed, 25 Jan 12 19:13:15 +0800」
|
|
|
224 |
#回傳的結果:
|
|
|
225 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
226 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
227 |
#$result["function"],當前執行的函式名稱.
|
|
|
228 |
#$result["content"],RFC822格式的時間.
|
|
|
229 |
#必填的參數:
|
|
|
230 |
$conf["time"]["get_RFC822_Time"]["timeZone"]="Asia/Taipei";#時區代號,可以設定的時區列表:http://www.php.net/manual/en/timezones.php
|
|
|
231 |
#ex:"Asia/Taipei"
|
|
|
232 |
$systemTime=time::get_RFC822_Time($conf["time"]["get_RFC822_Time"]);
|
|
|
233 |
unset($conf["time"]["get_RFC822_Time"]);
|
| 226 |
liveuser |
234 |
|
| 3 |
liveuser |
235 |
#如果取得時間失敗
|
|
|
236 |
if($systemTime["status"]=="false"){
|
| 226 |
liveuser |
237 |
|
| 3 |
liveuser |
238 |
#設置執行不正常
|
|
|
239 |
$result["status"]="false";
|
| 226 |
liveuser |
240 |
|
| 3 |
liveuser |
241 |
#設置錯誤訊息
|
|
|
242 |
$result["error"]=$systemTime;
|
| 226 |
liveuser |
243 |
|
| 3 |
liveuser |
244 |
#回傳結果
|
|
|
245 |
return $result;
|
| 226 |
liveuser |
246 |
|
| 3 |
liveuser |
247 |
}#if end
|
| 226 |
liveuser |
248 |
|
| 3 |
liveuser |
249 |
#設定檔案名稱
|
|
|
250 |
$conf["csvFilePathAndName"]=$systemTime;
|
| 226 |
liveuser |
251 |
|
| 3 |
liveuser |
252 |
}#if end
|
| 226 |
liveuser |
253 |
|
| 3 |
liveuser |
254 |
#加上副檔名csv
|
|
|
255 |
$conf["csvFilePathAndName"]=$conf["csvFilePathAndName"].".csv";
|
| 226 |
liveuser |
256 |
|
| 3 |
liveuser |
257 |
/*
|
| 226 |
liveuser |
258 |
|
| 3 |
liveuser |
259 |
#檢查 $conf["csvFilePathAndName"] 是否含有 "/"
|
|
|
260 |
#函式說明:
|
|
|
261 |
#檢查字串裡面有無指定的關鍵字
|
|
|
262 |
#回傳的結果:
|
|
|
263 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
264 |
#$result["error"],錯誤訊息
|
|
|
265 |
#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
266 |
#$result["keyWordCount"],找到的關鍵字數量.
|
|
|
267 |
#必填的參數:
|
|
|
268 |
$conf["search.findKeyWord"]["keyWord"]="/";#想要搜尋的關鍵字
|
|
|
269 |
$conf["search.findKeyWord"]["string"]=$conf["csvFilePathAndName"];#要被搜尋的字串內容
|
|
|
270 |
#可省略的參數:
|
|
|
271 |
#$conf["search.findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
272 |
$searchResult=search::findKeyWord($conf["search.findKeyWord"]);
|
|
|
273 |
unset($conf["search.findKeyWord"]);
|
| 226 |
liveuser |
274 |
|
| 3 |
liveuser |
275 |
#如果搜尋失敗
|
|
|
276 |
if($searchResult["status"]=="false"){
|
| 226 |
liveuser |
277 |
|
| 3 |
liveuser |
278 |
#設置執行異常
|
|
|
279 |
$result["status"]="false";
|
| 226 |
liveuser |
280 |
|
| 3 |
liveuser |
281 |
#設置錯誤訊息
|
|
|
282 |
$result["error"]=$searchResult;
|
| 226 |
liveuser |
283 |
|
| 3 |
liveuser |
284 |
#回傳結果
|
|
|
285 |
return $result;
|
| 226 |
liveuser |
286 |
|
| 3 |
liveuser |
287 |
}#if end
|
| 226 |
liveuser |
288 |
|
|
|
289 |
#如果csv的檔案位置含有 "/"
|
| 3 |
liveuser |
290 |
if($searchResult["founded"]=="true"){
|
| 226 |
liveuser |
291 |
|
| 3 |
liveuser |
292 |
#用 "/" 去分割csv檔案路徑字串
|
|
|
293 |
#涵式說明:
|
|
|
294 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
295 |
#回傳的參數:
|
|
|
296 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
297 |
#$result["error"],錯誤訊息陣列
|
|
|
298 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
299 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
300 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
301 |
#必填的參數:
|
|
|
302 |
$conf["stringProcess.spiltString"]["stringIn"]=$conf["csvFilePathAndName"];#要處理的字串。
|
|
|
303 |
$conf["stringProcess.spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
|
|
|
304 |
#備註:
|
|
|
305 |
#建議新增如果透過" "分割後的內容含有""的元素,將其移除,並將後面有內容的元素補上,key也重新排序。
|
|
|
306 |
$stringSpiltResult=stringProcess::spiltString($conf["stringProcess.spiltString"]);
|
|
|
307 |
unset($conf["stringProcess.spiltString"]);
|
| 226 |
liveuser |
308 |
|
| 3 |
liveuser |
309 |
#如果分割csv的檔案位置路徑字串失敗
|
|
|
310 |
if($stringSpiltResult["status"]=="false"){
|
| 226 |
liveuser |
311 |
|
| 3 |
liveuser |
312 |
#設置執行異常
|
|
|
313 |
$result["status"]="false";
|
| 226 |
liveuser |
314 |
|
| 3 |
liveuser |
315 |
#設置錯誤訊息
|
|
|
316 |
$result["error"]=$searchResult;
|
| 226 |
liveuser |
317 |
|
| 3 |
liveuser |
318 |
#回傳結果
|
|
|
319 |
return $result;
|
| 226 |
liveuser |
320 |
|
| 3 |
liveuser |
321 |
}#if end
|
| 226 |
liveuser |
322 |
|
| 3 |
liveuser |
323 |
#初始化檔案路徑變數
|
| 226 |
liveuser |
324 |
$filePath="";
|
|
|
325 |
|
| 3 |
liveuser |
326 |
#將資料夾路徑字串組合起來,剔除csv檔的名稱。
|
|
|
327 |
for($i=0;$i<$stringSpiltResult["dataCounts"]-1;$i++){
|
| 226 |
liveuser |
328 |
|
| 3 |
liveuser |
329 |
#串聯路徑
|
|
|
330 |
$filePath=$filePath.$stringSpiltResult["dataArray"][$i];
|
| 226 |
liveuser |
331 |
|
| 3 |
liveuser |
332 |
#如果不是最後一筆
|
|
|
333 |
if($i!=$stringSpiltResult["dataCounts"]-2){
|
| 226 |
liveuser |
334 |
|
| 3 |
liveuser |
335 |
#串聯路徑
|
|
|
336 |
$filePath=$filePath."/";
|
| 226 |
liveuser |
337 |
|
| 3 |
liveuser |
338 |
}#if end
|
| 226 |
liveuser |
339 |
|
| 3 |
liveuser |
340 |
}#for end
|
| 226 |
liveuser |
341 |
|
| 3 |
liveuser |
342 |
#涵式說明:
|
|
|
343 |
#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限.
|
|
|
344 |
#回傳的結果:
|
|
|
345 |
#$result["status"],"true"爲建立成功,"false"爲建立失敗.
|
|
|
346 |
#$result["error"],錯誤訊息陣列
|
|
|
347 |
#必填的參數:
|
|
|
348 |
$conf["fileAccess.createFolderAfterCheck"]["dirPositionAndName"]=$filePath;#新建的位置與名稱
|
|
|
349 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
350 |
$conf["fileAccess.createFolderAfterCheck"]["fileArgu"]=$conf["fileArgu"];
|
|
|
351 |
#可省略的參數:
|
|
|
352 |
#$conf["fileAccess.createFolderAfterCheck"]["dirPermission"]="";#新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
|
|
|
353 |
$pathCreateResult=fileAccess::createFolderAfterCheck($conf["fileAccess.createFolderAfterCheck"]);
|
|
|
354 |
unset($conf["fileAccess.createFolderAfterCheck"]);
|
| 226 |
liveuser |
355 |
|
| 3 |
liveuser |
356 |
#如果 建立資料夾路徑失敗
|
|
|
357 |
if($pathCreateResult["status"]=="false"){
|
| 226 |
liveuser |
358 |
|
| 3 |
liveuser |
359 |
#設置執行異常
|
|
|
360 |
$result["status"]="false";
|
| 226 |
liveuser |
361 |
|
| 3 |
liveuser |
362 |
#設置錯誤訊息
|
|
|
363 |
$result["error"]=$pathCreateResult;
|
| 226 |
liveuser |
364 |
|
| 3 |
liveuser |
365 |
#回傳結果
|
|
|
366 |
return $result;
|
| 226 |
liveuser |
367 |
|
| 3 |
liveuser |
368 |
}#if end
|
| 226 |
liveuser |
369 |
|
| 3 |
liveuser |
370 |
}#if end
|
| 226 |
liveuser |
371 |
|
| 3 |
liveuser |
372 |
*/
|
| 226 |
liveuser |
373 |
|
| 3 |
liveuser |
374 |
#var_dump($conf["csvFilePathAndName"]);
|
| 226 |
liveuser |
375 |
|
| 3 |
liveuser |
376 |
#建立csv檔案
|
|
|
377 |
#涵式說明:
|
|
|
378 |
#將字串寫入到檔案
|
|
|
379 |
#回傳的結果:
|
|
|
380 |
#$result["status"],true表示檔案寫入成功,false表示檔案寫入失敗.
|
|
|
381 |
#$result["error"],錯誤訊息陣列.
|
|
|
382 |
#必填的參數:
|
|
|
383 |
$conf["fileAccess"]["writeTextIntoFile"]["fileName"]=$conf["csvFilePathAndName"];#爲要編輯的檔案名稱
|
|
|
384 |
$conf["fileAccess"]["writeTextIntoFile"]["inputString"]="";#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
|
|
|
385 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
386 |
$conf["fileAccess"]["writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
387 |
#可省略的參數:
|
|
|
388 |
#$conf["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
|
|
|
389 |
$createStatus=fileAccess::writeTextIntoFile($conf["fileAccess"]["writeTextIntoFile"]);
|
|
|
390 |
unset($conf["fileAccess"]["writeTextIntoFile"]);
|
| 226 |
liveuser |
391 |
|
| 3 |
liveuser |
392 |
#如果 $createStatus["status"] 等於 "false"
|
|
|
393 |
if($createStatus["status"]=="false"){
|
| 226 |
liveuser |
394 |
|
| 3 |
liveuser |
395 |
#設置錯誤識別
|
|
|
396 |
$result["status"]="false";
|
| 226 |
liveuser |
397 |
|
| 3 |
liveuser |
398 |
#設置錯誤訊息
|
|
|
399 |
$result["error"]=$createStatus;
|
| 226 |
liveuser |
400 |
|
| 3 |
liveuser |
401 |
#回傳結果
|
|
|
402 |
return $result;
|
| 226 |
liveuser |
403 |
|
| 3 |
liveuser |
404 |
}#if end
|
| 226 |
liveuser |
405 |
|
| 3 |
liveuser |
406 |
#依據陣列組數寫入置檔案中
|
|
|
407 |
for($i=0;$i<count($conf["dataArray"]);$i++){
|
| 226 |
liveuser |
408 |
|
| 3 |
liveuser |
409 |
#如果該列資料不存在
|
|
|
410 |
if(!isset($conf["dataArray"][$i])){
|
| 226 |
liveuser |
411 |
|
| 3 |
liveuser |
412 |
#跳到下個迴圈
|
|
|
413 |
continue;
|
| 226 |
liveuser |
414 |
|
| 3 |
liveuser |
415 |
}#if end
|
| 226 |
liveuser |
416 |
|
| 3 |
liveuser |
417 |
#取得該筆資料有幾個欄位
|
|
|
418 |
$thisDataCotainElementsCount=count($conf["dataArray"][$i]);
|
|
|
419 |
|
|
|
420 |
#計數用的變數
|
|
|
421 |
$temp=0;
|
|
|
422 |
|
|
|
423 |
#針對每一組
|
|
|
424 |
foreach($conf["dataArray"][$i] as $key=>$value){
|
|
|
425 |
|
|
|
426 |
#如果不是最後一個元素
|
|
|
427 |
if($temp!=$thisDataCotainElementsCount-1){
|
|
|
428 |
|
|
|
429 |
#涵式說明:
|
|
|
430 |
#將字串寫入到檔案
|
|
|
431 |
#$result["status"],true表示檔案寫入成功,false表示檔案寫入失敗.
|
|
|
432 |
#$result["error"],錯誤訊息陣列.
|
|
|
433 |
#必填的參數:
|
|
|
434 |
$conf["fileAccess"]["writeTextIntoFile"]["fileName"]=$conf["csvFilePathAndName"];#爲要編輯的檔案名稱
|
|
|
435 |
|
|
|
436 |
#檢測$value的開頭與結尾是否有皆爲「"」
|
|
|
437 |
|
|
|
438 |
#將每欄的內容一個個字分開
|
|
|
439 |
$strArray=str_split($value,1);
|
|
|
440 |
|
|
|
441 |
#取得裏面有幾個元素
|
|
|
442 |
$strArrayElementCount=count($strArray);
|
|
|
443 |
|
|
|
444 |
#如果第一個元素爲「"」
|
|
|
445 |
if($strArray[0]=="\""){
|
|
|
446 |
|
|
|
447 |
#如果元素數量大於2
|
|
|
448 |
if($strArrayElementCount>2){
|
| 226 |
liveuser |
449 |
|
| 3 |
liveuser |
450 |
#如果最後一個元素爲「"」
|
|
|
451 |
if($strArray[$strArrayElementCount-1]=="\""){
|
|
|
452 |
|
|
|
453 |
#寫入欄位時不用加上「"」
|
|
|
454 |
$conf["fileAccess"]["writeTextIntoFile"]["inputString"]=$value.",";#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
|
|
|
455 |
|
|
|
456 |
#檢查變數內容
|
|
|
457 |
#var_dump($conf["fileAccess"]["writeTextIntoFile"]["inputString"]);
|
|
|
458 |
|
|
|
459 |
}#if end
|
|
|
460 |
|
|
|
461 |
}#if end
|
|
|
462 |
|
|
|
463 |
#元素內容小於2
|
|
|
464 |
else{
|
|
|
465 |
|
|
|
466 |
#寫入欄位時不用加上「"」
|
|
|
467 |
$conf["fileAccess"]["writeTextIntoFile"]["inputString"]=$value.",";#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
|
|
|
468 |
|
|
|
469 |
}#else end
|
|
|
470 |
|
|
|
471 |
}#if end
|
|
|
472 |
|
|
|
473 |
#反之第一個元素不爲「"」
|
|
|
474 |
else{
|
| 226 |
liveuser |
475 |
|
| 3 |
liveuser |
476 |
#檢查變數內容
|
|
|
477 |
#var_dump($value);
|
|
|
478 |
|
|
|
479 |
$conf["fileAccess"]["writeTextIntoFile"]["inputString"]="\"".$value."\",";#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
|
|
|
480 |
|
|
|
481 |
}#else end
|
|
|
482 |
|
|
|
483 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
484 |
$conf["fileAccess"]["writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
485 |
#可省略的參數:
|
|
|
486 |
$conf["fileAccess"]["writeTextIntoFile"]["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
|
|
|
487 |
$createStatus=fileAccess::writeTextIntoFile($conf["fileAccess"]["writeTextIntoFile"]);
|
|
|
488 |
unset($conf["fileAccess"]["writeTextIntoFile"]);
|
| 226 |
liveuser |
489 |
|
| 3 |
liveuser |
490 |
#計數用的變數加1
|
|
|
491 |
$temp++;
|
|
|
492 |
|
|
|
493 |
#如果 $createStatus["status"] 等於 "false"
|
|
|
494 |
if($createStatus["status"]=="false"){
|
| 226 |
liveuser |
495 |
|
| 3 |
liveuser |
496 |
#設置錯誤識別
|
|
|
497 |
$result["status"]="false";
|
| 226 |
liveuser |
498 |
|
| 3 |
liveuser |
499 |
#設置錯誤訊息
|
|
|
500 |
$result["error"]=$createStatus;
|
| 226 |
liveuser |
501 |
|
| 3 |
liveuser |
502 |
#回傳結果
|
|
|
503 |
return $result;
|
| 226 |
liveuser |
504 |
|
| 3 |
liveuser |
505 |
}#if end
|
|
|
506 |
|
|
|
507 |
}#if end
|
|
|
508 |
|
|
|
509 |
#反之爲最後一個元素
|
|
|
510 |
else{
|
| 226 |
liveuser |
511 |
|
| 3 |
liveuser |
512 |
#檢測$value的開頭與結尾是否有皆爲「"」
|
|
|
513 |
|
|
|
514 |
#將每欄的內容一個個字分開
|
|
|
515 |
$strArray=str_split($value,1);
|
|
|
516 |
|
|
|
517 |
#取得裏面有幾個元素
|
|
|
518 |
$strArrayElementCount=count($strArray);
|
|
|
519 |
|
|
|
520 |
#如果第一個元素爲「"」
|
|
|
521 |
if($strArray[0]=="\""){
|
|
|
522 |
|
|
|
523 |
#如果元素數量大於2
|
|
|
524 |
if($strArrayElementCount>2){
|
| 226 |
liveuser |
525 |
|
| 3 |
liveuser |
526 |
#如果倒數第2個元素爲「"」
|
|
|
527 |
if($strArray[$strArrayElementCount-1]=="\""){
|
|
|
528 |
|
|
|
529 |
#寫入欄位時不用加上「"」
|
|
|
530 |
$conf["fileAccess"]["writeTextIntoFile"]["inputString"]=$value."\r\n";#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
|
|
|
531 |
|
|
|
532 |
}#if end
|
|
|
533 |
|
|
|
534 |
}#if end
|
|
|
535 |
|
|
|
536 |
#元素內容小於2
|
|
|
537 |
else{
|
|
|
538 |
|
|
|
539 |
#寫入欄位時不用加上「"」
|
|
|
540 |
$conf["fileAccess"]["writeTextIntoFile"]["inputString"]=$value."\r\n";#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
|
|
|
541 |
|
|
|
542 |
}#else end
|
|
|
543 |
|
|
|
544 |
}#if end
|
|
|
545 |
|
|
|
546 |
#反之第一個元素不爲「"」
|
|
|
547 |
else{
|
|
|
548 |
|
|
|
549 |
$conf["fileAccess"]["writeTextIntoFile"]["inputString"]="\"".$value."\"\r\n";#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
|
|
|
550 |
|
|
|
551 |
}#else end
|
|
|
552 |
|
|
|
553 |
#寫入時加上換行符號
|
|
|
554 |
#涵式說明:
|
|
|
555 |
#將字串寫入到檔案
|
|
|
556 |
#回傳的結果:
|
|
|
557 |
#$result,true表示檔案建立成功,false表示檔案建立失敗
|
|
|
558 |
#必填的參數:
|
|
|
559 |
$conf["fileAccess"]["writeTextIntoFile"]["fileName"]=$conf["csvFilePathAndName"];#爲要編輯的檔案名稱
|
|
|
560 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
561 |
$conf["fileAccess"]["writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
562 |
#可省略的參數:
|
|
|
563 |
$conf["fileAccess"]["writeTextIntoFile"]["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
|
|
|
564 |
$createStatus=fileAccess::writeTextIntoFile($conf["fileAccess"]["writeTextIntoFile"]);
|
|
|
565 |
unset($conf["fileAccess"]["writeTextIntoFile"]);
|
| 226 |
liveuser |
566 |
|
| 3 |
liveuser |
567 |
#如果 $createStatus["status"] 等於 "false"
|
|
|
568 |
if($createStatus["status"]=="false"){
|
| 226 |
liveuser |
569 |
|
| 3 |
liveuser |
570 |
#設置錯誤識別
|
|
|
571 |
$result["status"]="false";
|
| 226 |
liveuser |
572 |
|
| 3 |
liveuser |
573 |
#設置錯誤訊息
|
|
|
574 |
$result["error"]=$createStatus;
|
| 226 |
liveuser |
575 |
|
| 3 |
liveuser |
576 |
#回傳結果
|
|
|
577 |
return $result;
|
| 226 |
liveuser |
578 |
|
| 3 |
liveuser |
579 |
}#if end
|
| 226 |
liveuser |
580 |
|
| 3 |
liveuser |
581 |
}#else end
|
|
|
582 |
|
|
|
583 |
}#foreach end
|
| 226 |
liveuser |
584 |
|
| 3 |
liveuser |
585 |
#函數說明:
|
|
|
586 |
#延長php的執行時間,每呼叫一次會初始化執行時間爲0,然後設定下次可以執行多久.
|
|
|
587 |
#回傳結果:
|
|
|
588 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
589 |
#$result["error"],錯誤訊息陣列.
|
|
|
590 |
#$result["function"],當前執行的函數名稱.
|
|
|
591 |
#必填參數:
|
|
|
592 |
#$conf["sec"],整數,要延長多少執行時間,單位爲秒
|
|
|
593 |
$conf["config::delayRunTimeExectionMax"]["sec"]=300;
|
|
|
594 |
#參考資料:
|
|
|
595 |
#http://php.net/manual/en/function.set-time-limit.php
|
|
|
596 |
$delayRunTimeExectionMax=config::delayRunTimeExectionMax($conf["config::delayRunTimeExectionMax"]);
|
|
|
597 |
unset($conf["config::delayRunTimeExectionMax"]);
|
| 226 |
liveuser |
598 |
|
| 3 |
liveuser |
599 |
#如果執行失敗
|
|
|
600 |
if($delayRunTimeExectionMax["status"]==="false"){
|
| 226 |
liveuser |
601 |
|
| 3 |
liveuser |
602 |
#設定類別圖繪製失敗
|
| 226 |
liveuser |
603 |
$result["status"]="false";
|
|
|
604 |
|
| 3 |
liveuser |
605 |
#設定該檔案的類別圖繪製失敗提示
|
|
|
606 |
$result["error"]=$delayRunTimeExectionMax;
|
| 226 |
liveuser |
607 |
|
| 3 |
liveuser |
608 |
#回傳結果
|
|
|
609 |
return $result;
|
| 226 |
liveuser |
610 |
|
| 3 |
liveuser |
611 |
}#if end
|
|
|
612 |
|
|
|
613 |
}#for end
|
| 226 |
liveuser |
614 |
|
| 3 |
liveuser |
615 |
#修改產生好的csv檔權限
|
|
|
616 |
$chmodResult=chmod($conf["csvFilePathAndName"],0775);
|
| 226 |
liveuser |
617 |
|
| 3 |
liveuser |
618 |
#如果修改檔案權限失敗
|
|
|
619 |
if($chmodResult==FALSE){
|
| 226 |
liveuser |
620 |
|
| 3 |
liveuser |
621 |
#設置錯誤識別
|
|
|
622 |
$result["status"]="false";
|
| 226 |
liveuser |
623 |
|
| 3 |
liveuser |
624 |
#設置錯誤訊息
|
|
|
625 |
$result["error"][]="檔案「".$conf["csvFilePathAndName"]."」的權限變更失敗";
|
| 226 |
liveuser |
626 |
|
| 3 |
liveuser |
627 |
#回傳結果
|
|
|
628 |
return $result;
|
| 226 |
liveuser |
629 |
|
| 3 |
liveuser |
630 |
}#if end
|
| 226 |
liveuser |
631 |
|
| 3 |
liveuser |
632 |
#如果 $conf["noDownload"] 有設置
|
|
|
633 |
if(isset($conf["noDownload"])){
|
| 226 |
liveuser |
634 |
|
| 3 |
liveuser |
635 |
#如果 $conf["noDownload"] 等於 true
|
|
|
636 |
if($conf["noDownload"]=="true"){
|
| 226 |
liveuser |
637 |
|
| 3 |
liveuser |
638 |
#設置執行正常
|
|
|
639 |
$result["status"]="true";
|
| 226 |
liveuser |
640 |
|
| 3 |
liveuser |
641 |
#設置檔案的位置
|
|
|
642 |
$result["content"]=$conf["csvFilePathAndName"];
|
| 226 |
liveuser |
643 |
|
| 3 |
liveuser |
644 |
#回傳結果
|
|
|
645 |
return $result;
|
| 226 |
liveuser |
646 |
|
| 3 |
liveuser |
647 |
}#if end
|
| 226 |
liveuser |
648 |
|
| 3 |
liveuser |
649 |
}#if end
|
|
|
650 |
|
|
|
651 |
#要求使用者下載該檔案
|
|
|
652 |
#說明:
|
|
|
653 |
#要求使用者Download某檔案
|
|
|
654 |
#回傳結果:
|
|
|
655 |
#$result["status"],字串,"true"爲成功,"false"反之失敗
|
|
|
656 |
#$result["error"],陣列,錯誤訊息
|
|
|
657 |
#$result["function"],字串,當前執行的函數名稱.
|
|
|
658 |
#必填的參數:
|
|
|
659 |
$conf["header"]["askUserDownloadFile"]["filePositionAndName"]=$conf["csvFilePathAndName"];#檔案的位置與名稱
|
|
|
660 |
#可省略的參數:
|
|
|
661 |
$conf["header"]["askUserDownloadFile"]["fileDisplayName"]=basename($conf["csvFilePathAndName"]);#要顯示的檔案名稱,若要放中文請將其文字放在()裏面,這樣種文字才會顯現。預設為 basename($conf["filePositionAndName"]);
|
|
|
662 |
#$conf["header"]["askUserDownloadFile"]["mimeType"],字串,檔案的mimeType,預設為"application/octet-stream".
|
|
|
663 |
#$conf["header"]["askUserDownloadFile"]["mimeType"]="application/octet-stream";s
|
|
|
664 |
#參考資料來源:
|
|
|
665 |
#http:#php.net/manual/en/function.readfile.php
|
|
|
666 |
$askUserDownloadFile=header::askUserDownloadFile($conf["header"]["askUserDownloadFile"]);
|
|
|
667 |
unset($conf["header"]["askUserDownloadFile"]);
|
| 226 |
liveuser |
668 |
|
| 3 |
liveuser |
669 |
#如果要求下載檔案失敗
|
|
|
670 |
if($askUserDownloadFile["status"]=="false"){
|
| 226 |
liveuser |
671 |
|
| 3 |
liveuser |
672 |
#設置執行正常
|
|
|
673 |
$result["status"]="false";
|
| 226 |
liveuser |
674 |
|
| 3 |
liveuser |
675 |
#設置檔案的位置
|
|
|
676 |
$result["content"]=$askUserDownloadFile;
|
| 226 |
liveuser |
677 |
|
| 3 |
liveuser |
678 |
#回傳結果
|
|
|
679 |
return $result;
|
| 226 |
liveuser |
680 |
|
| 3 |
liveuser |
681 |
}#if end
|
| 226 |
liveuser |
682 |
|
| 3 |
liveuser |
683 |
#設置執行正常
|
|
|
684 |
$result["status"]="true";
|
| 226 |
liveuser |
685 |
|
| 3 |
liveuser |
686 |
#設置檔案的位置
|
|
|
687 |
$result["content"]=$conf["csvFilePathAndName"];
|
| 226 |
liveuser |
688 |
|
| 3 |
liveuser |
689 |
#回傳結果
|
|
|
690 |
return $result;
|
| 226 |
liveuser |
691 |
|
| 3 |
liveuser |
692 |
}#function create end
|
| 226 |
liveuser |
693 |
|
| 3 |
liveuser |
694 |
/*
|
|
|
695 |
#函式說明:
|
|
|
696 |
#讀取csv檔案的內容
|
|
|
697 |
#回傳結果:
|
|
|
698 |
#$result["status"],執行是否正常,"true"代表正常;"false"代表不正常.
|
|
|
699 |
#$result["error"],錯誤訊息陣列.
|
|
|
700 |
#$result["function"],當前執行的函數名稱.
|
|
|
701 |
#$result["csvFileContent"],csv檔案內容的陣列.
|
|
|
702 |
#$result["csvFileContent"]["$i"]["$j"]代表第$i+1列第$j+1欄位的內容.
|
|
|
703 |
#如果 $conf["firstLineVarName"]爲"true"的話則會回傳 $result["csvFileContent"]["第幾列"]["第一列各個欄位的名稱"]
|
|
|
704 |
#$result["lineArray"],csv檔案逐列內容的陣列.
|
|
|
705 |
#$result["lineArrayCount"],總共幾列資料.
|
|
|
706 |
#必填參數:
|
|
|
707 |
#$conf["csvFilePositionAndName"],字串,csv檔案的位置
|
|
|
708 |
$conf["csvFilePositionAndName"]="";
|
|
|
709 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
710 |
$conf["fileArgu"]=__FILE__;
|
|
|
711 |
#可省略參數:
|
|
|
712 |
#$conf["firstLineVarName"],字串,第一行是否爲變數名稱(各個欄位的名稱),"預設為true".
|
|
|
713 |
#$conf["firstLineVarName"]="true";
|
|
|
714 |
#參考資料:
|
|
|
715 |
#http://www.php.net/manual/en/function.str-split.php
|
|
|
716 |
#http://chuangmaster.pixnet.net/blog/post/33560606-%5B%E8%BD%89%E8%B2%BC%5D%E9%97%9C%E6%96%BC%E5%9B%9E%E8%BB%8A(%5Cr)%E8%88%87%E6%8F%9B%E8%A1%8C(%5Cn)
|
|
|
717 |
#http://php.net/manual/en/function.fgetcsv.php
|
|
|
718 |
#備註:
|
|
|
719 |
#可用fgetcsv函數替代
|
|
|
720 |
*/
|
|
|
721 |
public static function loadCsvFile(&$conf){
|
| 226 |
liveuser |
722 |
|
| 3 |
liveuser |
723 |
#初始化要回傳的內容
|
|
|
724 |
$result=array();
|
| 226 |
liveuser |
725 |
|
| 3 |
liveuser |
726 |
#取得當前執行的函數名稱
|
|
|
727 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
728 |
|
| 3 |
liveuser |
729 |
#如果 $conf 不為陣列
|
|
|
730 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
731 |
|
| 3 |
liveuser |
732 |
#設置執行失敗
|
|
|
733 |
$result["status"]="false";
|
| 226 |
liveuser |
734 |
|
| 3 |
liveuser |
735 |
#設置執行錯誤訊息
|
|
|
736 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
737 |
|
|
|
738 |
#如果傳入的參數為 null
|
|
|
739 |
if($conf==null){
|
| 226 |
liveuser |
740 |
|
| 3 |
liveuser |
741 |
#設置執行錯誤訊息
|
|
|
742 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
743 |
|
| 3 |
liveuser |
744 |
}#if end
|
|
|
745 |
|
|
|
746 |
#回傳結果
|
|
|
747 |
return $result;
|
| 226 |
liveuser |
748 |
|
|
|
749 |
}#if end
|
|
|
750 |
|
| 3 |
liveuser |
751 |
#檢查參數
|
|
|
752 |
#函式說明:
|
|
|
753 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
754 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
755 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
756 |
#$result["function"],當前執行的函式名稱.
|
|
|
757 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
758 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
759 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
760 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
761 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
762 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
763 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
764 |
#必填寫的參數:
|
|
|
765 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
766 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
767 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
768 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("csvFilePositionAndName","fileArgu");
|
| 226 |
liveuser |
769 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
770 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
771 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
772 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
773 |
#可以省略的參數:
|
|
|
774 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
775 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
776 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
777 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("firstLineVarName");
|
| 226 |
liveuser |
778 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
779 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
780 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
781 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
|
|
|
782 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
783 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
784 |
#參考資料來源:
|
|
|
785 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
786 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
787 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
788 |
|
| 3 |
liveuser |
789 |
#如果檢查失敗
|
|
|
790 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
791 |
|
| 3 |
liveuser |
792 |
#設置執行不正常
|
|
|
793 |
$result["status"]="false";
|
| 226 |
liveuser |
794 |
|
| 3 |
liveuser |
795 |
#設置錯誤訊息
|
|
|
796 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
797 |
|
| 3 |
liveuser |
798 |
#回傳結果
|
|
|
799 |
return $result;
|
| 226 |
liveuser |
800 |
|
|
|
801 |
}#if end
|
|
|
802 |
|
| 3 |
liveuser |
803 |
#如果檢查不通過
|
|
|
804 |
if($checkResult["passed"]=="false"){
|
|
|
805 |
|
|
|
806 |
#設置執行不正常
|
|
|
807 |
$result["status"]="false";
|
| 226 |
liveuser |
808 |
|
| 3 |
liveuser |
809 |
#設置錯誤訊息
|
|
|
810 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
811 |
|
| 3 |
liveuser |
812 |
#回傳結果
|
|
|
813 |
return $result;
|
|
|
814 |
|
| 226 |
liveuser |
815 |
}#if end
|
|
|
816 |
|
| 3 |
liveuser |
817 |
#依據行號取得檔案所有內容
|
|
|
818 |
#函式說明:
|
|
|
819 |
#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
|
|
|
820 |
#回傳的變數說明:
|
|
|
821 |
#$result["fileContent"],爲檔案的內容陣列
|
|
|
822 |
#$result["lineCount"],爲檔案內容總共的行數
|
|
|
823 |
#必填的參數:
|
|
|
824 |
$conf["fileAccess"]["getFileContent"]["filePositionAndName"]=$conf["csvFilePositionAndName"];#爲檔案的位置以及名稱
|
|
|
825 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
826 |
$conf["fileAccess"]["getFileContent"]["fileArgu"]=$conf["fileArgu"];
|
|
|
827 |
#參考資料:
|
|
|
828 |
#file():取得檔案內容的行數
|
|
|
829 |
#http:#php.net/manual/en/function.file.php
|
|
|
830 |
$fileContentArray=fileAccess::getFileContent($conf["fileAccess"]["getFileContent"]);
|
|
|
831 |
unset($conf["fileAccess"]["getFileContent"]);
|
| 226 |
liveuser |
832 |
|
| 3 |
liveuser |
833 |
#如果 $fileContentArray["status"] 等於 "false" 則代表檔案內容抓取失敗
|
|
|
834 |
if($fileContentArray["status"]=="false"){
|
|
|
835 |
|
|
|
836 |
#設定執行錯誤識別
|
|
|
837 |
$result["status"]="false";
|
| 226 |
liveuser |
838 |
|
| 3 |
liveuser |
839 |
#記錄錯誤訊息
|
|
|
840 |
$result["error"]=$fileContentArray;
|
|
|
841 |
|
|
|
842 |
#回傳檔案內容
|
|
|
843 |
return $result;
|
|
|
844 |
|
|
|
845 |
}#if end
|
| 226 |
liveuser |
846 |
|
| 3 |
liveuser |
847 |
#初始化csv檔案逐行內容的陣列
|
|
|
848 |
$result["lineArray"]=$fileContentArray["fileContent"];
|
| 226 |
liveuser |
849 |
|
| 3 |
liveuser |
850 |
#取得內容有幾列
|
|
|
851 |
$result["lineArrayCount"]=$fileContentArray["lineCount"];
|
| 226 |
liveuser |
852 |
|
| 3 |
liveuser |
853 |
#初始化第一行的內容
|
|
|
854 |
$firstLineContent=array();
|
|
|
855 |
|
|
|
856 |
#有幾行就執行幾次
|
|
|
857 |
for($i=0;$i<$result["lineArrayCount"];$i++){
|
|
|
858 |
|
|
|
859 |
#將每行的文字一個個字分開
|
|
|
860 |
$lineContentArray=str_split($result["lineArray"][$i],1);
|
|
|
861 |
|
|
|
862 |
#取得陣列裏面字的長度
|
|
|
863 |
$wordCount=count($lineContentArray);
|
| 226 |
liveuser |
864 |
|
| 3 |
liveuser |
865 |
#初始化開始紀錄欄位內容的識別
|
|
|
866 |
#"false"代表目前沒有進行紀錄
|
|
|
867 |
#"true"代表目前在進行紀錄
|
|
|
868 |
$wordStart="false";
|
| 226 |
liveuser |
869 |
|
| 3 |
liveuser |
870 |
#初始化用於確保單欄裡面可以多逗號的雙引號「"」
|
|
|
871 |
#"false"代表目前在 「"」 外
|
|
|
872 |
#"true"代表目前在 「"」內
|
|
|
873 |
$testDelimiter="false";
|
| 226 |
liveuser |
874 |
|
| 3 |
liveuser |
875 |
#初始化欄位內容的陣列
|
|
|
876 |
$wordArray=array();
|
| 226 |
liveuser |
877 |
|
| 3 |
liveuser |
878 |
#暫存形成字的字串
|
|
|
879 |
$wordClip="";
|
| 226 |
liveuser |
880 |
|
| 3 |
liveuser |
881 |
#有幾個字就執行幾次
|
|
|
882 |
for($j=0;$j<$wordCount;$j++){
|
|
|
883 |
|
| 226 |
liveuser |
884 |
#如果
|
| 3 |
liveuser |
885 |
#$wordStart 為 "false"
|
|
|
886 |
#$testDelimiter 為 "false" 且
|
|
|
887 |
#$lineContentArray[$j] 等於 「"」
|
|
|
888 |
if($wordStart=="false" && $testDelimiter=="false" && $lineContentArray[$j]=="\"" ){
|
| 226 |
liveuser |
889 |
|
| 3 |
liveuser |
890 |
#進入""範圍裡面
|
|
|
891 |
$testDelimiter="true";
|
| 226 |
liveuser |
892 |
|
| 3 |
liveuser |
893 |
#開始讀取欄位內容
|
|
|
894 |
$wordStart="true";
|
| 226 |
liveuser |
895 |
|
| 3 |
liveuser |
896 |
#跳到下一個迴圈
|
|
|
897 |
continue;
|
| 226 |
liveuser |
898 |
|
| 3 |
liveuser |
899 |
}#if end
|
| 226 |
liveuser |
900 |
|
| 3 |
liveuser |
901 |
#如果 $testDelimiter 為 "true" 且
|
|
|
902 |
#$wordStart 為 "true" 且
|
|
|
903 |
#$lineContentArray[$j] 等於 「"」
|
|
|
904 |
if($wordStart=="true" && $testDelimiter=="true" && $lineContentArray[$j]=="\"" ){
|
| 226 |
liveuser |
905 |
|
| 3 |
liveuser |
906 |
#echo "<br>離開\"";
|
| 226 |
liveuser |
907 |
|
| 3 |
liveuser |
908 |
#離開""範圍裡面
|
|
|
909 |
$testDelimiter="false";
|
| 226 |
liveuser |
910 |
|
| 3 |
liveuser |
911 |
#停止讀取欄位內容
|
|
|
912 |
$wordStart="false";
|
| 226 |
liveuser |
913 |
|
| 3 |
liveuser |
914 |
#如果是最後一個字
|
|
|
915 |
if($j==$wordCount-1){
|
| 226 |
liveuser |
916 |
|
| 3 |
liveuser |
917 |
#將取得的片段內容儲存成一個欄位
|
|
|
918 |
$wordArray[]=$wordClip;
|
|
|
919 |
|
|
|
920 |
#將片段的內容初始化
|
|
|
921 |
$wordClip="";
|
| 226 |
liveuser |
922 |
|
| 3 |
liveuser |
923 |
#跳到下一個迴圈
|
|
|
924 |
continue;
|
| 226 |
liveuser |
925 |
|
| 3 |
liveuser |
926 |
}#if end
|
| 226 |
liveuser |
927 |
|
| 3 |
liveuser |
928 |
#跳到下一個迴圈
|
|
|
929 |
continue;
|
| 226 |
liveuser |
930 |
|
| 3 |
liveuser |
931 |
}#if end
|
|
|
932 |
|
|
|
933 |
#如果
|
|
|
934 |
#$wordStart 等於 "true" 或 $testDelimiter 等於 "true"
|
|
|
935 |
#或
|
|
|
936 |
#$wordStart 等於 "false" 且 $testDelimiter 等於 "false" 且 $lineContentArray[$j] 不等於 ","
|
|
|
937 |
if(
|
|
|
938 |
($wordStart=="true" || $testDelimiter=="true")
|
|
|
939 |
||
|
|
|
940 |
($wordStart=="false" && $testDelimiter=="false" && $lineContentArray[$j]!=",")
|
|
|
941 |
){
|
| 226 |
liveuser |
942 |
|
| 3 |
liveuser |
943 |
#暫存形成字的字串
|
|
|
944 |
$wordClip=$wordClip.$lineContentArray[$j];
|
| 226 |
liveuser |
945 |
|
| 3 |
liveuser |
946 |
#echo "<br>讀取".$lineContentArray[$j];
|
|
|
947 |
#echo "<br>暫存欄位內容變成".$wordClip;
|
| 226 |
liveuser |
948 |
|
| 3 |
liveuser |
949 |
#如果是最後一個字
|
|
|
950 |
if($j==$wordCount-1){
|
| 226 |
liveuser |
951 |
|
| 3 |
liveuser |
952 |
#將取得的片段內容儲存成一個欄位
|
|
|
953 |
$wordArray[]=$wordClip;
|
|
|
954 |
|
|
|
955 |
#將片段的內容初始化
|
|
|
956 |
$wordClip="";
|
| 226 |
liveuser |
957 |
|
| 3 |
liveuser |
958 |
#將欄位開始設為 "false"
|
|
|
959 |
$wordStart="false";
|
| 226 |
liveuser |
960 |
|
| 3 |
liveuser |
961 |
#跳到下一個迴圈
|
|
|
962 |
continue;
|
| 226 |
liveuser |
963 |
|
| 3 |
liveuser |
964 |
}#if end
|
| 226 |
liveuser |
965 |
|
| 3 |
liveuser |
966 |
#跳到下一個迴圈
|
|
|
967 |
continue;
|
| 226 |
liveuser |
968 |
|
| 3 |
liveuser |
969 |
}#if end
|
| 226 |
liveuser |
970 |
|
| 3 |
liveuser |
971 |
#如果 $lineContentArray[$j]等於 「,」 且 $testDelimiter 等於 "false"
|
|
|
972 |
if($lineContentArray[$j]=="," && $testDelimiter=="false" ){
|
| 226 |
liveuser |
973 |
|
| 3 |
liveuser |
974 |
#將取得的片段內容儲存成一個欄位
|
|
|
975 |
$wordArray[]=$wordClip;
|
|
|
976 |
|
|
|
977 |
#echo "<br>遇到逗號,欄位內容讀取完畢";
|
|
|
978 |
|
|
|
979 |
#將片段的內容初始化
|
|
|
980 |
$wordClip="";
|
| 226 |
liveuser |
981 |
|
| 3 |
liveuser |
982 |
#將欄位開始設為 "false"
|
|
|
983 |
$wordStart="false";
|
| 226 |
liveuser |
984 |
|
| 3 |
liveuser |
985 |
#跳到下一個迴圈
|
|
|
986 |
continue;
|
| 226 |
liveuser |
987 |
|
| 3 |
liveuser |
988 |
}#if end
|
| 226 |
liveuser |
989 |
|
| 3 |
liveuser |
990 |
}#for end
|
|
|
991 |
|
|
|
992 |
#如果目前讀到的是第一行
|
|
|
993 |
if($i==0){
|
|
|
994 |
|
|
|
995 |
#取得第一行的內容
|
|
|
996 |
$firstLineContent=$wordArray;
|
|
|
997 |
|
|
|
998 |
}#if end
|
|
|
999 |
|
|
|
1000 |
#如果 $conf["firstLineVarName"] 等於 true
|
|
|
1001 |
if($conf["firstLineVarName"]=="true"){
|
| 226 |
liveuser |
1002 |
|
| 3 |
liveuser |
1003 |
#將 $wordArray 的 key 更改爲第一行的欄位內容
|
|
|
1004 |
#函式說明:
|
|
|
1005 |
#將陣列的key重新排序,然後回傳,以便後續存取。
|
|
|
1006 |
#也可以指定key的內容,但一定要跟元素數量相同。
|
|
|
1007 |
#若指定了key的名稱,則 $result["dataContent"] 會變成 $result["dataContent"]["指定的key名稱"]
|
|
|
1008 |
#回傳的解果:
|
|
|
1009 |
#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
|
|
|
1010 |
#$result["error"],執行錯誤的訊息.
|
|
|
1011 |
#$result["function"],當前執行的函數名稱.
|
|
|
1012 |
#$result["dataContent"],儲存陣列元素的內容.
|
|
|
1013 |
#必填的參數:
|
|
|
1014 |
$conf["arrays"]["createV2"]["arrayContent"]=$wordArray;#陣列變數
|
|
|
1015 |
#可省略的參數:
|
|
|
1016 |
$conf["arrays"]["createV2"]["specifiesKeyArray"]=$firstLineContent;#指定key的名稱,須與$conf["arrayContent"]的元素數量相同
|
|
|
1017 |
$temp=arrays::createV2($conf["arrays"]["createV2"]);
|
|
|
1018 |
unset($conf["arrays"]["createV2"]);
|
|
|
1019 |
|
|
|
1020 |
#如果建立陣列失敗
|
|
|
1021 |
if($temp["status"]=="false"){
|
| 226 |
liveuser |
1022 |
|
| 3 |
liveuser |
1023 |
#設置執行錯誤
|
|
|
1024 |
$result["status"]="false";
|
| 226 |
liveuser |
1025 |
|
| 3 |
liveuser |
1026 |
#設置錯誤訊息
|
|
|
1027 |
$result["error"]=$temp;
|
| 226 |
liveuser |
1028 |
|
| 3 |
liveuser |
1029 |
#回傳結果
|
|
|
1030 |
return $result;
|
| 226 |
liveuser |
1031 |
|
| 3 |
liveuser |
1032 |
}#if end
|
|
|
1033 |
|
| 226 |
liveuser |
1034 |
#取得更改後的結果
|
| 3 |
liveuser |
1035 |
$wordArray=$temp["dataContent"];
|
|
|
1036 |
|
| 226 |
liveuser |
1037 |
}#if end
|
| 3 |
liveuser |
1038 |
|
|
|
1039 |
#取得該行的各欄位內容
|
|
|
1040 |
$result["csvFileContent"][$i]=$wordArray;
|
| 226 |
liveuser |
1041 |
|
| 3 |
liveuser |
1042 |
}#for end
|
| 226 |
liveuser |
1043 |
|
| 3 |
liveuser |
1044 |
#執行到這邊代表執行成功
|
|
|
1045 |
$result["status"]="true";
|
| 226 |
liveuser |
1046 |
|
| 3 |
liveuser |
1047 |
#回傳csv檔案的內容
|
|
|
1048 |
return $result;
|
| 226 |
liveuser |
1049 |
|
| 3 |
liveuser |
1050 |
}#function loadCsvFile end
|
| 226 |
liveuser |
1051 |
|
| 3 |
liveuser |
1052 |
/*
|
|
|
1053 |
#函式說明:
|
|
|
1054 |
#讀取csv檔案的內容
|
|
|
1055 |
#回傳結果:
|
|
|
1056 |
#$result["status"],執行是否正常,"true"代表正常;"false"代表不正常.
|
|
|
1057 |
#$result["error"],錯誤訊息陣列.
|
|
|
1058 |
#$result["function"],當前執行的函數名稱
|
|
|
1059 |
#$result["content"],csv檔案內容的陣列
|
|
|
1060 |
#$result["content"]["$i"]["$j"]代表第$i+1列第$j+1欄位的內容.
|
|
|
1061 |
#如果 $conf["firstLineVarName"]爲"true"的話則會多回傳 $result["content"]["第幾列"]["第一列各個欄位的名稱"]
|
|
|
1062 |
#$result["title"],欄位的名稱
|
|
|
1063 |
#$result["lineCount"],總共幾列資料
|
|
|
1064 |
#必填參數:
|
|
|
1065 |
#$conf["csvFilePositionAndName"],字串,csv檔案的位置
|
|
|
1066 |
$conf["csvFilePositionAndName"]="";
|
|
|
1067 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1068 |
$conf["fileArgu"]=__FILE__;
|
|
|
1069 |
#可省略參數:
|
|
|
1070 |
#$conf["firstLineVarName"]="true";#第一行是否爲變數名稱(各個欄位的名稱),預設為"true".
|
|
|
1071 |
#參考資料:
|
|
|
1072 |
#http://www.php.net/manual/en/function.str-split.php
|
|
|
1073 |
#http://php.net/manual/en/function.fgetcsv.php
|
|
|
1074 |
#備註:
|
|
|
1075 |
#無.
|
|
|
1076 |
*/
|
|
|
1077 |
public static function read(&$conf){
|
| 226 |
liveuser |
1078 |
|
| 3 |
liveuser |
1079 |
#初始化要回傳的內容
|
|
|
1080 |
$result=array();
|
| 226 |
liveuser |
1081 |
|
| 3 |
liveuser |
1082 |
#設置當前函數名稱
|
|
|
1083 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
1084 |
|
| 3 |
liveuser |
1085 |
#如果 $conf 不為陣列
|
|
|
1086 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
1087 |
|
| 3 |
liveuser |
1088 |
#設置執行失敗
|
|
|
1089 |
$result["status"]="false";
|
| 226 |
liveuser |
1090 |
|
| 3 |
liveuser |
1091 |
#設置執行錯誤訊息
|
|
|
1092 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1093 |
|
|
|
1094 |
#如果傳入的參數為 null
|
|
|
1095 |
if($conf==null){
|
| 226 |
liveuser |
1096 |
|
| 3 |
liveuser |
1097 |
#設置執行錯誤訊息
|
|
|
1098 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
1099 |
|
| 3 |
liveuser |
1100 |
}#if end
|
|
|
1101 |
|
|
|
1102 |
#回傳結果
|
|
|
1103 |
return $result;
|
| 226 |
liveuser |
1104 |
|
|
|
1105 |
}#if end
|
|
|
1106 |
|
| 3 |
liveuser |
1107 |
#檢查參數
|
|
|
1108 |
#檢查參數
|
|
|
1109 |
#函式說明:
|
|
|
1110 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1111 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1112 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1113 |
#$result["function"],當前執行的函式名稱.
|
|
|
1114 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1115 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1116 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1117 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1118 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1119 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1120 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1121 |
#必填寫的參數:
|
|
|
1122 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1123 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1124 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1125 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("csvFilePositionAndName","fileArgu");
|
| 226 |
liveuser |
1126 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1127 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
1128 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1129 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1130 |
#可以省略的參數:
|
|
|
1131 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
1132 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1133 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1134 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("firstLineVarName");
|
| 226 |
liveuser |
1135 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1136 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
1137 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1138 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
|
|
|
1139 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1140 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1141 |
#參考資料來源:
|
|
|
1142 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1143 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1144 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
1145 |
|
| 3 |
liveuser |
1146 |
#如果檢查失敗
|
|
|
1147 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
1148 |
|
| 3 |
liveuser |
1149 |
#設置執行不正常
|
|
|
1150 |
$result["status"]="false";
|
| 226 |
liveuser |
1151 |
|
| 3 |
liveuser |
1152 |
#設置錯誤訊息
|
|
|
1153 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1154 |
|
| 3 |
liveuser |
1155 |
#回傳結果
|
|
|
1156 |
return $result;
|
| 226 |
liveuser |
1157 |
|
|
|
1158 |
}#if end
|
|
|
1159 |
|
| 3 |
liveuser |
1160 |
#如果檢查不通過
|
|
|
1161 |
if($checkResult["passed"]=="false"){
|
|
|
1162 |
|
|
|
1163 |
#設置執行不正常
|
|
|
1164 |
$result["status"]="false";
|
| 226 |
liveuser |
1165 |
|
| 3 |
liveuser |
1166 |
#設置錯誤訊息
|
|
|
1167 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1168 |
|
| 3 |
liveuser |
1169 |
#回傳結果
|
|
|
1170 |
return $result;
|
|
|
1171 |
|
| 226 |
liveuser |
1172 |
}#if end
|
|
|
1173 |
|
| 3 |
liveuser |
1174 |
#初始化用來儲存csv內容的變數
|
|
|
1175 |
$csvFileContent=array();
|
| 226 |
liveuser |
1176 |
|
| 3 |
liveuser |
1177 |
#如果開啓 $conf["csvFilePositionAndName"] 成功
|
|
|
1178 |
if(($handle=fopen($conf["csvFilePositionAndName"],"r"))!==FALSE){
|
| 226 |
liveuser |
1179 |
|
| 3 |
liveuser |
1180 |
#如果檔案還有內容
|
|
|
1181 |
while(($data=fgetcsv($handle))!==FALSE){
|
| 226 |
liveuser |
1182 |
|
| 3 |
liveuser |
1183 |
#儲存該行內容
|
|
|
1184 |
$csvFileContent[]=$data;
|
| 226 |
liveuser |
1185 |
|
| 3 |
liveuser |
1186 |
}#while end
|
| 226 |
liveuser |
1187 |
|
| 3 |
liveuser |
1188 |
}#if end
|
| 226 |
liveuser |
1189 |
|
| 3 |
liveuser |
1190 |
#反之
|
|
|
1191 |
else{
|
| 226 |
liveuser |
1192 |
|
| 3 |
liveuser |
1193 |
#設置錯誤識別
|
|
|
1194 |
$result["status"]="false";
|
| 226 |
liveuser |
1195 |
|
| 3 |
liveuser |
1196 |
#設置錯訊息
|
|
|
1197 |
$resukt["error"][]="檔案".$conf["csvFilePositionAndName"]."開啓失敗!";
|
| 226 |
liveuser |
1198 |
|
| 3 |
liveuser |
1199 |
#回傳結果
|
|
|
1200 |
return $result;
|
| 226 |
liveuser |
1201 |
|
| 3 |
liveuser |
1202 |
}#else end
|
| 226 |
liveuser |
1203 |
|
| 3 |
liveuser |
1204 |
#初始化欄位標題陣列
|
| 226 |
liveuser |
1205 |
$title=array();
|
|
|
1206 |
|
| 3 |
liveuser |
1207 |
#如果 $conf["firstLineVarName"] 爲 "true"
|
|
|
1208 |
if($conf["firstLineVarName"]=="true"){
|
| 226 |
liveuser |
1209 |
|
| 3 |
liveuser |
1210 |
#迴圈,執行欄位數次數
|
|
|
1211 |
for($i=0;$i<count($csvFileContent[0]);$i++){
|
| 226 |
liveuser |
1212 |
|
| 3 |
liveuser |
1213 |
#取得欄位名稱
|
|
|
1214 |
$title[]=$csvFileContent[0][$i];
|
| 226 |
liveuser |
1215 |
|
| 3 |
liveuser |
1216 |
}#for end
|
| 226 |
liveuser |
1217 |
|
| 3 |
liveuser |
1218 |
#取得欄位名稱
|
|
|
1219 |
$result["title"]=$title;
|
| 226 |
liveuser |
1220 |
|
| 3 |
liveuser |
1221 |
#用欄位名稱作爲key來儲存每列內容
|
|
|
1222 |
#迴圈,執行列數次數
|
|
|
1223 |
for($i=1;$i<count($csvFileContent);$i++){
|
| 226 |
liveuser |
1224 |
|
| 3 |
liveuser |
1225 |
#迴圈,執行欄位數目次
|
|
|
1226 |
for($j=0;$j<count($csvFileContent[0]);$j++){
|
| 226 |
liveuser |
1227 |
|
| 3 |
liveuser |
1228 |
#用數字作爲key來儲存內容
|
|
|
1229 |
$result["content"][$j][$i-1]=$csvFileContent[$i][$j];
|
| 226 |
liveuser |
1230 |
|
| 3 |
liveuser |
1231 |
#用欄位名稱作爲key來儲存內容
|
|
|
1232 |
$result["content"][$title[$j]][$i-1]=$csvFileContent[$i][$j];
|
| 226 |
liveuser |
1233 |
|
| 3 |
liveuser |
1234 |
}#for end
|
| 226 |
liveuser |
1235 |
|
| 3 |
liveuser |
1236 |
}#for end
|
| 226 |
liveuser |
1237 |
|
| 3 |
liveuser |
1238 |
}#if end
|
| 226 |
liveuser |
1239 |
|
| 3 |
liveuser |
1240 |
#反之直接儲存 fgetcsv 取得的內容
|
|
|
1241 |
else{
|
| 226 |
liveuser |
1242 |
|
| 3 |
liveuser |
1243 |
#取得csv檔案內容
|
|
|
1244 |
$result["content"]=$csvFileContent;
|
| 226 |
liveuser |
1245 |
|
| 3 |
liveuser |
1246 |
}#else end
|
| 226 |
liveuser |
1247 |
|
| 3 |
liveuser |
1248 |
#取得資料筆數
|
|
|
1249 |
$result["lineCount"]=count($result["content"])/2;
|
| 226 |
liveuser |
1250 |
|
| 3 |
liveuser |
1251 |
#設置執行正常
|
|
|
1252 |
$result["status"]="true";
|
| 226 |
liveuser |
1253 |
|
| 3 |
liveuser |
1254 |
#回傳結果
|
|
|
1255 |
return $result;
|
| 226 |
liveuser |
1256 |
|
| 3 |
liveuser |
1257 |
}#funciton read end
|
| 226 |
liveuser |
1258 |
|
| 3 |
liveuser |
1259 |
/*
|
|
|
1260 |
#函式說明:
|
|
|
1261 |
#計屬csv檔裡面的關鍵字,亦即內容剛好等於關鍵字的次數.
|
|
|
1262 |
#回傳的結果:
|
|
|
1263 |
#$result["status"],執行正常與否,"true"為正常,"false"為不正常.
|
|
|
1264 |
#$result["error"],錯誤訊息陣列.
|
|
|
1265 |
#$result["content"],找到的關鍵字數量.
|
|
|
1266 |
#$result["function"],當前執行的函數名稱.
|
|
|
1267 |
#必填參數:
|
|
|
1268 |
#$conf["csvFileAddress"],字串,csv檔案的位置與名稱.
|
|
|
1269 |
$conf["csvFileAddress"]="";
|
|
|
1270 |
#$conf["keyWord"],字串,要尋找的關鍵字.
|
|
|
1271 |
$conf["keyWord"]="";
|
|
|
1272 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1273 |
$conf["fileArgu"]=__FILE__;
|
| 226 |
liveuser |
1274 |
#可省略參數:
|
| 3 |
liveuser |
1275 |
#$conf["firstLineVarName"],字串,第一行是否爲變數名稱(各個欄位的名稱),"true"表示第一列不在搜尋範圍裡,預設為"true".
|
|
|
1276 |
#$conf["firstLineVarName"]="true";
|
|
|
1277 |
#參考資料:
|
|
|
1278 |
#無.
|
|
|
1279 |
#備註:
|
|
|
1280 |
#無.
|
|
|
1281 |
*/
|
|
|
1282 |
public static function keyWordsCount(&$conf){
|
| 226 |
liveuser |
1283 |
|
| 3 |
liveuser |
1284 |
#初始化要回傳的變數
|
|
|
1285 |
$reuslt=array();
|
| 226 |
liveuser |
1286 |
|
| 3 |
liveuser |
1287 |
#取得當前執行的函數名稱
|
|
|
1288 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
1289 |
|
| 3 |
liveuser |
1290 |
#如果 $conf 不為陣列
|
|
|
1291 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
1292 |
|
| 3 |
liveuser |
1293 |
#設置執行失敗
|
|
|
1294 |
$result["status"]="false";
|
| 226 |
liveuser |
1295 |
|
| 3 |
liveuser |
1296 |
#設置執行錯誤訊息
|
|
|
1297 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1298 |
|
|
|
1299 |
#如果傳入的參數為 null
|
|
|
1300 |
if($conf==null){
|
| 226 |
liveuser |
1301 |
|
| 3 |
liveuser |
1302 |
#設置執行錯誤訊息
|
|
|
1303 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
1304 |
|
| 3 |
liveuser |
1305 |
}#if end
|
|
|
1306 |
|
|
|
1307 |
#回傳結果
|
|
|
1308 |
return $result;
|
| 226 |
liveuser |
1309 |
|
| 3 |
liveuser |
1310 |
}#if end
|
| 226 |
liveuser |
1311 |
|
| 3 |
liveuser |
1312 |
#初始化計數關鍵字的變數
|
|
|
1313 |
$result["content"]=0;
|
| 226 |
liveuser |
1314 |
|
| 3 |
liveuser |
1315 |
#檢查參數
|
|
|
1316 |
#函式說明:
|
|
|
1317 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1318 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1319 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1320 |
#$result["function"],當前執行的函式名稱.
|
|
|
1321 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1322 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1323 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1324 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1325 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1326 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1327 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1328 |
#必填寫的參數:
|
|
|
1329 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1330 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1331 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1332 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("csvFileAddress","keyWord","fileArgu");
|
| 226 |
liveuser |
1333 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1334 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
|
|
|
1335 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1336 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1337 |
#可以省略的參數:
|
|
|
1338 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
1339 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1340 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1341 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("firstLineVarName");
|
| 226 |
liveuser |
1342 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1343 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
1344 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1345 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
|
|
|
1346 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1347 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1348 |
#參考資料來源:
|
|
|
1349 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1350 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1351 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
1352 |
|
| 3 |
liveuser |
1353 |
#如果檢查失敗
|
|
|
1354 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
1355 |
|
| 3 |
liveuser |
1356 |
#設置執行不正常
|
|
|
1357 |
$result["status"]="false";
|
| 226 |
liveuser |
1358 |
|
| 3 |
liveuser |
1359 |
#設置錯誤訊息
|
|
|
1360 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1361 |
|
| 3 |
liveuser |
1362 |
#回傳結果
|
|
|
1363 |
return $result;
|
| 226 |
liveuser |
1364 |
|
|
|
1365 |
}#if end
|
|
|
1366 |
|
| 3 |
liveuser |
1367 |
#如果檢查不通過
|
|
|
1368 |
if($checkResult["passed"]=="false"){
|
|
|
1369 |
|
|
|
1370 |
#設置執行不正常
|
|
|
1371 |
$result["status"]="false";
|
| 226 |
liveuser |
1372 |
|
| 3 |
liveuser |
1373 |
#設置錯誤訊息
|
|
|
1374 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1375 |
|
| 3 |
liveuser |
1376 |
#回傳結果
|
|
|
1377 |
return $result;
|
|
|
1378 |
|
|
|
1379 |
}#if end
|
| 226 |
liveuser |
1380 |
|
| 3 |
liveuser |
1381 |
#讀座位表csv檔
|
|
|
1382 |
#涵式說明:
|
|
|
1383 |
#讀取csv檔案的內容
|
|
|
1384 |
#回傳得結果:
|
|
|
1385 |
#$result["status"],執行是否正常,"true"代表正常;"false"代表不正常.
|
|
|
1386 |
#$result["error"],錯誤訊息陣列.
|
|
|
1387 |
#$result["function"],當前執行的函數名稱.
|
|
|
1388 |
#$result["csvFileContent"],csv檔案內容的陣列.
|
|
|
1389 |
#$result["csvFileContent"]["$i"]["$j"]代表第$i+1列第$j+1欄位的內容.
|
|
|
1390 |
#如果 $conf["firstLineVarName"]爲"true"的話則會多回傳 $result["csvFileContent"]["第幾列"]["第一列各個欄位的名稱"]
|
|
|
1391 |
#$result["lineArray"],csv檔案逐列內容的陣列.
|
|
|
1392 |
#$result["lineArrayCount"],總共幾列資料.
|
|
|
1393 |
#必填的參數:
|
|
|
1394 |
$conf["csv"]["loadCsvFile"]["csvFilePositionAndName"]=$conf["csvFileAddress"];#csv檔案的位置
|
|
|
1395 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1396 |
$conf["csv"]["loadCsvFile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1397 |
#可省略的參數:
|
|
|
1398 |
$conf["csv"]["loadCsvFile"]["firstLineVarName"]=$conf["firstLineVarName"];#第一行是否爲變數名稱(各個欄位的名稱)
|
|
|
1399 |
#參考資料來源:
|
|
|
1400 |
#http://www.php.net/manual/en/function.str-split.php
|
|
|
1401 |
#參考資料來源
|
|
|
1402 |
#http://chuangmaster.pixnet.net/blog/post/33560606-%5B%E8%BD%89%E8%B2%BC%5D%E9%97%9C%E6%96%BC%E5%9B%9E%E8%BB%8A(%5Cr)%E8%88%87%E6%8F%9B%E8%A1%8C(%5Cn)
|
|
|
1403 |
$seatMap=csv::loadCsvFile($conf["csv"]["loadCsvFile"]);
|
|
|
1404 |
unset($conf["csv"]["loadCsvFile"]);
|
| 226 |
liveuser |
1405 |
|
| 3 |
liveuser |
1406 |
#如果 $seatMap["status"] 等於 "false"
|
|
|
1407 |
if($seatMap["status"]=="false"){
|
|
|
1408 |
|
|
|
1409 |
#設置執行錯誤
|
|
|
1410 |
$result["status"]="true";
|
| 226 |
liveuser |
1411 |
|
| 3 |
liveuser |
1412 |
#設置錯誤訊息
|
|
|
1413 |
$result["error"]=$seatMap;
|
| 226 |
liveuser |
1414 |
|
| 3 |
liveuser |
1415 |
#回傳結果
|
|
|
1416 |
return $result;
|
| 226 |
liveuser |
1417 |
|
| 3 |
liveuser |
1418 |
}#if end
|
| 226 |
liveuser |
1419 |
|
| 3 |
liveuser |
1420 |
#根據csv檔裡每列內容
|
|
|
1421 |
foreach($seatMap["csvFileContent"] as $row){
|
| 226 |
liveuser |
1422 |
|
| 3 |
liveuser |
1423 |
#根據每列的欄元素
|
| 226 |
liveuser |
1424 |
foreach($row as $col){
|
|
|
1425 |
|
| 3 |
liveuser |
1426 |
#如果欄位內容等於關鍵字
|
|
|
1427 |
if($col==$conf["keyWord"]){
|
| 226 |
liveuser |
1428 |
|
| 3 |
liveuser |
1429 |
#$result["content"]加1
|
|
|
1430 |
$result["content"]++;
|
| 226 |
liveuser |
1431 |
|
| 3 |
liveuser |
1432 |
}#if end
|
| 226 |
liveuser |
1433 |
|
| 3 |
liveuser |
1434 |
}#foreach end
|
| 226 |
liveuser |
1435 |
|
| 3 |
liveuser |
1436 |
}#foreach end
|
| 226 |
liveuser |
1437 |
|
| 3 |
liveuser |
1438 |
#執行到這邊代表執行正常
|
|
|
1439 |
$result["status"]="true";
|
| 226 |
liveuser |
1440 |
|
| 3 |
liveuser |
1441 |
#回傳結果
|
|
|
1442 |
return $result;
|
| 226 |
liveuser |
1443 |
|
| 3 |
liveuser |
1444 |
}#function keyWordCount end
|
| 226 |
liveuser |
1445 |
|
| 3 |
liveuser |
1446 |
/*
|
|
|
1447 |
#函式說明:
|
|
|
1448 |
#將透過db::fastGetDbData取得的資料表資料轉換成用csv::create建立csv檔所需的格式 ,亦即轉換成一個二維陣列記錄每筆資料每個欄位填寫的內容.
|
|
|
1449 |
#回傳結果:
|
|
|
1450 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1451 |
#$result["error"],錯誤訊息陣列.
|
|
|
1452 |
#$result["function"],當前執行的函數名稱.
|
|
|
1453 |
#$result["content"],轉換好要給csv::create建立csv檔所需的格式變數.
|
|
|
1454 |
#必填參數:
|
|
|
1455 |
#$conf["db::fastGetDbData"],陣列,透過db::fastGetDbData取得的回傳結果.
|
|
|
1456 |
$conf["db::fastGetDbData"]=$;
|
|
|
1457 |
#可省略參數:
|
|
|
1458 |
#$conf["columnTitleName"],字串陣列,每個欄位的名稱,預設為資料表欄位的名稱.
|
|
|
1459 |
#$conf["columnTitleName"]=array();
|
|
|
1460 |
#參考資料:
|
|
|
1461 |
#無.
|
|
|
1462 |
#備註:
|
|
|
1463 |
#無.
|
|
|
1464 |
*/
|
|
|
1465 |
public static function dataTable2csvFormat(&$conf){
|
| 226 |
liveuser |
1466 |
|
| 3 |
liveuser |
1467 |
#初始化要回傳的變數
|
|
|
1468 |
$reuslt=array();
|
| 226 |
liveuser |
1469 |
|
| 3 |
liveuser |
1470 |
#取得當前執行的函數名稱
|
|
|
1471 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
1472 |
|
|
|
1473 |
#初始化要回傳的csv格式變數
|
|
|
1474 |
$result["content"]=array();
|
|
|
1475 |
|
| 3 |
liveuser |
1476 |
#如果 $conf 不為陣列
|
|
|
1477 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
1478 |
|
| 3 |
liveuser |
1479 |
#設置執行失敗
|
|
|
1480 |
$result["status"]="false";
|
| 226 |
liveuser |
1481 |
|
| 3 |
liveuser |
1482 |
#設置執行錯誤訊息
|
|
|
1483 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1484 |
|
|
|
1485 |
#如果傳入的參數為 null
|
|
|
1486 |
if($conf==null){
|
| 226 |
liveuser |
1487 |
|
| 3 |
liveuser |
1488 |
#設置執行錯誤訊息
|
|
|
1489 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
1490 |
|
| 3 |
liveuser |
1491 |
}#if end
|
|
|
1492 |
|
|
|
1493 |
#回傳結果
|
|
|
1494 |
return $result;
|
| 226 |
liveuser |
1495 |
|
| 3 |
liveuser |
1496 |
}#if end
|
| 226 |
liveuser |
1497 |
|
| 3 |
liveuser |
1498 |
#檢查參數
|
|
|
1499 |
#函式說明:
|
|
|
1500 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1501 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1502 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1503 |
#$result["function"],當前執行的函式名稱.
|
|
|
1504 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1505 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1506 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1507 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1508 |
#必填寫的參數:
|
|
|
1509 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1510 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1511 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1512 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("db::fastGetDbData");
|
| 226 |
liveuser |
1513 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1514 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
|
|
|
1515 |
#可以省略的參數:
|
|
|
1516 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
1517 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1518 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1519 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("columnTitleName");
|
| 226 |
liveuser |
1520 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1521 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");
|
|
|
1522 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1523 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
1524 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1525 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1526 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1527 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1528 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1529 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
1530 |
|
| 3 |
liveuser |
1531 |
#如果檢查失敗
|
|
|
1532 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
1533 |
|
| 3 |
liveuser |
1534 |
#設置執行錯誤
|
|
|
1535 |
$result["status"]="false";
|
| 226 |
liveuser |
1536 |
|
| 3 |
liveuser |
1537 |
#設置錯誤訊息
|
|
|
1538 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1539 |
|
| 3 |
liveuser |
1540 |
#回傳結果
|
|
|
1541 |
return $result;
|
| 226 |
liveuser |
1542 |
|
| 3 |
liveuser |
1543 |
}#if end
|
| 226 |
liveuser |
1544 |
|
| 3 |
liveuser |
1545 |
#如果檢查不通過
|
|
|
1546 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
1547 |
|
| 3 |
liveuser |
1548 |
#設置執行錯誤
|
|
|
1549 |
$result["status"]="false";
|
| 226 |
liveuser |
1550 |
|
| 3 |
liveuser |
1551 |
#設置錯誤訊息
|
|
|
1552 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1553 |
|
| 3 |
liveuser |
1554 |
#回傳結果
|
|
|
1555 |
return $result;
|
| 226 |
liveuser |
1556 |
|
| 3 |
liveuser |
1557 |
}#if end
|
| 226 |
liveuser |
1558 |
|
| 3 |
liveuser |
1559 |
#如果 $conf["db::fastGetDbData"] 的執行結果不為正常的
|
|
|
1560 |
if($conf["db::fastGetDbData"]["status"]=="false"){
|
| 226 |
liveuser |
1561 |
|
| 3 |
liveuser |
1562 |
#echo "123";
|
| 226 |
liveuser |
1563 |
|
| 3 |
liveuser |
1564 |
#設置執行錯誤
|
|
|
1565 |
$result["status"]="false";
|
| 226 |
liveuser |
1566 |
|
| 3 |
liveuser |
1567 |
#設置錯誤訊息
|
|
|
1568 |
$result["error"]=$conf["db::fastGetDbData"];
|
| 226 |
liveuser |
1569 |
|
| 3 |
liveuser |
1570 |
#回傳結果
|
|
|
1571 |
return $result;
|
| 226 |
liveuser |
1572 |
|
| 3 |
liveuser |
1573 |
}#if end
|
| 226 |
liveuser |
1574 |
|
| 3 |
liveuser |
1575 |
#如果 $conf["db::fastGetDbData"] 的資料筆數為 0
|
|
|
1576 |
if($conf["db::fastGetDbData"]["dataCount"]==0){
|
| 226 |
liveuser |
1577 |
|
| 3 |
liveuser |
1578 |
#echo "123";
|
| 226 |
liveuser |
1579 |
|
| 3 |
liveuser |
1580 |
#設置執行錯誤
|
|
|
1581 |
$result["status"]="false";
|
| 226 |
liveuser |
1582 |
|
| 3 |
liveuser |
1583 |
#設置錯誤訊息
|
|
|
1584 |
$result["error"]=$conf["db::fastGetDbData"];
|
| 226 |
liveuser |
1585 |
|
| 3 |
liveuser |
1586 |
#回傳結果
|
|
|
1587 |
return $result;
|
| 226 |
liveuser |
1588 |
|
| 3 |
liveuser |
1589 |
}#if end
|
| 226 |
liveuser |
1590 |
|
| 3 |
liveuser |
1591 |
#如果沒有設置 $conf["columnTitleName"]
|
|
|
1592 |
if(!isset($conf["columnTitleName"])){
|
| 226 |
liveuser |
1593 |
|
| 3 |
liveuser |
1594 |
#預設為資料表的欄位名稱
|
|
|
1595 |
$conf["columnTitleName"]=$conf["db::fastGetDbData"]["dataColumnName"];
|
| 226 |
liveuser |
1596 |
|
| 3 |
liveuser |
1597 |
}#if end
|
| 226 |
liveuser |
1598 |
|
| 3 |
liveuser |
1599 |
#反之有設置 $conf["columnName"]
|
|
|
1600 |
else{
|
| 226 |
liveuser |
1601 |
|
| 3 |
liveuser |
1602 |
#如果 $conf["columnName"] 的數量與 $conf["db::fastGetDbData"]["dataColumnName"] 不一樣
|
|
|
1603 |
if(count($conf["columnTitleName"])!=count($conf["db::fastGetDbData"]["dataColumnName"])){
|
| 226 |
liveuser |
1604 |
|
| 3 |
liveuser |
1605 |
#設置執行錯誤
|
|
|
1606 |
$result["status"]="false";
|
| 226 |
liveuser |
1607 |
|
| 3 |
liveuser |
1608 |
#設置錯誤訊息
|
|
|
1609 |
$result["error"][]="參數\$conf[\"columnName\"]與\$conf[\"db::fastGetDbData\"][\"dataColumnName\"]的元素數量要一樣";
|
| 226 |
liveuser |
1610 |
|
| 3 |
liveuser |
1611 |
#回傳結果
|
|
|
1612 |
return $result;
|
| 226 |
liveuser |
1613 |
|
| 3 |
liveuser |
1614 |
}#if end
|
| 226 |
liveuser |
1615 |
|
| 3 |
liveuser |
1616 |
}#else end
|
| 226 |
liveuser |
1617 |
|
|
|
1618 |
#建立標題欄的內容
|
| 3 |
liveuser |
1619 |
$result["content"][]=$conf["columnTitleName"];
|
| 226 |
liveuser |
1620 |
|
| 3 |
liveuser |
1621 |
#有幾筆資料就執行幾次迴圈
|
|
|
1622 |
for($i=0;$i<$conf["db::fastGetDbData"]["dataCount"];$i++){
|
| 226 |
liveuser |
1623 |
|
| 3 |
liveuser |
1624 |
#初始化暫存的陣列
|
|
|
1625 |
$temp["oneData"]=array();
|
| 226 |
liveuser |
1626 |
|
| 3 |
liveuser |
1627 |
#有幾個欄位就執行幾次迴圈
|
|
|
1628 |
for($j=0;$j<count($conf["columnTitleName"]);$j++){
|
| 226 |
liveuser |
1629 |
|
| 3 |
liveuser |
1630 |
#記錄第$i+1筆資料的第$j+1欄位的內容
|
|
|
1631 |
$temp["oneData"][]=$conf["db::fastGetDbData"]["dataContent"][$conf["db::fastGetDbData"]["dataColumnName"][$j]][$i];
|
| 226 |
liveuser |
1632 |
|
| 3 |
liveuser |
1633 |
}#for end
|
| 226 |
liveuser |
1634 |
|
| 3 |
liveuser |
1635 |
#記錄第$i+1筆資料的內容
|
|
|
1636 |
$result["content"][]=$temp["oneData"];
|
| 226 |
liveuser |
1637 |
|
| 3 |
liveuser |
1638 |
}#for end
|
| 226 |
liveuser |
1639 |
|
| 3 |
liveuser |
1640 |
#執行到這邊代表執行正常
|
|
|
1641 |
$result["status"]="true";
|
| 226 |
liveuser |
1642 |
|
| 3 |
liveuser |
1643 |
#回傳結果
|
|
|
1644 |
return $result;
|
| 226 |
liveuser |
1645 |
|
| 3 |
liveuser |
1646 |
}#function dataTable2csvFormat end
|
| 226 |
liveuser |
1647 |
|
| 3 |
liveuser |
1648 |
}#class csv end
|
| 226 |
liveuser |
1649 |
|
| 3 |
liveuser |
1650 |
?>
|