| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
|
|
6 |
Copyright (C) 2015~2025 Min-Jhin,Chen
|
|
|
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 |
|
|
|
26 |
/*
|
|
|
27 |
類別說明:
|
|
|
28 |
跟問卷整理與分析有關的類別.
|
|
|
29 |
備註:
|
|
|
30 |
無.
|
|
|
31 |
*/
|
|
|
32 |
class analyse{
|
|
|
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 |
#將逗號分隔的字串 "1,2,5,7" 變成 "1,1,0,0,1,0,1"
|
|
|
101 |
#回傳的結果:
|
|
|
102 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
103 |
#$result["error"],錯誤訊息陣列.
|
|
|
104 |
#$result["function"],當前執行的函數名稱.
|
|
|
105 |
#$result["content"],分割好的字串
|
|
|
106 |
#必填參數:
|
|
|
107 |
#$conf["stringData"],字串,類似"1,2,5,7"的字串.
|
|
|
108 |
$conf["stringData"]="";
|
|
|
109 |
#可省略參數:
|
|
|
110 |
#$conf["optionNameArray"],陣列,選項的名稱依序爲?
|
|
|
111 |
#$conf["optionNameArray"]=array("a1,a2,a3,b1,b2,c1,d1,d2,d3,e");
|
|
|
112 |
#參考資料:
|
|
|
113 |
#無.
|
|
|
114 |
#備註:
|
|
|
115 |
#無
|
|
|
116 |
*/
|
|
|
117 |
public static function changeMultiChoiceToSingleChoice(&$conf){
|
|
|
118 |
|
|
|
119 |
#初始化要回傳的內容
|
|
|
120 |
$result=array();
|
|
|
121 |
|
|
|
122 |
#取得當前執行的函數名稱
|
|
|
123 |
$result["function"]=__FUNCTION__;
|
|
|
124 |
|
|
|
125 |
#初始化要回傳的內容
|
|
|
126 |
$result["content"]="";
|
|
|
127 |
|
|
|
128 |
#如果 $conf 不為陣列
|
|
|
129 |
if(gettype($conf)!="array"){
|
|
|
130 |
|
|
|
131 |
#設置執行失敗
|
|
|
132 |
$result["status"]="false";
|
|
|
133 |
|
|
|
134 |
#設置執行錯誤訊息
|
|
|
135 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
136 |
|
|
|
137 |
#如果傳入的參數為 null
|
|
|
138 |
if($conf==null){
|
|
|
139 |
|
|
|
140 |
#設置執行錯誤訊息
|
|
|
141 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
142 |
|
|
|
143 |
}#if end
|
|
|
144 |
|
|
|
145 |
#回傳結果
|
|
|
146 |
return $result;
|
|
|
147 |
|
|
|
148 |
}#if end
|
|
|
149 |
|
|
|
150 |
#儲存那幾個選項有勾選或未勾選的字串陣列
|
|
|
151 |
$strArray=array();
|
|
|
152 |
|
|
|
153 |
#如果 $conf["stringData"] 不存在
|
|
|
154 |
if(!isset($conf["stringData"])){
|
|
|
155 |
|
|
|
156 |
#設置執行失敗
|
|
|
157 |
$result["status"]="false";
|
|
|
158 |
|
|
|
159 |
#設置錯誤訊息
|
|
|
160 |
$result["error"][]="\$conf[\"stringData\"]參數未設定";
|
|
|
161 |
|
|
|
162 |
#回傳錯誤訊息
|
|
|
163 |
return $result;
|
|
|
164 |
|
|
|
165 |
}#if end
|
|
|
166 |
|
|
|
167 |
#涵式說明:
|
|
|
168 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
169 |
#回傳的參數:
|
|
|
170 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
171 |
#$result["error"],錯誤訊息陣列
|
|
|
172 |
#$result["function"],當前執行的函數名稱.
|
|
|
173 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
174 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
175 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
176 |
#必填參數:
|
|
|
177 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$conf["stringData"];#要處理的字串。
|
|
|
178 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]=",";#爲以哪個符號作爲分割
|
|
|
179 |
$spiledStr=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
180 |
unset($conf["stringProcess"]["spiltString"]);
|
|
|
181 |
|
|
|
182 |
#如果分割字串失敗
|
|
|
183 |
if($spiledStr["status"]=="false"){
|
|
|
184 |
|
|
|
185 |
#設置執行失敗
|
|
|
186 |
$result["status"]="false";
|
|
|
187 |
|
|
|
188 |
#設置錯誤訊息
|
|
|
189 |
$result["error"]=$spiledStr;
|
|
|
190 |
|
|
|
191 |
#回傳錯誤訊息
|
|
|
192 |
return $result;
|
|
|
193 |
|
|
|
194 |
}#if end
|
|
|
195 |
|
|
|
196 |
#將字串中的 " 符號去除
|
|
|
197 |
#有幾個選項就執行幾次
|
|
|
198 |
for($i=0;$i<$spiledStr["dataCounts"];$i++){
|
|
|
199 |
|
|
|
200 |
#涵式說明:
|
|
|
201 |
#處理字串避免網頁出錯
|
|
|
202 |
#回傳的結果:
|
|
|
203 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
204 |
#$result["function"],當前執行的函數.
|
|
|
205 |
#$result["content"],爲處理好的字串.
|
|
|
206 |
#$result["error"],錯誤訊息陣列.
|
|
|
207 |
#必天寫的參數:
|
|
|
208 |
$conf["stringProcess"]["correctCharacter"]["stringIn"]=$spiledStr["dataArray"][$i];#爲要處理的字串
|
|
|
209 |
#可省略參數:
|
|
|
210 |
$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array("\"");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
211 |
#若不設定則預設爲要將這些字串作替換("<",">",";","=","#","*","'","$","%","&","|")。
|
|
|
212 |
#$conf["changeTo"];#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
213 |
$correctCharacter=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
|
|
|
214 |
unset($conf["stringProcess"]["correctCharacter"]);
|
|
|
215 |
|
|
|
216 |
#如果剔除 " 符號失敗
|
|
|
217 |
if($correctCharacter["status"]=="false"){
|
|
|
218 |
|
|
|
219 |
#設置執行失敗
|
|
|
220 |
$result["status"]="false";
|
|
|
221 |
|
|
|
222 |
#設置錯誤訊息
|
|
|
223 |
$result["error"]=$correctCharacter;
|
|
|
224 |
|
|
|
225 |
#回傳錯誤訊息
|
|
|
226 |
return $result;
|
|
|
227 |
|
|
|
228 |
}#if end
|
|
|
229 |
|
|
|
230 |
#取得處理好的字串
|
|
|
231 |
$spiledStr["dataArray"][$i]=$correctCharacter["content"];
|
|
|
232 |
|
|
|
233 |
}#for end
|
|
|
234 |
|
|
|
235 |
#如果 $conf["optionNameArray"] 有設定
|
|
|
236 |
if(isset($conf["optionNameArray"])){
|
|
|
237 |
|
|
|
238 |
#取得選項的上限數值
|
|
|
239 |
$conf["maxOptionNum"]=count($conf["optionNameArray"]);
|
|
|
240 |
|
|
|
241 |
#有幾個選項就執行幾次
|
|
|
242 |
for($i=0;$i<$spiledStr["dataCounts"];$i++){
|
|
|
243 |
|
|
|
244 |
#取得當前選項的位置
|
|
|
245 |
#涵式說明:
|
|
|
246 |
#檢查一個數值是否與陣列裏面的元素相同,如果有相同的則會傳其變數內容。
|
|
|
247 |
#回傳的結果:
|
|
|
248 |
#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
|
|
|
249 |
#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
|
|
|
250 |
#$result["error"],錯誤訊息
|
|
|
251 |
#$result["equalVarName"],相等的變數名稱或key.
|
|
|
252 |
#$result["equalVarValue"],相等的變數數值內容.
|
|
|
253 |
#必填參數:
|
|
|
254 |
$conf["search"]["getEqualVar"]["conditionElement"]=$spiledStr["dataArray"][$i];#條件元素,要等於的元素內容。
|
|
|
255 |
$conf["search"]["getEqualVar"]["compareElements"]=$conf["optionNameArray"];#要比對的陣列變數內容。
|
|
|
256 |
$search["getEqualVar"]=search::getEqualVar($conf["search"]["getEqualVar"]);
|
|
|
257 |
unset($conf["search"]["getEqualVar"]);
|
|
|
258 |
|
|
|
259 |
#如果取得當前選項位置失敗
|
|
|
260 |
if($search["getEqualVar"]["status"]=="false"){
|
|
|
261 |
|
|
|
262 |
#設置執行失敗
|
|
|
263 |
$result["status"]="false";
|
|
|
264 |
|
|
|
265 |
#設置錯誤訊息
|
|
|
266 |
$result["error"]=$search;
|
|
|
267 |
|
|
|
268 |
#回傳錯誤訊息
|
|
|
269 |
return $result;
|
|
|
270 |
|
|
|
271 |
}#if end
|
|
|
272 |
|
|
|
273 |
#var_dump($search["getEqualVar"]);
|
|
|
274 |
|
|
|
275 |
#如果 $search["getEqualVar"]["founded"] 爲 "true"
|
|
|
276 |
if($search["getEqualVar"]["founded"]=="true"){
|
|
|
277 |
|
|
|
278 |
#將其選項勾選處設爲1,表示有選擇
|
|
|
279 |
$strArray[$search["getEqualVar"]["equalVarName"]]="1";
|
|
|
280 |
|
|
|
281 |
}#if end
|
|
|
282 |
|
|
|
283 |
}#for end
|
|
|
284 |
|
|
|
285 |
}#if end
|
|
|
286 |
|
|
|
287 |
#反之沒有設定
|
|
|
288 |
else{
|
|
|
289 |
|
|
|
290 |
#有幾個選項就執行幾次
|
|
|
291 |
for($i=0;$i<$spiledStr["dataCounts"];$i++){
|
|
|
292 |
|
|
|
293 |
#debug
|
|
|
294 |
#var_dump($spiledStr["dataArray"][$i]);
|
|
|
295 |
|
|
|
296 |
#將有填寫的選項設爲1
|
|
|
297 |
#將 $result[["dataArray"][$i]] 設爲 1;
|
|
|
298 |
$strArray[$spiledStr["dataArray"][$i]-1]="1";
|
|
|
299 |
|
|
|
300 |
}#for end
|
|
|
301 |
|
|
|
302 |
}#else end
|
|
|
303 |
|
|
|
304 |
#檢查變數內容
|
|
|
305 |
#var_dump($strArray);
|
|
|
306 |
|
|
|
307 |
#檢查變數內容
|
|
|
308 |
#var_dump($conf["maxOptionNum"]);
|
|
|
309 |
|
|
|
310 |
#如果 $conf["maxOptionNum"] 有設定
|
|
|
311 |
if(isset($conf["maxOptionNum"])){
|
|
|
312 |
|
|
|
313 |
#將 $result 陣列中不存在的key指派爲0
|
|
|
314 |
for($i=0;$i<$conf["maxOptionNum"];$i++){
|
|
|
315 |
|
|
|
316 |
#如果該key不存在
|
|
|
317 |
if(!isset($strArray[$i])){
|
|
|
318 |
|
|
|
319 |
#則指派其key與 value
|
|
|
320 |
$strArray[$i]="0";
|
|
|
321 |
|
|
|
322 |
}#if end
|
|
|
323 |
|
|
|
324 |
}#for end
|
|
|
325 |
|
|
|
326 |
}#if end
|
|
|
327 |
|
|
|
328 |
#反之沒有設定
|
|
|
329 |
else{
|
|
|
330 |
|
|
|
331 |
#檢查變數內容
|
|
|
332 |
#var_dump($spiledStr["dataArray"]);
|
|
|
333 |
|
|
|
334 |
#尋找 $spiledStr["dataArray"][$i] 陣列中的最大值
|
|
|
335 |
#涵式說明:
|
|
|
336 |
#找最大值,結果會回傳最大值.
|
|
|
337 |
#回傳的結果
|
|
|
338 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
339 |
#$result["error"],錯誤訊息陣列.
|
|
|
340 |
#$result["function"],當前執行的函數名稱.
|
|
|
341 |
#$result["key"],最大值原先的key.
|
|
|
342 |
#$result["value"],最大值的數字.
|
|
|
343 |
#必填參數:
|
|
|
344 |
$conf["math"]["getMaxValue"]["rawDataArray"]=$spiledStr["dataArray"];#爲原始數據
|
|
|
345 |
$maxValue=math::getMaxValue($conf["math"]["getMaxValue"]);
|
|
|
346 |
unset($conf["math"]["getMaxValue"]);
|
|
|
347 |
|
|
|
348 |
#如果取得 $spiledStr["dataArray"][$i] 陣列中的最大值失敗
|
|
|
349 |
if($maxValue["status"]=="false"){
|
|
|
350 |
|
|
|
351 |
#設置執行失敗
|
|
|
352 |
$result["status"]="false";
|
|
|
353 |
|
|
|
354 |
#設置錯誤訊息
|
|
|
355 |
$result["error"]=$maxValue;
|
|
|
356 |
|
|
|
357 |
#回傳錯誤訊息
|
|
|
358 |
return $result;
|
|
|
359 |
|
|
|
360 |
}#if end
|
|
|
361 |
|
|
|
362 |
$maxValue=$maxValue["value"];
|
|
|
363 |
|
|
|
364 |
#將最大值視爲最後一個選項的號碼
|
|
|
365 |
for($i=0;$i<$maxValue;$i++){
|
|
|
366 |
|
|
|
367 |
#如果該key不存在
|
|
|
368 |
if(!isset($strArray[$i])){
|
|
|
369 |
|
|
|
370 |
#則指派其key與 value
|
|
|
371 |
$strArray[$i]="0";
|
|
|
372 |
|
|
|
373 |
}#if end
|
|
|
374 |
|
|
|
375 |
}#for end
|
|
|
376 |
|
|
|
377 |
}#else end
|
|
|
378 |
|
|
|
379 |
#將 $result 陣列轉爲逗號分隔的字串("1","3","4","7")
|
|
|
380 |
#$result陣列有幾個元素,就執行幾次
|
|
|
381 |
for($i=0;$i<count($strArray);$i++){
|
|
|
382 |
|
|
|
383 |
#如果是最後一個元素
|
|
|
384 |
if($i==(count($strArray)-1)){
|
|
|
385 |
|
|
|
386 |
#串接內容
|
|
|
387 |
$result["content"]=$result["content"].$strArray[$i];
|
|
|
388 |
|
|
|
389 |
}#if end
|
|
|
390 |
|
|
|
391 |
#反之不是最後一個元素
|
|
|
392 |
else{
|
|
|
393 |
|
|
|
394 |
#串接內容,結尾用逗號
|
|
|
395 |
$result["content"]=$result["content"].$strArray[$i].",";
|
|
|
396 |
|
|
|
397 |
}#else end
|
|
|
398 |
|
|
|
399 |
}#for end
|
|
|
400 |
|
|
|
401 |
#設置執行正常
|
|
|
402 |
$result["status"]="true";
|
|
|
403 |
|
|
|
404 |
#回傳結果
|
|
|
405 |
return $result;
|
|
|
406 |
|
|
|
407 |
}#function changeMultiChoiceToSingleChoice end
|
|
|
408 |
|
|
|
409 |
/*
|
|
|
410 |
#函式說明:
|
|
|
411 |
#讀取csv檔案,一列代表一個選項填寫的情況,然後交由 analyse::changeMutiChoiceToSingleChoice 處理,並將結果寫入新的檔案裏面。
|
|
|
412 |
#回傳的結果:
|
|
|
413 |
#$result["status"],執行是否正常.
|
|
|
414 |
#$result["error"],錯誤訊息.
|
|
|
415 |
#$result["function"],當前執行的函數名稱.
|
|
|
416 |
#$result["outputCsvFileAddress"],處理完畢後新檔案的位置.
|
|
|
417 |
#必填參數:
|
|
|
418 |
#$conf["oriCsvFileAddAndName"],字串,原始csv檔案的位置.
|
|
|
419 |
$conf["oriCsvFileAddAndName"]="";
|
|
|
420 |
$conf["maxOptionNum"],字串,總共有幾個選項爲?
|
|
|
421 |
$conf["maxOptionNum"]="";
|
|
|
422 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
423 |
$conf["fileArgu"]=__FILE__;
|
|
|
424 |
#可省略參數:
|
|
|
425 |
#$conf["newCsvFileAddAndName"],字串,處理好的新csv檔案位置.
|
|
|
426 |
#$conf["newCsvFileAddAndName"]="";
|
|
|
427 |
#$conf["optionNameArray"],陣列,選項的名稱依序爲?
|
|
|
428 |
#$conf["optionNameArray"]=array("a1,a2,a3,b1,b2,c1,d1,d2,d3,e");
|
|
|
429 |
#參考資料:
|
|
|
430 |
#無.
|
|
|
431 |
#備註:
|
|
|
432 |
#無
|
|
|
433 |
*/
|
|
|
434 |
public static function changeMultiChoiceToSingleChoiceFromCsvFile(&$conf){
|
|
|
435 |
|
|
|
436 |
#初始化要回傳的變數
|
|
|
437 |
$result=array();
|
|
|
438 |
|
|
|
439 |
#取得當前執行的函數名稱
|
|
|
440 |
$result["function"]=__FUNCTION__;
|
|
|
441 |
|
|
|
442 |
#如果 $conf 不為陣列
|
|
|
443 |
if(gettype($conf)!="array"){
|
|
|
444 |
|
|
|
445 |
#設置執行失敗
|
|
|
446 |
$result["status"]="false";
|
|
|
447 |
|
|
|
448 |
#設置執行錯誤訊息
|
|
|
449 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
450 |
|
|
|
451 |
#如果傳入的參數為 null
|
|
|
452 |
if($conf==null){
|
|
|
453 |
|
|
|
454 |
#設置執行錯誤訊息
|
|
|
455 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
456 |
|
|
|
457 |
}#if end
|
|
|
458 |
|
|
|
459 |
#回傳結果
|
|
|
460 |
return $result;
|
|
|
461 |
|
|
|
462 |
}#if end
|
|
|
463 |
|
|
|
464 |
#涵式說明:
|
|
|
465 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
466 |
#回傳的結果:
|
|
|
467 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
468 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
469 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
470 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
471 |
#必填參數:
|
|
|
472 |
$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
473 |
$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("oriCsvFileAddAndName","fileArgu");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
474 |
#可以省略的參數:
|
|
|
475 |
$conf["variableCheck"]["isexistMuti"]["variableType"]=array("string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
|
|
476 |
$conf["variableCheck"]["isexistMuti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
477 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
|
|
|
478 |
unset($conf["variableCheck"]["isexistMuti"]);
|
|
|
479 |
|
|
|
480 |
#如果檢查參數失敗
|
|
|
481 |
if($checkResult["status"]=="false"){
|
|
|
482 |
|
|
|
483 |
#設置執行錯誤
|
|
|
484 |
$result["status"]="false";
|
|
|
485 |
|
|
|
486 |
#設置錯誤訊息
|
|
|
487 |
$result["error"]=$checkResult;
|
|
|
488 |
|
|
|
489 |
#回傳結果
|
|
|
490 |
return $result;
|
|
|
491 |
|
|
|
492 |
}#if end
|
|
|
493 |
|
|
|
494 |
#如果 $checkResult["passed"] 等於 "false"
|
|
|
495 |
if($checkResult["passed"]=="false"){
|
|
|
496 |
|
|
|
497 |
#設置執行錯誤
|
|
|
498 |
$result["status"]="false";
|
|
|
499 |
|
|
|
500 |
#設置錯誤訊息
|
|
|
501 |
$result["error"]=$checkResult;
|
|
|
502 |
|
|
|
503 |
#回傳結果
|
|
|
504 |
return $result;
|
|
|
505 |
|
|
|
506 |
}#if end
|
|
|
507 |
|
|
|
508 |
#如果新檔案名稱已設置
|
|
|
509 |
if(isset($conf["newCsvFileAddAndName"])){
|
|
|
510 |
|
|
|
511 |
#確認新檔案是否不存在
|
|
|
512 |
if(file_exists($conf["newCsvFileAddAndName"])==false){
|
|
|
513 |
|
|
|
514 |
#不存在,所以建立新檔案
|
|
|
515 |
#涵式說明:
|
|
|
516 |
#將字串寫入到檔案
|
|
|
517 |
#回傳的結果:
|
|
|
518 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
519 |
#$result["error"],錯誤訊息陣列.
|
|
|
520 |
#必填參數:
|
|
|
521 |
$conf["fileAccess"]["writeTextIntoFile"]["fileName"]=$conf["newCsvFileAddAndName"];#爲要編輯的檔案名稱
|
|
|
522 |
$conf["fileAccess"]["writeTextIntoFile"]["inputString"]="";#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
|
|
|
523 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
524 |
$conf["fileAccess"]["writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
525 |
#可省略參數:
|
|
|
526 |
#$conf["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
|
|
|
527 |
$fileCreateStatus=fileAccess::writeTextIntoFile($conf["fileAccess"]["writeTextIntoFile"]);
|
|
|
528 |
unset($conf["fileAccess"]["writeTextIntoFile"]);
|
|
|
529 |
|
|
|
530 |
#如果 $fileCreateStatus["status"] 等於 "false"
|
|
|
531 |
if($fileCreateStatus["status"]=="false"){
|
|
|
532 |
|
|
|
533 |
#設置執行錯誤
|
|
|
534 |
$result["status"]="false";
|
|
|
535 |
|
|
|
536 |
#設置錯誤訊息
|
|
|
537 |
$result["error"]=$fileCreateStatus;
|
|
|
538 |
|
|
|
539 |
#回傳結果
|
|
|
540 |
return $result;
|
|
|
541 |
|
|
|
542 |
}#if end
|
|
|
543 |
|
|
|
544 |
}#if end
|
|
|
545 |
|
|
|
546 |
}#if end
|
|
|
547 |
|
|
|
548 |
#反之沒有設定新檔案的位置與名稱
|
|
|
549 |
else{
|
|
|
550 |
|
|
|
551 |
#按照預設建立新檔案名稱與位置
|
|
|
552 |
$conf["newCsvFileAddAndName"]=$conf["oriCsvFileAddAndName"]."(已處理過).csv";
|
|
|
553 |
|
|
|
554 |
#不存在,所以建立新檔案
|
|
|
555 |
#涵式說明:
|
|
|
556 |
#將字串寫入到檔案
|
|
|
557 |
#回傳的結果:
|
|
|
558 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
559 |
#$result["error"],錯誤訊息陣列.
|
|
|
560 |
#必填參數:
|
|
|
561 |
$conf["fileAccess"]["writeTextIntoFile"]["fileName"]=$conf["newCsvFileAddAndName"];#爲要編輯的檔案名稱
|
|
|
562 |
$conf["fileAccess"]["writeTextIntoFile"]["inputString"]="";#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
|
|
|
563 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
564 |
$conf["fileAccess"]["writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
565 |
#可省略參數:
|
|
|
566 |
#$conf["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
|
|
|
567 |
$fileCreateStatus=fileAccess::writeTextIntoFile($conf["fileAccess"]["writeTextIntoFile"]);
|
|
|
568 |
unset($conf["fileAccess"]["writeTextIntoFile"]);
|
|
|
569 |
|
|
|
570 |
#如果 $fileCreateStatus["status"] 等於 "false"
|
|
|
571 |
if($fileCreateStatus["status"]=="false"){
|
|
|
572 |
|
|
|
573 |
#設置執行錯誤
|
|
|
574 |
$result["status"]="false";
|
|
|
575 |
|
|
|
576 |
#設置錯誤訊息
|
|
|
577 |
$result["error"]=$fileCreateStatus;
|
|
|
578 |
|
|
|
579 |
#回傳結果
|
|
|
580 |
return $result;
|
|
|
581 |
|
|
|
582 |
}#if end
|
|
|
583 |
|
|
|
584 |
}#else end
|
|
|
585 |
|
|
|
586 |
#初始化儲存處理好資訊的陣列
|
|
|
587 |
$processedStrArray=array();
|
|
|
588 |
|
|
|
589 |
#函式說明:
|
|
|
590 |
#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
|
|
|
591 |
#回傳的變數說明:
|
|
|
592 |
#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗。
|
|
|
593 |
#$result["error"],錯誤訊息提示
|
|
|
594 |
#$result["fileContent"],爲檔案的內容陣列
|
|
|
595 |
#$result["lineCount"],爲檔案內容總共的行數
|
|
|
596 |
#$result["fullContent"],為檔案的完整內容
|
|
|
597 |
#必填參數:
|
|
|
598 |
$conf["fileAccess"]["getFileContent"]["filePositionAndName"]=$conf["oriCsvFileAddAndName"];#爲檔案的位置以及名稱
|
|
|
599 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
600 |
$conf["fileAccess"]["getFileContent"]["fileArgu"]=$conf["fileArgu"];
|
|
|
601 |
#參考資料:
|
|
|
602 |
#file():取得檔案內容的行數
|
|
|
603 |
#http://php.net/manual/en/function.file.php
|
|
|
604 |
$fileGetResult=fileAccess::getFileContent($conf["fileAccess"]["getFileContent"]);
|
|
|
605 |
unset($conf["fileAccess"]["getFileContent"]);
|
|
|
606 |
|
|
|
607 |
#如果 $fileGetResult["status"] 等於 "false"
|
|
|
608 |
if($fileGetResult["status"]=="false"){
|
|
|
609 |
|
|
|
610 |
#設置執行錯誤
|
|
|
611 |
$result["status"]="false";
|
|
|
612 |
|
|
|
613 |
#設置錯誤訊息
|
|
|
614 |
$result["error"]=$fileGetResult;
|
|
|
615 |
|
|
|
616 |
#回傳結果
|
|
|
617 |
return $result;
|
|
|
618 |
|
|
|
619 |
}#if end
|
|
|
620 |
|
|
|
621 |
#有幾行內容就執行幾次
|
|
|
622 |
for($i=0;$i<$fileGetResult["lineCount"];$i++){
|
|
|
623 |
|
|
|
624 |
#涵式說明
|
|
|
625 |
#將逗號分隔的字串 "1,2,5,7" 變成 "1,1,0,0,1,0,1"
|
|
|
626 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
627 |
#$result["error"],錯誤訊息陣列.
|
|
|
628 |
#$result["function"],當前執行的函數名稱.
|
|
|
629 |
#$result["content"],分割好的字串
|
|
|
630 |
#必填參數:
|
|
|
631 |
$conf["analyse"]["changeMutiChoiceToSingleChoice"]["stringData"]=$fileGetResult["fileContent"][$i];#類似"1,2,5,7"的字串
|
|
|
632 |
#可省略參數:
|
|
|
633 |
|
|
|
634 |
/* 無效的參數
|
|
|
635 |
|
|
|
636 |
#如果 $conf["maxOptionNum"] 有設定
|
|
|
637 |
if(isset($conf["maxOptionNum"])){
|
|
|
638 |
|
|
|
639 |
#則套用之
|
|
|
640 |
$conf["analyse"]["changeMutiChoiceToSingleChoice"]["maxOptionNum"]=$conf["maxOptionNum"];#最後一個問項的號碼爲?
|
|
|
641 |
|
|
|
642 |
}#if end
|
|
|
643 |
|
|
|
644 |
*/
|
|
|
645 |
|
|
|
646 |
#如果 $conf["optionNameArray"] 有設定
|
|
|
647 |
if(isset($conf["optionNameArray"])){
|
|
|
648 |
|
|
|
649 |
#則套用之
|
|
|
650 |
$conf["analyse"]["changeMutiChoiceToSingleChoice"]["optionNameArray"]=$conf["optionNameArray"];
|
|
|
651 |
|
|
|
652 |
}#if end
|
|
|
653 |
|
|
|
654 |
$changeMultiChoiceToSingleChoice=analyse::changeMultiChoiceToSingleChoice($conf["analyse"]["changeMutiChoiceToSingleChoice"]);
|
|
|
655 |
|
|
|
656 |
#如果 analyse::changeMultiChoiceToSingleChoice 執行失敗
|
|
|
657 |
if($changeMultiChoiceToSingleChoice["status"]=="false"){
|
|
|
658 |
|
|
|
659 |
#設置執行失敗
|
|
|
660 |
$result["status"]="false";
|
|
|
661 |
|
|
|
662 |
#設置執行錯誤訊息
|
|
|
663 |
$result["error"]=$changeMultiChoiceToSingleChoice;
|
|
|
664 |
|
|
|
665 |
#回傳結果
|
|
|
666 |
return $result;
|
|
|
667 |
|
|
|
668 |
}#if end
|
|
|
669 |
|
|
|
670 |
#取得好的字串
|
|
|
671 |
$processedStrArray[$i]=$changeMultiChoiceToSingleChoice["content"];
|
|
|
672 |
|
|
|
673 |
#檢查變數內容
|
|
|
674 |
#var_dump($conf["analyse"]["changeMutiChoiceToSingleChoice"]["optionNameArray"]);
|
|
|
675 |
|
|
|
676 |
unset($conf["analyse"]["changeMutiChoiceToSingleChoice"]);
|
|
|
677 |
|
|
|
678 |
}#for end
|
|
|
679 |
|
|
|
680 |
#有幾行內容就執行幾次
|
|
|
681 |
for($i=0;$i<$fileGetResult["lineCount"];$i++){
|
|
|
682 |
|
|
|
683 |
#將取得的結果寫入到新檔案裏面
|
|
|
684 |
#涵式說明:
|
|
|
685 |
#將字串寫入到檔案
|
|
|
686 |
#回傳的結果:
|
|
|
687 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
688 |
#$result["error"],錯誤訊息陣列.
|
|
|
689 |
#必填參數:
|
|
|
690 |
$conf["fileAccess"]["writeTextIntoFile"]["fileName"]=$conf["newCsvFileAddAndName"];#爲要編輯的檔案名稱
|
|
|
691 |
$conf["fileAccess"]["writeTextIntoFile"]["inputString"]=$processedStrArray[$i]."\r\n";#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
|
|
|
692 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
693 |
$conf["fileAccess"]["writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
694 |
#可省略參數:
|
|
|
695 |
$conf["fileAccess"]["writeTextIntoFile"]["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
|
|
|
696 |
$fileCreateStatus=fileAccess::writeTextIntoFile($conf["fileAccess"]["writeTextIntoFile"]);
|
|
|
697 |
unset($conf["fileAccess"]["writeTextIntoFile"]);
|
|
|
698 |
|
|
|
699 |
#如果 $fileCreateStatus["status"] 等於 "false"
|
|
|
700 |
if($fileCreateStatus["status"]=="false"){
|
|
|
701 |
|
|
|
702 |
#設置執行錯誤
|
|
|
703 |
$result["status"]="false";
|
|
|
704 |
|
|
|
705 |
#設置錯誤訊息
|
|
|
706 |
$result["error"]=$fileCreateStatus;
|
|
|
707 |
|
|
|
708 |
#回傳結果
|
|
|
709 |
return $result;
|
|
|
710 |
|
|
|
711 |
}#if end
|
|
|
712 |
|
|
|
713 |
}#for end
|
|
|
714 |
|
|
|
715 |
#設置執行成功
|
|
|
716 |
$result["status"]="true";
|
|
|
717 |
|
|
|
718 |
#設置檔案的位置與名稱
|
|
|
719 |
$result["outputCsvFileAddress"]=$conf["newCsvFileAddAndName"];
|
|
|
720 |
|
|
|
721 |
#回傳結果
|
|
|
722 |
return $result;
|
|
|
723 |
|
|
|
724 |
}#function changeMutiChoiceToSingleChoiceFromCsvFile end
|
|
|
725 |
|
|
|
726 |
/*
|
|
|
727 |
#函式說明:
|
|
|
728 |
#將兩份csv檔案裡面特定一個同名的欄位的數值進行對照,僅留下有相同數值的資料,然後回傳
|
|
|
729 |
#回傳結果:
|
|
|
730 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
731 |
#$result["error"],錯誤訊息陣列.
|
|
|
732 |
#$result["function"],當前執行的函數名稱
|
|
|
733 |
#必填參數:
|
|
|
734 |
#$conf["csvFileA"],字串,第1個csv檔案的位置與名稱
|
|
|
735 |
$conf["csvFileA"]="";
|
|
|
736 |
#$conf["csvFileB"],字串,第2個csv檔案的位置與名稱
|
|
|
737 |
$conf["csvFileB"]="";
|
|
|
738 |
#$conf["compareColumnName"],字串,要對照值是否相等的欄位名稱
|
|
|
739 |
$conf["compareColumnName"]="";
|
|
|
740 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
741 |
$conf["fileArgu"]=__FILE__;
|
|
|
742 |
#可省略參數:
|
|
|
743 |
#$conf["csvFilePathAndName"],字串,要儲存到哪個位置,副檔名csv會自動建立,預設會建立一個以系統時間命名的資料,裡面放以系統時間為名的csv檔案.
|
|
|
744 |
#$conf["csvFilePathAndName"]="";
|
|
|
745 |
#$conf["noDownload"],字串,如果爲"true"則代表不要讓使用者下載,但會回傳檔案的相對位置.
|
|
|
746 |
#$conf["noDownload"]="true";
|
|
|
747 |
#參考資料:
|
|
|
748 |
#無.
|
|
|
749 |
#備註:
|
|
|
750 |
#無
|
|
|
751 |
*/
|
|
|
752 |
public static function mergePairedData(&$conf){
|
|
|
753 |
|
|
|
754 |
#初始化要回傳的變數
|
|
|
755 |
$result=array();
|
|
|
756 |
|
|
|
757 |
#取得當前執行的函數名稱
|
|
|
758 |
$result["function"]=__FUNCTION__;
|
|
|
759 |
|
|
|
760 |
#如果 $conf 不為陣列
|
|
|
761 |
if(gettype($conf)!="array"){
|
|
|
762 |
|
|
|
763 |
#設置執行失敗
|
|
|
764 |
$result["status"]="false";
|
|
|
765 |
|
|
|
766 |
#設置執行錯誤訊息
|
|
|
767 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
768 |
|
|
|
769 |
#如果傳入的參數為 null
|
|
|
770 |
if($conf==null){
|
|
|
771 |
|
|
|
772 |
#設置執行錯誤訊息
|
|
|
773 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
774 |
|
|
|
775 |
}#if end
|
|
|
776 |
|
|
|
777 |
#回傳結果
|
|
|
778 |
return $result;
|
|
|
779 |
|
|
|
780 |
}#if end
|
|
|
781 |
|
|
|
782 |
#涵式說明:
|
|
|
783 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
784 |
#回傳的結果:
|
|
|
785 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
786 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
787 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
788 |
#必填參數:
|
|
|
789 |
$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
790 |
$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("csvFileA","csvFileB","compareColumnName","fileArgu");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
791 |
#可以省略的參數:
|
|
|
792 |
$conf["variableCheck"]["isexistMuti"]["variableType"]=array("string","string","string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
|
|
793 |
#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
794 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
|
|
|
795 |
unset($conf["variableCheck"]);
|
|
|
796 |
|
|
|
797 |
#如果檢查有誤
|
|
|
798 |
if($checkResult["status"]=="false"){
|
|
|
799 |
|
|
|
800 |
#設置執行不正常
|
|
|
801 |
$result["status"]="false";
|
|
|
802 |
|
|
|
803 |
#設置錯誤訊息
|
|
|
804 |
$result["error"]=$checkResult;
|
|
|
805 |
|
|
|
806 |
#回傳結果
|
|
|
807 |
return $result;
|
|
|
808 |
|
|
|
809 |
}#if end
|
|
|
810 |
|
|
|
811 |
#如果檢查不通過
|
|
|
812 |
if($checkResult["passed"]=="false"){
|
|
|
813 |
|
|
|
814 |
#設置執行不正常
|
|
|
815 |
$result["status"]="false";
|
|
|
816 |
|
|
|
817 |
#設置錯誤訊息
|
|
|
818 |
$result["error"]=$checkResult;
|
|
|
819 |
|
|
|
820 |
#回傳結果
|
|
|
821 |
return $result;
|
|
|
822 |
|
|
|
823 |
}#if end
|
|
|
824 |
|
|
|
825 |
#涵式說明:
|
|
|
826 |
#讀取csv檔案的內容
|
|
|
827 |
#回傳得結果:
|
|
|
828 |
#$result["status"],執行是否正常,"true"代表正常;"false"代表不正常.
|
|
|
829 |
#$result["error"],錯誤訊息陣列.
|
|
|
830 |
#$result["csvFileContent"],csv檔案內容的陣列
|
|
|
831 |
#$result["csvFileContent"]["$i"]["$j"]代表第$i+1列第$j+1欄位的內容.
|
|
|
832 |
#如果 $conf["firstLineVarName"]爲"true"的話則會回傳 $result["csvFileContent"]["第幾列"]["第一列各個欄位的名稱"]
|
|
|
833 |
#$result["lineArray"],csv檔案逐列內容的陣列.
|
|
|
834 |
#$result["lineArrayCount"],總共幾列資料
|
|
|
835 |
#必填參數:
|
|
|
836 |
$conf["csv"]["loadCsvFile"]["csvFilePositionAndName"]=$conf["csvFileA"];#csv檔案的位置
|
|
|
837 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
838 |
$conf["csv"]["loadCsvFile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
839 |
#可省略參數:
|
|
|
840 |
$conf["csv"]["loadCsvFile"]["firstLineVarName"]="true";#第一行是否爲變數名稱(各個欄位的名稱)
|
|
|
841 |
#參考資料來源:
|
|
|
842 |
#http://www.php.net/manual/en/function.str-split.php
|
|
|
843 |
#參考資料來源
|
|
|
844 |
#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)
|
|
|
845 |
$csvFileContentA=csv::loadCsvFile($conf["csv"]["loadCsvFile"]);
|
|
|
846 |
unset($conf["csv"]);
|
|
|
847 |
|
|
|
848 |
#如果 $csvFileContentA["status"] 等於 "false"
|
|
|
849 |
if($csvFileContentA["status"]=="false"){
|
|
|
850 |
|
|
|
851 |
#設置執行失敗
|
|
|
852 |
$result["false"]="false";
|
|
|
853 |
|
|
|
854 |
#取得錯誤訊息
|
|
|
855 |
$result["error"]=$csvFileContentA;
|
|
|
856 |
|
|
|
857 |
#回傳結果
|
|
|
858 |
return $result;
|
|
|
859 |
|
|
|
860 |
}#if end
|
|
|
861 |
|
|
|
862 |
#涵式說明:
|
|
|
863 |
#讀取csv檔案的內容
|
|
|
864 |
#回傳得結果:
|
|
|
865 |
#$result["status"],執行是否正常,"true"代表正常;"false"代表不正常.
|
|
|
866 |
#$result["error"],錯誤訊息陣列.
|
|
|
867 |
#$result["csvFileContent"],csv檔案內容的陣列
|
|
|
868 |
#$result["csvFileContent"]["$i"]["$j"]代表第$i+1列第$j+1欄位的內容.
|
|
|
869 |
#如果 $conf["firstLineVarName"]爲"true"的話則會回傳 $result["csvFileContent"]["第幾列"]["第一列各個欄位的名稱"]
|
|
|
870 |
#$result["lineArray"],csv檔案逐列內容的陣列.
|
|
|
871 |
#$result["lineArrayCount"],總共幾列資料
|
|
|
872 |
#必填參數:
|
|
|
873 |
$conf["csv"]["loadCsvFile"]["csvFilePositionAndName"]=$conf["csvFileB"];#csv檔案的位置
|
|
|
874 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
875 |
$conf["csv"]["loadCsvFile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
876 |
#可省略參數:
|
|
|
877 |
$conf["csv"]["loadCsvFile"]["firstLineVarName"]="true";#第一行是否爲變數名稱(各個欄位的名稱)
|
|
|
878 |
#參考資料來源:
|
|
|
879 |
#http://www.php.net/manual/en/function.str-split.php
|
|
|
880 |
#參考資料來源
|
|
|
881 |
#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)
|
|
|
882 |
$csvFileContentB=csv::loadCsvFile($conf["csv"]["loadCsvFile"]);
|
|
|
883 |
unset($conf["csv"]);
|
|
|
884 |
|
|
|
885 |
#如果 $csvFileContentB["status"] 等於 "false"
|
|
|
886 |
if($csvFileContentB["status"]=="false"){
|
|
|
887 |
|
|
|
888 |
#設置執行失敗
|
|
|
889 |
$result["false"]="false";
|
|
|
890 |
|
|
|
891 |
#取得錯誤訊息
|
|
|
892 |
$result["error"]=$csvFileContentB;
|
|
|
893 |
|
|
|
894 |
#回傳結果
|
|
|
895 |
return $result;
|
|
|
896 |
|
|
|
897 |
}#if end
|
|
|
898 |
|
|
|
899 |
#取得csv檔案A的資料筆數
|
|
|
900 |
$DataCountA=$csvFileContentA["lineArrayCount"];
|
|
|
901 |
|
|
|
902 |
#取得csv檔案B的資料筆數
|
|
|
903 |
$DataCountB=$csvFileContentB["lineArrayCount"];
|
|
|
904 |
|
|
|
905 |
#初始化合併好的陣列變數
|
|
|
906 |
$mergedArray=array();
|
|
|
907 |
|
|
|
908 |
#初始化計屬的變數
|
|
|
909 |
$time=0;
|
|
|
910 |
|
|
|
911 |
#針對csv檔案A的每一筆資料
|
|
|
912 |
for($i=0;$i<$DataCountA;$i++){
|
|
|
913 |
|
|
|
914 |
#針對csv檔案B的每一筆資料
|
|
|
915 |
for($j=0;$j<$DataCountB;$j++){
|
|
|
916 |
|
|
|
917 |
#如果有發現csv檔案A與檔案B相同欄位的值有相同
|
|
|
918 |
if($csvFileContentA["csvFileContent"][$i][$conf["compareColumnName"]]==$csvFileContentB["csvFileContent"][$j][$conf["compareColumnName"]]){
|
|
|
919 |
|
|
|
920 |
#則將其合併
|
|
|
921 |
|
|
|
922 |
#針對檔案A的每一個欄位
|
|
|
923 |
foreach($csvFileContentA["csvFileContent"][$i] as $key=>$value){
|
|
|
924 |
|
|
|
925 |
#取得每個欄位的內容
|
|
|
926 |
$mergedArray["line"][$time][$key]=$value;
|
|
|
927 |
|
|
|
928 |
}#foreach end
|
|
|
929 |
|
|
|
930 |
#針對檔案B的每一個欄位
|
|
|
931 |
foreach($csvFileContentB["csvFileContent"][$j] as $key=>$value){
|
|
|
932 |
|
|
|
933 |
#如果不是要比較的變數欄位
|
|
|
934 |
if($key!=$conf["compareColumnName"]){
|
|
|
935 |
|
|
|
936 |
#取得每個欄位的內容
|
|
|
937 |
$mergedArray["line"][$time][$key]=$value;
|
|
|
938 |
|
|
|
939 |
}#if end
|
|
|
940 |
|
|
|
941 |
}#foreach end
|
|
|
942 |
|
|
|
943 |
#計數加1
|
|
|
944 |
$time++;
|
|
|
945 |
|
|
|
946 |
}#if end
|
|
|
947 |
|
|
|
948 |
}#for end
|
|
|
949 |
|
|
|
950 |
}#for end
|
|
|
951 |
|
|
|
952 |
#將合併結果寫入到檔案裡面
|
|
|
953 |
#涵式說明:
|
|
|
954 |
#快速建立一個csv檔案,並且要求使用者下載。
|
|
|
955 |
#回傳的結果:
|
|
|
956 |
#如果有設置$conf["noDownload"]爲"true"的話,則會回傳檔案的位置
|
|
|
957 |
#必填參數:
|
|
|
958 |
$conf["csv"]["create"]["dataArray"]=$mergedArray["line"];#要寫入的文字,$conf["dataArray"][$i],代表第 $i 行的內容。
|
|
|
959 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
960 |
$conf["csv"]["create"]["fileArgu"]=$conf["fileArgu"];
|
|
|
961 |
#可省略參數:
|
|
|
962 |
|
|
|
963 |
#如果有設置 $conf["csvFilePathAndName"]
|
|
|
964 |
if(isset($conf["csvFilePathAndName"])){
|
|
|
965 |
|
|
|
966 |
$conf["csv"]["create"]["csvFilePathAndName"]=$conf["csvFilePathAndName"];#csv檔案輸出的路徑.
|
|
|
967 |
|
|
|
968 |
}#if end
|
|
|
969 |
|
|
|
970 |
#如果有設置 $conf["noDownload"]
|
|
|
971 |
if(isset($conf["noDownload"])){
|
|
|
972 |
|
|
|
973 |
#如果其等於 "true"
|
|
|
974 |
if($conf["noDownload"]=="true"){
|
|
|
975 |
|
|
|
976 |
#設定不自動下載檔案
|
|
|
977 |
$conf["csv"]["create"]["noDownload"]=$conf["noDownload"];
|
|
|
978 |
|
|
|
979 |
}#if end
|
|
|
980 |
|
|
|
981 |
}#if end
|
|
|
982 |
|
|
|
983 |
#$conf["csv"]["create"]["noDownload"]="true";#如果爲"true"則代表不要讓使用者下載,但會回傳檔案的相對位置
|
|
|
984 |
#參考資料來源:
|
|
|
985 |
#http://php.net/manual/en/function.str-split.php
|
|
|
986 |
$csvCreateResult=csv::create($conf["csv"]["create"]);
|
|
|
987 |
unset($conf["csv"]["create"]);
|
|
|
988 |
|
|
|
989 |
#如果檢查有誤
|
|
|
990 |
if($csvCreateResult["status"]=="false"){
|
|
|
991 |
|
|
|
992 |
#設置執行不正常
|
|
|
993 |
$result["status"]="false";
|
|
|
994 |
|
|
|
995 |
#設置錯誤訊息
|
|
|
996 |
$result["error"]=$csvCreateResult;
|
|
|
997 |
|
|
|
998 |
#回傳結果
|
|
|
999 |
return $result;
|
|
|
1000 |
|
|
|
1001 |
}#if end
|
|
|
1002 |
|
|
|
1003 |
#儲存csv檔案
|
|
|
1004 |
$result["content"]=$csvCreateResult["content"];
|
|
|
1005 |
|
|
|
1006 |
#設置執行正常
|
|
|
1007 |
$result["status"]="true";
|
|
|
1008 |
|
|
|
1009 |
#回傳結果
|
|
|
1010 |
return $result;
|
|
|
1011 |
|
|
|
1012 |
}#function mergePairedData end
|
|
|
1013 |
|
|
|
1014 |
/*
|
|
|
1015 |
#函式說明:
|
|
|
1016 |
#刪除csv檔中多個欄位中其數值符合指定條件的資料(將該列刪除).
|
|
|
1017 |
#回傳的結果:
|
|
|
1018 |
#$result["status"],執行是否成功的識別.
|
|
|
1019 |
#$result["error"],錯誤訊息.
|
|
|
1020 |
#$result["csvFileAddress"],處理好的csv檔案位置.
|
|
|
1021 |
#$result["function"],當前執行的函數名稱.
|
|
|
1022 |
#檔案的路徑或下載該檔案的動作
|
|
|
1023 |
#必填參數:
|
|
|
1024 |
#$conf["csvFileLocation"],字串,要進行處理的csv位置與名稱
|
|
|
1025 |
$conf["csvFileLocation"]="";
|
|
|
1026 |
#$conf["coditionColumn"],陣列,要檢查的欄位名稱
|
|
|
1027 |
$conf["coditionColumn"]=array();
|
|
|
1028 |
#$conf["coditionValue"],字串,欄位數值內容若等於多少則符合要移除的條件
|
|
|
1029 |
$conf["coditionValue"]="";
|
|
|
1030 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1031 |
$conf["fileArgu"]=__FILE__;
|
|
|
1032 |
#可省略參數:
|
|
|
1033 |
#$conf["csvFilePathAndName"],字串,輸出的csv檔案位置與名稱,csv副檔名會自動補上.
|
|
|
1034 |
#$conf["csvFilePathAndName"]="";
|
|
|
1035 |
#$conf["noDownload"],字串,如果爲"true"則代表不要讓使用者下載,但會回傳檔案的相對位置.
|
|
|
1036 |
#$conf["noDownload"]="true";
|
|
|
1037 |
#參考資料:
|
|
|
1038 |
#無.
|
|
|
1039 |
#備註:
|
|
|
1040 |
#無
|
|
|
1041 |
*/
|
|
|
1042 |
public static function delSepecificData(&$conf){
|
|
|
1043 |
|
|
|
1044 |
#初始化要回傳的變數
|
|
|
1045 |
$result=array();
|
|
|
1046 |
|
|
|
1047 |
#取得當前執行的函數名稱
|
|
|
1048 |
$result["function"]=__FUNCTION__;
|
|
|
1049 |
|
|
|
1050 |
#如果 $conf 不為陣列
|
|
|
1051 |
if(gettype($conf)!="array"){
|
|
|
1052 |
|
|
|
1053 |
#設置執行失敗
|
|
|
1054 |
$result["status"]="false";
|
|
|
1055 |
|
|
|
1056 |
#設置執行錯誤訊息
|
|
|
1057 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1058 |
|
|
|
1059 |
#如果傳入的參數為 null
|
|
|
1060 |
if($conf==null){
|
|
|
1061 |
|
|
|
1062 |
#設置執行錯誤訊息
|
|
|
1063 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1064 |
|
|
|
1065 |
}#if end
|
|
|
1066 |
|
|
|
1067 |
#回傳結果
|
|
|
1068 |
return $result;
|
|
|
1069 |
|
|
|
1070 |
}#if end
|
|
|
1071 |
|
|
|
1072 |
#涵式說明:
|
|
|
1073 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
1074 |
#回傳的結果:
|
|
|
1075 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1076 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1077 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1078 |
#必填參數:
|
|
|
1079 |
$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
1080 |
$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("csvFileLocation","coditionColumn","coditionValue","fileArgu");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
1081 |
#可以省略的參數:
|
|
|
1082 |
$conf["variableCheck"]["isexistMuti"]["variableType"]=array("string","array","string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
|
|
1083 |
#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
1084 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
|
|
|
1085 |
unset($conf["variableCheck"]["isexistMuti"]);
|
|
|
1086 |
|
|
|
1087 |
#如果檢查必填參數失敗
|
|
|
1088 |
if($checkResult["status"]=="false"){
|
|
|
1089 |
|
|
|
1090 |
#設置執行失敗
|
|
|
1091 |
$result["status"]="false";
|
|
|
1092 |
|
|
|
1093 |
#設置錯誤訊息
|
|
|
1094 |
$result["error"]=$checkResult;
|
|
|
1095 |
|
|
|
1096 |
#回傳結果
|
|
|
1097 |
return $result;
|
|
|
1098 |
|
|
|
1099 |
}#if end
|
|
|
1100 |
|
|
|
1101 |
#如果檢查不通過
|
|
|
1102 |
if($checkResult["passed"]=="false"){
|
|
|
1103 |
|
|
|
1104 |
$result["status"]="false";
|
|
|
1105 |
|
|
|
1106 |
#設置錯誤訊息
|
|
|
1107 |
$result["error"]=$checkResult;
|
|
|
1108 |
|
|
|
1109 |
#回傳結果
|
|
|
1110 |
return $result;
|
|
|
1111 |
|
|
|
1112 |
}#if end
|
|
|
1113 |
|
|
|
1114 |
#涵式說明:
|
|
|
1115 |
#讀取csv檔案的內容
|
|
|
1116 |
#回傳得結果:
|
|
|
1117 |
#$result["status"],執行是否正常,"true"代表正常;"false"代表不正常.
|
|
|
1118 |
#$result["error"],錯誤訊息陣列.
|
|
|
1119 |
#$result["function"],當前執行的函數名稱.
|
|
|
1120 |
#$result["csvFileContent"],csv檔案內容的陣列.
|
|
|
1121 |
#$result["csvFileContent"]["$i"]["$j"]代表第$i+1列第$j+1欄位的內容.
|
|
|
1122 |
#如果 $conf["firstLineVarName"]爲"true"的話則會多回傳 $result["csvFileContent"]["第幾列"]["第一列各個欄位的名稱"]
|
|
|
1123 |
#$result["lineArray"],csv檔案逐列內容的陣列.
|
|
|
1124 |
#$result["lineArrayCount"],總共幾列資料.
|
|
|
1125 |
#如果 $conf["firstLineVarName"]爲"true"的話則會回傳 $csvFileContent["line"]["第幾行"]["第一行各個欄位的名稱"]
|
|
|
1126 |
#必填參數:
|
|
|
1127 |
$conf["csv"]["loadCsvFile"]["csvFilePositionAndName"]=$conf["csvFileLocation"];#csv檔案的位置
|
|
|
1128 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1129 |
$conf["csv"]["loadCsvFile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1130 |
#可省略參數:
|
|
|
1131 |
$conf["csv"]["loadCsvFile"]["firstLineVarName"]="true";#第一行是否爲變數名稱(各個欄位的名稱)
|
|
|
1132 |
#參考資料來源:
|
|
|
1133 |
#http://www.php.net/manual/en/function.str-split.php
|
|
|
1134 |
#參考資料來源
|
|
|
1135 |
#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)
|
|
|
1136 |
$csvFileContent=csv::loadCsvFile($conf["csv"]["loadCsvFile"]);
|
|
|
1137 |
unset($conf["csv"]["loadCsvFile"]);
|
|
|
1138 |
|
|
|
1139 |
#如果讀取csv檔案的內容失敗
|
|
|
1140 |
if($csvFileContent["status"]=="false"){
|
|
|
1141 |
|
|
|
1142 |
#設置執行錯誤
|
|
|
1143 |
$result["status"]="false";
|
|
|
1144 |
|
|
|
1145 |
#設置錯誤訊息
|
|
|
1146 |
$result["error"]=$csvFileContent;
|
|
|
1147 |
|
|
|
1148 |
#回傳結果
|
|
|
1149 |
return $result;
|
|
|
1150 |
|
|
|
1151 |
}#if end
|
|
|
1152 |
|
|
|
1153 |
#初始化要紀錄整理好的資料
|
|
|
1154 |
$arrayData=array();
|
|
|
1155 |
|
|
|
1156 |
#針對每一筆資料/每一列
|
|
|
1157 |
for($i=0;$i<$csvFileContent["lineArrayCount"];$i++){
|
|
|
1158 |
|
|
|
1159 |
#初始化是否要移除的變數為 "false"
|
|
|
1160 |
$del="false";
|
|
|
1161 |
|
|
|
1162 |
#如果是標題列
|
|
|
1163 |
if($i!=0){
|
|
|
1164 |
|
|
|
1165 |
#針對每一筆資料的各個欄位
|
|
|
1166 |
foreach($csvFileContent["csvFileContent"][$i] as $key=>$value){
|
|
|
1167 |
|
|
|
1168 |
#有幾個要檢查的欄位就執行幾次
|
|
|
1169 |
for($j=0;$j<count($conf["coditionColumn"]);$j++){
|
|
|
1170 |
|
|
|
1171 |
#如果是要檢查的欄位
|
|
|
1172 |
if($key==$conf["coditionColumn"][$j]){
|
|
|
1173 |
|
|
|
1174 |
#檢查其數值是否等於 $conf["coditionValue"]
|
|
|
1175 |
if($value==$conf["coditionValue"]){
|
|
|
1176 |
|
|
|
1177 |
#將是否移除的變數設為"true"
|
|
|
1178 |
$del="true";
|
|
|
1179 |
|
|
|
1180 |
#跳出 for
|
|
|
1181 |
break;
|
|
|
1182 |
|
|
|
1183 |
}#if end
|
|
|
1184 |
|
|
|
1185 |
}#if end
|
|
|
1186 |
|
|
|
1187 |
}#for end
|
|
|
1188 |
|
|
|
1189 |
}#foreach end
|
|
|
1190 |
|
|
|
1191 |
}#end
|
|
|
1192 |
|
|
|
1193 |
#如果 $del等於 "false"
|
|
|
1194 |
if($del=="false"){
|
|
|
1195 |
|
|
|
1196 |
#紀錄該筆資料
|
|
|
1197 |
$arrayData["line"][]=$csvFileContent["csvFileContent"][$i];
|
|
|
1198 |
|
|
|
1199 |
}#if end
|
|
|
1200 |
|
|
|
1201 |
}#for end
|
|
|
1202 |
|
|
|
1203 |
#將處理好的內容轉成csv檔
|
|
|
1204 |
#涵式說明:
|
|
|
1205 |
#快速建立一個csv檔案,並且要求使用者下載。
|
|
|
1206 |
#回傳的結果:
|
|
|
1207 |
#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
|
|
|
1208 |
#$result["error"],錯誤訊息陣列.
|
|
|
1209 |
#$result["content"],輸出的csv檔案位置.
|
|
|
1210 |
#必填參數:
|
|
|
1211 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1212 |
$conf["csv"]["create"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1213 |
$conf["csv"]["create"]["dataArray"]=$arrayData["line"];#要寫入的文字,$conf["dataArray"][$i],代表第 $i 行的內容。
|
|
|
1214 |
#可省略參數:
|
|
|
1215 |
|
|
|
1216 |
#如果 $conf["csvFilePathAndName"]有設置
|
|
|
1217 |
if(isset($conf["csvFilePathAndName"])){
|
|
|
1218 |
|
|
|
1219 |
#設置要輸出到哪個位置
|
|
|
1220 |
$conf["csv"]["create"]["csvFilePathAndName"]=$conf["csvFilePathAndName"];
|
|
|
1221 |
|
|
|
1222 |
}#if end
|
|
|
1223 |
|
|
|
1224 |
#如果有設置 $conf["noDownload"]
|
|
|
1225 |
if(isset($conf["noDownload"])){
|
|
|
1226 |
|
|
|
1227 |
#如果其等於 "true"
|
|
|
1228 |
if($conf["noDownload"]=="true"){
|
|
|
1229 |
|
|
|
1230 |
#設定不自動下載檔案
|
|
|
1231 |
$conf["csv"]["create"]["noDownload"]=$conf["noDownload"];
|
|
|
1232 |
|
|
|
1233 |
}#if end
|
|
|
1234 |
|
|
|
1235 |
}#if end
|
|
|
1236 |
|
|
|
1237 |
$conf["ssv"]["create"]["csvFilePathAndName"]=$conf["csvFilePathAndName"];#要儲存到哪個位置,預設爲跟網頁檔案一樣的位置
|
|
|
1238 |
#$conf["csv"]["create"]["noDownload"]="true";#如果爲"true"則代表不要讓使用者下載,但會回傳檔案的相對位置
|
|
|
1239 |
#參考資料來源:
|
|
|
1240 |
#http://php.net/manual/en/function.str-split.php
|
|
|
1241 |
$csvCreateResult=csv::create($conf["csv"]["create"]);
|
|
|
1242 |
unset($conf["csv"]["create"]);
|
|
|
1243 |
|
|
|
1244 |
#如果 $csvCreateResult["status"] 等於 "false"
|
|
|
1245 |
if($csvCreateResult["status"]=="false"){
|
|
|
1246 |
|
|
|
1247 |
#設置錯誤識別
|
|
|
1248 |
$result["status"]="false";
|
|
|
1249 |
|
|
|
1250 |
#設置錯誤訊息
|
|
|
1251 |
$result["error"]=$csvCreateResult;
|
|
|
1252 |
|
|
|
1253 |
#回傳結果
|
|
|
1254 |
return $result;
|
|
|
1255 |
|
|
|
1256 |
}#if end
|
|
|
1257 |
|
|
|
1258 |
#設置執行正常的識別
|
|
|
1259 |
$result["status"]="true";
|
|
|
1260 |
|
|
|
1261 |
#取得處理好的檔案路徑
|
|
|
1262 |
$result["csvFileAddress"]=$csvCreateResult["content"];
|
|
|
1263 |
|
|
|
1264 |
#回傳結果
|
|
|
1265 |
return $result;
|
|
|
1266 |
|
|
|
1267 |
}#function delSepecificData end
|
|
|
1268 |
|
|
|
1269 |
/*
|
|
|
1270 |
#函式說明:
|
|
|
1271 |
#將用於統計分析的原始的陣列中將一個變數分成兩個變數,並且新增在原始的陣列中
|
|
|
1272 |
#回傳的結果:
|
|
|
1273 |
#$result["status"],執行是否正常,正常的話為"true",不正常的話為"false".
|
|
|
1274 |
#$result["error"],錯誤訊息.
|
|
|
1275 |
#$result["function"],當前執行的函數名稱
|
|
|
1276 |
#$result["content"],過增加兩個欄位(統計學上的變數)後的陣列變數
|
|
|
1277 |
#$result["content"][n1][n2],爲第n1行的n2欄位數值內容
|
|
|
1278 |
#必填參數:
|
|
|
1279 |
#$conf["varArray"],陣列,要處理的陣列變數
|
|
|
1280 |
$conf["varArray"]=array();
|
|
|
1281 |
#$conf["addFromVar"],陣列,要從哪些元素來產生要新的變數內容
|
|
|
1282 |
$conf["addFromVar"]=array("");
|
|
|
1283 |
#$conf["newVarName"],字串,資料是新產生的欄位(變數)名稱
|
|
|
1284 |
$conf["newVarName"]="";
|
|
|
1285 |
#$conf["newVarValue"],陣列,要增加變數的數值內容陣列,須與$conf["addFromVar"]的元素數量相同.
|
|
|
1286 |
$conf["newVarValue"]=array();
|
|
|
1287 |
#$conf["sameValueColumnName"],陣列,使用舊有資料的新欄位(變數)名稱.
|
|
|
1288 |
$conf["sameValueColumnName"]=array();
|
|
|
1289 |
#可省略參數:
|
|
|
1290 |
#$conf["firstLineVarName"],字串,第一行是否爲變數名稱(各個欄位的名稱)
|
|
|
1291 |
#$conf["firstLineVarName"]="true";#第一行是否爲變數名稱(各個欄位的名稱)
|
|
|
1292 |
#參考資料:
|
|
|
1293 |
#無.
|
|
|
1294 |
#備註:
|
|
|
1295 |
#無
|
|
|
1296 |
*/
|
|
|
1297 |
public static function add2Var($conf){
|
|
|
1298 |
|
|
|
1299 |
#初始化要回傳的變數
|
|
|
1300 |
$result=array();
|
|
|
1301 |
|
|
|
1302 |
#取得當前執行的函數名稱
|
|
|
1303 |
$result["function"]=__FUNCTION__;
|
|
|
1304 |
|
|
|
1305 |
#如果 $conf 不為陣列
|
|
|
1306 |
if(gettype($conf)!="array"){
|
|
|
1307 |
|
|
|
1308 |
#設置執行失敗
|
|
|
1309 |
$result["status"]="false";
|
|
|
1310 |
|
|
|
1311 |
#設置執行錯誤訊息
|
|
|
1312 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1313 |
|
|
|
1314 |
#如果傳入的參數為 null
|
|
|
1315 |
if($conf==null){
|
|
|
1316 |
|
|
|
1317 |
#設置執行錯誤訊息
|
|
|
1318 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1319 |
|
|
|
1320 |
}#if end
|
|
|
1321 |
|
|
|
1322 |
#回傳結果
|
|
|
1323 |
return $result;
|
|
|
1324 |
|
|
|
1325 |
}#if end
|
|
|
1326 |
|
|
|
1327 |
#檢查參數
|
|
|
1328 |
#涵式說明:
|
|
|
1329 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
1330 |
#回傳的結果:
|
|
|
1331 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1332 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1333 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1334 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1335 |
#必填參數:
|
|
|
1336 |
$conf["analyse"]["isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
1337 |
$conf["analyse"]["isexistMulti"]["variableCheck"]=array("varArray","addFromVar","newVarName","newVarValue","sameValueColumnName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
1338 |
#可以省略的參數:
|
|
|
1339 |
$conf["analyse"]["isexistMulti"]["variableType"]=array("string","array","string","array","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
|
|
1340 |
$conf["analyse"]["isexistMulti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
1341 |
$checkResult=variableCheck::isexistMulti($conf["analyse"]["isexistMulti"]);
|
|
|
1342 |
unset($conf["analyse"]["isexistMulti"]);
|
|
|
1343 |
|
|
|
1344 |
#如果 $checkResult["status"] 等於 "false"
|
|
|
1345 |
if($checkResult["status"]=="false"){
|
|
|
1346 |
|
|
|
1347 |
#設置錯誤識別
|
|
|
1348 |
$result["status"]="false";
|
|
|
1349 |
|
|
|
1350 |
#設置錯誤訊息
|
|
|
1351 |
$result["error"]=$checkResult;
|
|
|
1352 |
|
|
|
1353 |
#回傳結果
|
|
|
1354 |
return $result;
|
|
|
1355 |
|
|
|
1356 |
}#if end
|
|
|
1357 |
|
|
|
1358 |
#計數用的變數
|
|
|
1359 |
$times=0;
|
|
|
1360 |
|
|
|
1361 |
#初始化暫存變數名稱的陣列
|
|
|
1362 |
$varTitleArray=array();
|
|
|
1363 |
|
|
|
1364 |
#一行行處理(一筆筆處理)
|
|
|
1365 |
for($i=0;$i<count($conf["varArray"]);$i++){
|
|
|
1366 |
|
|
|
1367 |
#初始化暫存每行變數內容的陣列
|
|
|
1368 |
$tempArray=array();
|
|
|
1369 |
|
|
|
1370 |
#初始化計數元素欄位數的暫存變數
|
|
|
1371 |
$j=0;
|
|
|
1372 |
|
|
|
1373 |
#如果是在處理標題行,且有設定 $conf["firstLineVarName"]
|
|
|
1374 |
if($i==0 && isset($conf["firstLineVarName"]) ){
|
|
|
1375 |
|
|
|
1376 |
#如果 $conf["firstLineVarName"] 等於 true
|
|
|
1377 |
if($conf["firstLineVarName"]=="true"){
|
|
|
1378 |
|
|
|
1379 |
#針對每行各欄位
|
|
|
1380 |
foreach($conf["varArray"][$i] as $key=>$value){
|
|
|
1381 |
|
|
|
1382 |
#取得標題行變數
|
|
|
1383 |
$varTitleArray[$key]=$value;
|
|
|
1384 |
|
|
|
1385 |
}#foreach end
|
|
|
1386 |
|
|
|
1387 |
#取得標題行新增的變數
|
|
|
1388 |
$varTitleArray[$conf["newVarName"]]=$conf["newVarName"];
|
|
|
1389 |
$varTitleArray[$conf["sameValueColumnName"]]=$conf["sameValueColumnName"];
|
|
|
1390 |
|
|
|
1391 |
#取得標題列
|
|
|
1392 |
$result["content"][$times]=$varTitleArray;
|
|
|
1393 |
|
|
|
1394 |
#計數加1
|
|
|
1395 |
$times++;
|
|
|
1396 |
|
|
|
1397 |
}#if end
|
|
|
1398 |
|
|
|
1399 |
}#if end
|
|
|
1400 |
|
|
|
1401 |
#反之代表不是標題列
|
|
|
1402 |
else{
|
|
|
1403 |
|
|
|
1404 |
#針對要從哪些變數產生新變數內容的陣列
|
|
|
1405 |
for($k=0;$k<count($conf["addFromVar"]);$k++){
|
|
|
1406 |
|
|
|
1407 |
#針對每行各欄位
|
|
|
1408 |
foreach($conf["varArray"][$i] as $key=>$value){
|
|
|
1409 |
|
|
|
1410 |
#先儲存原始的內容
|
|
|
1411 |
$tempArray[$key]=$value;
|
|
|
1412 |
|
|
|
1413 |
}#foreach end
|
|
|
1414 |
|
|
|
1415 |
#新增一個元素
|
|
|
1416 |
$tempArray[$conf["newVarName"]]=$conf["newVarValue"][$k];
|
|
|
1417 |
|
|
|
1418 |
#新增一個元素
|
|
|
1419 |
$tempArray[$conf["sameValueColumnName"]]=$conf["varArray"][$i][$conf["addFromVar"][$k]];
|
|
|
1420 |
|
|
|
1421 |
#儲存新行
|
|
|
1422 |
$result["content"][$times]=$tempArray;
|
|
|
1423 |
|
|
|
1424 |
#計算總共有幾筆的計數+1
|
|
|
1425 |
$times++;
|
|
|
1426 |
|
|
|
1427 |
#如果已經是最後一個欄位
|
|
|
1428 |
if($j=count($conf["newVarValue"])+1){
|
|
|
1429 |
|
|
|
1430 |
#將之初始化爲0
|
|
|
1431 |
$j=0;
|
|
|
1432 |
|
|
|
1433 |
}#if end
|
|
|
1434 |
|
|
|
1435 |
#反之不是最後一各欄位
|
|
|
1436 |
else{
|
|
|
1437 |
|
|
|
1438 |
#欄位計數加1
|
|
|
1439 |
$j++;
|
|
|
1440 |
|
|
|
1441 |
}#else end
|
|
|
1442 |
|
|
|
1443 |
}#for end
|
|
|
1444 |
|
|
|
1445 |
}#if end
|
|
|
1446 |
|
|
|
1447 |
}#for end
|
|
|
1448 |
|
|
|
1449 |
#設置執行正常的識別
|
|
|
1450 |
$result["status"]="true";
|
|
|
1451 |
|
|
|
1452 |
#回傳結果
|
|
|
1453 |
return $result;
|
|
|
1454 |
|
|
|
1455 |
}#function add2Var end
|
|
|
1456 |
|
|
|
1457 |
/*
|
|
|
1458 |
#函式說明:
|
|
|
1459 |
#將csv檔中的一個變數變成兩個變數,並輸出成csv檔。
|
|
|
1460 |
#回傳的結果:
|
|
|
1461 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1462 |
#$result["error"],錯誤訊息.
|
|
|
1463 |
#$result["function"],當前執行的函數名稱.
|
|
|
1464 |
#$result["outputCsvFileAddress"],csv檔案輸出的位置與名稱.
|
|
|
1465 |
#必填參數:
|
|
|
1466 |
#$conf["csvFileLocation"],字串,csv檔案的位置.
|
|
|
1467 |
$conf["csvFileLocation"]="";
|
|
|
1468 |
#$conf["addFromVar"],陣列,要從哪些元素來產生要新的變數內容.
|
|
|
1469 |
$conf["addFromVar"]=array("");
|
|
|
1470 |
#$conf["newVarName"],字串,資料是新產生的欄位(變數)名稱.
|
|
|
1471 |
$conf["newVarName"]="";
|
|
|
1472 |
#$conf["sameValueColumnName"],字串,使用舊有資料的新欄位(變數)名稱.
|
|
|
1473 |
$conf["sameValueColumnName"]="";
|
|
|
1474 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1475 |
$conf["fileArgu"]=__FILE__;
|
|
|
1476 |
#可省略參數:
|
|
|
1477 |
#$conf["newVarValue"],陣列,要增加變數的數值內容陣列,須與$conf["addFromVar"]的元素數量相同。預設與$conf["addFromVar"]相同
|
|
|
1478 |
#$conf["newVarValue"]=array();
|
|
|
1479 |
#$conf["outputCsvFilePathAndName"],字串,要儲存到哪個位置,預設爲跟網頁檔案一樣的位置,檔案名稱預設爲系統時間,副檔名csv會自動加上.
|
|
|
1480 |
#$conf["outputCsvFilePathAndName"]="";
|
|
|
1481 |
#$conf["noDownload"],字串,如果爲"true"則代表不要讓使用者下載,但會回傳檔案的相對位置.
|
|
|
1482 |
#$conf["noDownload"]="true";
|
|
|
1483 |
#參考資料:
|
|
|
1484 |
#無.
|
|
|
1485 |
#備註:
|
|
|
1486 |
#可能需要優化效能
|
|
|
1487 |
*/
|
|
|
1488 |
public static function build2VarForm1(&$conf){
|
|
|
1489 |
|
|
|
1490 |
#初始化要回傳的變數
|
|
|
1491 |
$result=array();
|
|
|
1492 |
|
|
|
1493 |
#取得當前執行的函數名稱
|
|
|
1494 |
$result["function"]=__FUNCTION__;
|
|
|
1495 |
|
|
|
1496 |
#如果 $conf 不為陣列
|
|
|
1497 |
if(gettype($conf)!="array"){
|
|
|
1498 |
|
|
|
1499 |
#設置執行失敗
|
|
|
1500 |
$result["status"]="false";
|
|
|
1501 |
|
|
|
1502 |
#設置執行錯誤訊息
|
|
|
1503 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1504 |
|
|
|
1505 |
#如果傳入的參數為 null
|
|
|
1506 |
if($conf==null){
|
|
|
1507 |
|
|
|
1508 |
#設置執行錯誤訊息
|
|
|
1509 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1510 |
|
|
|
1511 |
}#if end
|
|
|
1512 |
|
|
|
1513 |
#回傳結果
|
|
|
1514 |
return $result;
|
|
|
1515 |
|
|
|
1516 |
}#if end
|
|
|
1517 |
|
|
|
1518 |
#涵式說明:
|
|
|
1519 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
1520 |
#回傳的結果:
|
|
|
1521 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1522 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1523 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1524 |
#必填參數:
|
|
|
1525 |
$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
1526 |
$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("csvFileLocation","addFromVar","newVarName","sameValueColumnName","fileArgu");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
1527 |
#可以省略的參數:
|
|
|
1528 |
$conf["variableCheck"]["isexistMuti"]["variableType"]=array("string","array","string","string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
|
|
1529 |
#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
1530 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
|
|
|
1531 |
unset($conf["variableCheck"]["isexistMuti"]);
|
|
|
1532 |
|
|
|
1533 |
#如果檢查不通過
|
|
|
1534 |
if($checkResult["passed"]=="false"){
|
|
|
1535 |
|
|
|
1536 |
#設置錯誤識別
|
|
|
1537 |
$result["status"]="false";
|
|
|
1538 |
|
|
|
1539 |
#設置錯誤訊息
|
|
|
1540 |
$result["error"]=$checkResult;
|
|
|
1541 |
|
|
|
1542 |
#回傳結果
|
|
|
1543 |
return $result;
|
|
|
1544 |
|
|
|
1545 |
}#if end
|
|
|
1546 |
|
|
|
1547 |
#涵式說明:
|
|
|
1548 |
#讀取csv檔案的內容
|
|
|
1549 |
#回傳得結果:
|
|
|
1550 |
#$result["status"],執行是否正常,"true"代表正常;"false"代表不正常.
|
|
|
1551 |
#$result["error"],錯誤訊息陣列.
|
|
|
1552 |
#$result["csvFileContent"],csv檔案內容的陣列
|
|
|
1553 |
#$result["csvFileContent"]["$i"]["$j"]代表第$i+1列第$j+1欄位的內容.
|
|
|
1554 |
#如果 $conf["firstLineVarName"]爲"true"的話則會回傳 $result["csvFileContent"]["第幾列"]["第一列各個欄位的名稱"]
|
|
|
1555 |
#$result["lineArray"],csv檔案逐列內容的陣列.
|
|
|
1556 |
#$result["lineArrayCount"],總共幾列資料
|
|
|
1557 |
#必填參數:
|
|
|
1558 |
$conf["csv"]["loadCsvFile"]["csvFilePositionAndName"]=$conf["csvFileLocation"];#csv檔案的位置
|
|
|
1559 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1560 |
$conf["csv"]["loadCsvFile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1561 |
#可省略參數:
|
|
|
1562 |
$conf["csv"]["loadCsvFile"]["firstLineVarName"]="true";#第一行是否爲變數名稱(各個欄位的名稱)
|
|
|
1563 |
#參考資料來源:
|
|
|
1564 |
#http://www.php.net/manual/en/function.str-split.php
|
|
|
1565 |
#參考資料來源
|
|
|
1566 |
#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)
|
|
|
1567 |
$csvFileContent=csv::loadCsvFile($conf["csv"]["loadCsvFile"]);
|
|
|
1568 |
unset($conf["csv"]["loadCsvFile"]);
|
|
|
1569 |
|
|
|
1570 |
#檢查變數內容
|
|
|
1571 |
#var_dump($csvFileContent);
|
|
|
1572 |
|
|
|
1573 |
#如果讀取csv檔案失敗
|
|
|
1574 |
if($csvFileContent["status"]=="false"){
|
|
|
1575 |
|
|
|
1576 |
#設置錯誤識別
|
|
|
1577 |
$result["status"]="false";
|
|
|
1578 |
|
|
|
1579 |
#設置錯誤訊息
|
|
|
1580 |
$result["error"]=$csvFileContent;
|
|
|
1581 |
|
|
|
1582 |
#回傳結果
|
|
|
1583 |
return $result;
|
|
|
1584 |
|
|
|
1585 |
}#if end
|
|
|
1586 |
|
|
|
1587 |
#如果 $conf["newVarValue"] 沒有設定
|
|
|
1588 |
if(!isset($conf["newVarValue"])){
|
|
|
1589 |
|
|
|
1590 |
#則 $conf["newVarValue"] 設為 $conf["addFromVar"]
|
|
|
1591 |
$conf["newVarValue"]=$conf["addFromVar"];
|
|
|
1592 |
|
|
|
1593 |
}#if end
|
|
|
1594 |
|
|
|
1595 |
#涵式說明:
|
|
|
1596 |
#從原始的陣列中將一個變數分成兩個變數,並且新增在原始的陣列中
|
|
|
1597 |
#回傳的結果:
|
|
|
1598 |
#$result["status"],執行是否正常,正常的話為"true",不正常的話為"false".
|
|
|
1599 |
#$result["error"],錯誤訊息.
|
|
|
1600 |
#$result["content"],過增加兩個欄位(統計學上的變數)後的陣列變數
|
|
|
1601 |
#$result["content"][n1][n2],爲第n1行的n2欄位數值內容
|
|
|
1602 |
#必填參數:
|
|
|
1603 |
$conf["math"]["add2Var"]["varArray"]=$csvFileContent["csvFileContent"];#要處理的陣列變數
|
|
|
1604 |
$conf["math"]["add2Var"]["addFromVar"]=$conf["addFromVar"];#要從哪些元素來產生要新的變數內容
|
|
|
1605 |
$conf["math"]["add2Var"]["newVarName"]=$conf["newVarName"];#要新增的變數(欄位)名稱
|
|
|
1606 |
$conf["math"]["add2Var"]["newVarValue"]=$conf["newVarValue"];#要增加變數的數值內容陣列,須與$conf["addFromVar"]的元素數量相同。
|
|
|
1607 |
$conf["math"]["add2Var"]["sameValueColumnName"]=$conf["sameValueColumnName"];#要新增的變數(欄位)名稱
|
|
|
1608 |
#可省略參數:
|
|
|
1609 |
$conf["math"]["add2Var"]["firstLineVarName"]="true";#第一行是否爲變數名稱(各個欄位的名稱)
|
|
|
1610 |
$addedCsvFile=analyse::add2Var($conf["math"]["add2Var"]);
|
|
|
1611 |
unset($conf["math"]["add2Var"]);
|
|
|
1612 |
|
|
|
1613 |
#如果analyse::add2Var執行失敗
|
|
|
1614 |
if($addedCsvFile["status"]=="false"){
|
|
|
1615 |
|
|
|
1616 |
#設置錯誤識別
|
|
|
1617 |
$result["status"]="false";
|
|
|
1618 |
|
|
|
1619 |
#設置錯誤訊息
|
|
|
1620 |
$result["error"]=$addedCsvFile;
|
|
|
1621 |
|
|
|
1622 |
#回傳結果
|
|
|
1623 |
return $result;
|
|
|
1624 |
|
|
|
1625 |
}#if end
|
|
|
1626 |
|
|
|
1627 |
#將處理好的內容轉成csv檔
|
|
|
1628 |
#涵式說明:
|
|
|
1629 |
#快速建立一個csv檔案,並且要求使用者下載。
|
|
|
1630 |
#回傳的結果:
|
|
|
1631 |
#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
|
|
|
1632 |
#$result["error"],錯誤訊息陣列.
|
|
|
1633 |
#$result["content"],輸出的csv檔案位置.
|
|
|
1634 |
#必填參數:
|
|
|
1635 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1636 |
$conf["csv"]["create"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1637 |
$conf["csv"]["create"]["dataArray"]=$addedCsvFile["content"];#要寫入的文字,$conf["dataArray"][$i],代表第 $i 行的內容。
|
|
|
1638 |
#可省略參數:
|
|
|
1639 |
|
|
|
1640 |
#如果有設置 $conf["outputCsvFilePathAndName"]
|
|
|
1641 |
if(isset($conf["outputCsvFilePathAndName"])){
|
|
|
1642 |
|
|
|
1643 |
#將輸出目錄與名稱設為 $conf["outputCsvFilePathAndName"]
|
|
|
1644 |
$conf["csv"]["create"]["csvFilePathAndName"]=$conf["outputCsvFilePathAndName"];#輸出的csv檔案路徑與名稱,預設爲系統時間,副檔名"csv"會自動加上.
|
|
|
1645 |
|
|
|
1646 |
}#if end
|
|
|
1647 |
|
|
|
1648 |
#如果有設置 $conf["noDownload"]
|
|
|
1649 |
if(isset($conf["noDownload"])){
|
|
|
1650 |
|
|
|
1651 |
#如果其等於 "true"
|
|
|
1652 |
if($conf["noDownload"]=="true"){
|
|
|
1653 |
|
|
|
1654 |
#設定自動下載檔案
|
|
|
1655 |
$conf["csv"]["create"]["noDownload"]=$conf["noDownload"];
|
|
|
1656 |
|
|
|
1657 |
}#if end
|
|
|
1658 |
|
|
|
1659 |
}#if end
|
|
|
1660 |
|
|
|
1661 |
#$conf["csv"]["create"]["noDownload"]="true";#如果爲"true"則代表不要讓使用者下載,但會回傳檔案的相對位置
|
|
|
1662 |
#參考資料來源:
|
|
|
1663 |
#http://php.net/manual/en/function.str-split.php
|
|
|
1664 |
$csvFileCreateResult=csv::create($conf["csv"]["create"]);
|
|
|
1665 |
unset($conf["csv"]["create"]);
|
|
|
1666 |
|
|
|
1667 |
#如果 $csvFileCreateResult["status"] 等於 "false"
|
|
|
1668 |
if($csvFileCreateResult["status"]=="false"){
|
|
|
1669 |
|
|
|
1670 |
#設置錯誤識別
|
|
|
1671 |
$result["status"]="false";
|
|
|
1672 |
|
|
|
1673 |
#設置錯誤訊息
|
|
|
1674 |
$result["error"]=$csvFileCreateResult;
|
|
|
1675 |
|
|
|
1676 |
#回傳結果
|
|
|
1677 |
return $result;
|
|
|
1678 |
|
|
|
1679 |
}#if end
|
|
|
1680 |
|
|
|
1681 |
#執行到這邊代表執行正常
|
|
|
1682 |
$result["status"]="true";
|
|
|
1683 |
|
|
|
1684 |
#儲存csv檔輸出的路徑
|
|
|
1685 |
$result["outputCsvFileAddress"]=$csvFileCreateResult["content"];
|
|
|
1686 |
|
|
|
1687 |
#回傳結果
|
|
|
1688 |
return $result;
|
|
|
1689 |
|
|
|
1690 |
}#function addSample end
|
|
|
1691 |
|
|
|
1692 |
/*
|
|
|
1693 |
#函式說明:
|
|
|
1694 |
#將單一欄格式為"a1,a2,a3,b1,b4,c5,c6,d1"且
|
|
|
1695 |
#a的選項有a1,a2,a3.
|
|
|
1696 |
#b的選項有b1,b2,b3.b4,b5
|
|
|
1697 |
#c的選項有c1,c2,c3,c4,c5,c6
|
|
|
1698 |
#d的選項有d1,d2,d3
|
|
|
1699 |
#的字串轉變成1,2,3,5,7,13,14,15
|
|
|
1700 |
#回傳的結果:
|
|
|
1701 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1702 |
#$result["error"],錯誤訊息陣列.
|
|
|
1703 |
#$result["content"],處理好的字串.
|
|
|
1704 |
#$result["function"],當前執行的函數名稱.
|
|
|
1705 |
#必填參數:
|
|
|
1706 |
#$conf["inputStr"],要處理的字串.
|
|
|
1707 |
$conf["inputStr"]="";
|
|
|
1708 |
#$conf["leaderWordArray"],字串陣列,為代表某一類的代號陣列,請按照順序排列.
|
|
|
1709 |
$conf["leaderWordArray"]=array("a","b","c");
|
|
|
1710 |
#$conf["leaderWordOptionCountArray"],字串陣列,每類代號的選項數目,請按照順序排列.
|
|
|
1711 |
$conf["leaderWordOptionCountArray"]=array("3","5","6");
|
|
|
1712 |
#可省略參數:
|
|
|
1713 |
#無.
|
|
|
1714 |
#參考資料:
|
|
|
1715 |
#無.
|
|
|
1716 |
#備註:
|
|
|
1717 |
#無
|
|
|
1718 |
*/
|
|
|
1719 |
public static function changeToNumberList(&$conf){
|
|
|
1720 |
|
|
|
1721 |
#初始化要回傳的內容
|
|
|
1722 |
$result=array();
|
|
|
1723 |
|
|
|
1724 |
#取得當前執行的函數名稱
|
|
|
1725 |
$result["function"]=__FUNCTION__;
|
|
|
1726 |
|
|
|
1727 |
#如果 $conf 不為陣列
|
|
|
1728 |
if(gettype($conf)!="array"){
|
|
|
1729 |
|
|
|
1730 |
#設置執行失敗
|
|
|
1731 |
$result["status"]="false";
|
|
|
1732 |
|
|
|
1733 |
#設置執行錯誤訊息
|
|
|
1734 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1735 |
|
|
|
1736 |
#如果傳入的參數為 null
|
|
|
1737 |
if($conf==null){
|
|
|
1738 |
|
|
|
1739 |
#設置執行錯誤訊息
|
|
|
1740 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1741 |
|
|
|
1742 |
}#if end
|
|
|
1743 |
|
|
|
1744 |
#回傳結果
|
|
|
1745 |
return $result;
|
|
|
1746 |
|
|
|
1747 |
}#if end
|
|
|
1748 |
|
|
|
1749 |
#檢查參數
|
|
|
1750 |
#涵式說明:
|
|
|
1751 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
1752 |
#回傳的結果:
|
|
|
1753 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1754 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1755 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1756 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1757 |
#必填參數:
|
|
|
1758 |
$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
1759 |
$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("inputStr","leaderWordArray","leaderWordOptionCountArray");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
1760 |
#可以省略的參數:
|
|
|
1761 |
$conf["variableCheck"]["isexistMuti"]["variableType"]=array("string","array","array");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
|
|
1762 |
$conf["variableCheck"]["isexistMuti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
1763 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
|
|
|
1764 |
unset($conf["variableCheck"]["isexistMuti"]);
|
|
|
1765 |
|
|
|
1766 |
#如果 $checkResult["status"] 等於 "fasle"
|
|
|
1767 |
if($checkResult["status"]=="false"){
|
|
|
1768 |
|
|
|
1769 |
#設置錯誤識別
|
|
|
1770 |
$result["status"]="false";
|
|
|
1771 |
|
|
|
1772 |
#設置錯誤訊息
|
|
|
1773 |
$result["error"]=$checkResult;
|
|
|
1774 |
|
|
|
1775 |
#回傳結果
|
|
|
1776 |
return $result;
|
|
|
1777 |
|
|
|
1778 |
}#if end
|
|
|
1779 |
|
|
|
1780 |
#如果 $checkResult["passed"] 等於 "fasle"
|
|
|
1781 |
if($checkResult["passed"]=="false"){
|
|
|
1782 |
|
|
|
1783 |
#設置錯誤識別
|
|
|
1784 |
$result["status"]="false";
|
|
|
1785 |
|
|
|
1786 |
#設置錯誤訊息
|
|
|
1787 |
$result["error"]=$checkResult;
|
|
|
1788 |
|
|
|
1789 |
#回傳結果
|
|
|
1790 |
return $result;
|
|
|
1791 |
|
|
|
1792 |
}#if end
|
|
|
1793 |
|
|
|
1794 |
#初始化編號對應的號碼順序陣列
|
|
|
1795 |
$pairedTable=array();
|
|
|
1796 |
|
|
|
1797 |
#有幾個非數字開頭的編號前置字串,就執行幾次.
|
|
|
1798 |
for($i=0;$i<count($conf["leaderWordArray"]);$i++){
|
|
|
1799 |
|
|
|
1800 |
#針對每個非數字開頭編號前置字串的選項數量
|
|
|
1801 |
for($j=0;$j<$conf["leaderWordOptionCountArray"][$i];$j++){
|
|
|
1802 |
|
|
|
1803 |
#儲存編號對應的數字順序號碼
|
|
|
1804 |
$pairedTable[]=$conf["leaderWordArray"][$i].(string)($j+1);
|
|
|
1805 |
|
|
|
1806 |
#var_dump($pairedTable);
|
|
|
1807 |
|
|
|
1808 |
}#for end
|
|
|
1809 |
|
|
|
1810 |
}#for end
|
|
|
1811 |
|
|
|
1812 |
#var_dump($pairedTable);
|
|
|
1813 |
|
|
|
1814 |
#將輸入字串用「,」分隔
|
|
|
1815 |
#涵式說明:
|
|
|
1816 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
1817 |
#回傳的參數:
|
|
|
1818 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1819 |
#$result["error"],錯誤訊息陣列
|
|
|
1820 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
1821 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
1822 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
1823 |
#必填參數:
|
|
|
1824 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$conf["inputStr"];#要處理的字串。
|
|
|
1825 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]=",";#爲以哪個符號作爲分割
|
|
|
1826 |
$spiltedStr=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
1827 |
unset($conf["stringProcess"]["spiltString"]);
|
|
|
1828 |
|
|
|
1829 |
#如果 $spiltedStr["status"] 等於 "false"
|
|
|
1830 |
if($spiltedStr["status"]=="false"){
|
|
|
1831 |
|
|
|
1832 |
#設置錯誤識別
|
|
|
1833 |
$result["status"]="false";
|
|
|
1834 |
|
|
|
1835 |
#設置錯誤訊息
|
|
|
1836 |
$result["error"]=$spiltedStr;
|
|
|
1837 |
|
|
|
1838 |
#回傳結果
|
|
|
1839 |
return $result;
|
|
|
1840 |
|
|
|
1841 |
}#if end
|
|
|
1842 |
|
|
|
1843 |
#初始化編號轉換過後對應的號碼順序陣列
|
|
|
1844 |
$transformedNumber=array();
|
|
|
1845 |
|
|
|
1846 |
#針對輸入有幾個編號
|
|
|
1847 |
for($i=0;$i<$spiltedStr["dataCounts"];$i++){
|
|
|
1848 |
|
|
|
1849 |
#判斷編號對應的數字為何
|
|
|
1850 |
#涵式說明:
|
|
|
1851 |
#檢查一個數值是否與陣列裏面的元素相同
|
|
|
1852 |
#回傳的結果:
|
|
|
1853 |
#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
|
|
|
1854 |
#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
|
|
|
1855 |
#$result["error"],錯誤訊息
|
|
|
1856 |
#$result["function"],當前執行的函數名稱
|
|
|
1857 |
#$result["equalVarName"],相等的變數名稱或key.
|
|
|
1858 |
#$result["equalVarValue"],相等的變數數值內容.
|
|
|
1859 |
#必填參數:
|
|
|
1860 |
$conf["search"]["getEqualVar"]["conditionElement"]=$spiltedStr["dataArray"][$i];#條件元素,要等於的元素內容。
|
|
|
1861 |
$conf["search"]["getEqualVar"]["compareElements"]=$pairedTable;#要比對的陣列變數內容。
|
|
|
1862 |
$searchResult=search::getEqualVar($conf["search"]["getEqualVar"]);
|
|
|
1863 |
unset($conf["search"]["getEqualVar"]);
|
|
|
1864 |
|
|
|
1865 |
#如果搜尋出錯
|
|
|
1866 |
if($searchResult["status"]=="false"){
|
|
|
1867 |
|
|
|
1868 |
#設置錯誤識別
|
|
|
1869 |
$result["status"]="false";
|
|
|
1870 |
|
|
|
1871 |
#設置錯誤訊息
|
|
|
1872 |
$result["error"]=$searchResult;
|
|
|
1873 |
|
|
|
1874 |
#回傳結果
|
|
|
1875 |
return $result;
|
|
|
1876 |
|
|
|
1877 |
}#if end
|
|
|
1878 |
|
|
|
1879 |
#如果沒有找到編號對應的數字
|
|
|
1880 |
if($searchResult["founded"]=="false"){
|
|
|
1881 |
|
|
|
1882 |
#設置錯誤識別
|
|
|
1883 |
$result["status"]="false";
|
|
|
1884 |
|
|
|
1885 |
#設置錯誤訊息
|
|
|
1886 |
$result["error"]=$searchResult;
|
|
|
1887 |
|
|
|
1888 |
#回傳結果
|
|
|
1889 |
return $result;
|
|
|
1890 |
|
|
|
1891 |
}#if end
|
|
|
1892 |
|
|
|
1893 |
#儲存編號對應到的數字號碼
|
|
|
1894 |
$transformedNumber[]=$searchResult["equalVarName"]+1;
|
|
|
1895 |
|
|
|
1896 |
}#for end
|
|
|
1897 |
|
|
|
1898 |
#將轉換好的數字陣列變成用「,」分隔字串
|
|
|
1899 |
#函式說明:
|
|
|
1900 |
#將陣列裡的元素內容用特定符號連接在一起變成字串.
|
|
|
1901 |
#回傳的結果:
|
|
|
1902 |
#$result["statu"],執行是否正常,"true"代表執行正常,"false"代表執行失敗
|
|
|
1903 |
#$result["error"],錯誤訊息陣列.
|
|
|
1904 |
#$result["content"],處理過後的字串.
|
|
|
1905 |
#必填的字串:
|
|
|
1906 |
#$conf["inputArray"],字串陣列,要處理的陣列.
|
|
|
1907 |
$conf["stringProcess"]["combineElementWithSymbol"]["inputArray"]=$transformedNumber;
|
|
|
1908 |
#$conf["combineSymbol"],字串,用來連結各元素的符號.
|
|
|
1909 |
$conf["stringProcess"]["combineElementWithSymbol"]["combineSymbol"]=",";
|
|
|
1910 |
$combineedStr=stringProcess::combineElementWithSymbol($conf["stringProcess"]["combineElementWithSymbol"]);
|
|
|
1911 |
unset($conf["stringProcess"]["combineElementWithSymbol"]);
|
|
|
1912 |
|
|
|
1913 |
# $combineedStr["status"] 為 "false"
|
|
|
1914 |
if($combineedStr["status"]=="false"){
|
|
|
1915 |
|
|
|
1916 |
#設置錯誤識別
|
|
|
1917 |
$result["status"]="false";
|
|
|
1918 |
|
|
|
1919 |
#設置錯誤訊息
|
|
|
1920 |
$result["error"]=$combineedStr;
|
|
|
1921 |
|
|
|
1922 |
#回傳結果
|
|
|
1923 |
return $result;
|
|
|
1924 |
|
|
|
1925 |
}#if end
|
|
|
1926 |
|
|
|
1927 |
#取得處理好的字串
|
|
|
1928 |
$result["content"]=$combineedStr["content"];
|
|
|
1929 |
|
|
|
1930 |
#執行到這邊代表正常
|
|
|
1931 |
|
|
|
1932 |
#設置執行正常
|
|
|
1933 |
$result["status"]="true";
|
|
|
1934 |
|
|
|
1935 |
#回傳結果
|
|
|
1936 |
return $result;
|
|
|
1937 |
|
|
|
1938 |
}#function changeToNumberList end
|
|
|
1939 |
|
|
|
1940 |
/*
|
|
|
1941 |
#函式說明:
|
|
|
1942 |
#將csv檔中多行用「,」分隔且有不同前置字元的順序字串,變成多行用數字且按順序排列用「,」分隔的csv檔案.
|
|
|
1943 |
#回傳的結果:
|
|
|
1944 |
#$result["status"],執形式否正常,"true"代表正常,"false"代表不正常.
|
|
|
1945 |
#$result["error"],錯誤訊息.
|
|
|
1946 |
#$result["csvFile"],處理好的csv檔案位置與名稱.
|
|
|
1947 |
#$result["function"],當前執行的函數名稱.
|
|
|
1948 |
#必填參數:
|
|
|
1949 |
#$conf["csvIn"],字串,要處理的csv檔案;
|
|
|
1950 |
$conf["csvIn"]=".csv";
|
|
|
1951 |
#$conf["leaderWordArray"],陣列,為代表某一類的代號陣列,請按照順序排列.
|
|
|
1952 |
$conf["leaderWordArray"]=array();
|
|
|
1953 |
#$conf["leaderWordOptionCountArray"],陣列,每類代號的選項數目,請按照順序排列.
|
|
|
1954 |
$conf["leaderWordOptionCountArray"]=array();
|
|
|
1955 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1956 |
$conf["fileArgu"]=__FILE__;
|
|
|
1957 |
#可省略參數:
|
|
|
1958 |
#$conf["csvOutFilePathAndName"],字串,輸出的檔案要存放在那裡與其名稱為何?預設為同目錄底下其檔案名稱為系統時間.
|
|
|
1959 |
#$conf["csvOutFilePathAndName"]="";
|
|
|
1960 |
#$conf["noDownload"],字串,"true"代表要立即下載產生好的csv檔案,"false"代表不要立即下載,預設為"true".
|
|
|
1961 |
#$conf["noDownload"]="true";
|
|
|
1962 |
#參考資料:
|
|
|
1963 |
#無.
|
|
|
1964 |
#備註:
|
|
|
1965 |
#無
|
|
|
1966 |
*/
|
|
|
1967 |
public static function changeToNumberListInCsv(&$conf){
|
|
|
1968 |
|
|
|
1969 |
#初始化要回傳的結果
|
|
|
1970 |
$result=array();
|
|
|
1971 |
|
|
|
1972 |
#取得當前執行的函數名稱
|
|
|
1973 |
$result["function"]=__FUNCTION__;
|
|
|
1974 |
|
|
|
1975 |
#如果 $conf 不為陣列
|
|
|
1976 |
if(gettype($conf)!="array"){
|
|
|
1977 |
|
|
|
1978 |
#設置執行失敗
|
|
|
1979 |
$result["status"]="false";
|
|
|
1980 |
|
|
|
1981 |
#設置執行錯誤訊息
|
|
|
1982 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1983 |
|
|
|
1984 |
#如果傳入的參數為 null
|
|
|
1985 |
if($conf==null){
|
|
|
1986 |
|
|
|
1987 |
#設置執行錯誤訊息
|
|
|
1988 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1989 |
|
|
|
1990 |
}#if end
|
|
|
1991 |
|
|
|
1992 |
#回傳結果
|
|
|
1993 |
return $result;
|
|
|
1994 |
|
|
|
1995 |
}#if end
|
|
|
1996 |
|
|
|
1997 |
#產生系統時間
|
|
|
1998 |
#回傳西元的目前時間,格式為2010年07月24日15時30分33秒
|
|
|
1999 |
#必填參數:
|
|
|
2000 |
$conf["time::getFullDateAndTime"]["timeZone"]="Asia/Taipei";#時區代號,可以設定的時區列表:http://www.php.net/manual/en/timezones.php
|
|
|
2001 |
#ex:"Asia/Taipei"
|
|
|
2002 |
#可省略參數:
|
|
|
2003 |
#$conf["showSecond"]="true";#若爲"true"則會顯示秒數
|
|
|
2004 |
$systemTime=time::getFullDateAndTime($conf["time::getFullDateAndTime"]);
|
|
|
2005 |
unset($conf["time::getFullDateAndTime"]);
|
|
|
2006 |
|
|
|
2007 |
#檢查參數
|
|
|
2008 |
#函式說明:
|
|
|
2009 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
2010 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2011 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2012 |
#$result["function"],當前執行的函式名稱.
|
|
|
2013 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2014 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2015 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2016 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2017 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2018 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2019 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2020 |
#必填參數:
|
|
|
2021 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2022 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
2023 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2024 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("csvIn","leaderWordArray","leaderWordOptionCountArray","fileArgu");
|
|
|
2025 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
2026 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array","array","string");
|
|
|
2027 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2028 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2029 |
#可以省略的參數:
|
|
|
2030 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
2031 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
2032 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2033 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("csvOutFilePathAndName","noDownload");
|
|
|
2034 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
2035 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
2036 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2037 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($systemTime,"true");
|
|
|
2038 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2039 |
$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("leaderWordArray","leaderWordOptionCountArray");
|
|
|
2040 |
#參考資料來源:
|
|
|
2041 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2042 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2043 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
2044 |
|
|
|
2045 |
#如果 $checkResult["status"] 等於 "fasle"
|
|
|
2046 |
if($checkResult["status"]=="false"){
|
|
|
2047 |
|
|
|
2048 |
#設置錯誤識別
|
|
|
2049 |
$result["status"]="false";
|
|
|
2050 |
|
|
|
2051 |
#設置錯誤訊息
|
|
|
2052 |
$result["error"]=$checkResult;
|
|
|
2053 |
|
|
|
2054 |
#回傳結果
|
|
|
2055 |
return $result;
|
|
|
2056 |
|
|
|
2057 |
}#if end
|
|
|
2058 |
|
|
|
2059 |
#如果 $checkResult["passed"] 等於 "fasle"
|
|
|
2060 |
if($checkResult["passed"]=="false"){
|
|
|
2061 |
|
|
|
2062 |
#設置錯誤識別
|
|
|
2063 |
$result["status"]="false";
|
|
|
2064 |
|
|
|
2065 |
#設置錯誤訊息
|
|
|
2066 |
$result["error"]=$checkResult;
|
|
|
2067 |
|
|
|
2068 |
#回傳結果
|
|
|
2069 |
return $result;
|
|
|
2070 |
|
|
|
2071 |
}#if end
|
|
|
2072 |
|
|
|
2073 |
#涵式說明:
|
|
|
2074 |
#讀取csv檔案的內容
|
|
|
2075 |
#回傳得結果:
|
|
|
2076 |
#$result["status"],執行是否正常,"true"代表正常;"false"代表不正常.
|
|
|
2077 |
#$result["error"],錯誤訊息陣列.
|
|
|
2078 |
#$result["csvFileContent"],csv檔案內容的陣列
|
|
|
2079 |
#$result["csvFileContent"]["$i"]["$j"]代表第$i+1列第$j+1欄位的內容.
|
|
|
2080 |
#如果 $conf["firstLineVarName"]爲"true"的話則會回傳 $result["csvFileContent"]["第幾列"]["第一列各個欄位的名稱"]
|
|
|
2081 |
#$result["lineArray"],csv檔案逐列內容的陣列.
|
|
|
2082 |
#$result["lineArrayCount"],總共幾列資料
|
|
|
2083 |
#必填參數:
|
|
|
2084 |
$conf["csv"]["loadCsvFile"]["csvFilePositionAndName"]=$conf["csvIn"];#csv檔案的位置
|
|
|
2085 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
2086 |
$conf["csv"]["loadCsvFile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
2087 |
#可省略參數:
|
|
|
2088 |
$conf["csv"]["loadCsvFile"]["firstLineVarName"]="false";#第一行是否爲變數名稱(各個欄位的名稱)
|
|
|
2089 |
#參考資料來源:
|
|
|
2090 |
#http://www.php.net/manual/en/function.str-split.php
|
|
|
2091 |
#參考資料來源
|
|
|
2092 |
#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)
|
|
|
2093 |
$csv=csv::loadCsvFile($conf["csv"]["loadCsvFile"]);
|
|
|
2094 |
unset($conf["csv"]["loadCsvFile"]);
|
|
|
2095 |
|
|
|
2096 |
#如果 $csv["status"] 等於 "false"
|
|
|
2097 |
if($csv["status"]=="false"){
|
|
|
2098 |
|
|
|
2099 |
#設置錯誤識別
|
|
|
2100 |
$result["status"]="false";
|
|
|
2101 |
|
|
|
2102 |
#設置錯誤訊息
|
|
|
2103 |
$result["error"]=$csv;
|
|
|
2104 |
|
|
|
2105 |
#回傳結果
|
|
|
2106 |
return $result;
|
|
|
2107 |
|
|
|
2108 |
}#if end
|
|
|
2109 |
|
|
|
2110 |
#初始化處理好的字串陣列
|
|
|
2111 |
$processedStrArray=array();
|
|
|
2112 |
|
|
|
2113 |
#針對每個 $csv["csvFileContent"] 中的元素
|
|
|
2114 |
foreach($csv["csvFileContent"] as $row){
|
|
|
2115 |
|
|
|
2116 |
#函式說明:
|
|
|
2117 |
#將單一欄格式為"a1,a2,a3,b1,b4,c5,c6,d1"且
|
|
|
2118 |
#a的選項有a1,a2,a3.
|
|
|
2119 |
#b的選項有b1,b2,b3.b4,b5
|
|
|
2120 |
#c的選項有c1,c2,c3,c4,c5,c6
|
|
|
2121 |
#d的選項有d1,d2,d3
|
|
|
2122 |
#的字串轉變成1,2,3,5,7,13,14,15
|
|
|
2123 |
#回傳的結果:
|
|
|
2124 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2125 |
#$result["error"],錯誤訊息陣列
|
|
|
2126 |
#$result["content"],處理好的字串
|
|
|
2127 |
#必填參數:
|
|
|
2128 |
#$conf["inputStr"],要處理的字串.
|
|
|
2129 |
$conf["analyse"]["changeToNumberList"]["inputStr"]=$row[0];
|
|
|
2130 |
#$conf["leaderWordArray"],字串陣列,為代表某一類的代號陣列,請按照順序排列.
|
|
|
2131 |
$conf["analyse"]["changeToNumberList"]["leaderWordArray"]=$conf["leaderWordArray"];
|
|
|
2132 |
#$conf["leaderWordOptionCountArray"],字串陣列,每類代號的選項數目,請按照順序排列.
|
|
|
2133 |
$conf["analyse"]["changeToNumberList"]["leaderWordOptionCountArray"]=$conf["leaderWordOptionCountArray"];
|
|
|
2134 |
$processedStr=analyse::changeToNumberList($conf["analyse"]["changeToNumberList"]);
|
|
|
2135 |
unset($conf["analyse"]["changeToNumberList"]);
|
|
|
2136 |
|
|
|
2137 |
#如果 $processedStr["status"] 等於 "false"
|
|
|
2138 |
if($processedStr["status"]=="false"){
|
|
|
2139 |
|
|
|
2140 |
#設置錯誤識別
|
|
|
2141 |
$result["status"]="false";
|
|
|
2142 |
|
|
|
2143 |
#設置錯誤訊息
|
|
|
2144 |
$result["error"]=$processedStr;
|
|
|
2145 |
|
|
|
2146 |
#回傳結果
|
|
|
2147 |
return $result;
|
|
|
2148 |
|
|
|
2149 |
}#if end
|
|
|
2150 |
|
|
|
2151 |
#記錄處理好的字串
|
|
|
2152 |
$processedStrArray[][]=$processedStr["content"];
|
|
|
2153 |
|
|
|
2154 |
}#foreach end
|
|
|
2155 |
|
|
|
2156 |
#將 $processedStrArray 寫入到 csv 檔案裡面.
|
|
|
2157 |
#涵式說明:
|
|
|
2158 |
#快速建立一個csv檔案,並且要求使用者下載。
|
|
|
2159 |
#回傳的結果:
|
|
|
2160 |
#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
|
|
|
2161 |
#$result["error"],錯誤訊息陣列.
|
|
|
2162 |
#$result["function"],取得當前執行的函數名稱
|
|
|
2163 |
#$result["content"],輸出的csv檔案位置.
|
|
|
2164 |
#如果有設置$conf["noDownload"]爲"true"的話,則會回傳檔案的位置
|
|
|
2165 |
#必填參數:
|
|
|
2166 |
$conf["csv"]["create"]["dataArray"]=$processedStrArray;#要寫入的文字,$conf["dataArray"][$i],代表第 $i 行的內容。
|
|
|
2167 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
2168 |
$conf["csv"]["create"]["fileArgu"]=$conf["fileArgu"];
|
|
|
2169 |
#可省略參數:
|
|
|
2170 |
#$conf["csvFilePathAndName"]="";#輸出的csv檔案路徑與名稱,預設爲系統時間,副檔名"csv"會自動加上.
|
|
|
2171 |
$conf["csv"]["create"]["csvFilePathAndName"]=$conf["csvOutFilePathAndName"];
|
|
|
2172 |
$conf["csv"]["create"]["noDownload"]=$conf["noDownload"];#如果爲"true"則代表不要讓使用者下載,但會回傳檔案的相對位置
|
|
|
2173 |
#參考資料來源:
|
|
|
2174 |
#http://php.net/manual/en/function.str-split.php
|
|
|
2175 |
$create=csv::create($conf["csv"]["create"]);
|
|
|
2176 |
unset($conf["csv"]["create"]);
|
|
|
2177 |
|
|
|
2178 |
#如果建立csv檔案失敗
|
|
|
2179 |
if($create["status"]=="false"){
|
|
|
2180 |
|
|
|
2181 |
#設置執行失敗
|
|
|
2182 |
$result["status"]="false";
|
|
|
2183 |
|
|
|
2184 |
#設置執行錯誤訊息
|
|
|
2185 |
$result["error"]=$create;
|
|
|
2186 |
|
|
|
2187 |
#回傳結果
|
|
|
2188 |
return $result;
|
|
|
2189 |
|
|
|
2190 |
}#if end
|
|
|
2191 |
|
|
|
2192 |
#取得產生出來的csv檔案位置
|
|
|
2193 |
$result["csvFile"]=$create["content"];
|
|
|
2194 |
|
|
|
2195 |
#執行到這邊代表執行正常
|
|
|
2196 |
$result["status"]="true";
|
|
|
2197 |
|
|
|
2198 |
#回傳結果
|
|
|
2199 |
return $result;
|
|
|
2200 |
|
|
|
2201 |
}#function changeToNumberListInCsv end
|
|
|
2202 |
|
|
|
2203 |
/*
|
|
|
2204 |
#函式說明:
|
|
|
2205 |
#將csv檔的時間欄位格式「2009-07-11 13:21:45」分為多個欄位,變成年、月、日、時、分、秒等六個欄位,然後下載.
|
|
|
2206 |
#回傳的結果:
|
|
|
2207 |
#$result["status"],執行是否正確,"true"代表正確,"false"代表不正常.
|
|
|
2208 |
#$result["error"],錯誤訊息陣列.
|
|
|
2209 |
#$result["function"],當前執行的函數名稱.
|
|
|
2210 |
#$result["csvFilePathAndName"],輸出的csv檔案路徑與檔案名稱.
|
|
|
2211 |
#必填參數:
|
|
|
2212 |
#$conf["oriCsvFilePath"]="";#字串,要轉換的單一版本問卷樣本.
|
|
|
2213 |
#$conf["outputCsvFilePath"]="";#字串,轉換好的問卷樣本要儲存到哪邊,副檔名csv要加上.
|
|
|
2214 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
2215 |
$conf["fileArgu"]=__FILE__;
|
|
|
2216 |
#可省略參數:
|
|
|
2217 |
#$conf["noDownlaod"],字串,是否不要立即下載產生好的csv檔案,"true"為不立即下載,"false"為立即下載,預設為"true".
|
|
|
2218 |
#$conf["noDownlaod"]="true";
|
|
|
2219 |
#參考資料:
|
|
|
2220 |
#無.
|
|
|
2221 |
#備註:
|
|
|
2222 |
#無
|
|
|
2223 |
*/
|
|
|
2224 |
public static function spiltTimeColumn($conf){
|
|
|
2225 |
|
|
|
2226 |
#初始化要回傳的變數
|
|
|
2227 |
$result=array();
|
|
|
2228 |
|
|
|
2229 |
#取得當前執行的函數名稱
|
|
|
2230 |
$result["function"]=__FUNCTION__;
|
|
|
2231 |
|
|
|
2232 |
#如果 $conf 不為陣列
|
|
|
2233 |
if(gettype($conf)!="array"){
|
|
|
2234 |
|
|
|
2235 |
#設置執行失敗
|
|
|
2236 |
$result["status"]="false";
|
|
|
2237 |
|
|
|
2238 |
#設置執行錯誤訊息
|
|
|
2239 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
2240 |
|
|
|
2241 |
#如果傳入的參數為 null
|
|
|
2242 |
if($conf==null){
|
|
|
2243 |
|
|
|
2244 |
#設置執行錯誤訊息
|
|
|
2245 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
2246 |
|
|
|
2247 |
}#if end
|
|
|
2248 |
|
|
|
2249 |
#回傳結果
|
|
|
2250 |
return $result;
|
|
|
2251 |
|
|
|
2252 |
}#if end
|
|
|
2253 |
|
|
|
2254 |
#檢查參數
|
|
|
2255 |
#函式說明:
|
|
|
2256 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
2257 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2258 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2259 |
#$result["function"],當前執行的函式名稱.
|
|
|
2260 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2261 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2262 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2263 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2264 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2265 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2266 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2267 |
#必填參數:
|
|
|
2268 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2269 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
2270 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2271 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("oriCsvFilePath","outputCsvFilePath","fileArgu");
|
|
|
2272 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
2273 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
|
|
|
2274 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2275 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2276 |
#可以省略的參數:
|
|
|
2277 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
2278 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
2279 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2280 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("noDownload");
|
|
|
2281 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
2282 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
2283 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2284 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
|
|
|
2285 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2286 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
2287 |
#參考資料來源:
|
|
|
2288 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2289 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2290 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
2291 |
|
|
|
2292 |
#如果 $checkResult["status"] 等於 "false"
|
|
|
2293 |
if($checkResult["status"]=="false"){
|
|
|
2294 |
|
|
|
2295 |
#設置錯誤識別
|
|
|
2296 |
$result["status"]="false";
|
|
|
2297 |
|
|
|
2298 |
#設置錯誤訊息
|
|
|
2299 |
$result["error"]=$checkResult;
|
|
|
2300 |
|
|
|
2301 |
#回傳結果
|
|
|
2302 |
return $result;
|
|
|
2303 |
|
|
|
2304 |
}#if end
|
|
|
2305 |
|
|
|
2306 |
#如果 $checkResult["passed"] 等於 "false"
|
|
|
2307 |
if($checkResult["passed"]=="false"){
|
|
|
2308 |
|
|
|
2309 |
#設置錯誤識別
|
|
|
2310 |
$result["status"]="false";
|
|
|
2311 |
|
|
|
2312 |
#設置錯誤訊息
|
|
|
2313 |
$result["error"]=$checkResult;
|
|
|
2314 |
|
|
|
2315 |
#回傳結果
|
|
|
2316 |
return $result;
|
|
|
2317 |
|
|
|
2318 |
}#if end
|
|
|
2319 |
|
|
|
2320 |
#讀取csv檔案
|
|
|
2321 |
#涵式說明:
|
|
|
2322 |
#讀取csv檔案的內容
|
|
|
2323 |
#回傳得結果:
|
|
|
2324 |
#$result["status"],執行是否正常,"true"代表正常;"false"代表不正常.
|
|
|
2325 |
#$result["error"],錯誤訊息陣列.
|
|
|
2326 |
#$result["csvFileContent"],csv檔案內容的陣列
|
|
|
2327 |
#$result["csvFileContent"]["$i"]["$j"]代表第$i+1列第$j+1欄位的內容.
|
|
|
2328 |
#如果 $conf["firstLineVarName"]爲"true"的話則會回傳 $result["csvFileContent"]["第幾列"]["第一列各個欄位的名稱"]
|
|
|
2329 |
#$result["lineArray"],csv檔案逐列內容的陣列.
|
|
|
2330 |
#$result["lineArrayCount"],總共幾列資料
|
|
|
2331 |
#必填參數:
|
|
|
2332 |
$conf["csv"]["loadCsvFile"]["csvFilePositionAndName"]=$conf["oriCsvFilePath"];#csv檔案的位置
|
|
|
2333 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
2334 |
$conf["csv"]["loadCsvFile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
2335 |
#可省略參數:
|
|
|
2336 |
$conf["csv"]["loadCsvFile"]["firstLineVarName"]="false";#第一行是否爲變數名稱(各個欄位的名稱)
|
|
|
2337 |
#參考資料來源:
|
|
|
2338 |
#http://www.php.net/manual/en/function.str-split.php
|
|
|
2339 |
#參考資料來源
|
|
|
2340 |
#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)
|
|
|
2341 |
$csvFile=csv::loadCsvFile($conf["csv"]["loadCsvFile"]);
|
|
|
2342 |
unset($conf["csv"]["loadCsvFile"]);
|
|
|
2343 |
|
|
|
2344 |
#如果 $csvFile["status"] 等於 "false"
|
|
|
2345 |
if($csvFile["status"]=="false"){
|
|
|
2346 |
|
|
|
2347 |
#設置錯誤識別
|
|
|
2348 |
$result["status"]="false";
|
|
|
2349 |
|
|
|
2350 |
#設置錯誤訊息
|
|
|
2351 |
$result["error"]=$csvFile;
|
|
|
2352 |
|
|
|
2353 |
#回傳結果
|
|
|
2354 |
return $result;
|
|
|
2355 |
|
|
|
2356 |
}#if end
|
|
|
2357 |
|
|
|
2358 |
#初始化儲存分割好的時間資料陣列
|
|
|
2359 |
$time["year"]=array();#西元年
|
|
|
2360 |
$time["month"]=array();#月份
|
|
|
2361 |
$time["day"]=array();#天
|
|
|
2362 |
$time["week"]=array();#星期
|
|
|
2363 |
$time["hour"]=array();#小時
|
|
|
2364 |
$time["min"]=array();#分鐘
|
|
|
2365 |
$time["sec"]=array();#秒
|
|
|
2366 |
|
|
|
2367 |
#針每行資料
|
|
|
2368 |
foreach($csvFile["csvFileContent"] as $timeStr){
|
|
|
2369 |
|
|
|
2370 |
#將第一個欄位依據 " " 進行分段
|
|
|
2371 |
#涵式說明:
|
|
|
2372 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
2373 |
#回傳的參數:
|
|
|
2374 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2375 |
#$result["error"],錯誤訊息陣列
|
|
|
2376 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
2377 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
2378 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
2379 |
#必填參數:
|
|
|
2380 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$timeStr[0];#要處理的字串。
|
|
|
2381 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
|
|
|
2382 |
$spiltedTimeStr=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
2383 |
unset($conf["stringProcess"]["spiltString"]);
|
|
|
2384 |
|
|
|
2385 |
#如果 $spiltedTimeStr["status"] 等於 "false"
|
|
|
2386 |
if($spiltedTimeStr["status"]=="false"){
|
|
|
2387 |
|
|
|
2388 |
#設置錯誤識別
|
|
|
2389 |
$result["status"]="false";
|
|
|
2390 |
|
|
|
2391 |
#設置錯誤訊息
|
|
|
2392 |
$result["error"]=$spiltedTimeStr;
|
|
|
2393 |
|
|
|
2394 |
#回傳結果
|
|
|
2395 |
return $result;
|
|
|
2396 |
|
|
|
2397 |
}#if end
|
|
|
2398 |
|
|
|
2399 |
#照理說會分成兩段
|
|
|
2400 |
#如果不是分成兩段,勢必有錯誤發生
|
|
|
2401 |
if($spiltedTimeStr["dataCounts"]!=2){
|
|
|
2402 |
|
|
|
2403 |
#設置錯誤識別
|
|
|
2404 |
$result["status"]="false";
|
|
|
2405 |
|
|
|
2406 |
#設置錯誤訊息
|
|
|
2407 |
$result["error"]=$spiltedTimeStr;
|
|
|
2408 |
|
|
|
2409 |
#設置錯誤訊息
|
|
|
2410 |
$result["error"][]="時間欄位字串用 \" \" 分割應該會分割出兩段字串才對!";
|
|
|
2411 |
|
|
|
2412 |
#回傳結果
|
|
|
2413 |
return $result;
|
|
|
2414 |
|
|
|
2415 |
}#if end
|
|
|
2416 |
|
|
|
2417 |
#將 $spiltedTimeStr["dataArray"][0] 用「-」分成西元年月日
|
|
|
2418 |
#涵式說明:
|
|
|
2419 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
2420 |
#回傳的參數:
|
|
|
2421 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2422 |
#$result["error"],錯誤訊息陣列
|
|
|
2423 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
2424 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
2425 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
2426 |
#必填參數:
|
|
|
2427 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$spiltedTimeStr["dataArray"][0];#要處理的字串。
|
|
|
2428 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]="-";#爲以哪個符號作爲分割
|
|
|
2429 |
$spiltedTimeStrPart1=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
2430 |
unset($conf["stringProcess"]["spiltString"]);
|
|
|
2431 |
|
|
|
2432 |
#如果 $spiltedTimeStrPart1["status"] 等於 "false"
|
|
|
2433 |
if($spiltedTimeStrPart1["status"]=="false"){
|
|
|
2434 |
|
|
|
2435 |
#設置錯誤識別
|
|
|
2436 |
$result["status"]="false";
|
|
|
2437 |
|
|
|
2438 |
#設置錯誤訊息
|
|
|
2439 |
$result["error"]=$spiltedTimeStrPart1;
|
|
|
2440 |
|
|
|
2441 |
#回傳結果
|
|
|
2442 |
return $result;
|
|
|
2443 |
|
|
|
2444 |
}#if end
|
|
|
2445 |
|
|
|
2446 |
#照理說會分成三段
|
|
|
2447 |
#如果不是分成三段,勢必有錯誤發生
|
|
|
2448 |
if($spiltedTimeStrPart1["dataCounts"]!=3){
|
|
|
2449 |
|
|
|
2450 |
#設置錯誤識別
|
|
|
2451 |
$result["status"]="false";
|
|
|
2452 |
|
|
|
2453 |
#設置錯誤訊息
|
|
|
2454 |
$result["error"]=$spiltedTimeStrPart1;
|
|
|
2455 |
|
|
|
2456 |
#設置錯誤訊息
|
|
|
2457 |
$result["error"][]="年月日時間欄位字串用 \"-\" 分割應該會分割出三段字串才對!";
|
|
|
2458 |
|
|
|
2459 |
#回傳結果
|
|
|
2460 |
return $result;
|
|
|
2461 |
|
|
|
2462 |
}#if end
|
|
|
2463 |
|
|
|
2464 |
#取得年
|
|
|
2465 |
$time["year"][]=$spiltedTimeStrPart1["dataArray"][0];
|
|
|
2466 |
|
|
|
2467 |
#取得月
|
|
|
2468 |
$time["month"][]=$spiltedTimeStrPart1["dataArray"][1];
|
|
|
2469 |
|
|
|
2470 |
#取得日
|
|
|
2471 |
$time["day"][]=$spiltedTimeStrPart1["dataArray"][2];
|
|
|
2472 |
|
|
|
2473 |
#函式說明:
|
|
|
2474 |
#計算特定年月日為星期幾
|
|
|
2475 |
#回傳的結果:
|
|
|
2476 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2477 |
#$result["error"],錯誤訊息陣列
|
|
|
2478 |
#$result["content"],0~6,依序代表星期天到星期六.
|
|
|
2479 |
#必填參數:
|
|
|
2480 |
#$conf["time"]["computeWeekNumber"]["year"],字串,要求算該日為星期幾的所屬年份.
|
|
|
2481 |
$conf["time"]["computeWeekNumber"]["year"]=$spiltedTimeStrPart1["dataArray"][0];
|
|
|
2482 |
#$conf["time"]["computeWeekNumber"]["month"],字串,要求算該日為星期幾的所屬月份.
|
|
|
2483 |
$conf["time"]["computeWeekNumber"]["month"]=$spiltedTimeStrPart1["dataArray"][1];
|
|
|
2484 |
#$conf["time"]["computeWeekNumber"]["day"],字串,要求算該日為星期幾的日.
|
|
|
2485 |
$conf["time"]["computeWeekNumber"]["day"]=$spiltedTimeStrPart1["dataArray"][2];
|
|
|
2486 |
$getWeekResult=time::computeWeekNumber($conf["time"]["computeWeekNumber"]);
|
|
|
2487 |
unset($conf["time"]["computeWeekNumber"]);
|
|
|
2488 |
|
|
|
2489 |
#如果 $getWeekResult["status"] 等於 "false"
|
|
|
2490 |
if($getWeekResult["status"]=="false"){
|
|
|
2491 |
|
|
|
2492 |
#設置錯誤識別
|
|
|
2493 |
$result["status"]="false";
|
|
|
2494 |
|
|
|
2495 |
#設置錯誤訊息
|
|
|
2496 |
$result["error"]=$getWeekResult;
|
|
|
2497 |
|
|
|
2498 |
#回傳結果
|
|
|
2499 |
return $result;
|
|
|
2500 |
|
|
|
2501 |
}#if end
|
|
|
2502 |
|
|
|
2503 |
#取得星期
|
|
|
2504 |
$time["week"][]=$getWeekResult["content"][0];
|
|
|
2505 |
|
|
|
2506 |
#將 $spiltedTimeStr["dataArray"][1] 用「:」分成時分秒
|
|
|
2507 |
#涵式說明:
|
|
|
2508 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
2509 |
#回傳的參數:
|
|
|
2510 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2511 |
#$result["error"],錯誤訊息陣列
|
|
|
2512 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
2513 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
2514 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
2515 |
#必填參數:
|
|
|
2516 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$spiltedTimeStr["dataArray"][1];#要處理的字串。
|
|
|
2517 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]=":";#爲以哪個符號作爲分割
|
|
|
2518 |
$spiltedTimeStrPart2=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
2519 |
unset($conf["stringProcess"]["spiltString"]);
|
|
|
2520 |
|
|
|
2521 |
#如果 $spiltedTimeStrPart2["status"] 等於 "false"
|
|
|
2522 |
if($spiltedTimeStrPart2["status"]=="false"){
|
|
|
2523 |
|
|
|
2524 |
#設置錯誤識別
|
|
|
2525 |
$result["status"]="false";
|
|
|
2526 |
|
|
|
2527 |
#設置錯誤訊息
|
|
|
2528 |
$result["error"]=$spiltedTimeStrPart2;
|
|
|
2529 |
|
|
|
2530 |
#回傳結果
|
|
|
2531 |
return $result;
|
|
|
2532 |
|
|
|
2533 |
}#if end
|
|
|
2534 |
|
|
|
2535 |
#照理說會分成三段
|
|
|
2536 |
#如果不是分成三段,勢必有錯誤發生
|
|
|
2537 |
if($spiltedTimeStrPart2["dataCounts"]!=3){
|
|
|
2538 |
|
|
|
2539 |
#設置錯誤識別
|
|
|
2540 |
$result["status"]="false";
|
|
|
2541 |
|
|
|
2542 |
#設置錯誤訊息
|
|
|
2543 |
$result["error"]=$spiltedTimeStrPart2;
|
|
|
2544 |
|
|
|
2545 |
#設置錯誤訊息
|
|
|
2546 |
$result["error"][]="時分秒時間欄位字串用 \":\" 分割應該會分割出三段字串才對!";
|
|
|
2547 |
|
|
|
2548 |
#回傳結果
|
|
|
2549 |
return $result;
|
|
|
2550 |
|
|
|
2551 |
}#if end
|
|
|
2552 |
|
|
|
2553 |
#取得時
|
|
|
2554 |
$time["hour"][]=$spiltedTimeStrPart2["dataArray"][0];
|
|
|
2555 |
|
|
|
2556 |
#取得分
|
|
|
2557 |
$time["min"][]=$spiltedTimeStrPart2["dataArray"][1];
|
|
|
2558 |
|
|
|
2559 |
#取得秒
|
|
|
2560 |
$time["sec"][]=$spiltedTimeStrPart2["dataArray"][2];
|
|
|
2561 |
|
|
|
2562 |
}#foreach end
|
|
|
2563 |
|
|
|
2564 |
#初始化要寫入到csv檔裡面的2維陣列.
|
|
|
2565 |
$dataArrayToWrite=array(array());
|
|
|
2566 |
|
|
|
2567 |
#轉換要寫入的檔案內容
|
|
|
2568 |
#根據有幾筆資料
|
|
|
2569 |
for($i=0;$i<count($time["year"]);$i++){
|
|
|
2570 |
|
|
|
2571 |
#取得每個時間欄位的內容
|
|
|
2572 |
$dataArrayToWrite[$i][]=$time["year"][$i];#西元年
|
|
|
2573 |
$dataArrayToWrite[$i][]=$time["month"][$i];#月份
|
|
|
2574 |
$dataArrayToWrite[$i][]=$time["day"][$i];#天
|
|
|
2575 |
$dataArrayToWrite[$i][]=$time["week"][$i];#星期
|
|
|
2576 |
$dataArrayToWrite[$i][]=$time["hour"][$i];#小時
|
|
|
2577 |
$dataArrayToWrite[$i][]=$time["min"][$i];#分鐘
|
|
|
2578 |
$dataArrayToWrite[$i][]=$time["sec"][$i];#秒
|
|
|
2579 |
|
|
|
2580 |
}#foreach end
|
|
|
2581 |
|
|
|
2582 |
#依據每筆資料的年月日時分秒依序寫入到不同的欄位裡面.
|
|
|
2583 |
#建立新的csv檔案
|
|
|
2584 |
#涵式說明:
|
|
|
2585 |
#快速建立一個csv檔案,並且要求使用者下載。
|
|
|
2586 |
#回傳的結果:
|
|
|
2587 |
#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
|
|
|
2588 |
#$result["error"],錯誤訊息陣列.
|
|
|
2589 |
#$result["content"],輸出的csv檔案位置.
|
|
|
2590 |
#必填參數:
|
|
|
2591 |
$conf["csv"]["create"]["dataArray"]=$dataArrayToWrite;#要寫入的文字,$conf["dataArray"][$i],代表第 $i 行的內容。
|
|
|
2592 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
2593 |
$conf["csv"]["create"]["fileArgu"]=$conf["fileArgu"];
|
|
|
2594 |
#可省略參數:
|
|
|
2595 |
$conf["csv"]["create"]["csvFilePathAndName"]=$conf["outputCsvFilePath"];#輸出的csv檔案路徑與名稱,預設爲系統時間,副檔名"csv"會自動加上.
|
|
|
2596 |
$conf["csv"]["create"]["noDownload"]=$conf["noDownload"];#如果爲"true"則代表不要讓使用者下載,但會回傳檔案的相對位置
|
|
|
2597 |
#參考資料來源:
|
|
|
2598 |
#http://php.net/manual/en/function.str-split.php
|
|
|
2599 |
$csvCreateResult=csv::create($conf["csv"]["create"]);
|
|
|
2600 |
unset($conf["csv"]["create"]);
|
|
|
2601 |
|
|
|
2602 |
#var_dump($csvCreateResult);
|
|
|
2603 |
|
|
|
2604 |
#如果 $csvCreateResult["status"] 等於 "false"
|
|
|
2605 |
if($csvCreateResult["status"]=="false"){
|
|
|
2606 |
|
|
|
2607 |
#設置錯誤識別
|
|
|
2608 |
$result["status"]="false";
|
|
|
2609 |
|
|
|
2610 |
#設置錯誤訊息
|
|
|
2611 |
$result["error"]=$csvCreateResult;
|
|
|
2612 |
|
|
|
2613 |
#回傳結果
|
|
|
2614 |
return $result;
|
|
|
2615 |
|
|
|
2616 |
}#if end
|
|
|
2617 |
|
|
|
2618 |
#記錄產生好的csv檔案位置
|
|
|
2619 |
$result["csvFilePathAndName"]=$csvCreateResult["content"];
|
|
|
2620 |
|
|
|
2621 |
#執行到這表代表執行正常
|
|
|
2622 |
$result["status"]="true";
|
|
|
2623 |
|
|
|
2624 |
#回傳結果
|
|
|
2625 |
return $result;
|
|
|
2626 |
|
|
|
2627 |
}#function spiltTimeColumn end
|
|
|
2628 |
|
|
|
2629 |
/*
|
|
|
2630 |
#函式說明:
|
|
|
2631 |
#透過專用的問卷設定檔與問卷樣本檔來將問卷樣本匯入資料表
|
|
|
2632 |
#問卷樣本檔的
|
|
|
2633 |
#第1列各欄位依序為 "sampleNo"(樣本編號),題目(以;區隔的填寫選項,結尾也要;),"year"(調查時間的西元年),"month"(調查時間的月份),"week"(調查時間所屬星期),"day"(調查時間的日),"hour"(調查時間的時),"min"(調查時間的分),"sec"(調查時間的秒).
|
|
|
2634 |
#第1列第1欄代表樣本編號的標題,不需要從1開始,只要可以識別是跟其他樣本不同即可.
|
|
|
2635 |
#第1列第2欄代表樣本第1題的代號
|
|
|
2636 |
#第2列第1欄代表第1個樣本的編號
|
|
|
2637 |
#第2列第2欄代表第1個樣本的第1題回答內容,
|
|
|
2638 |
#填寫的選項之間用分號「;」分隔
|
|
|
2639 |
#第m列第1欄代表第m-1個樣本的編號
|
|
|
2640 |
#第m列第n欄代表第m-1個樣本的第n-1題回答內容
|
|
|
2641 |
#week欄位的內容為從0~6的數字,依序以星期日,星期一,星期二...到星期六
|
|
|
2642 |
#問卷資訊檔題目設定必須跟資料庫中的問卷題目設定相同,否則該樣本題項將不會匯入。
|
|
|
2643 |
#回傳的結果:
|
|
|
2644 |
#$result["status"],執行是否正確,"true"代表正確,"false"代表不正常.
|
|
|
2645 |
#$result["function"],當前執行的函數名稱.
|
|
|
2646 |
#$result["error"],錯誤訊息陣列.
|
|
|
2647 |
#$result["warning"],警告訊息陣列
|
|
|
2648 |
#必填參數:
|
|
|
2649 |
#$conf["questionnaireSamplePath"],字串,要轉換的單一版本問卷樣本.
|
|
|
2650 |
$conf["questionnaireSamplePath"]="";
|
|
|
2651 |
#$conf["questionnaireSetupCsvPath"],字串,記錄問卷資訊的csv檔案.
|
|
|
2652 |
$conf["questionnaireSetupCsvPath"]="";
|
|
|
2653 |
#$conf["dbAddress"],字串,問卷資料庫的網路位址.
|
|
|
2654 |
$conf["dbAddress"]=$dbAddress;
|
|
|
2655 |
#$conf["dbAccount"],字串,要連線到資料庫時所用的帳戶名稱.
|
|
|
2656 |
$conf["dbAccount"]=$dbAccount;
|
|
|
2657 |
#$conf["dbName"],字串,問卷相關資料所儲存的資料庫名稱.
|
|
|
2658 |
$conf["dbName"]=$dbName;
|
|
|
2659 |
#可省略參數:
|
|
|
2660 |
#$conf["dbPassword"],字串,要連線到資料庫時所用的密碼.
|
|
|
2661 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
2662 |
#$conf["questionnaireType.dtName"],字串,問卷資訊儲存在哪個資料表,預設為"questionnaireType".
|
|
|
2663 |
#$conf["questionnaireType.dtName"]="questionnaireType";
|
|
|
2664 |
#$conf["questionnaireType.typeNoColumnName"],字串,問卷編號的資料欄位名稱,預設為"typeNo".
|
|
|
2665 |
#$conf["questionnaireType.typeNoColumnName"]="typeNo";
|
|
|
2666 |
#$conf["questionnaireType.questionnaireTitleColumnName"],字串,問卷標題的資料欄位名稱,預設為"title".
|
|
|
2667 |
#$conf["questionnaireType.questionnaireTitleColumnName"]="title";
|
|
|
2668 |
#$conf["questionnaireType.pointsColumnName"],字串,問卷量表的資料欄位名稱,預設為"points".
|
|
|
2669 |
#$conf["questionnaireType.pointsColumnName"]="points";
|
|
|
2670 |
#$conf["questionnaireQuest.dtName"],字串,儲存問卷題項資料的資料表名稱
|
|
|
2671 |
#$conf["questionnaireQuest.dtName"]="questionnaireQuest";
|
|
|
2672 |
#$conf["questionnaireQuest.typeNoColumnName"],字串,問卷編號的資料欄位名稱,預設為"typeNo".
|
|
|
2673 |
#$conf["questionnaireQuest.typeNoColumnName"]="typeNo";
|
|
|
2674 |
#$conf["questionnaireQuest.questNoColumnName"],字串,題號資料欄位名稱,預設為"questNo".
|
|
|
2675 |
#$conf["questionnaireQuest.questNoColumnName"]="questNo";
|
|
|
2676 |
#$conf["questionnaireQuest.questTypeCodeColumnName"],字串,題型的資料欄位名稱,預設為"questTypeCode".
|
|
|
2677 |
#$conf["questionnaireQuest.questTypeCodeColumnName"]="questTypeCode";
|
|
|
2678 |
#$conf["questionnaireQuest.selectedQuestOptionMaxCountColumnName"],字串,題目選項的選擇上限的資料欄位名稱,預設為"selectedQuestOptionMaxCount".
|
|
|
2679 |
#$conf["questionnaireQuest.selectedQuestOptionMaxCountColumnName"]="selectedQuestOptionMaxCount";
|
|
|
2680 |
#$conf["questionnaireQuest.questContentColumnName"],字串,題目內容的資料欄位名稱,預設為"questContent".
|
|
|
2681 |
#$conf["questionnaireQuest.questContentColumnName"]="questContent";
|
|
|
2682 |
#$conf["questionnaireQuest.choiceValueColumnName"],字串,題目選項的資料欄位名稱,預設為"choiceValue".
|
|
|
2683 |
#$conf["questionnaireQuest.choiceValueColumnName"]="choiceValue";
|
|
|
2684 |
#$conf["questionnaireQuest.maxLengthColumnName"],字串,題目回答內容的最大長度限制的資料欄位名稱,預設為"maxLength".
|
|
|
2685 |
#$conf["questionnaireQuest.maxLengthColumnName"]="maxLength";
|
|
|
2686 |
#$conf["questionnaireQuest.nullColumnName"],字串,題目是否可以忽略的資料欄位名稱,預設為"null".
|
|
|
2687 |
#$conf["questionnaireQuest.nullColumnName"]="null";
|
|
|
2688 |
#$conf["questionnaireQuest.perspectiveColumnName"],字串,題目所屬構面的資料欄位名稱,預設為"perspective".
|
|
|
2689 |
#$conf["questionnaireQuest.perspectiveColumnName"]="perspective";
|
|
|
2690 |
#$conf["questionnaireQuest.indicatorColumnName"],字串,題目對應的指標的資料欄位名稱,預設為"indicator".
|
|
|
2691 |
#$conf["questionnaireQuest.indicatorColumnName"]="indicator";
|
|
|
2692 |
#$conf["importedQuestionnaireSample.dtName"],字串,問卷樣本的資料表名稱,預設為"questionnaireSample".
|
|
|
2693 |
#$conf["importedQuestionnaireSample.dtName"]="questionnaireSample";
|
|
|
2694 |
#$conf["importedQuestionnaireSample.questionnaireTypeColumnName"],字串,問卷樣本的問卷編號資料欄位名稱,預設為"typeNo".
|
|
|
2695 |
#$conf["importedQuestionnaireSample.questionnaireTypeColumnName"]="typeNo";
|
|
|
2696 |
#$conf["importedQuestionnaireSample.noColumnName"],字串,問卷樣本的編號資料欄位名稱,預設為"guestNo".
|
|
|
2697 |
#$conf["importedQuestionnaireSample.noColumnName"]="guestNo";
|
|
|
2698 |
#$conf["importedQuestionnaireSample.questNoColumnName"],字串,問卷樣本的題號資料欄位名稱,預設為"questNo".
|
|
|
2699 |
#$conf["importedQuestionnaireSample.questNoColumnName"]="questNo";
|
|
|
2700 |
#$conf["importedQuestionnaireSample.answerColumnName"],字串,問卷樣本的答題選項與內容資料欄位名稱,預設為"questAnsSelet".
|
|
|
2701 |
#$conf["importedQuestionnaireSample.answerColumnName"]="questAnsSelet";
|
|
|
2702 |
#$conf["importedQuestionnaireSample.filledColumnName"],字串,問卷樣本題項是否有填寫的資料欄位名稱,預設為"filled".
|
|
|
2703 |
#$conf["importedQuestionnaireSample.filledColumnName"]="filled";
|
|
|
2704 |
#$conf["importedQuestionnaireSample.startSurveyPointDtName"],字串,儲存樣本調查時間點的資料表名稱
|
|
|
2705 |
#$conf["importedQuestionnaireSample.startSurveyPointDtName"]="startSurveyTimePoint";
|
|
|
2706 |
#$conf["importedQuestionnaireSample.recordedYearColumnName"],字串,問卷樣本開始記錄的西元年份欄位名稱.
|
|
|
2707 |
#$conf["importedQuestionnaireSample.recordedYearColumnName"]="recordedYear";
|
|
|
2708 |
#$conf["importedQuestionnaireSample.recordedMonthColumnName"],字串,問卷樣本開始記錄的月份欄位名稱.
|
|
|
2709 |
#$conf["importedQuestionnaireSample.recordedMonthColumnName"]="recordedMonth";
|
|
|
2710 |
#$conf["importedQuestionnaireSample.recordedDayColumnName"],字串,問卷樣本開始記錄的日欄位名稱.
|
|
|
2711 |
#$conf["importedQuestionnaireSample.recordedDayColumnName"]="recordedDay";
|
|
|
2712 |
#$conf["importedQuestionnaireSample.recordedWeekColumnName"],字串,問卷樣本開始紀錄的周欄位名稱;
|
|
|
2713 |
#$conf["importedQuestionnaireSample.recordedWeekColumnName"]="recordedWeek";
|
|
|
2714 |
#$conf["importedQuestionnaireSample.recordedHourColumnName"],字串,問卷樣本開始記錄的小時欄位名稱.
|
|
|
2715 |
#$conf["importedQuestionnaireSample.recordedHourColumnName"]="recordedHour";
|
|
|
2716 |
#$conf["importedQuestionnaireSample.recordedMinColumnName"],字串,問卷樣本開始記錄的分鐘欄位名稱.
|
|
|
2717 |
#$conf["importedQuestionnaireSample.recordedMinColumnName"]="recordedMin";
|
|
|
2718 |
#$conf["importedQuestionnaireSample.recordedSecColumnName"],字串,問卷樣本開始記錄的秒數欄位名稱.
|
|
|
2719 |
#$conf["importedQuestionnaireSample.recordedSecColumnName"]="recordedSec";
|
|
|
2720 |
#參考資料:
|
|
|
2721 |
#無.
|
|
|
2722 |
#備註:
|
|
|
2723 |
#需要測試,由於案例特殊,因此最後再測試。第一題的填達內容無法匯入。
|
|
|
2724 |
*/
|
|
|
2725 |
public static function importQuestionnaireSampleFileWithValidation(&$conf){
|
|
|
2726 |
|
|
|
2727 |
#初始話要回傳的變數
|
|
|
2728 |
$result=array();
|
|
|
2729 |
|
|
|
2730 |
#記錄當前執行的函數
|
|
|
2731 |
$result["function"]=__FUNCTION__;
|
|
|
2732 |
|
|
|
2733 |
#如果 $conf 不為陣列
|
|
|
2734 |
if(gettype($conf)!="array"){
|
|
|
2735 |
|
|
|
2736 |
#設置執行失敗
|
|
|
2737 |
$result["status"]="false";
|
|
|
2738 |
|
|
|
2739 |
#設置執行錯誤訊息
|
|
|
2740 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
2741 |
|
|
|
2742 |
#如果傳入的參數為 null
|
|
|
2743 |
if($conf==null){
|
|
|
2744 |
|
|
|
2745 |
#設置執行錯誤訊息
|
|
|
2746 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
2747 |
|
|
|
2748 |
}#if end
|
|
|
2749 |
|
|
|
2750 |
#回傳結果
|
|
|
2751 |
return $result;
|
|
|
2752 |
|
|
|
2753 |
}#if end
|
|
|
2754 |
|
|
|
2755 |
#檢查參數
|
|
|
2756 |
#涵式說明:
|
|
|
2757 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
2758 |
#回傳的結果:
|
|
|
2759 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2760 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2761 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2762 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2763 |
#必填參數:
|
|
|
2764 |
$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
2765 |
$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("questionnaireSamplePath","questionnaireSetupCsvPath","dbAddress","dbName","dbAccount");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
2766 |
#可以省略的參數:
|
|
|
2767 |
$conf["variableCheck"]["isexistMuti"]["variableType"]=array("string","string","string","string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
|
|
2768 |
$conf["variableCheck"]["isexistMuti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
2769 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
|
|
|
2770 |
unset($conf["variableCheck"]["isexistMuti"]);
|
|
|
2771 |
|
|
|
2772 |
#如果 $checkResult["status"] 等於 "false"
|
|
|
2773 |
if($checkResult["status"]=="false"){
|
|
|
2774 |
|
|
|
2775 |
#設置錯誤識別
|
|
|
2776 |
$result["status"]="false";
|
|
|
2777 |
|
|
|
2778 |
#設置錯誤訊息
|
|
|
2779 |
$result["error"]=$checkResult;
|
|
|
2780 |
|
|
|
2781 |
#回傳結果
|
|
|
2782 |
return $result;
|
|
|
2783 |
|
|
|
2784 |
}#if end
|
|
|
2785 |
|
|
|
2786 |
#如果 $checkResult["passed"] 等於 "false"
|
|
|
2787 |
if($checkResult["passed"]=="false"){
|
|
|
2788 |
|
|
|
2789 |
#設置錯誤識別
|
|
|
2790 |
$result["status"]="false";
|
|
|
2791 |
|
|
|
2792 |
#設置錯誤訊息
|
|
|
2793 |
$result["error"]=$checkResult;
|
|
|
2794 |
|
|
|
2795 |
#回傳結果
|
|
|
2796 |
return $result;
|
|
|
2797 |
|
|
|
2798 |
}#if end
|
|
|
2799 |
|
|
|
2800 |
#設定參數預設值
|
|
|
2801 |
#函式說明:
|
|
|
2802 |
#檢查一包含數個可省略變數的陣列變數,其型態是否正確,省略掉的陣列變數可以直接給定預設值。
|
|
|
2803 |
#回傳結果:
|
|
|
2804 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2805 |
#$result["error"],錯誤訊息陣列.
|
|
|
2806 |
#$result["function"],當前執行的函式名稱.
|
|
|
2807 |
#$result["passed"],參數是否都通過檢查,"true",代表有通過檢查,"false"代表沒有通過檢查。
|
|
|
2808 |
#必填參數:
|
|
|
2809 |
#$conf["checkedVar"],陣列,要檢查的變數陣列名稱為?
|
|
|
2810 |
$conf["variableCheck.checkSkipableVarType"]["checkedVar"]=$conf;
|
|
|
2811 |
#$conf["sikpableVarNameArray"],字串陣列,要檢查型態是否設定正確的變數名稱陣列.
|
|
|
2812 |
#$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"]=array("",);
|
|
|
2813 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireType.dtName";
|
|
|
2814 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireType.typeNoColumnName";
|
|
|
2815 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireType.questionnaireTitleColumnName";
|
|
|
2816 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireType.pointsColumnName";
|
|
|
2817 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireQuest.dtName";
|
|
|
2818 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireQuest.typeNoColumnName";
|
|
|
2819 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireQuest.questNoColumnName";
|
|
|
2820 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireQuest.questTypeCodeColumnName";
|
|
|
2821 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireQuest.selectedQuestOptionMaxCountColumnName";
|
|
|
2822 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireQuest.questContentColumnName";
|
|
|
2823 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireQuest.choiceValueColumnName";
|
|
|
2824 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireQuest.maxLengthColumnName";
|
|
|
2825 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireQuest.nullColumnName";
|
|
|
2826 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireQuest.perspectiveColumnName";
|
|
|
2827 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireQuest.indicatorColumnName";
|
|
|
2828 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"][]="importedQuestionnaireSample.dtName";
|
|
|
2829 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"][]="importedQuestionnaireSample.questionnaireTypeColumnName";
|
|
|
2830 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"][]="importedQuestionnaireSample.noColumnName";
|
|
|
2831 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"][]="importedQuestionnaireSample.questNoColumnName";
|
|
|
2832 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"][]="importedQuestionnaireSample.answerColumnName";
|
|
|
2833 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"][]="importedQuestionnaireSample.filledColumnName";
|
|
|
2834 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"][]="importedQuestionnaireSample.startSurveyPointDtName";
|
|
|
2835 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"][]="importedQuestionnaireSample.recordedYearColumnName";
|
|
|
2836 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"][]="importedQuestionnaireSample.recordedMonthColumnName";
|
|
|
2837 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"][]="importedQuestionnaireSample.recordedDayColumnName";
|
|
|
2838 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"][]="importedQuestionnaireSample.recordedWeekColumnName";
|
|
|
2839 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"][]="importedQuestionnaireSample.recordedHourColumnName";
|
|
|
2840 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"][]="importedQuestionnaireSample.recordedMinColumnName";
|
|
|
2841 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"][]="importedQuestionnaireSample.recordedSecColumnName";
|
|
|
2842 |
#$conf["skipableVarTypeArray"],字串陣列,要檢查的每個變數,其型態應該要為何?
|
|
|
2843 |
#$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"]=array("",);
|
|
|
2844 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
2845 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
2846 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
2847 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
2848 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
2849 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
2850 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
2851 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
2852 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
2853 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
2854 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
2855 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
2856 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
2857 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
2858 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
2859 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
2860 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
2861 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
2862 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
2863 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
2864 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
2865 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
2866 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
2867 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
2868 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
2869 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
2870 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
2871 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
2872 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
2873 |
#$argu,要直接存取的陣列變數名稱,變數前面加上「&」,如果要在別的函式裡面使用本函式,請記得將變動過結果($argu)給使用該函式的設定變數(通常是$conf=$argu).
|
|
|
2874 |
$argu=&$conf;
|
|
|
2875 |
#可省略參數:
|
|
|
2876 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存的變數要初始化為什麼,"null"代表不指定.
|
|
|
2877 |
#$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"]=array("",);
|
|
|
2878 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][]="questionnaireType";
|
|
|
2879 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][]="typeNo";
|
|
|
2880 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][]="title";
|
|
|
2881 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][]="points";
|
|
|
2882 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][]="questionnaireQuest";
|
|
|
2883 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][]="typeNo";
|
|
|
2884 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][]="questNo";
|
|
|
2885 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][]="questTypeCode";
|
|
|
2886 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][]="selectedQuestOptionMaxCount";
|
|
|
2887 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][]="questContent";
|
|
|
2888 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][]="choiceValue";
|
|
|
2889 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][]="maxLength";
|
|
|
2890 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][]="null";
|
|
|
2891 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][]="perspective";
|
|
|
2892 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][]="indicator";
|
|
|
2893 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][]="questionnaireSample";
|
|
|
2894 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][]="typeNo";
|
|
|
2895 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][]="guestNo";
|
|
|
2896 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][]="questNo";
|
|
|
2897 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][]="questAnsSelet";
|
|
|
2898 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][]="filled";
|
|
|
2899 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][]="startSurveyTimePoint";
|
|
|
2900 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][]="recordedYear";
|
|
|
2901 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][]="recordedMonth";
|
|
|
2902 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][]="recordedDay";
|
|
|
2903 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][]="recordedWeek";
|
|
|
2904 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][]="recordedHour";
|
|
|
2905 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][]="recordedMin";
|
|
|
2906 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][]="recordedSec";
|
|
|
2907 |
$checkResult=variableCheck::checkSkipableVarType($conf["variableCheck.checkSkipableVarType"],$argu);
|
|
|
2908 |
unset($conf["variableCheck.checkSkipableVarType"]);
|
|
|
2909 |
|
|
|
2910 |
#如果 $checkResult["status"] 等於 "false"
|
|
|
2911 |
if($checkResult["status"]=="false"){
|
|
|
2912 |
|
|
|
2913 |
#設置錯誤識別
|
|
|
2914 |
$result["status"]="false";
|
|
|
2915 |
|
|
|
2916 |
#設置錯誤訊息
|
|
|
2917 |
$result["error"]=$checkResult;
|
|
|
2918 |
|
|
|
2919 |
#回傳結果
|
|
|
2920 |
return $result;
|
|
|
2921 |
|
|
|
2922 |
}#if end
|
|
|
2923 |
|
|
|
2924 |
#如果 $checkResult["passed"] 等於 "false"
|
|
|
2925 |
if($checkResult["passed"]=="false"){
|
|
|
2926 |
|
|
|
2927 |
#設置錯誤識別
|
|
|
2928 |
$result["status"]="false";
|
|
|
2929 |
|
|
|
2930 |
#設置錯誤訊息
|
|
|
2931 |
$result["error"]=$checkResult;
|
|
|
2932 |
|
|
|
2933 |
#回傳結果
|
|
|
2934 |
return $result;
|
|
|
2935 |
|
|
|
2936 |
}#if end
|
|
|
2937 |
|
|
|
2938 |
#var_dump($conf);
|
|
|
2939 |
|
|
|
2940 |
#讀取問卷樣本csv檔
|
|
|
2941 |
#涵式說明:
|
|
|
2942 |
#讀取csv檔案的內容
|
|
|
2943 |
#回傳得結果:
|
|
|
2944 |
#$result["status"],執行是否正常,"true"代表正常;"false"代表不正常.
|
|
|
2945 |
#$result["error"],錯誤訊息陣列.
|
|
|
2946 |
#$result["csvFileContent"],csv檔案內容的陣列
|
|
|
2947 |
#$result["csvFileContent"]["$i"]["$j"]代表第$i+1列第$j+1欄位的內容.
|
|
|
2948 |
#如果 $conf["firstLineVarName"]爲"true"的話則會回傳 $result["csvFileContent"]["第幾列"]["第一列各個欄位的名稱"]
|
|
|
2949 |
#$result["lineArray"],csv檔案逐列內容的陣列.
|
|
|
2950 |
#$result["lineArrayCount"],總共幾列資料
|
|
|
2951 |
#必填參數:
|
|
|
2952 |
$conf["csv"]["loadCsvFile"]["csvFilePositionAndName"]=$conf["questionnaireSamplePath"];#csv檔案的位置
|
|
|
2953 |
#可省略參數:
|
|
|
2954 |
#$conf["csv"]["loadCsvFile"]["firstLineVarName"]="true";#第一行是否爲變數名稱(各個欄位的名稱)
|
|
|
2955 |
#參考資料來源:
|
|
|
2956 |
#http://www.php.net/manual/en/function.str-split.php
|
|
|
2957 |
#參考資料來源
|
|
|
2958 |
#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)
|
|
|
2959 |
$sampleCsvFile=csv::loadCsvFile($conf["csv"]["loadCsvFile"]);
|
|
|
2960 |
unset($conf["csv"]["loadCsvFile"]);
|
|
|
2961 |
|
|
|
2962 |
#如果 $sampleCsvFile["status"] 等於 "false"
|
|
|
2963 |
if($sampleCsvFile["status"]=="false"){
|
|
|
2964 |
|
|
|
2965 |
#設置錯誤識別
|
|
|
2966 |
$result["status"]="false";
|
|
|
2967 |
|
|
|
2968 |
#設置錯誤訊息
|
|
|
2969 |
$result["error"]=$sampleCsvFile;
|
|
|
2970 |
|
|
|
2971 |
#回傳結果
|
|
|
2972 |
return $result;
|
|
|
2973 |
|
|
|
2974 |
}#if end
|
|
|
2975 |
|
|
|
2976 |
#debug
|
|
|
2977 |
#var_dump($sampleCsvFile["csvFileContent"][3]);
|
|
|
2978 |
|
|
|
2979 |
#讀取問卷設定檔
|
|
|
2980 |
#涵式說明:
|
|
|
2981 |
#讀取csv檔案的內容
|
|
|
2982 |
#回傳得結果:
|
|
|
2983 |
#$result["status"],執行是否正常,"true"代表正常;"false"代表不正常.
|
|
|
2984 |
#$result["error"],錯誤訊息陣列.
|
|
|
2985 |
#$result["csvFileContent"],csv檔案內容的陣列
|
|
|
2986 |
#$result["csvFileContent"]["$i"]["$j"]代表第$i+1列第$j+1欄位的內容.
|
|
|
2987 |
#如果 $conf["firstLineVarName"]爲"true"的話則會回傳 $result["csvFileContent"]["第幾列"]["第一列各個欄位的名稱"]
|
|
|
2988 |
#$result["lineArray"],csv檔案逐列內容的陣列.
|
|
|
2989 |
#$result["lineArrayCount"],總共幾列資料
|
|
|
2990 |
#必填參數:
|
|
|
2991 |
$conf["csv"]["loadCsvFile"]["csvFilePositionAndName"]=$conf["questionnaireSetupCsvPath"];#csv檔案的位置
|
|
|
2992 |
#可省略參數:
|
|
|
2993 |
#$conf["csv"]["loadCsvFile"]["firstLineVarName"]="true";#第一行是否爲變數名稱(各個欄位的名稱)
|
|
|
2994 |
#參考資料來源:
|
|
|
2995 |
#http://www.php.net/manual/en/function.str-split.php
|
|
|
2996 |
#參考資料來源
|
|
|
2997 |
#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)
|
|
|
2998 |
$setupCsvFile=csv::loadCsvFile($conf["csv"]["loadCsvFile"]);
|
|
|
2999 |
unset($conf["csv"]["loadCsvFile"]);
|
|
|
3000 |
|
|
|
3001 |
#如果 $setupCsvFile["status"] 等於 "false"
|
|
|
3002 |
if($setupCsvFile["status"]=="false"){
|
|
|
3003 |
|
|
|
3004 |
#設置錯誤識別
|
|
|
3005 |
$result["status"]="false";
|
|
|
3006 |
|
|
|
3007 |
#設置錯誤訊息
|
|
|
3008 |
$result["error"]=$setupCsvFile;
|
|
|
3009 |
|
|
|
3010 |
#回傳結果
|
|
|
3011 |
return $result;
|
|
|
3012 |
|
|
|
3013 |
}#if end
|
|
|
3014 |
|
|
|
3015 |
#函數說明:
|
|
|
3016 |
#延長php的執行時間,每呼叫一次會初始化執行時間爲0,然後設定下次可以執行多久.
|
|
|
3017 |
#回傳結果:
|
|
|
3018 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
3019 |
#$result["error"],錯誤訊息陣列.
|
|
|
3020 |
#$result["function"],當前執行的函數名稱.
|
|
|
3021 |
#必填參數:
|
|
|
3022 |
#$conf["sec"],整數,要延長多少執行時間,單位爲秒
|
|
|
3023 |
$conf["config::delayRunTimeExectionMax"]["sec"]=300;
|
|
|
3024 |
#參考資料:
|
|
|
3025 |
#http://php.net/manual/en/function.set-time-limit.php
|
|
|
3026 |
$delayRunTimeExectionMax=config::delayRunTimeExectionMax($conf["config::delayRunTimeExectionMax"]);
|
|
|
3027 |
unset($conf["config::delayRunTimeExectionMax"]);
|
|
|
3028 |
|
|
|
3029 |
#如果執行失敗
|
|
|
3030 |
if($delayRunTimeExectionMax["status"]==="false"){
|
|
|
3031 |
|
|
|
3032 |
#設定類別圖繪製失敗
|
|
|
3033 |
$result["status"]="false";
|
|
|
3034 |
|
|
|
3035 |
#設定該檔案的類別圖繪製失敗提示
|
|
|
3036 |
$result["error"]=$delayRunTimeExectionMax;
|
|
|
3037 |
|
|
|
3038 |
#回傳結果
|
|
|
3039 |
return $result;
|
|
|
3040 |
|
|
|
3041 |
}#if end
|
|
|
3042 |
|
|
|
3043 |
#透過問卷設定檔 $setupCsvFile 來檢查目標問卷是否存在
|
|
|
3044 |
|
|
|
3045 |
#取得問卷標題
|
|
|
3046 |
$questionnaireTitle=$setupCsvFile["csvFileContent"][0][0];
|
|
|
3047 |
|
|
|
3048 |
#檢查問卷系統現有的問卷列表是否有跟 $questionnaireTitle 一樣的名稱
|
|
|
3049 |
#函式說明:
|
|
|
3050 |
#檢查資料庫裏的資料表有無指定條件的資料
|
|
|
3051 |
#回傳的結果:
|
|
|
3052 |
#$result["status"],執行是否成功,成功為"true",失敗為"false"。
|
|
|
3053 |
#$result["error"],錯誤訊息
|
|
|
3054 |
#$result["founded"],是否找到資料,"true"代表有符合的資料;"false"代表沒有符合的資料.
|
|
|
3055 |
#$result["sql"],執行的sql字串.
|
|
|
3056 |
#必填參數:
|
|
|
3057 |
$conf["db"]["checkDataExists"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
3058 |
$conf["db"]["checkDataExists"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
3059 |
$conf["db"]["checkDataExists"]["selectedDataBaseName"]=$conf["dbName"];#爲指定的資料庫名稱,欲選擇的資料庫名稱
|
|
|
3060 |
$conf["db"]["checkDataExists"]["selectedDataTableName"]=$conf["questionnaireType.dtName"];#欲選擇的資料表名稱
|
|
|
3061 |
#可省略參數:
|
|
|
3062 |
|
|
|
3063 |
#如果 $conf["dbPassword"] 有設定
|
|
|
3064 |
if(isset($conf["dbPassword"])){
|
|
|
3065 |
|
|
|
3066 |
$conf["db"]["checkDataExists"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
3067 |
|
|
|
3068 |
}#if end
|
|
|
3069 |
|
|
|
3070 |
$conf["db"]["checkDataExists"]["conditionTargetName"]=array($conf["questionnaireType.questionnaireTitleColumnName"]);#用來判斷的資料表數值名稱,需爲陣列,可省略
|
|
|
3071 |
$conf["db"]["checkDataExists"]["conditionTargetValue"]=array($questionnaireTitle);#用來判斷的資料表數值名稱若等於該數值,表示條件成立,需爲陣列,可省略
|
|
|
3072 |
$checkResult=db::checkDataExists($conf["db"]["checkDataExists"]);
|
|
|
3073 |
unset($conf["db"]["checkDataExists"]);
|
|
|
3074 |
|
|
|
3075 |
#var_dump($checkResult);
|
|
|
3076 |
|
|
|
3077 |
#如果 $checkResult["status"] 等於 "false"
|
|
|
3078 |
if($checkResult["status"]=="false"){
|
|
|
3079 |
|
|
|
3080 |
#設置錯誤識別
|
|
|
3081 |
$result["status"]="false";
|
|
|
3082 |
|
|
|
3083 |
#設置錯誤訊息
|
|
|
3084 |
$result["error"]=$checkResult;
|
|
|
3085 |
|
|
|
3086 |
#回傳結果
|
|
|
3087 |
return $result;
|
|
|
3088 |
|
|
|
3089 |
}#if end
|
|
|
3090 |
|
|
|
3091 |
#如果 $checkResult["founded"] 等於 "false"
|
|
|
3092 |
if($checkResult["founded"]=="false"){
|
|
|
3093 |
|
|
|
3094 |
#設置錯誤識別
|
|
|
3095 |
$result["status"]="false";
|
|
|
3096 |
|
|
|
3097 |
#設置錯誤訊息
|
|
|
3098 |
$result["error"][]="要匯入樣本的目標問卷「".$questionnaireTitle."」並不存在";
|
|
|
3099 |
|
|
|
3100 |
#回傳結果
|
|
|
3101 |
return $result;
|
|
|
3102 |
|
|
|
3103 |
}#if end
|
|
|
3104 |
|
|
|
3105 |
#執行到這代表目標問卷存在
|
|
|
3106 |
|
|
|
3107 |
#透過對應到的問卷標題取得該問卷的編號
|
|
|
3108 |
#涵式說明:
|
|
|
3109 |
#一次取得資料庫、表的資料
|
|
|
3110 |
#回傳的結果
|
|
|
3111 |
#$result["status"],執行結果"true"為成功;"false"為執行失敗。
|
|
|
3112 |
#$result["error"],錯誤訊息陣列。
|
|
|
3113 |
#$result["dataColumnName"],抓取的資料欄位名稱陣列.
|
|
|
3114 |
#$result["dataColumnName"][$i]代表第$i+1個欄位名稱
|
|
|
3115 |
#$result["dataContent"],爲資料的內容。
|
|
|
3116 |
#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
|
|
|
3117 |
#$dataSetNum 爲第$dataSetNum+1筆資料
|
|
|
3118 |
#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
|
|
|
3119 |
#$result["dataCount"],爲取得的資料筆數。
|
|
|
3120 |
#$result["sql"],執行的sql字串.
|
|
|
3121 |
#必填參數:
|
|
|
3122 |
$conf["db"]["fastGetDbData"]["dbAddress"]=$conf["dbAddress"];#爲dbServer的位置。
|
|
|
3123 |
$conf["db"]["fastGetDbData"]["dbAccount"]=$conf["dbAccount"];#爲登入dbServer的帳號。
|
|
|
3124 |
$conf["db"]["fastGetDbData"]["dbName"]=$conf["dbName"];#爲要存取的資料庫名稱
|
|
|
3125 |
$conf["db"]["fastGetDbData"]["tableName"]=$conf["questionnaireType.dtName"];#爲要存取的資料表名稱
|
|
|
3126 |
$conf["db"]["fastGetDbData"]["columnYouWant"]=array($conf["questionnaireType.typeNoColumnName"]);#你想要的欄位!,若設為「array("*")」則代表全部欄位.
|
|
|
3127 |
#可省略參數:
|
|
|
3128 |
|
|
|
3129 |
#如果 $conf["dbPassword"] 有設置
|
|
|
3130 |
if(isset($conf["dbPassword"])){
|
|
|
3131 |
|
|
|
3132 |
$conf["db"]["fastGetDbData"]["dbPassword"]=$conf["dbPassword"];#爲要存取dbServer的密碼
|
|
|
3133 |
|
|
|
3134 |
}#if end
|
|
|
3135 |
|
|
|
3136 |
$conf["db"]["fastGetDbData"]["WhereColumnName"]=array($conf["questionnaireType.questionnaireTitleColumnName"]);#用於判斷語句的欄位項目陣列。
|
|
|
3137 |
$conf["db"]["fastGetDbData"]["WhereColumnValue"]=array($questionnaireTitle);#用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
|
|
|
3138 |
#$conf["db"]["fastGetDbData"]["WhereColumnCombine"]=array("");#用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
|
|
|
3139 |
#$conf["db"]["fastGetDbData"]["WhereColumnOperator"]=array("");#用於判斷語句的比較符號陣列,可以用的符號有「"="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
|
|
|
3140 |
#$conf["db"]["fastGetDbData"]["WhereColumnAndOr"]=array("");#用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
|
|
|
3141 |
#$conf["db"]["fastGetDbData"]["orderItem"]="";#爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
|
|
|
3142 |
#$conf["db"]["fastGetDbData"]["ascORdesc"]="";#爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
|
|
|
3143 |
#$conf["db"]["fastGetDbData"]["numberStart"]="0";#為從第幾筆開始讀取,預設為0,代筆第一筆。
|
|
|
3144 |
#$conf["db"]["fastGetDbData"]["numLimit"]="30";#為要取幾筆資料,可以省略,省略則表示不限制數目。
|
|
|
3145 |
#$conf["db"]["fastGetDbData"]["groupBy"]=array("");#爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
|
|
|
3146 |
$getQuestionnaireTypeNoResult=db::fastGetDbData($conf["db"]["fastGetDbData"]);
|
|
|
3147 |
unset($conf["db"]["fastGetDbData"]);
|
|
|
3148 |
|
|
|
3149 |
#如果 $getQuestionnaireTypeNoResult["status"] 等於 "false"
|
|
|
3150 |
if($getQuestionnaireTypeNoResult["status"]=="false"){
|
|
|
3151 |
|
|
|
3152 |
#設置錯誤識別
|
|
|
3153 |
$result["status"]="false";
|
|
|
3154 |
|
|
|
3155 |
#設置錯誤訊息
|
|
|
3156 |
$result["error"]=$getQuestionnaireTypeNoResult;
|
|
|
3157 |
|
|
|
3158 |
#回傳結果
|
|
|
3159 |
return $result;
|
|
|
3160 |
|
|
|
3161 |
}#if end
|
|
|
3162 |
|
|
|
3163 |
#如果 $getQuestionnaireTypeNoResult["dataCount"] 等於 0
|
|
|
3164 |
if($getQuestionnaireTypeNoResult["dataCount"]==0){
|
|
|
3165 |
|
|
|
3166 |
#設置錯誤識別
|
|
|
3167 |
$result["status"]="false";
|
|
|
3168 |
|
|
|
3169 |
#設置錯誤訊息
|
|
|
3170 |
$result["error"][]="找不到目標問卷的編號";
|
|
|
3171 |
|
|
|
3172 |
#回傳結果
|
|
|
3173 |
return $result;
|
|
|
3174 |
|
|
|
3175 |
}#if end
|
|
|
3176 |
|
|
|
3177 |
#轉存目標問卷的編號
|
|
|
3178 |
$questionnaireTypeNo=$getQuestionnaireTypeNoResult["dataContent"][$conf["questionnaireType.typeNoColumnName"]][0];
|
|
|
3179 |
|
|
|
3180 |
#將問卷樣本檔 $sampleCsvFile 匯入資料表
|
|
|
3181 |
|
|
|
3182 |
#初始化儲存樣本檔裡面哪幾題可匯入為樣本
|
|
|
3183 |
$importableQuestNumArrayInSamples=array();
|
|
|
3184 |
|
|
|
3185 |
#初始化儲存問卷設定檔題目對應的資料庫題號陣列變數
|
|
|
3186 |
$questNumberArrayInDb=array();
|
|
|
3187 |
|
|
|
3188 |
#檢查問卷設定檔與資料庫裡的問卷資訊是否相符
|
|
|
3189 |
#檢查該題的題目對應到資料庫是否存在
|
|
|
3190 |
|
|
|
3191 |
#有幾題就執行幾次
|
|
|
3192 |
for($i=4;$i<count($setupCsvFile["csvFileContent"]);$i++){
|
|
|
3193 |
|
|
|
3194 |
#檢查該題的題目是否存在於資料庫
|
|
|
3195 |
#函式說明:
|
|
|
3196 |
#檢查資料庫裏的資料表有無指定條件的資料
|
|
|
3197 |
#回傳的結果:
|
|
|
3198 |
#$result["status"],執行是否成功,成功為"true",失敗為"false"。
|
|
|
3199 |
#$result["error"],錯誤訊息
|
|
|
3200 |
#$result["founded"],是否找到資料,"true"代表有符合的資料;"false"代表沒有符合的資料.
|
|
|
3201 |
#$result["sql"],執行的sql字串.
|
|
|
3202 |
#必填參數:
|
|
|
3203 |
$conf["db"]["checkDataExists"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
3204 |
$conf["db"]["checkDataExists"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
3205 |
$conf["db"]["checkDataExists"]["selectedDataBaseName"]=$conf["dbName"];#爲指定的資料庫名稱,欲選擇的資料庫名稱
|
|
|
3206 |
$conf["db"]["checkDataExists"]["selectedDataTableName"]=$conf["questionnaireQuest.dtName"];#欲選擇的資料表名稱
|
|
|
3207 |
#可省略參數:
|
|
|
3208 |
|
|
|
3209 |
#如果 $conf["dbPassword"] 有設定
|
|
|
3210 |
if(isset($conf["dbPassword"])){
|
|
|
3211 |
|
|
|
3212 |
$conf["db"]["checkDataExists"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
3213 |
|
|
|
3214 |
}#if end
|
|
|
3215 |
|
|
|
3216 |
$conf["db"]["checkDataExists"]["conditionTargetName"]=array($conf["questionnaireQuest.typeNoColumnName"],$conf["questionnaireQuest.questContentColumnName"]);#用來判斷的資料表數值名稱,需爲陣列,可省略
|
|
|
3217 |
$conf["db"]["checkDataExists"]["conditionTargetValue"]=array($questionnaireTypeNo,$setupCsvFile["csvFileContent"][$i][0]);#用來判斷的資料表數值名稱若等於該數值,表示條件成立,需爲陣列,可省略
|
|
|
3218 |
$checkResult=db::checkDataExists($conf["db"]["checkDataExists"]);
|
|
|
3219 |
unset($conf["db"]["checkDataExists"]);
|
|
|
3220 |
|
|
|
3221 |
#如果 $checkResult["status"] 等於 "false"
|
|
|
3222 |
if($checkResult["status"]=="false"){
|
|
|
3223 |
|
|
|
3224 |
#設置錯誤識別
|
|
|
3225 |
$result["status"]="false";
|
|
|
3226 |
|
|
|
3227 |
#設置錯誤訊息
|
|
|
3228 |
$result["error"]=$checkResult;
|
|
|
3229 |
|
|
|
3230 |
#回傳結果
|
|
|
3231 |
return $result;
|
|
|
3232 |
|
|
|
3233 |
}#if end
|
|
|
3234 |
|
|
|
3235 |
#如果 $checkResult["founded"] 等於 "false"
|
|
|
3236 |
if($checkResult["founded"]=="false"){
|
|
|
3237 |
|
|
|
3238 |
#設置錯誤識別
|
|
|
3239 |
$result["status"]="false";
|
|
|
3240 |
|
|
|
3241 |
#設置警示訊息
|
|
|
3242 |
$result["warning"][]="樣本對應的問題「".$setupCsvFile["csvFileContent"][$i][0]."」並不存在";
|
|
|
3243 |
|
|
|
3244 |
#跳過該次迴圈
|
|
|
3245 |
continue;
|
|
|
3246 |
|
|
|
3247 |
}#if end
|
|
|
3248 |
|
|
|
3249 |
#執行到這邊代表有對應到題目內容
|
|
|
3250 |
|
|
|
3251 |
#透過題目內容來找對應的題號
|
|
|
3252 |
#涵式說明:
|
|
|
3253 |
#一次取得資料庫、表的資料
|
|
|
3254 |
#回傳的結果
|
|
|
3255 |
#$result["status"],執行結果"true"為成功;"false"為執行失敗。
|
|
|
3256 |
#$result["error"],錯誤訊息陣列。
|
|
|
3257 |
#$result["dataColumnName"],抓取的資料欄位名稱陣列.
|
|
|
3258 |
#$result["dataColumnName"][$i]代表第$i+1個欄位名稱
|
|
|
3259 |
#$result["dataContent"],爲資料的內容。
|
|
|
3260 |
#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
|
|
|
3261 |
#$dataSetNum 爲第$dataSetNum+1筆資料
|
|
|
3262 |
#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
|
|
|
3263 |
#$result["dataCount"],爲取得的資料筆數。
|
|
|
3264 |
#$result["sql"],執行的sql字串.
|
|
|
3265 |
#必填參數:
|
|
|
3266 |
$conf["db"]["fastGetDbData"]["dbAddress"]=$conf["dbAddress"];#爲dbServer的位置。
|
|
|
3267 |
$conf["db"]["fastGetDbData"]["dbAccount"]=$conf["dbAccount"];#爲登入dbServer的帳號。
|
|
|
3268 |
$conf["db"]["fastGetDbData"]["dbName"]=$conf["dbName"];#爲要存取的資料庫名稱
|
|
|
3269 |
$conf["db"]["fastGetDbData"]["tableName"]=$conf["questionnaireQuest.dtName"];#爲要存取的資料表名稱
|
|
|
3270 |
$conf["db"]["fastGetDbData"]["columnYouWant"]=array($conf["questionnaireQuest.questNoColumnName"]);#你想要的欄位!,若設為「array("*")」則代表全部欄位.
|
|
|
3271 |
#可省略參數:
|
|
|
3272 |
|
|
|
3273 |
#如果 $conf["dbPassword"] 有設置
|
|
|
3274 |
if(isset($conf["dbPassword"])){
|
|
|
3275 |
|
|
|
3276 |
$conf["db"]["fastGetDbData"]["dbPassword"]=$conf["dbPassword"];#爲要存取dbServer的密碼
|
|
|
3277 |
|
|
|
3278 |
}#if end
|
|
|
3279 |
|
|
|
3280 |
$conf["db"]["fastGetDbData"]["WhereColumnName"]=array($conf["questionnaireQuest.typeNoColumnName"],$conf["questionnaireQuest.questContentColumnName"]);#用於判斷語句的欄位項目陣列。
|
|
|
3281 |
$conf["db"]["fastGetDbData"]["WhereColumnValue"]=array($questionnaireTypeNo,$setupCsvFile["csvFileContent"][$i][0]);#用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
|
|
|
3282 |
#$conf["db"]["fastGetDbData"]["WhereColumnCombine"]=array("");#用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
|
|
|
3283 |
#$conf["db"]["fastGetDbData"]["WhereColumnOperator"]=array("");#用於判斷語句的比較符號陣列,可以用的符號有「"="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
|
|
|
3284 |
#$conf["db"]["fastGetDbData"]["WhereColumnAndOr"]=array("");#用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
|
|
|
3285 |
#$conf["db"]["fastGetDbData"]["orderItem"]="";#爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
|
|
|
3286 |
#$conf["db"]["fastGetDbData"]["ascORdesc"]="";#爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
|
|
|
3287 |
#$conf["db"]["fastGetDbData"]["numberStart"]="0";#為從第幾筆開始讀取,預設為0,代筆第一筆。
|
|
|
3288 |
#$conf["db"]["fastGetDbData"]["numLimit"]="30";#為要取幾筆資料,可以省略,省略則表示不限制數目。
|
|
|
3289 |
#$conf["db"]["fastGetDbData"]["groupBy"]=array("");#爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
|
|
|
3290 |
$getQuestNo=db::fastGetDbData($conf["db"]["fastGetDbData"]);
|
|
|
3291 |
unset($conf["db"]["fastGetDbData"]);
|
|
|
3292 |
|
|
|
3293 |
#如果 $getQuestNo["status"] 等於 "false"
|
|
|
3294 |
if($getQuestNo["status"]=="false"){
|
|
|
3295 |
|
|
|
3296 |
#設置錯誤識別
|
|
|
3297 |
$result["status"]="false";
|
|
|
3298 |
|
|
|
3299 |
#設置錯誤訊息
|
|
|
3300 |
$result["error"]=$getQuestNo;
|
|
|
3301 |
|
|
|
3302 |
#回傳結果
|
|
|
3303 |
return $result;
|
|
|
3304 |
|
|
|
3305 |
}#if end
|
|
|
3306 |
|
|
|
3307 |
#如果 $getQuestNo["dataCount"] 等於 0
|
|
|
3308 |
if($getQuestNo["dataCount"]==0){
|
|
|
3309 |
|
|
|
3310 |
#設置錯誤識別
|
|
|
3311 |
$result["status"]="false";
|
|
|
3312 |
|
|
|
3313 |
#設置警示訊息
|
|
|
3314 |
$result["warning"][]="該題「".$setupCsvFile["csvFileContent"][$i][0]."」找不到對應的題號";
|
|
|
3315 |
|
|
|
3316 |
#跳過該次迴圈
|
|
|
3317 |
continue;
|
|
|
3318 |
|
|
|
3319 |
}#if end
|
|
|
3320 |
|
|
|
3321 |
#執行到這代表有找到題號
|
|
|
3322 |
$thisQuestNo=$getQuestNo["dataContent"][$conf["questionnaireQuest.questNoColumnName"]][0];
|
|
|
3323 |
|
|
|
3324 |
#根據問卷編號、問題題號去檢查設定檔提供該題的題型是否正確
|
|
|
3325 |
#函式說明:
|
|
|
3326 |
#檢查資料庫裏的資料表有無指定條件的資料
|
|
|
3327 |
#回傳的結果:
|
|
|
3328 |
#$result["status"],執行是否成功,成功為"true",失敗為"false"。
|
|
|
3329 |
#$result["error"],錯誤訊息
|
|
|
3330 |
#$result["founded"],是否找到資料,"true"代表有符合的資料;"false"代表沒有符合的資料.
|
|
|
3331 |
#$result["sql"],執行的sql字串.
|
|
|
3332 |
#必填參數:
|
|
|
3333 |
$conf["db"]["checkDataExists"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
3334 |
$conf["db"]["checkDataExists"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
3335 |
$conf["db"]["checkDataExists"]["selectedDataBaseName"]=$conf["dbName"];#爲指定的資料庫名稱,欲選擇的資料庫名稱
|
|
|
3336 |
$conf["db"]["checkDataExists"]["selectedDataTableName"]=$conf["questionnaireQuest.dtName"];#欲選擇的資料表名稱
|
|
|
3337 |
#可省略參數:
|
|
|
3338 |
|
|
|
3339 |
#如果 $conf["dbPassword"] 有設定
|
|
|
3340 |
if(isset($conf["dbPassword"])){
|
|
|
3341 |
|
|
|
3342 |
$conf["db"]["checkDataExists"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
3343 |
|
|
|
3344 |
}#if end
|
|
|
3345 |
|
|
|
3346 |
$conf["db"]["checkDataExists"]["conditionTargetName"]=array($conf["questionnaireQuest.typeNoColumnName"],$conf["questionnaireQuest.questNoColumnName"],$conf["questionnaireQuest.questTypeCodeColumnName"]);#用來判斷的資料表數值名稱,需爲陣列,可省略
|
|
|
3347 |
$conf["db"]["checkDataExists"]["conditionTargetValue"]=array($questionnaireTypeNo,$thisQuestNo,$setupCsvFile["csvFileContent"][$i][1]);#用來判斷的資料表數值名稱若等於該數值,表示條件成立,需爲陣列,可省略
|
|
|
3348 |
$checkResult=db::checkDataExists($conf["db"]["checkDataExists"]);
|
|
|
3349 |
unset($conf["db"]["checkDataExists"]);
|
|
|
3350 |
|
|
|
3351 |
#如果 $checkResult["status"] 等於 "false"
|
|
|
3352 |
if($checkResult["status"]=="false"){
|
|
|
3353 |
|
|
|
3354 |
#設置錯誤識別
|
|
|
3355 |
$result["status"]="false";
|
|
|
3356 |
|
|
|
3357 |
#設置錯誤訊息
|
|
|
3358 |
$result["error"]=$checkResult;
|
|
|
3359 |
|
|
|
3360 |
#回傳結果
|
|
|
3361 |
return $result;
|
|
|
3362 |
|
|
|
3363 |
}#if end
|
|
|
3364 |
|
|
|
3365 |
#如果 $checkResult["founded"] 等於 "false"
|
|
|
3366 |
if($checkResult["founded"]=="false"){
|
|
|
3367 |
|
|
|
3368 |
#設置錯誤識別
|
|
|
3369 |
$result["status"]="false";
|
|
|
3370 |
|
|
|
3371 |
#設置警示訊息
|
|
|
3372 |
$result["warning"][]="樣本對應的問題「".$setupCsvFile["csvFileContent"][$i][0]."」,其題型不應該為「".$setupCsvFile["csvFileContent"][$i][1]."」";
|
|
|
3373 |
|
|
|
3374 |
#跳過該次迴圈
|
|
|
3375 |
continue;
|
|
|
3376 |
|
|
|
3377 |
}#if end
|
|
|
3378 |
|
|
|
3379 |
#執行到這邊代表問卷資訊檔的題型跟資料庫資料相符
|
|
|
3380 |
|
|
|
3381 |
#檢查問題對應的填答選項上限是否正確
|
|
|
3382 |
#函式說明:
|
|
|
3383 |
#檢查資料庫裏的資料表有無指定條件的資料
|
|
|
3384 |
#回傳的結果:
|
|
|
3385 |
#$result["status"],執行是否成功,成功為"true",失敗為"false"。
|
|
|
3386 |
#$result["error"],錯誤訊息
|
|
|
3387 |
#$result["founded"],是否找到資料,"true"代表有符合的資料;"false"代表沒有符合的資料.
|
|
|
3388 |
#$result["sql"],執行的sql字串.
|
|
|
3389 |
#必填參數:
|
|
|
3390 |
$conf["db"]["checkDataExists"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
3391 |
$conf["db"]["checkDataExists"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
3392 |
$conf["db"]["checkDataExists"]["selectedDataBaseName"]=$conf["dbName"];#爲指定的資料庫名稱,欲選擇的資料庫名稱
|
|
|
3393 |
$conf["db"]["checkDataExists"]["selectedDataTableName"]=$conf["questionnaireQuest.dtName"];#欲選擇的資料表名稱
|
|
|
3394 |
#可省略參數:
|
|
|
3395 |
|
|
|
3396 |
#如果 $conf["dbPassword"] 有設定
|
|
|
3397 |
if(isset($conf["dbPassword"])){
|
|
|
3398 |
|
|
|
3399 |
$conf["db"]["checkDataExists"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
3400 |
|
|
|
3401 |
}#if end
|
|
|
3402 |
|
|
|
3403 |
$conf["db"]["checkDataExists"]["conditionTargetName"]=array($conf["questionnaireQuest.typeNoColumnName"],$conf["questionnaireQuest.questNoColumnName"],$conf["questionnaireQuest.selectedQuestOptionMaxCountColumnName"]);#用來判斷的資料表數值名稱,需爲陣列,可省略
|
|
|
3404 |
$conf["db"]["checkDataExists"]["conditionTargetValue"]=array($questionnaireTypeNo,$thisQuestNo,$setupCsvFile["csvFileContent"][$i][2]);#用來判斷的資料表數值名稱若等於該數值,表示條件成立,需爲陣列,可省略
|
|
|
3405 |
$checkResult=db::checkDataExists($conf["db"]["checkDataExists"]);
|
|
|
3406 |
unset($conf["db"]["checkDataExists"]);
|
|
|
3407 |
|
|
|
3408 |
#如果 $checkResult["status"] 等於 "false"
|
|
|
3409 |
if($checkResult["status"]=="false"){
|
|
|
3410 |
|
|
|
3411 |
#設置錯誤識別
|
|
|
3412 |
$result["status"]="false";
|
|
|
3413 |
|
|
|
3414 |
#設置錯誤訊息
|
|
|
3415 |
$result["error"]=$checkResult;
|
|
|
3416 |
|
|
|
3417 |
#回傳結果
|
|
|
3418 |
return $result;
|
|
|
3419 |
|
|
|
3420 |
}#if end
|
|
|
3421 |
|
|
|
3422 |
#如果 $checkResult["founded"] 等於 "false"
|
|
|
3423 |
if($checkResult["founded"]=="false"){
|
|
|
3424 |
|
|
|
3425 |
#設置錯誤識別
|
|
|
3426 |
$result["status"]="false";
|
|
|
3427 |
|
|
|
3428 |
#設置警示訊息
|
|
|
3429 |
$result["warning"][]="樣本對應的問題「".$setupCsvFile["csvFileContent"][$i][0]."」,其填答選項上限不應該為「".$setupCsvFile["csvFileContent"][$i][2]."」";
|
|
|
3430 |
|
|
|
3431 |
#跳過該次迴圈
|
|
|
3432 |
continue;
|
|
|
3433 |
|
|
|
3434 |
}#if end
|
|
|
3435 |
|
|
|
3436 |
#執行到這邊代表問卷資訊檔的題目回答選項上限跟資料庫相符
|
|
|
3437 |
|
|
|
3438 |
#檢查該題的選項內容是否對應正確
|
|
|
3439 |
#函式說明:
|
|
|
3440 |
#檢查資料庫裏的資料表有無指定條件的資料
|
|
|
3441 |
#回傳的結果:
|
|
|
3442 |
#$result["status"],執行是否成功,成功為"true",失敗為"false"。
|
|
|
3443 |
#$result["error"],錯誤訊息
|
|
|
3444 |
#$result["founded"],是否找到資料,"true"代表有符合的資料;"false"代表沒有符合的資料.
|
|
|
3445 |
#$result["sql"],執行的sql字串.
|
|
|
3446 |
#必填參數:
|
|
|
3447 |
$conf["db"]["checkDataExists"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
3448 |
$conf["db"]["checkDataExists"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
3449 |
$conf["db"]["checkDataExists"]["selectedDataBaseName"]=$conf["dbName"];#爲指定的資料庫名稱,欲選擇的資料庫名稱
|
|
|
3450 |
$conf["db"]["checkDataExists"]["selectedDataTableName"]=$conf["questionnaireQuest.dtName"];#欲選擇的資料表名稱
|
|
|
3451 |
#可省略參數:
|
|
|
3452 |
|
|
|
3453 |
#如果 $conf["dbPassword"] 有設定
|
|
|
3454 |
if(isset($conf["dbPassword"])){
|
|
|
3455 |
|
|
|
3456 |
$conf["db"]["checkDataExists"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
3457 |
|
|
|
3458 |
}#if end
|
|
|
3459 |
|
|
|
3460 |
$conf["db"]["checkDataExists"]["conditionTargetName"]=array($conf["questionnaireQuest.typeNoColumnName"],$conf["questionnaireQuest.questNoColumnName"],$conf["questionnaireQuest.choiceValueColumnName"]);#用來判斷的資料表數值名稱,需爲陣列,可省略
|
|
|
3461 |
$conf["db"]["checkDataExists"]["conditionTargetValue"]=array($questionnaireTypeNo,$thisQuestNo,$setupCsvFile["csvFileContent"][$i][3]);#用來判斷的資料表數值名稱若等於該數值,表示條件成立,需爲陣列,可省略
|
|
|
3462 |
$checkResult=db::checkDataExists($conf["db"]["checkDataExists"]);
|
|
|
3463 |
unset($conf["db"]["checkDataExists"]);
|
|
|
3464 |
|
|
|
3465 |
#var_dump($checkResult);
|
|
|
3466 |
|
|
|
3467 |
#如果 $checkResult["status"] 等於 "false"
|
|
|
3468 |
if($checkResult["status"]=="false"){
|
|
|
3469 |
|
|
|
3470 |
#設置錯誤識別
|
|
|
3471 |
$result["status"]="false";
|
|
|
3472 |
|
|
|
3473 |
#設置錯誤訊息
|
|
|
3474 |
$result["error"]=$checkResult;
|
|
|
3475 |
|
|
|
3476 |
#回傳結果
|
|
|
3477 |
return $result;
|
|
|
3478 |
|
|
|
3479 |
}#if end
|
|
|
3480 |
|
|
|
3481 |
#如果 $checkResult["founded"] 等於 "false"
|
|
|
3482 |
if($checkResult["founded"]=="false"){
|
|
|
3483 |
|
|
|
3484 |
#設置錯誤識別
|
|
|
3485 |
$result["status"]="false";
|
|
|
3486 |
|
|
|
3487 |
#設置警示訊息
|
|
|
3488 |
$result["warning"][]="樣本對應的問題「".$setupCsvFile["csvFileContent"][$i][0]."」,其選項內容不應該為「".$setupCsvFile["csvFileContent"][$i][3]."」,系統已自動修正!";
|
|
|
3489 |
|
|
|
3490 |
#各版本問題的題項內容要相同太困難
|
|
|
3491 |
#跳過該次迴圈
|
|
|
3492 |
#continue;
|
|
|
3493 |
|
|
|
3494 |
}#if end
|
|
|
3495 |
|
|
|
3496 |
#執行到這邊代表問卷資訊檔的題目選項跟資料庫相符
|
|
|
3497 |
|
|
|
3498 |
#檢查該題是否必填的設定是否正確
|
|
|
3499 |
#函式說明:
|
|
|
3500 |
#檢查資料庫裏的資料表有無指定條件的資料
|
|
|
3501 |
#回傳的結果:
|
|
|
3502 |
#$result["status"],執行是否成功,成功為"true",失敗為"false"。
|
|
|
3503 |
#$result["error"],錯誤訊息
|
|
|
3504 |
#$result["founded"],是否找到資料,"true"代表有符合的資料;"false"代表沒有符合的資料.
|
|
|
3505 |
#$result["sql"],執行的sql字串.
|
|
|
3506 |
#必填參數:
|
|
|
3507 |
$conf["db"]["checkDataExists"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
3508 |
$conf["db"]["checkDataExists"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
3509 |
$conf["db"]["checkDataExists"]["selectedDataBaseName"]=$conf["dbName"];#爲指定的資料庫名稱,欲選擇的資料庫名稱
|
|
|
3510 |
$conf["db"]["checkDataExists"]["selectedDataTableName"]=$conf["questionnaireQuest.dtName"];#欲選擇的資料表名稱
|
|
|
3511 |
#可省略參數:
|
|
|
3512 |
|
|
|
3513 |
#如果 $conf["dbPassword"] 有設定
|
|
|
3514 |
if(isset($conf["dbPassword"])){
|
|
|
3515 |
|
|
|
3516 |
$conf["db"]["checkDataExists"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
3517 |
|
|
|
3518 |
}#if end
|
|
|
3519 |
|
|
|
3520 |
$conf["db"]["checkDataExists"]["conditionTargetName"]=array($conf["questionnaireQuest.typeNoColumnName"],$conf["questionnaireQuest.questNoColumnName"],$conf["questionnaireQuest.nullColumnName"]);#用來判斷的資料表數值名稱,需爲陣列,可省略
|
|
|
3521 |
$conf["db"]["checkDataExists"]["conditionTargetValue"]=array($questionnaireTypeNo,$thisQuestNo,$setupCsvFile["csvFileContent"][$i][4]);#用來判斷的資料表數值名稱若等於該數值,表示條件成立,需爲陣列,可省略
|
|
|
3522 |
$checkResult=db::checkDataExists($conf["db"]["checkDataExists"]);
|
|
|
3523 |
unset($conf["db"]);
|
|
|
3524 |
|
|
|
3525 |
#如果 $checkResult["status"] 等於 "false"
|
|
|
3526 |
if($checkResult["status"]=="false"){
|
|
|
3527 |
|
|
|
3528 |
#設置錯誤識別
|
|
|
3529 |
$result["status"]="false";
|
|
|
3530 |
|
|
|
3531 |
#設置錯誤訊息
|
|
|
3532 |
$result["error"]=$checkResult;
|
|
|
3533 |
|
|
|
3534 |
#回傳結果
|
|
|
3535 |
return $result;
|
|
|
3536 |
|
|
|
3537 |
}#if end
|
|
|
3538 |
|
|
|
3539 |
#如果 $checkResult["founded"] 等於 "false"
|
|
|
3540 |
if($checkResult["founded"]=="false"){
|
|
|
3541 |
|
|
|
3542 |
#設置錯誤識別
|
|
|
3543 |
$result["status"]="false";
|
|
|
3544 |
|
|
|
3545 |
#設置警示訊息
|
|
|
3546 |
$result["warning"][]="樣本對應的問題「".$setupCsvFile["csvFileContent"][$i][0]."」,其是否必填的設定不應該為「".$setupCsvFile["csvFileContent"][$i][4]."」";
|
|
|
3547 |
|
|
|
3548 |
#跳過該次迴圈
|
|
|
3549 |
continue;
|
|
|
3550 |
|
|
|
3551 |
}#if end
|
|
|
3552 |
|
|
|
3553 |
#執行到這邊代表問卷設定檔是否必填的設定跟資料庫相符
|
|
|
3554 |
|
|
|
3555 |
#檢查題目對應的構面是否相符
|
|
|
3556 |
#函式說明:
|
|
|
3557 |
#檢查資料庫裏的資料表有無指定條件的資料
|
|
|
3558 |
#回傳的結果:
|
|
|
3559 |
#$result["status"],執行是否成功,成功為"true",失敗為"false"。
|
|
|
3560 |
#$result["error"],錯誤訊息
|
|
|
3561 |
#$result["founded"],是否找到資料,"true"代表有符合的資料;"false"代表沒有符合的資料.
|
|
|
3562 |
#$result["sql"],執行的sql字串.
|
|
|
3563 |
#必填參數:
|
|
|
3564 |
$conf["db"]["checkDataExists"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
3565 |
$conf["db"]["checkDataExists"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
3566 |
$conf["db"]["checkDataExists"]["selectedDataBaseName"]=$conf["dbName"];#爲指定的資料庫名稱,欲選擇的資料庫名稱
|
|
|
3567 |
$conf["db"]["checkDataExists"]["selectedDataTableName"]=$conf["questionnaireQuest.dtName"];#欲選擇的資料表名稱
|
|
|
3568 |
#可省略參數:
|
|
|
3569 |
|
|
|
3570 |
#如果 $conf["dbPassword"] 有設定
|
|
|
3571 |
if(isset($conf["dbPassword"])){
|
|
|
3572 |
|
|
|
3573 |
$conf["db"]["checkDataExists"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
3574 |
|
|
|
3575 |
}#if end
|
|
|
3576 |
|
|
|
3577 |
$conf["db"]["checkDataExists"]["conditionTargetName"]=array($conf["questionnaireQuest.typeNoColumnName"],$conf["questionnaireQuest.questNoColumnName"],$conf["questionnaireQuest.perspectiveColumnName"]);#用來判斷的資料表數值名稱,需爲陣列,可省略
|
|
|
3578 |
$conf["db"]["checkDataExists"]["conditionTargetValue"]=array($questionnaireTypeNo,$thisQuestNo,$setupCsvFile["csvFileContent"][$i][5]);#用來判斷的資料表數值名稱若等於該數值,表示條件成立,需爲陣列,可省略
|
|
|
3579 |
$checkResult=db::checkDataExists($conf["db"]["checkDataExists"]);
|
|
|
3580 |
unset($conf["db"]["checkDataExists"]);
|
|
|
3581 |
|
|
|
3582 |
#如果 $checkResult["status"] 等於 "false"
|
|
|
3583 |
if($checkResult["status"]=="false"){
|
|
|
3584 |
|
|
|
3585 |
#設置錯誤識別
|
|
|
3586 |
$result["status"]="false";
|
|
|
3587 |
|
|
|
3588 |
#設置錯誤訊息
|
|
|
3589 |
$result["error"]=$checkResult;
|
|
|
3590 |
|
|
|
3591 |
#回傳結果
|
|
|
3592 |
return $result;
|
|
|
3593 |
|
|
|
3594 |
}#if end
|
|
|
3595 |
|
|
|
3596 |
#如果 $checkResult["founded"] 等於 "false"
|
|
|
3597 |
if($checkResult["founded"]=="false"){
|
|
|
3598 |
|
|
|
3599 |
#設置錯誤識別
|
|
|
3600 |
$result["status"]="false";
|
|
|
3601 |
|
|
|
3602 |
#設置警示訊息
|
|
|
3603 |
$result["warning"][]="樣本對應的問題「".$setupCsvFile["csvFileContent"][$i][0]."」,其歸屬的構面不應該為「".$setupCsvFile["csvFileContent"][$i][5]."」";
|
|
|
3604 |
|
|
|
3605 |
#跳過該次迴圈
|
|
|
3606 |
continue;
|
|
|
3607 |
|
|
|
3608 |
}#if end
|
|
|
3609 |
|
|
|
3610 |
#執行到這邊代表問卷資訊檔的構面設定跟資料庫相符
|
|
|
3611 |
|
|
|
3612 |
#檢查題目對應的指標是否相符
|
|
|
3613 |
#函式說明:
|
|
|
3614 |
#檢查資料庫裏的資料表有無指定條件的資料
|
|
|
3615 |
#回傳的結果:
|
|
|
3616 |
#$result["status"],執行是否成功,成功為"true",失敗為"false"。
|
|
|
3617 |
#$result["error"],錯誤訊息
|
|
|
3618 |
#$result["founded"],是否找到資料,"true"代表有符合的資料;"false"代表沒有符合的資料.
|
|
|
3619 |
#$result["sql"],執行的sql字串.
|
|
|
3620 |
#必填參數:
|
|
|
3621 |
$conf["db"]["checkDataExists"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
3622 |
$conf["db"]["checkDataExists"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
3623 |
$conf["db"]["checkDataExists"]["selectedDataBaseName"]=$conf["dbName"];#爲指定的資料庫名稱,欲選擇的資料庫名稱
|
|
|
3624 |
$conf["db"]["checkDataExists"]["selectedDataTableName"]=$conf["questionnaireQuest.dtName"];#欲選擇的資料表名稱
|
|
|
3625 |
#可省略參數:
|
|
|
3626 |
|
|
|
3627 |
#如果 $conf["dbPassword"] 有設定
|
|
|
3628 |
if(isset($conf["dbPassword"])){
|
|
|
3629 |
|
|
|
3630 |
$conf["db"]["checkDataExists"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
3631 |
|
|
|
3632 |
}#if end
|
|
|
3633 |
|
|
|
3634 |
$conf["db"]["checkDataExists"]["conditionTargetName"]=array($conf["questionnaireQuest.typeNoColumnName"],$conf["questionnaireQuest.questNoColumnName"],$conf["questionnaireQuest.indicatorColumnName"]);#用來判斷的資料表數值名稱,需爲陣列,可省略
|
|
|
3635 |
$conf["db"]["checkDataExists"]["conditionTargetValue"]=array($questionnaireTypeNo,$thisQuestNo,$setupCsvFile["csvFileContent"][$i][6]);#用來判斷的資料表數值名稱若等於該數值,表示條件成立,需爲陣列,可省略
|
|
|
3636 |
$checkResult=db::checkDataExists($conf["db"]["checkDataExists"]);
|
|
|
3637 |
unset($conf["db"]["checkDataExists"]);
|
|
|
3638 |
|
|
|
3639 |
#如果 $checkResult["status"] 等於 "false"
|
|
|
3640 |
if($checkResult["status"]=="false"){
|
|
|
3641 |
|
|
|
3642 |
#設置錯誤識別
|
|
|
3643 |
$result["status"]="false";
|
|
|
3644 |
|
|
|
3645 |
#設置錯誤訊息
|
|
|
3646 |
$result["error"]=$checkResult;
|
|
|
3647 |
|
|
|
3648 |
#回傳結果
|
|
|
3649 |
return $result;
|
|
|
3650 |
|
|
|
3651 |
}#if end
|
|
|
3652 |
|
|
|
3653 |
#如果 $checkResult["founded"] 等於 "false"
|
|
|
3654 |
if($checkResult["founded"]=="false"){
|
|
|
3655 |
|
|
|
3656 |
#設置錯誤識別
|
|
|
3657 |
$result["status"]="false";
|
|
|
3658 |
|
|
|
3659 |
#設置警示訊息
|
|
|
3660 |
$result["warning"][]="樣本對應的問題「".$setupCsvFile["csvFileContent"][$i][0]."」,其對應的指標不應該為「".$setupCsvFile["csvFileContent"][$i][6]."」";
|
|
|
3661 |
|
|
|
3662 |
#跳過該次迴圈
|
|
|
3663 |
continue;
|
|
|
3664 |
|
|
|
3665 |
}#if end
|
|
|
3666 |
|
|
|
3667 |
#執行到這邊代表問卷設定的檔指標設定與資料庫相符
|
|
|
3668 |
|
|
|
3669 |
#取得題目對應的題號,儲存的key為從0開始的整數,題目內容也是key.
|
|
|
3670 |
$questNumberArrayInDb[$i-4]=$thisQuestNo;
|
|
|
3671 |
$questNumberArrayInDb[$setupCsvFile["csvFileContent"][$i][0]]=$thisQuestNo;
|
|
|
3672 |
|
|
|
3673 |
#儲存可以匯入到樣本資料庫的題號(從0開始)
|
|
|
3674 |
$importableQuestNumArrayInSamples[]=$i-4;
|
|
|
3675 |
|
|
|
3676 |
#初始$j為7
|
|
|
3677 |
$j=7;
|
|
|
3678 |
|
|
|
3679 |
#檢查題目預測的KRI題項是否相符
|
|
|
3680 |
#無窮迴圈
|
|
|
3681 |
while(true){
|
|
|
3682 |
|
|
|
3683 |
#如果 $setupCsvFile["csvFileContent"][$i][$j] 有設定
|
|
|
3684 |
if(isset($setupCsvFile["csvFileContent"][$i][$j])){
|
|
|
3685 |
|
|
|
3686 |
#如果 $setupCsvFile["csvFileContent"][$i][$j] 不為空
|
|
|
3687 |
if($setupCsvFile["csvFileContent"][$i][$j]!=""){
|
|
|
3688 |
|
|
|
3689 |
#尋找該題的題號
|
|
|
3690 |
#涵式說明:
|
|
|
3691 |
#一次取得資料庫、表的資料
|
|
|
3692 |
#回傳的結果
|
|
|
3693 |
#$result["status"],執行結果"true"為成功;"false"為執行失敗。
|
|
|
3694 |
#$result["error"],錯誤訊息陣列。
|
|
|
3695 |
#$result["dataColumnName"],抓取的資料欄位名稱陣列.
|
|
|
3696 |
#$result["dataColumnName"][$i]代表第$i+1個欄位名稱
|
|
|
3697 |
#$result["dataContent"],爲資料的內容。
|
|
|
3698 |
#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
|
|
|
3699 |
#$dataSetNum 爲第$dataSetNum+1筆資料
|
|
|
3700 |
#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
|
|
|
3701 |
#$result["dataCount"],爲取得的資料筆數。
|
|
|
3702 |
#$result["sql"],執行的sql字串.
|
|
|
3703 |
#必填參數:
|
|
|
3704 |
$conf["db"]["fastGetDbData"]["dbAddress"]=$conf["dbAddress"];#爲dbServer的位置。
|
|
|
3705 |
$conf["db"]["fastGetDbData"]["dbAccount"]=$conf["dbAccount"];#爲登入dbServer的帳號。
|
|
|
3706 |
$conf["db"]["fastGetDbData"]["dbName"]=$dbName;#爲要存取的資料庫名稱
|
|
|
3707 |
$conf["db"]["fastGetDbData"]["tableName"]=$conf["questionnaireQuest.dtName"];#爲要存取的資料表名稱
|
|
|
3708 |
$conf["db"]["fastGetDbData"]["columnYouWant"]=array($conf["questionnaireQuest.questNoColumnName"]);#你想要的欄位!,若設為「array("*")」則代表全部欄位.
|
|
|
3709 |
#可省略參數:
|
|
|
3710 |
$conf["db"]["fastGetDbData"]["dbPassword"]=$conf["dbPassword"];#爲要存取dbServer的密碼
|
|
|
3711 |
$conf["db"]["fastGetDbData"]["WhereColumnName"]=array($conf["questionnaireQuest.typeNoColumnName"],$conf["questionnaireQuest.questContentColumnName"]);#用於判斷語句的欄位項目陣列。
|
|
|
3712 |
$conf["db"]["fastGetDbData"]["WhereColumnValue"]=array($questionnaireTypeNo,$setupCsvFile["csvFileContent"][$i][$j]);#用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
|
|
|
3713 |
#$conf["db"]["fastGetDbData"]["WhereColumnCombine"]=array("");#用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
|
|
|
3714 |
#$conf["db"]["fastGetDbData"]["WhereColumnOperator"]=array("");#用於判斷語句的比較符號陣列,可以用的符號有「"="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
|
|
|
3715 |
#$conf["db"]["fastGetDbData"]["WhereColumnAndOr"]=array("");#用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
|
|
|
3716 |
#$conf["db"]["fastGetDbData"]["orderItem"]="";#爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
|
|
|
3717 |
#$conf["db"]["fastGetDbData"]["ascORdesc"]="";#爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
|
|
|
3718 |
#$conf["db"]["fastGetDbData"]["numberStart"]="0";#為從第幾筆開始讀取,預設為0,代筆第一筆。
|
|
|
3719 |
#$conf["db"]["fastGetDbData"]["numLimit"]="30";#為要取幾筆資料,可以省略,省略則表示不限制數目。
|
|
|
3720 |
#$conf["db"]["fastGetDbData"]["groupBy"]=array("");#爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
|
|
|
3721 |
$getQuestNoResult=db::fastGetDbData($conf["db"]["fastGetDbData"]);
|
|
|
3722 |
unset($conf["db"]["fastGetDbData"]);
|
|
|
3723 |
|
|
|
3724 |
#如果 $getQuestNoResult["status"] 等於 "false"
|
|
|
3725 |
if($getQuestNoResult["status"]=="false"){
|
|
|
3726 |
|
|
|
3727 |
#設置執行錯誤
|
|
|
3728 |
$result["status"]="false";
|
|
|
3729 |
|
|
|
3730 |
#取得是在哪個函式發現錯誤的
|
|
|
3731 |
$result["functionName"]=__FUNCTION__;
|
|
|
3732 |
|
|
|
3733 |
#設置錯誤訊息
|
|
|
3734 |
$result["error"]=$getQuestNoResult;
|
|
|
3735 |
|
|
|
3736 |
#回傳結果
|
|
|
3737 |
return $result;
|
|
|
3738 |
|
|
|
3739 |
}#if end
|
|
|
3740 |
|
|
|
3741 |
#往後尋找
|
|
|
3742 |
$j++;
|
|
|
3743 |
|
|
|
3744 |
#如果 $getQuestNoResult["dataCount"] 為 0
|
|
|
3745 |
if($getQuestNoResult["dataCount"]==0){
|
|
|
3746 |
|
|
|
3747 |
#設置警告訊息
|
|
|
3748 |
$result["warning"][]="找不名為".$csvFileContent["csvFileContent"][i][0]."的題項";
|
|
|
3749 |
|
|
|
3750 |
#代表沒有該題目
|
|
|
3751 |
#跳出while
|
|
|
3752 |
break;
|
|
|
3753 |
|
|
|
3754 |
}#if end
|
|
|
3755 |
|
|
|
3756 |
}#if end
|
|
|
3757 |
|
|
|
3758 |
#反之代表沒有預測指標的資料
|
|
|
3759 |
else{
|
|
|
3760 |
|
|
|
3761 |
#跳出while
|
|
|
3762 |
break;
|
|
|
3763 |
|
|
|
3764 |
}#else end
|
|
|
3765 |
|
|
|
3766 |
}#if end
|
|
|
3767 |
|
|
|
3768 |
#反之代表沒有預測指標的資料
|
|
|
3769 |
else{
|
|
|
3770 |
|
|
|
3771 |
#跳出while
|
|
|
3772 |
break;
|
|
|
3773 |
|
|
|
3774 |
}#else end
|
|
|
3775 |
|
|
|
3776 |
}#while end
|
|
|
3777 |
|
|
|
3778 |
}#for end
|
|
|
3779 |
|
|
|
3780 |
#取得題目對應的題號,儲存的key為從0開始的整數,題目內容也是key.
|
|
|
3781 |
#var_dump(count($questNumberArrayInDb));
|
|
|
3782 |
|
|
|
3783 |
#儲存可以匯入到樣本資料庫的樣本檔題號
|
|
|
3784 |
#var_dump(count($importableQuestNumArrayInSamples));
|
|
|
3785 |
|
|
|
3786 |
#函數說明:
|
|
|
3787 |
#延長php的執行時間,每呼叫一次會初始化執行時間爲0,然後設定下次可以執行多久.
|
|
|
3788 |
#回傳結果:
|
|
|
3789 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
3790 |
#$result["error"],錯誤訊息陣列.
|
|
|
3791 |
#$result["function"],當前執行的函數名稱.
|
|
|
3792 |
#必填參數:
|
|
|
3793 |
#$conf["sec"],整數,要延長多少執行時間,單位爲秒
|
|
|
3794 |
$conf["config::delayRunTimeExectionMax"]["sec"]=300;
|
|
|
3795 |
#參考資料:
|
|
|
3796 |
#http://php.net/manual/en/function.set-time-limit.php
|
|
|
3797 |
$delayRunTimeExectionMax=config::delayRunTimeExectionMax($conf["config::delayRunTimeExectionMax"]);
|
|
|
3798 |
unset($conf["config::delayRunTimeExectionMax"]);
|
|
|
3799 |
|
|
|
3800 |
#如果執行失敗
|
|
|
3801 |
if($delayRunTimeExectionMax["status"]==="false"){
|
|
|
3802 |
|
|
|
3803 |
#設定類別圖繪製失敗
|
|
|
3804 |
$result["status"]="false";
|
|
|
3805 |
|
|
|
3806 |
#設定該檔案的類別圖繪製失敗提示
|
|
|
3807 |
$result["error"]=$delayRunTimeExectionMax;
|
|
|
3808 |
|
|
|
3809 |
#回傳結果
|
|
|
3810 |
return $result;
|
|
|
3811 |
|
|
|
3812 |
}#if end
|
|
|
3813 |
|
|
|
3814 |
#依據每筆樣本(剔除標題攔)
|
|
|
3815 |
for($i=1;$i<$sampleCsvFile["lineArrayCount"];$i++){
|
|
|
3816 |
|
|
|
3817 |
#初始化該樣本尚未插入調查的時間點
|
|
|
3818 |
#"false"代表該樣本尚未插入調查的時間點
|
|
|
3819 |
$insertedStartSurveyPointStatus="false";
|
|
|
3820 |
|
|
|
3821 |
#依據每一題(該行的每一欄)
|
|
|
3822 |
#-7是因為有年月日周時分秒的欄位
|
|
|
3823 |
for($j=1;$j<count($sampleCsvFile["csvFileContent"][$i])-7;$j++){
|
|
|
3824 |
|
|
|
3825 |
#題目對應的題號,儲存的key為從0開始的整數,題目內容也是key.
|
|
|
3826 |
#$questNumberArrayInDb
|
|
|
3827 |
|
|
|
3828 |
#問卷設定檔題目對應的資料庫題號陣列變數
|
|
|
3829 |
#$importableQuestNumArrayInSamples
|
|
|
3830 |
|
|
|
3831 |
#檢查該題是否為可以匯入的題項
|
|
|
3832 |
#涵式說明:
|
|
|
3833 |
#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.
|
|
|
3834 |
#回傳的結果:
|
|
|
3835 |
#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
|
|
|
3836 |
#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
|
|
|
3837 |
#$result["error"],錯誤訊息
|
|
|
3838 |
#$result["equalVarName"],相等的變數名稱或key.
|
|
|
3839 |
#$result["equalVarValue"],相等的變數數值內容.
|
|
|
3840 |
#必填參數:
|
|
|
3841 |
$conf["search.getEqualVar"]["conditionElement"]=$j-1;#條件元素,要等於的元素內容.
|
|
|
3842 |
$conf["search.getEqualVar"]["compareElements"]=$importableQuestNumArrayInSamples;#要比對的陣列變數內容.
|
|
|
3843 |
$searchResult=search::getEqualVar($conf["search.getEqualVar"]);
|
|
|
3844 |
unset($conf["search.getEqualVar"]);
|
|
|
3845 |
|
|
|
3846 |
#var_dump($searchResult);
|
|
|
3847 |
|
|
|
3848 |
#如果搜尋出錯
|
|
|
3849 |
if($searchResult["status"]=="false"){
|
|
|
3850 |
|
|
|
3851 |
#設置錯誤識別
|
|
|
3852 |
$result["status"]="false";
|
|
|
3853 |
|
|
|
3854 |
#設置錯誤訊息
|
|
|
3855 |
$result["error"]=$searchResult;
|
|
|
3856 |
|
|
|
3857 |
#回傳結果
|
|
|
3858 |
return $result;
|
|
|
3859 |
|
|
|
3860 |
}#if end
|
|
|
3861 |
|
|
|
3862 |
#初始化儲存該題對應在資料庫裡面的題號
|
|
|
3863 |
$questNoInDb="";
|
|
|
3864 |
|
|
|
3865 |
#如果沒有找到對應的題項
|
|
|
3866 |
if($searchResult["founded"]=="false"){
|
|
|
3867 |
|
|
|
3868 |
#跳過該題
|
|
|
3869 |
continue;
|
|
|
3870 |
|
|
|
3871 |
}#if end
|
|
|
3872 |
|
|
|
3873 |
#反之代表有找到對應的題項
|
|
|
3874 |
else{
|
|
|
3875 |
|
|
|
3876 |
#取得該題在資料庫裡面的題號為何
|
|
|
3877 |
$questNoInDb=$questNumberArrayInDb[$searchResult["equalVarValue"]];
|
|
|
3878 |
|
|
|
3879 |
}#else end
|
|
|
3880 |
|
|
|
3881 |
#寫入該題填寫的內容
|
|
|
3882 |
#涵式說明:
|
|
|
3883 |
#插入資料到指定的資料表裡面,插入資料完畢可以選擇是否要進行轉址。
|
|
|
3884 |
#回傳的數值:
|
|
|
3885 |
#$result["status"],爲查詢是否成功,若爲0則成功,若爲1則表示失敗了.
|
|
|
3886 |
#$result["error"],錯誤訊息.
|
|
|
3887 |
#$result["sql"],執行的sql語法.
|
|
|
3888 |
#必填參數:
|
|
|
3889 |
$conf["db"]["insertData"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
3890 |
$conf["db"]["insertData"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
3891 |
$conf["db"]["insertData"]["selectedDataBaseName"]=$conf["dbName"];#要選取的資料庫名稱
|
|
|
3892 |
$conf["db"]["insertData"]["tableName"]=$conf["importedQuestionnaireSample.dtName"];#爲要插入資料的資料表名稱
|
|
|
3893 |
$conf["db"]["insertData"]["columnName"]=array($conf["questionnaireType.typeNoColumnName"],$conf["importedQuestionnaireSample.noColumnName"],$conf["importedQuestionnaireSample.questNoColumnName"],$conf["importedQuestionnaireSample.answerColumnName"],$conf["importedQuestionnaireSample.filledColumnName"]);#爲資料表的項目名稱,
|
|
|
3894 |
#例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);
|
|
|
3895 |
|
|
|
3896 |
#初始化記錄該題是否有填寫的變數
|
|
|
3897 |
$filled="";
|
|
|
3898 |
|
|
|
3899 |
#如果填答內容不存在
|
|
|
3900 |
if(!isset($sampleCsvFile["csvFileContent"][$i][$j])){
|
|
|
3901 |
|
|
|
3902 |
#則代表該題未填寫
|
|
|
3903 |
$filled="false";
|
|
|
3904 |
|
|
|
3905 |
}#if end
|
|
|
3906 |
|
|
|
3907 |
#不滿足以上條件,但如果填答內容為""
|
|
|
3908 |
else if($sampleCsvFile["csvFileContent"][$i][$j]==""){
|
|
|
3909 |
|
|
|
3910 |
#則代表該題未填寫
|
|
|
3911 |
$filled="false";
|
|
|
3912 |
|
|
|
3913 |
}#if end
|
|
|
3914 |
|
|
|
3915 |
#不滿足以上條件,代表該題有填寫
|
|
|
3916 |
else{
|
|
|
3917 |
|
|
|
3918 |
$filled="true";
|
|
|
3919 |
|
|
|
3920 |
}#else end
|
|
|
3921 |
|
|
|
3922 |
#取得題號
|
|
|
3923 |
$thisQuestNo=$j;
|
|
|
3924 |
|
|
|
3925 |
#取得填寫的內容字串
|
|
|
3926 |
$filledContent=$sampleCsvFile["csvFileContent"][$i][$thisQuestNo];
|
|
|
3927 |
|
|
|
3928 |
$conf["db"]["insertData"]["insertValue"]=array($questionnaireTypeNo,$sampleCsvFile["csvFileContent"][$i][0],$questNoInDb,$filledContent,$filled);#爲要插入的數值
|
|
|
3929 |
#例如:$conf["insertValue"]=array("insertValue1","insertValue2","insertValue3",...);
|
|
|
3930 |
#可以省略的變數:
|
|
|
3931 |
|
|
|
3932 |
#如果 $conf["dbPassword"] 有設置
|
|
|
3933 |
if(isset($conf["dbPassword"])){
|
|
|
3934 |
|
|
|
3935 |
#則用密碼來連線
|
|
|
3936 |
$conf["db"]["insertData"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
3937 |
|
|
|
3938 |
}#if end
|
|
|
3939 |
|
|
|
3940 |
$fillQuestResult=db::insertData($conf["db"]["insertData"]);
|
|
|
3941 |
unset($conf["db"]["insertData"]);
|
|
|
3942 |
|
|
|
3943 |
#debug
|
|
|
3944 |
#var_dump($fillQuestResult);
|
|
|
3945 |
|
|
|
3946 |
#移除題號內容,避免寫入重複的題號.
|
|
|
3947 |
unset($thisQuestNo);
|
|
|
3948 |
|
|
|
3949 |
#如果 $fillQuestResult["status"] 等於 "false"
|
|
|
3950 |
if($fillQuestResult["status"]=="false"){
|
|
|
3951 |
|
|
|
3952 |
#設置錯誤識別
|
|
|
3953 |
$result["status"]="false";
|
|
|
3954 |
|
|
|
3955 |
#設置錯誤訊息
|
|
|
3956 |
$result["error"]=$fillQuestResult;
|
|
|
3957 |
|
|
|
3958 |
#回傳結果
|
|
|
3959 |
return $result;
|
|
|
3960 |
|
|
|
3961 |
}#if end
|
|
|
3962 |
|
|
|
3963 |
#檢查有無插入過該筆樣本的調查時間點
|
|
|
3964 |
#"false"代表該樣本尚未插入調查的時間點
|
|
|
3965 |
if($insertedStartSurveyPointStatus=="false"){
|
|
|
3966 |
|
|
|
3967 |
#插入接受調查的時間
|
|
|
3968 |
|
|
|
3969 |
#涵式說明:
|
|
|
3970 |
#插入資料到指定的資料表裡面,插入資料完畢可以選擇是否要進行轉址。
|
|
|
3971 |
#回傳的數值:
|
|
|
3972 |
#$result["status"],爲查詢是否成功,若爲"true"則成功,若爲"false"則表示失敗了.
|
|
|
3973 |
#$result["error"],錯誤訊息.
|
|
|
3974 |
#$result["sql"],執行的sql語法.
|
|
|
3975 |
#必填參數:
|
|
|
3976 |
$conf["db.insertData"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
3977 |
$conf["db.insertData"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
3978 |
$conf["db.insertData"]["selectedDataBaseName"]=$conf["dbName"];#要選取的資料庫名稱
|
|
|
3979 |
$conf["db.insertData"]["tableName"]=$conf["importedQuestionnaireSample.startSurveyPointDtName"];#爲要插入資料的資料表名稱
|
|
|
3980 |
|
|
|
3981 |
#爲資料表的項目名稱,
|
|
|
3982 |
#例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);
|
|
|
3983 |
$conf["db.insertData"]["columnName"][]=$conf["questionnaireType.typeNoColumnName"];
|
|
|
3984 |
$conf["db.insertData"]["columnName"][]=$conf["importedQuestionnaireSample.noColumnName"];
|
|
|
3985 |
$conf["db.insertData"]["columnName"][]=$conf["importedQuestionnaireSample.recordedYearColumnName"];
|
|
|
3986 |
$conf["db.insertData"]["columnName"][]=$conf["importedQuestionnaireSample.recordedMonthColumnName"];
|
|
|
3987 |
$conf["db.insertData"]["columnName"][]=$conf["importedQuestionnaireSample.recordedDayColumnName"];
|
|
|
3988 |
$conf["db.insertData"]["columnName"][]=$conf["importedQuestionnaireSample.recordedWeekColumnName"];
|
|
|
3989 |
$conf["db.insertData"]["columnName"][]=$conf["importedQuestionnaireSample.recordedHourColumnName"];
|
|
|
3990 |
$conf["db.insertData"]["columnName"][]=$conf["importedQuestionnaireSample.recordedMinColumnName"];
|
|
|
3991 |
$conf["db.insertData"]["columnName"][]=$conf["importedQuestionnaireSample.recordedSecColumnName"];
|
|
|
3992 |
|
|
|
3993 |
#爲要插入度數值,
|
|
|
3994 |
#例如:$conf["insertValue"]=array("insertValue1","insertValue2","insertValue3",...);
|
|
|
3995 |
$conf["db.insertData"]["insertValue"][]=$questionnaireTypeNo;
|
|
|
3996 |
$conf["db.insertData"]["insertValue"][]=$sampleCsvFile["csvFileContent"][$i][0];
|
|
|
3997 |
$conf["db.insertData"]["insertValue"][]=$sampleCsvFile["csvFileContent"][$i][count($sampleCsvFile["csvFileContent"][$i])-7];
|
|
|
3998 |
$conf["db.insertData"]["insertValue"][]=$sampleCsvFile["csvFileContent"][$i][count($sampleCsvFile["csvFileContent"][$i])-6];
|
|
|
3999 |
$conf["db.insertData"]["insertValue"][]=$sampleCsvFile["csvFileContent"][$i][count($sampleCsvFile["csvFileContent"][$i])-5];
|
|
|
4000 |
$conf["db.insertData"]["insertValue"][]=$sampleCsvFile["csvFileContent"][$i][count($sampleCsvFile["csvFileContent"][$i])-4];
|
|
|
4001 |
$conf["db.insertData"]["insertValue"][]=$sampleCsvFile["csvFileContent"][$i][count($sampleCsvFile["csvFileContent"][$i])-3];
|
|
|
4002 |
$conf["db.insertData"]["insertValue"][]=$sampleCsvFile["csvFileContent"][$i][count($sampleCsvFile["csvFileContent"][$i])-2];
|
|
|
4003 |
$conf["db.insertData"]["insertValue"][]=$sampleCsvFile["csvFileContent"][$i][count($sampleCsvFile["csvFileContent"][$i])-1];
|
|
|
4004 |
|
|
|
4005 |
#可以省略的變數:
|
|
|
4006 |
$conf["db.insertData"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
4007 |
$insertStartSurveyPointResult=db::insertData($conf["db.insertData"]);
|
|
|
4008 |
unset($conf["db.insertData"]);
|
|
|
4009 |
|
|
|
4010 |
#debug
|
|
|
4011 |
#var_dump($insertStartSurveyPointResult);
|
|
|
4012 |
|
|
|
4013 |
#如果插入調查詩時間失敗
|
|
|
4014 |
if($insertStartSurveyPointResult["status"]=="false"){
|
|
|
4015 |
|
|
|
4016 |
#設置執行不正常
|
|
|
4017 |
$result["status"]="false";
|
|
|
4018 |
|
|
|
4019 |
#設置執行的錯誤訊息
|
|
|
4020 |
$result["error"]=$insertStartSurveyPointResult;
|
|
|
4021 |
|
|
|
4022 |
#回傳結果
|
|
|
4023 |
return $result;
|
|
|
4024 |
|
|
|
4025 |
}#if end
|
|
|
4026 |
|
|
|
4027 |
#設置有插入過該筆樣本的開始調查時間
|
|
|
4028 |
$insertedStartSurveyPointStatus="true";
|
|
|
4029 |
|
|
|
4030 |
}#if end
|
|
|
4031 |
|
|
|
4032 |
#函數說明:
|
|
|
4033 |
#延長php的執行時間,每呼叫一次會初始化執行時間爲0,然後設定下次可以執行多久.
|
|
|
4034 |
#回傳結果:
|
|
|
4035 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
4036 |
#$result["error"],錯誤訊息陣列.
|
|
|
4037 |
#$result["function"],當前執行的函數名稱.
|
|
|
4038 |
#必填參數:
|
|
|
4039 |
#$conf["sec"],整數,要延長多少執行時間,單位爲秒
|
|
|
4040 |
$conf["config::delayRunTimeExectionMax"]["sec"]=300;
|
|
|
4041 |
#參考資料:
|
|
|
4042 |
#http://php.net/manual/en/function.set-time-limit.php
|
|
|
4043 |
$delayRunTimeExectionMax=config::delayRunTimeExectionMax($conf["config::delayRunTimeExectionMax"]);
|
|
|
4044 |
unset($conf["config::delayRunTimeExectionMax"]);
|
|
|
4045 |
|
|
|
4046 |
#如果執行失敗
|
|
|
4047 |
if($delayRunTimeExectionMax["status"]==="false"){
|
|
|
4048 |
|
|
|
4049 |
#設定類別圖繪製失敗
|
|
|
4050 |
$result["status"]="false";
|
|
|
4051 |
|
|
|
4052 |
#設定該檔案的類別圖繪製失敗提示
|
|
|
4053 |
$result["error"]=$delayRunTimeExectionMax;
|
|
|
4054 |
|
|
|
4055 |
#回傳結果
|
|
|
4056 |
return $result;
|
|
|
4057 |
|
|
|
4058 |
}#if end
|
|
|
4059 |
|
|
|
4060 |
}#for end
|
|
|
4061 |
|
|
|
4062 |
#函數說明:
|
|
|
4063 |
#延長php的執行時間,每呼叫一次會初始化執行時間爲0,然後設定下次可以執行多久.
|
|
|
4064 |
#回傳結果:
|
|
|
4065 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
4066 |
#$result["error"],錯誤訊息陣列.
|
|
|
4067 |
#$result["function"],當前執行的函數名稱.
|
|
|
4068 |
#必填參數:
|
|
|
4069 |
#$conf["sec"],整數,要延長多少執行時間,單位爲秒
|
|
|
4070 |
$conf["config::delayRunTimeExectionMax"]["sec"]=300;
|
|
|
4071 |
#參考資料:
|
|
|
4072 |
#http://php.net/manual/en/function.set-time-limit.php
|
|
|
4073 |
$delayRunTimeExectionMax=config::delayRunTimeExectionMax($conf["config::delayRunTimeExectionMax"]);
|
|
|
4074 |
unset($conf["config::delayRunTimeExectionMax"]);
|
|
|
4075 |
|
|
|
4076 |
#如果執行失敗
|
|
|
4077 |
if($delayRunTimeExectionMax["status"]==="false"){
|
|
|
4078 |
|
|
|
4079 |
#設定類別圖繪製失敗
|
|
|
4080 |
$result["status"]="false";
|
|
|
4081 |
|
|
|
4082 |
#設定該檔案的類別圖繪製失敗提示
|
|
|
4083 |
$result["error"]=$delayRunTimeExectionMax;
|
|
|
4084 |
|
|
|
4085 |
#回傳結果
|
|
|
4086 |
return $result;
|
|
|
4087 |
|
|
|
4088 |
}#if end
|
|
|
4089 |
|
|
|
4090 |
}#for end
|
|
|
4091 |
|
|
|
4092 |
#執行到這邊代表執行正常
|
|
|
4093 |
$result["status"]="true";
|
|
|
4094 |
|
|
|
4095 |
#回傳結果
|
|
|
4096 |
return $result;
|
|
|
4097 |
|
|
|
4098 |
}#function convertSampleToValidatedAddVersion end
|
|
|
4099 |
|
|
|
4100 |
/*
|
|
|
4101 |
#函式說明:
|
|
|
4102 |
#依據問卷資訊csv格式檔匯入問卷
|
|
|
4103 |
#回傳結果:
|
|
|
4104 |
#$result["status"],執行是否正確,"true"代表正確,"false"代表不正常.
|
|
|
4105 |
#$result["error"],錯誤訊息陣列.
|
|
|
4106 |
#$result["function"],在哪個函式出現錯誤的
|
|
|
4107 |
#$result["warning"].警告訊息陣列
|
|
|
4108 |
#必填參數:
|
|
|
4109 |
#$conf["questionnaireSetupCsvPath"],字串,記錄問卷資訊的csv檔案.
|
|
|
4110 |
$conf["questionnaireSetupCsvPath"]="";
|
|
|
4111 |
#$conf["dbAddress"],字串,問卷資料庫的網路位址.
|
|
|
4112 |
$conf["dbAddress"]=$dbAddress;
|
|
|
4113 |
#$conf["dbAccount"],字串,要連線到資料庫時所用的帳戶名稱.
|
|
|
4114 |
$conf["dbAccount"]=$dbAccount;
|
|
|
4115 |
#$conf["dbName"],字串,問卷相關資料所儲存的資料庫名稱.
|
|
|
4116 |
$conf["dbName"]=$dbName;
|
|
|
4117 |
#$argu,變數,參數陣列的名稱,記得前面要加&.
|
|
|
4118 |
$argu=&$conf;
|
|
|
4119 |
#可省略參數:
|
|
|
4120 |
#$conf["dbPassword"],字串,要連線到資料庫時所用的密碼.
|
|
|
4121 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
4122 |
#$conf["delFileAfterImport"],字串,若為"true"則代表要在匯入檔案完畢後,移除csv檔案。
|
|
|
4123 |
#$conf["delFileAfterImport"]="true";
|
|
|
4124 |
#$conf["questionnaireType.dtName"],字串,問卷資訊儲存在哪個資料表,預設為"questionnaireType".
|
|
|
4125 |
#$conf["questionnaireType.dtName"]="questionnaireType";
|
|
|
4126 |
#$conf["questionnaireType.typeNoColumnName"],字串,問卷編號的資料欄位名稱,預設為"typeNo".
|
|
|
4127 |
#$conf["questionnaireType.typeNoColumnName"]="typeNo";
|
|
|
4128 |
#$conf["questionnaireType.questionnaireTitleColumnName"],字串,問卷標題的資料欄位名稱,預設為"title".
|
|
|
4129 |
#$conf["questionnaireType.questionnaireTitleColumnName"]="title";
|
|
|
4130 |
#$conf["questionnaireType.questionnaireCommentColumnName"],字串,問卷註解的資料欄位名稱,預設為"comments".
|
|
|
4131 |
#$conf["questionnaireType.questionnaireCommentColumnName"]="comments";
|
|
|
4132 |
#$conf["questionnaireType.pointsColumnName"],字串,問卷量表的資料欄位名稱,預設為"points".
|
|
|
4133 |
#$conf["questionnaireType.pointsColumnName"]="points";
|
|
|
4134 |
#$conf["questionnaireType.startSurveyColumnName"],字串,問卷是否開始調查的資料欄位,預設為"startSurvey".
|
|
|
4135 |
#$conf["questionnaireType.startSurveyColumnName"]="startSurvey";
|
|
|
4136 |
#$conf["questionnaireTurnaroundTime.dtName"],字串,問卷查週期與期間的資料表名稱,預設為"questionnaireTurnaroundTime".
|
|
|
4137 |
#$conf["questionnaireTurnaroundTime.dtName"]="questionnaireTurnaroundTime";
|
|
|
4138 |
#$conf["questionnaireTurnaroundTime.turnaroundTimeColumnName"],字串,問卷調查週期的資料表欄位名稱,預設為"turnaroundTimeByDays".
|
|
|
4139 |
#$conf["questionnaireTurnaroundTime.turnaroundTimeColumnName"]="turnaroundTime";
|
|
|
4140 |
#$conf["questionnaireTurnaroundTime.durationTimeColumnName"],字串,問卷調查期間的資料表欄位名稱.
|
|
|
4141 |
#$conf["questionnaireTurnaroundTime.durationTimeColumnName"]="durationByDays";
|
|
|
4142 |
#$conf["questionnaireQuest.dtName"],字串,儲存問卷題項資料的資料表名稱
|
|
|
4143 |
#$conf["questionnaireQuest.dtName"]="questionnaireQuest";
|
|
|
4144 |
#$conf["questionnaireQuest.typeNoColumnName"],字串,問卷編號的資料欄位名稱,預設為"typeNo".
|
|
|
4145 |
#$conf["questionnaireQuest.typeNoColumnName"]="typeNo";
|
|
|
4146 |
#$conf["questionnaireQuest.questNoColumnName"],字串,題號資料欄位名稱,預設為"questNo".
|
|
|
4147 |
#$conf["questionnaireQuest.questNoColumnName"]="questNo";
|
|
|
4148 |
#$conf["questionnaireQuest.questTypeCodeColumnName"],字串,題型的資料欄位名稱,預設為"questTypeCode".
|
|
|
4149 |
#$conf["questionnaireQuest.questTypeCodeColumnName"]="questTypeCode";
|
|
|
4150 |
#$conf["questionnaireQuest.selectedQuestOptionMaxCountColumnName"],字串,題目選項的選擇上限的資料欄位名稱,預設為"selectedQuestOptionMaxCount".
|
|
|
4151 |
#$conf["questionnaireQuest.selectedQuestOptionMaxCountColumnName"]="selectedQuestOptionMaxCount";
|
|
|
4152 |
#$conf["questionnaireQuest.questContentColumnName"],字串,題目內容的資料欄位名稱,預設為"questContent".
|
|
|
4153 |
#$conf["questionnaireQuest.questContentColumnName"]="questContent";
|
|
|
4154 |
#$conf["questionnaireQuest.choiceValueColumnName"],字串,題目選項的資料欄位名稱,預設為"choiceValue".
|
|
|
4155 |
#$conf["questionnaireQuest.choiceValueColumnName"]="choiceValue";
|
|
|
4156 |
#$conf["questionnaireQuest.maxLengthColumnName"],字串,題目回答內容的最大長度限制的資料欄位名稱,預設為"maxLength".
|
|
|
4157 |
#$conf["questionnaireQuest.maxLengthColumnName"]="maxLength";
|
|
|
4158 |
#$conf["questionnaireQuest.nullColumnName"],字串,題目是否可以忽略的資料欄位名稱,預設為"null".
|
|
|
4159 |
#$conf["questionnaireQuest.nullColumnName"]="null";
|
|
|
4160 |
#$conf["questionnaireQuest.perspectiveColumnName"],字串,題目所屬構面的資料欄位名稱,預設為"perspective".
|
|
|
4161 |
#$conf["questionnaireQuest.perspectiveColumnName"]="perspective";
|
|
|
4162 |
#$conf["questionnaireQuest.indicatorColumnName"],字串,題目對應的指標的資料欄位名稱,預設為"indicator".
|
|
|
4163 |
#$conf["questionnaireQuest.indicatorColumnName"]="indicator";
|
|
|
4164 |
#參考資料:
|
|
|
4165 |
#無.
|
|
|
4166 |
#備註:
|
|
|
4167 |
#需要測試.須增加建立於特定時間自動執行問卷樣本ETL程序的程式
|
|
|
4168 |
*/
|
|
|
4169 |
public static function importQuestionnaire($conf,&$argu){
|
|
|
4170 |
|
|
|
4171 |
#初始化要回傳的結果
|
|
|
4172 |
$result=array();
|
|
|
4173 |
|
|
|
4174 |
#取得當前執行的函數名稱
|
|
|
4175 |
$result["function"]=__FUNCTION__;
|
|
|
4176 |
|
|
|
4177 |
#如果 $conf 不為陣列
|
|
|
4178 |
if(gettype($conf)!="array"){
|
|
|
4179 |
|
|
|
4180 |
#設置執行失敗
|
|
|
4181 |
$result["status"]="false";
|
|
|
4182 |
|
|
|
4183 |
#設置執行錯誤訊息
|
|
|
4184 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
4185 |
|
|
|
4186 |
#如果傳入的參數為 null
|
|
|
4187 |
if($conf==null){
|
|
|
4188 |
|
|
|
4189 |
#設置執行錯誤訊息
|
|
|
4190 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
4191 |
|
|
|
4192 |
}#if end
|
|
|
4193 |
|
|
|
4194 |
#回傳結果
|
|
|
4195 |
return $result;
|
|
|
4196 |
|
|
|
4197 |
}#if end
|
|
|
4198 |
|
|
|
4199 |
#檢查必填的參數
|
|
|
4200 |
#涵式說明:
|
|
|
4201 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
4202 |
#回傳的結果:
|
|
|
4203 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4204 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4205 |
#$result["function"],當前執行的函式名稱.
|
|
|
4206 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
4207 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
4208 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
4209 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
4210 |
#必填參數:
|
|
|
4211 |
$conf["variableCheck"]["isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
4212 |
$conf["variableCheck"]["isexistMulti"]["variableCheck"]=array("questionnaireSetupCsvPath","dbAddress","dbAccount","dbName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
4213 |
#可以省略的參數:
|
|
|
4214 |
$conf["variableCheck"]["isexistMulti"]["variableType"]=array("string","string","string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
|
|
4215 |
$conf["variableCheck"]["isexistMulti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
4216 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMulti"]);
|
|
|
4217 |
unset($conf["variableCheck"]);
|
|
|
4218 |
|
|
|
4219 |
#如果 $checkResult["status"] 等於 "false"
|
|
|
4220 |
if($checkResult["status"]=="false"){
|
|
|
4221 |
|
|
|
4222 |
#設置執行錯誤
|
|
|
4223 |
$result["status"]="false";
|
|
|
4224 |
|
|
|
4225 |
#設置錯誤訊息
|
|
|
4226 |
$result["error"]=$checkResult;
|
|
|
4227 |
|
|
|
4228 |
#回傳結果
|
|
|
4229 |
return $result;
|
|
|
4230 |
|
|
|
4231 |
}#if end
|
|
|
4232 |
|
|
|
4233 |
#如果 $checkResult["passed"] 等於 "false"
|
|
|
4234 |
if($checkResult["passed"]=="false"){
|
|
|
4235 |
|
|
|
4236 |
#設置執行錯誤
|
|
|
4237 |
$result["status"]="false";
|
|
|
4238 |
|
|
|
4239 |
#設置錯誤訊息
|
|
|
4240 |
$result["error"]=$checkResult;
|
|
|
4241 |
|
|
|
4242 |
#回傳結果
|
|
|
4243 |
return $result;
|
|
|
4244 |
|
|
|
4245 |
}#if end
|
|
|
4246 |
|
|
|
4247 |
#檢查可省略的參數
|
|
|
4248 |
#函式說明:
|
|
|
4249 |
#檢查一包含數個可省略變數的陣列變數,其型態是否正確
|
|
|
4250 |
#回傳的結果:
|
|
|
4251 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4252 |
#$result["error"],錯誤訊息陣列.
|
|
|
4253 |
#$result["function"],當前執行的函式名稱.
|
|
|
4254 |
#$result["passed"],參數是否都通過檢查,"true",代表有通過檢查,"false"代表沒有通過檢查.
|
|
|
4255 |
#必填參數:
|
|
|
4256 |
#$conf["variableCheck"]["checkSkipableVarType"]["checkedVar"],陣列,要檢查的變數陣列名稱為?
|
|
|
4257 |
$conf["variableCheck"]["checkSkipableVarType"]["checkedVar"]=$conf;
|
|
|
4258 |
|
|
|
4259 |
#$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarNameArray"],字串陣列,要檢查型態是否設定正確的變數名稱陣列.
|
|
|
4260 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarNameArray"][]="dbPassword";
|
|
|
4261 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarNameArray"][]="delFileAfterImport";
|
|
|
4262 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireType.dtName";
|
|
|
4263 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireType.typeNoColumnName";
|
|
|
4264 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireType.questionnaireTitleColumnName";
|
|
|
4265 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireType.questionnaireCommentColumnName";
|
|
|
4266 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireType.pointsColumnName";
|
|
|
4267 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireType.startSurveyColumnName";
|
|
|
4268 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireTurnaroundTime.dtName";
|
|
|
4269 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireTurnaroundTime.turnaroundTimeColumnName";
|
|
|
4270 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireTurnaroundTime.durationTimeColumnName";
|
|
|
4271 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireQuest.dtName";
|
|
|
4272 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireQuest.typeNoColumnName";
|
|
|
4273 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireQuest.questNoColumnName";
|
|
|
4274 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireQuest.questTypeCodeColumnName";
|
|
|
4275 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireQuest.selectedQuestOptionMaxCountColumnName";
|
|
|
4276 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireQuest.questContentColumnName";
|
|
|
4277 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireQuest.choiceValueColumnName";
|
|
|
4278 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireQuest.maxLengthColumnName";
|
|
|
4279 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireQuest.nullColumnName";
|
|
|
4280 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireQuest.perspectiveColumnName";
|
|
|
4281 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarNameArray"][]="questionnaireQuest.indicatorColumnName";
|
|
|
4282 |
|
|
|
4283 |
#$conf["variableCheck"]["checkSkipableVarType"]["skipableVarTypeArray"],字串陣列,要檢查的每個變數,其型態應該要為何?
|
|
|
4284 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
4285 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
4286 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
4287 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
4288 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
4289 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
4290 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
4291 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
4292 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarTypeArray"][]="string";
|
|
|
4293 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarTypeArray"][]="string";
|
|
|
4294 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarTypeArray"][]="string";
|
|
|
4295 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarTypeArray"][]="string";
|
|
|
4296 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarTypeArray"][]="string";
|
|
|
4297 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarTypeArray"][]="string";
|
|
|
4298 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarTypeArray"][]="string";
|
|
|
4299 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarTypeArray"][]="string";
|
|
|
4300 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarTypeArray"][]="string";
|
|
|
4301 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarTypeArray"][]="string";
|
|
|
4302 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarTypeArray"][]="string";
|
|
|
4303 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarTypeArray"][]="string";
|
|
|
4304 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarTypeArray"][]="string";
|
|
|
4305 |
$conf["variableCheck"]["checkSkipableVarType"]["sikpableVarTypeArray"][]="string";
|
|
|
4306 |
|
|
|
4307 |
#$argu,要直接存取的陣列變數名稱,變數前面加上「&」.
|
|
|
4308 |
#$argu=&$argu;
|
|
|
4309 |
#可省略參數:
|
|
|
4310 |
|
|
|
4311 |
#$conf["variableCheck"]["checkSkipableVarType"]["skipableVarDefaultValue"],字串陣列,每個不存的變數要初始化為什麼,"null"代表不指定.
|
|
|
4312 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarDefaultValue"][]="null";
|
|
|
4313 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarDefaultValue"][]="null";
|
|
|
4314 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarDefaultValue"][]="questionnaireType";
|
|
|
4315 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarDefaultValue"][]="typeNo";
|
|
|
4316 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarDefaultValue"][]="title";
|
|
|
4317 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarDefaultValue"][]="comments";
|
|
|
4318 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarDefaultValue"][]="points";
|
|
|
4319 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarDefaultValue"][]="startSurvey";
|
|
|
4320 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarDefaultValue"][]="questionnaireTurnaroundTime";
|
|
|
4321 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarDefaultValue"][]="turnaroundTime";
|
|
|
4322 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarDefaultValue"][]="durationByDays";
|
|
|
4323 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarDefaultValue"][]="questionnaireQuest";
|
|
|
4324 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarDefaultValue"][]="typeNo";
|
|
|
4325 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarDefaultValue"][]="questNo";
|
|
|
4326 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarDefaultValue"][]="questTypeCode";
|
|
|
4327 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarDefaultValue"][]="selectedQuestOptionMaxCount";
|
|
|
4328 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarDefaultValue"][]="questContent";
|
|
|
4329 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarDefaultValue"][]="choiceValue";
|
|
|
4330 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarDefaultValue"][]="maxLength";
|
|
|
4331 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarDefaultValue"][]="null";
|
|
|
4332 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarDefaultValue"][]="perspective";
|
|
|
4333 |
$conf["variableCheck"]["checkSkipableVarType"]["skipableVarDefaultValue"][]="indicator";
|
|
|
4334 |
|
|
|
4335 |
$checkResult=variableCheck::checkSkipableVarType($conf["variableCheck"]["checkSkipableVarType"],$argu);
|
|
|
4336 |
unset($conf["variableCheck"]);
|
|
|
4337 |
|
|
|
4338 |
#置換$conf為更新好的$argu
|
|
|
4339 |
$conf=$argu;
|
|
|
4340 |
|
|
|
4341 |
#如果 $checkResult["status"] 等於 "false"
|
|
|
4342 |
if($checkResult["status"]=="false"){
|
|
|
4343 |
|
|
|
4344 |
#設置執行錯誤
|
|
|
4345 |
$result["status"]="false";
|
|
|
4346 |
|
|
|
4347 |
#設置錯誤訊息
|
|
|
4348 |
$result["error"]=$checkResult;
|
|
|
4349 |
|
|
|
4350 |
#回傳結果
|
|
|
4351 |
return $result;
|
|
|
4352 |
|
|
|
4353 |
}#if end
|
|
|
4354 |
|
|
|
4355 |
#如果 $checkResult["passed"] 等於 "false"
|
|
|
4356 |
if($checkResult["passed"]=="false"){
|
|
|
4357 |
|
|
|
4358 |
#設置執行錯誤
|
|
|
4359 |
$result["status"]="false";
|
|
|
4360 |
|
|
|
4361 |
#設置錯誤訊息
|
|
|
4362 |
$result["error"]=$checkResult;
|
|
|
4363 |
|
|
|
4364 |
#回傳結果
|
|
|
4365 |
return $result;
|
|
|
4366 |
|
|
|
4367 |
}#if end
|
|
|
4368 |
|
|
|
4369 |
#讀取檔案的內容
|
|
|
4370 |
#涵式說明:
|
|
|
4371 |
#讀取csv檔案的內容
|
|
|
4372 |
#回傳得結果:
|
|
|
4373 |
#$result["status"],執行是否正常,"true"代表正常;"false"代表不正常.
|
|
|
4374 |
#$result["error"],錯誤訊息陣列.
|
|
|
4375 |
#$result["csvFileContent"],csv檔案內容的陣列
|
|
|
4376 |
#$result["csvFileContent"]["$i"]["$j"]代表第$i+1列第$j+1欄位的內容.
|
|
|
4377 |
#如果 $conf["firstLineVarName"]爲"true"的話則會回傳 $result["csvFileContent"]["第幾列"]["第一列各個欄位的名稱"]
|
|
|
4378 |
#$result["lineArray"],csv檔案逐列內容的陣列.
|
|
|
4379 |
#$result["lineArrayCount"],總共幾列資料
|
|
|
4380 |
#必填參數:
|
|
|
4381 |
$conf["csv"]["loadCsvFile"]["csvFilePositionAndName"]=$conf["questionnaireSetupCsvPath"];#csv檔案的位置
|
|
|
4382 |
#可省略參數:
|
|
|
4383 |
#$conf["firstLineVarName"]="true";#第一行是否爲變數名稱(各個欄位的名稱)
|
|
|
4384 |
#參考資料來源:
|
|
|
4385 |
#http://www.php.net/manual/en/function.str-split.php
|
|
|
4386 |
#參考資料來源
|
|
|
4387 |
#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)
|
|
|
4388 |
$csvFileContent=csv::loadCsvFile($conf["csv"]["loadCsvFile"]);
|
|
|
4389 |
unset($conf["csv"]);
|
|
|
4390 |
|
|
|
4391 |
#如果讀取csv檔案失敗
|
|
|
4392 |
if($csvFileContent["status"]=="false"){
|
|
|
4393 |
|
|
|
4394 |
#設置執行錯誤
|
|
|
4395 |
$result["status"]="false";
|
|
|
4396 |
|
|
|
4397 |
#設置錯誤訊息
|
|
|
4398 |
$result["error"]=$csvFileContent;
|
|
|
4399 |
|
|
|
4400 |
#回傳結果
|
|
|
4401 |
return $result;
|
|
|
4402 |
|
|
|
4403 |
}#if end
|
|
|
4404 |
|
|
|
4405 |
#var_dump($csvFileContent);
|
|
|
4406 |
|
|
|
4407 |
#搜尋可用的問卷編號
|
|
|
4408 |
#涵式說明:
|
|
|
4409 |
#尋找特定資料庫裏特定資料表裏面特定欄位有無可用整數編號,可以指定數字的起點與終點,此函式會回傳可用的編號。
|
|
|
4410 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4411 |
#$result["error"],錯誤訊息陣列
|
|
|
4412 |
#$result["function"],當前執行的函數.
|
|
|
4413 |
#$result["founded"],爲搜尋可以用的數字是否成功,"true"表示成功,"false"表示失敗.
|
|
|
4414 |
#$result["usableNumber"],爲可用的整數。
|
|
|
4415 |
#$result["sql"],執行的sql語法.
|
|
|
4416 |
#必填參數
|
|
|
4417 |
$conf["db"]["findUsableNumber"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
4418 |
$conf["db"]["findUsableNumber"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
4419 |
$conf["db"]["findUsableNumber"]["selectedDataBaseName"]=$conf["dbName"];#爲要檢查的資料庫名稱
|
|
|
4420 |
$conf["db"]["findUsableNumber"]["checkDataTableName"]=$conf["questionnaireType.dtName"];#爲要檢查的資料表名稱
|
|
|
4421 |
$conf["db"]["findUsableNumber"]["conditionTargetName"]=$conf["questionnaireType.typeNoColumnName"];#用來判斷的資料表數值名稱
|
|
|
4422 |
$conf["db"]["findUsableNumber"]["startPoint"]="1";#要執行的迴圈起點(資料的起始檢查點),須爲int
|
|
|
4423 |
$conf["db"]["findUsableNumber"]["endPoint"]="99999";#要執行的迴圈終點(資料的結束檢查點),須爲int
|
|
|
4424 |
#可省略參數
|
|
|
4425 |
|
|
|
4426 |
#如果 $conf["dbPassword"] 有設定
|
|
|
4427 |
if(isset($conf["dbPassword"])){
|
|
|
4428 |
|
|
|
4429 |
#設置連線用的密碼
|
|
|
4430 |
$conf["db"]["findUsableNumber"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
4431 |
|
|
|
4432 |
}#if end
|
|
|
4433 |
|
|
|
4434 |
#$conf["otherConditionTargetName"]=array();#查詢欄位項目可用數值的其它條件欄位名稱,爲陣列值。
|
|
|
4435 |
#須搭配 $conf["otherConditionTargetValue"] 一起使用
|
|
|
4436 |
#$conf["otherConditionTargetValue"]=array();#查詢欄位項目可用數值的其它條件欄位數值,爲陣列值。
|
|
|
4437 |
#須搭配 $conf["otherConditionTargetName"] 一起使用
|
|
|
4438 |
$questionnaireType=db::findUsableNumber($conf["db"]["findUsableNumber"]);
|
|
|
4439 |
unset($conf["db"]["findUsableNumber"]);
|
|
|
4440 |
|
|
|
4441 |
#如果取得可用問卷編號失敗
|
|
|
4442 |
if($questionnaireType["status"]=="false"){
|
|
|
4443 |
|
|
|
4444 |
#設置執行錯誤
|
|
|
4445 |
$result["status"]="false";
|
|
|
4446 |
|
|
|
4447 |
#設置錯誤訊息
|
|
|
4448 |
$result["error"]=$questionnaireType;
|
|
|
4449 |
|
|
|
4450 |
#回傳結果
|
|
|
4451 |
return $result;
|
|
|
4452 |
|
|
|
4453 |
}#if end
|
|
|
4454 |
|
|
|
4455 |
#如果沒有可用的問卷編號
|
|
|
4456 |
if($questionnaireType["founded"]=="false"){
|
|
|
4457 |
|
|
|
4458 |
#設置執行錯誤
|
|
|
4459 |
$result["status"]="false";
|
|
|
4460 |
|
|
|
4461 |
#設置錯誤訊息
|
|
|
4462 |
$result["error"]=$questionnaireType;
|
|
|
4463 |
|
|
|
4464 |
#回傳結果
|
|
|
4465 |
return $result;
|
|
|
4466 |
|
|
|
4467 |
}#if end
|
|
|
4468 |
|
|
|
4469 |
#根據問卷名稱、描述、幾點量表來建立問卷
|
|
|
4470 |
#涵式說明:
|
|
|
4471 |
#插入資料到指定的資料表裡面,插入資料完畢可以選擇是否要進行轉址。
|
|
|
4472 |
#回傳的數值:
|
|
|
4473 |
#$result["connectInformation"],爲連線到該mysql-server的資訊。
|
|
|
4474 |
#$result["connectStatus"],爲查詢是否成功,若爲0則成功,若爲1則表示失敗了
|
|
|
4475 |
#$result["error"],錯誤訊息
|
|
|
4476 |
#必填參數:
|
|
|
4477 |
$conf["db"]["insertData"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
4478 |
$conf["db"]["insertData"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
4479 |
$conf["db"]["insertData"]["selectedDataBaseName"]=$conf["dbName"];#要選取的資料庫名稱
|
|
|
4480 |
$conf["db"]["insertData"]["tableName"]=$conf["questionnaireType.dtName"];#爲要插入資料的資料表名稱
|
|
|
4481 |
|
|
|
4482 |
#串連需要寫入的問卷欄位
|
|
|
4483 |
#爲資料表的項目名稱,
|
|
|
4484 |
#例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);
|
|
|
4485 |
$conf["db"]["insertData"]["columnName"][]=$conf["questionnaireType.typeNoColumnName"];
|
|
|
4486 |
$conf["db"]["insertData"]["columnName"][]=$conf["questionnaireType.questionnaireTitleColumnName"];
|
|
|
4487 |
$conf["db"]["insertData"]["columnName"][]=$conf["questionnaireType.questionnaireCommentColumnName"];
|
|
|
4488 |
$conf["db"]["insertData"]["columnName"][]=$conf["questionnaireType.pointsColumnName"];
|
|
|
4489 |
$conf["db"]["insertData"]["columnName"][]=$conf["questionnaireType.startSurveyColumnName"];
|
|
|
4490 |
|
|
|
4491 |
#爲要插入度數值
|
|
|
4492 |
#例如:$conf["insertValue"]=array("insertValue1","insertValue2","insertValue3",...);
|
|
|
4493 |
#$conf["db"]["insertData"]["insertValue"]=array(,,,);
|
|
|
4494 |
$conf["db"]["insertData"]["insertValue"][]=$questionnaireType["usableNumber"];
|
|
|
4495 |
$conf["db"]["insertData"]["insertValue"][]=$csvFileContent["csvFileContent"][0][0];
|
|
|
4496 |
$conf["db"]["insertData"]["insertValue"][]=$csvFileContent["csvFileContent"][0][1];
|
|
|
4497 |
$conf["db"]["insertData"]["insertValue"][]=$csvFileContent["csvFileContent"][0][2];
|
|
|
4498 |
$conf["db"]["insertData"]["insertValue"][]=$csvFileContent["csvFileContent"][0][7];
|
|
|
4499 |
|
|
|
4500 |
#可以省略的變數:
|
|
|
4501 |
$conf["db"]["insertData"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
4502 |
$insertQuesttionaireBasicDataResult=db::insertData($conf["db"]["insertData"]);
|
|
|
4503 |
unset($conf["db"]["insertData"]);
|
|
|
4504 |
|
|
|
4505 |
#如果 $insertQuesttionaireBasicDataResult["status"] 等於 "false"
|
|
|
4506 |
if($insertQuesttionaireBasicDataResult["status"]=="false"){
|
|
|
4507 |
|
|
|
4508 |
#設置執行錯誤
|
|
|
4509 |
$result["status"]="false";
|
|
|
4510 |
|
|
|
4511 |
#設置錯誤訊息
|
|
|
4512 |
$result["error"]=$insertQuesttionaireBasicDataResult;
|
|
|
4513 |
|
|
|
4514 |
#回傳結果
|
|
|
4515 |
return $result;
|
|
|
4516 |
|
|
|
4517 |
}#if end
|
|
|
4518 |
|
|
|
4519 |
#根據問卷調查週期來補充資料
|
|
|
4520 |
#涵式說明:
|
|
|
4521 |
#插入資料到指定的資料表裡面,插入資料完畢可以選擇是否要進行轉址。
|
|
|
4522 |
#回傳的數值:
|
|
|
4523 |
#$result["status"],爲查詢是否成功,若爲"true"則成功,若爲"false"則表示失敗了.
|
|
|
4524 |
#$result["error"],錯誤訊息.
|
|
|
4525 |
#$result["sql"],執行的sql語法.
|
|
|
4526 |
#必填參數:
|
|
|
4527 |
$conf["db"]["insertData"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
4528 |
$conf["db"]["insertData"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
4529 |
$conf["db"]["insertData"]["selectedDataBaseName"]=$conf["dbName"];#要選取的資料庫名稱
|
|
|
4530 |
$conf["db"]["insertData"]["tableName"]=$conf["questionnaireTurnaroundTime.dtName"];#爲要插入資料的資料表名稱
|
|
|
4531 |
|
|
|
4532 |
#爲資料表的項目名稱,
|
|
|
4533 |
#例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);
|
|
|
4534 |
$conf["db"]["insertData"]["columnName"]=array("questionnaireTypeNo","turnaroundTime","durationByDays","startNumberOfMonth","startNumberOfDay");
|
|
|
4535 |
|
|
|
4536 |
$conf["db"]["insertData"]["insertValue"]=array($questionnaireType["usableNumber"],$csvFileContent["csvFileContent"][0][3],$csvFileContent["csvFileContent"][0][4],$csvFileContent["csvFileContent"][0][5],$csvFileContent["csvFileContent"][0][6]);#爲要插入度數值,
|
|
|
4537 |
#例如:$conf["insertValue"]=array("insertValue1","insertValue2","insertValue3",...);
|
|
|
4538 |
|
|
|
4539 |
#可以省略的變數:
|
|
|
4540 |
$conf["db"]["insertData"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
4541 |
$db["insertData"]=db::insertData($conf["db"]["insertData"]);
|
|
|
4542 |
unset($conf["db"]["insertData"]);
|
|
|
4543 |
|
|
|
4544 |
#如果 $db["insertData"]["status"] 等於 "false"
|
|
|
4545 |
if($db["insertData"]["status"]=="false"){
|
|
|
4546 |
|
|
|
4547 |
#設置執行錯誤
|
|
|
4548 |
$result["status"]="false";
|
|
|
4549 |
|
|
|
4550 |
#設置錯誤訊息
|
|
|
4551 |
$result["error"]=$db["insertData"];
|
|
|
4552 |
|
|
|
4553 |
#回傳結果
|
|
|
4554 |
return $result;
|
|
|
4555 |
|
|
|
4556 |
}#if end
|
|
|
4557 |
|
|
|
4558 |
#有幾個構面就執行幾次
|
|
|
4559 |
for($i=0;$i<count($csvFileContent["csvFileContent"][1]);$i++){
|
|
|
4560 |
|
|
|
4561 |
#如果讀到的構面是空白的就跳出迴圈
|
|
|
4562 |
if($csvFileContent["csvFileContent"][1][$i]=="" || $csvFileContent["csvFileContent"][1][$i]=="�"){
|
|
|
4563 |
|
|
|
4564 |
#跳出迴圈
|
|
|
4565 |
break;
|
|
|
4566 |
|
|
|
4567 |
}#if end
|
|
|
4568 |
|
|
|
4569 |
#要先檢查目標構面是否已存在,若存在則不用插入該構面.
|
|
|
4570 |
#函式說明:
|
|
|
4571 |
#檢查資料庫裏的資料表有無指定條件的資料
|
|
|
4572 |
#回傳的結果:
|
|
|
4573 |
#$result["status"],執行是否成功,成功為"true",失敗為"false"。
|
|
|
4574 |
#$result["error"],錯誤訊息
|
|
|
4575 |
#$result["founded"],是否找到資料,"true"代表有符合的資料;"false"代表沒有符合的資料.
|
|
|
4576 |
#$result["sql"],執行的sql字串.
|
|
|
4577 |
#必填參數:
|
|
|
4578 |
$conf["db"]["checkDataExists"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
4579 |
$conf["db"]["checkDataExists"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
4580 |
$conf["db"]["checkDataExists"]["selectedDataBaseName"]=$conf["dbName"];#爲指定的資料庫名稱,欲選擇的資料庫名稱
|
|
|
4581 |
$conf["db"]["checkDataExists"]["selectedDataTableName"]="perspective";#欲選擇的資料表名稱
|
|
|
4582 |
#可省略參數:
|
|
|
4583 |
$conf["db"]["checkDataExists"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
4584 |
$conf["db"]["checkDataExists"]["conditionTargetName"]=array("name");#用來判斷的資料表數值名稱,需爲陣列,可省略
|
|
|
4585 |
$conf["db"]["checkDataExists"]["conditionTargetValue"]=array($csvFileContent["csvFileContent"][1][$i]);#用來判斷的資料表數值名稱若等於該數值,表示條件成立,需爲陣列,可省略
|
|
|
4586 |
$checkDataBaseExists=db::checkDataExists($conf["db"]["checkDataExists"]);
|
|
|
4587 |
unset($conf["db"]["checkDataExists"]);
|
|
|
4588 |
|
|
|
4589 |
#var_dump($checkDataBaseExists);
|
|
|
4590 |
|
|
|
4591 |
#如果 $checkDataBaseExists["status"] 等於 "false"
|
|
|
4592 |
if($checkDataBaseExists["status"]=="false"){
|
|
|
4593 |
|
|
|
4594 |
#設置執行錯誤
|
|
|
4595 |
$result["status"]="false";
|
|
|
4596 |
|
|
|
4597 |
#設置錯誤訊息
|
|
|
4598 |
$result["error"]=$checkDataBaseExists;
|
|
|
4599 |
|
|
|
4600 |
#回傳結果
|
|
|
4601 |
return $result;
|
|
|
4602 |
|
|
|
4603 |
}#if end
|
|
|
4604 |
|
|
|
4605 |
#如果 $checkDataBaseExists["founded"] 等於 "true"
|
|
|
4606 |
if($checkDataBaseExists["founded"]=="true"){
|
|
|
4607 |
|
|
|
4608 |
#跳過該次迴圈
|
|
|
4609 |
continue;
|
|
|
4610 |
|
|
|
4611 |
}#if end
|
|
|
4612 |
|
|
|
4613 |
#涵式說明:
|
|
|
4614 |
#插入資料到指定的資料表裡面,插入資料完畢可以選擇是否要進行轉址。
|
|
|
4615 |
#回傳的數值:
|
|
|
4616 |
#$result["status"],爲查詢是否成功,若爲"true"則成功,若爲"false"則表示失敗了.
|
|
|
4617 |
#$result["error"],錯誤訊息.
|
|
|
4618 |
#$result["sql"],執行的sql語法.
|
|
|
4619 |
#必填參數:
|
|
|
4620 |
$conf["db"]["insertData"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
4621 |
$conf["db"]["insertData"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
4622 |
$conf["db"]["insertData"]["selectedDataBaseName"]=$conf["dbName"];#要選取的資料庫名稱
|
|
|
4623 |
$conf["db"]["insertData"]["tableName"]="perspective";#爲要插入資料的資料表名稱
|
|
|
4624 |
$conf["db"]["insertData"]["columnName"]=array("name","description");#爲資料表的項目名稱,
|
|
|
4625 |
#例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);
|
|
|
4626 |
$conf["db"]["insertData"]["insertValue"]=array($csvFileContent["csvFileContent"][1][$i],$csvFileContent["csvFileContent"][2][$i]);#爲要插入度數值,
|
|
|
4627 |
#例如:$conf["insertValue"]=array("insertValue1","insertValue2","insertValue3",...);
|
|
|
4628 |
#可以省略的變數:
|
|
|
4629 |
$conf["db"]["insertData"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
4630 |
$db["insertData"]=db::insertData($conf["db"]["insertData"]);
|
|
|
4631 |
unset($conf["db"]["insertData"]);
|
|
|
4632 |
|
|
|
4633 |
#如果$db["insertData"]["status"]等於"false"
|
|
|
4634 |
if($db["insertData"]["status"]=="false"){
|
|
|
4635 |
|
|
|
4636 |
#設置執行錯誤
|
|
|
4637 |
$result["status"]="false";
|
|
|
4638 |
|
|
|
4639 |
#設置錯誤訊息
|
|
|
4640 |
$result["error"]=$db["insertData"];
|
|
|
4641 |
|
|
|
4642 |
#回傳結果
|
|
|
4643 |
return $result;
|
|
|
4644 |
|
|
|
4645 |
}#if end
|
|
|
4646 |
|
|
|
4647 |
}#for end
|
|
|
4648 |
|
|
|
4649 |
#根據每個 $csvFileContent["csvFileContent"] 的數量,從 $csvFileContent["csvFileContent"][4] 開始建立每一題的題目、描述、題型、選項、必填或可省略、指標等欄位資料。
|
|
|
4650 |
for($i=4;$i<count($csvFileContent["csvFileContent"]);$i++){
|
|
|
4651 |
|
|
|
4652 |
#檢查是否有完全相同的題目
|
|
|
4653 |
#函式說明:
|
|
|
4654 |
#檢查資料庫裏的資料表有無指定條件的資料
|
|
|
4655 |
#回傳的結果:
|
|
|
4656 |
#$result["status"],執行是否成功,成功為"true",失敗為"false"。
|
|
|
4657 |
#$result["error"],錯誤訊息
|
|
|
4658 |
#$result["founded"],是否找到資料,"true"代表有符合的資料;"false"代表沒有符合的資料.
|
|
|
4659 |
#$result["sql"],執行的sql字串.
|
|
|
4660 |
#必填參數:
|
|
|
4661 |
$conf["db"]["checkDataExists"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
4662 |
$conf["db"]["checkDataExists"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
4663 |
$conf["db"]["checkDataExists"]["selectedDataBaseName"]=$conf["dbName"];#爲指定的資料庫名稱,欲選擇的資料庫名稱
|
|
|
4664 |
$conf["db"]["checkDataExists"]["selectedDataTableName"]="questionnaireQuest";#欲選擇的資料表名稱
|
|
|
4665 |
#可省略參數:
|
|
|
4666 |
$conf["db"]["checkDataExists"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
4667 |
$conf["db"]["checkDataExists"]["conditionTargetName"]=array("typeNo","questContent","questTypeCode","selectedQuestOptionMaxCount","choiceValue","null","perspective");#用來判斷的資料表數值名稱,需爲陣列,可省略
|
|
|
4668 |
$conf["db"]["checkDataExists"]["conditionTargetValue"]=array($questionnaireType["usableNumber"],$csvFileContent["csvFileContent"][$i][0],$csvFileContent["csvFileContent"][$i][1],$csvFileContent["csvFileContent"][$i][2],$csvFileContent["csvFileContent"][$i][3],$csvFileContent["csvFileContent"][$i][4],$csvFileContent["csvFileContent"][$i][5]);#用來判斷的資料表數值名稱若等於該數值,表示條件成立,需爲陣列,可省略
|
|
|
4669 |
$checkDataBaseExists=db::checkDataExists($conf["db"]["checkDataExists"]);
|
|
|
4670 |
unset($conf["db"]["checkDataExists"]);
|
|
|
4671 |
|
|
|
4672 |
#如果 $checkDataBaseExists 等於 "false"
|
|
|
4673 |
if($checkDataBaseExists["status"]=="false"){
|
|
|
4674 |
|
|
|
4675 |
#設置執行錯誤
|
|
|
4676 |
$result["status"]="false";
|
|
|
4677 |
|
|
|
4678 |
#設置錯誤訊息
|
|
|
4679 |
$result["error"]=$checkDataBaseExists;
|
|
|
4680 |
|
|
|
4681 |
#回傳結果
|
|
|
4682 |
return $result;
|
|
|
4683 |
|
|
|
4684 |
}#if end
|
|
|
4685 |
|
|
|
4686 |
#如果 $checkDataBaseExists["founded"] 等於 "true"
|
|
|
4687 |
if($checkDataBaseExists["founded"]=="true"){
|
|
|
4688 |
|
|
|
4689 |
#跳過該次迴圈
|
|
|
4690 |
continue;
|
|
|
4691 |
|
|
|
4692 |
}#if end
|
|
|
4693 |
|
|
|
4694 |
#var_dump($questionnaireType["usableNumber"]);
|
|
|
4695 |
|
|
|
4696 |
#尋找可用的題號
|
|
|
4697 |
#涵式說明:
|
|
|
4698 |
#尋找特定資料庫裏特定資料表裏面特定欄位有無可用整數編號,可以指定數字的起點與終點,此函式會回傳可用的編號。
|
|
|
4699 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4700 |
#$result["error"],錯誤訊息陣列
|
|
|
4701 |
#$result["founded"],爲搜尋可以用的數字是否成功,"true"表示成功,"false"表示失敗.
|
|
|
4702 |
#$result["usableNumber"],爲可用的整數。
|
|
|
4703 |
#$result["sql"],執行的sql語法.
|
|
|
4704 |
#必填參數
|
|
|
4705 |
$conf["db"]["findUsableNumber"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
4706 |
$conf["db"]["findUsableNumber"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
4707 |
$conf["db"]["findUsableNumber"]["selectedDataBaseName"]=$conf["dbName"];#爲要檢查的資料庫名稱
|
|
|
4708 |
$conf["db"]["findUsableNumber"]["checkDataTableName"]="questionnaireQuest";#爲要檢查的資料表名稱
|
|
|
4709 |
$conf["db"]["findUsableNumber"]["conditionTargetName"]="questNo";#用來判斷的資料表數值名稱
|
|
|
4710 |
$conf["db"]["findUsableNumber"]["startPoint"]="1";#要執行的迴圈起點(資料的起始檢查點)
|
|
|
4711 |
$conf["db"]["findUsableNumber"]["endPoint"]="9999";#要執行的迴圈終點(資料的結束檢查點)
|
|
|
4712 |
#可省略參數
|
|
|
4713 |
$conf["db"]["findUsableNumber"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
4714 |
$conf["db"]["findUsableNumber"]["otherConditionTargetName"]=array("typeNo");#查詢欄位項目可用數值的其它條件欄位名稱,爲陣列值。
|
|
|
4715 |
#須搭配 $conf["otherConditionTargetValue"] 一起使用
|
|
|
4716 |
$conf["db"]["findUsableNumber"]["otherConditionTargetValue"]=array($questionnaireType["usableNumber"]);#查詢欄位項目可用數值的其它條件欄位數值,爲陣列值。
|
|
|
4717 |
#須搭配 $conf["otherConditionTargetName"] 一起使用
|
|
|
4718 |
$questFindUsableNumber=db::findUsableNumber($conf["db"]["findUsableNumber"]);
|
|
|
4719 |
unset($conf["db"]["findUsableNumber"]);
|
|
|
4720 |
|
|
|
4721 |
#如果 $questFindUsableNumber["status"]等於"false"
|
|
|
4722 |
if($questFindUsableNumber["status"]=="false"){
|
|
|
4723 |
|
|
|
4724 |
#設置執行錯誤
|
|
|
4725 |
$result["status"]="false";
|
|
|
4726 |
|
|
|
4727 |
#設置錯誤訊息
|
|
|
4728 |
$result["error"]=$checkDataBaseExists;
|
|
|
4729 |
|
|
|
4730 |
#回傳結果
|
|
|
4731 |
return $result;
|
|
|
4732 |
|
|
|
4733 |
}#if end
|
|
|
4734 |
|
|
|
4735 |
if($questFindUsableNumber["founded"]=="false"){
|
|
|
4736 |
|
|
|
4737 |
#設置執行錯誤
|
|
|
4738 |
$result["status"]="false";
|
|
|
4739 |
|
|
|
4740 |
#設置錯誤訊息
|
|
|
4741 |
$result["error"][]="儲存題號的資料表其資料筆數已達上限!";
|
|
|
4742 |
|
|
|
4743 |
#回傳結果
|
|
|
4744 |
return $result;
|
|
|
4745 |
|
|
|
4746 |
}#if end
|
|
|
4747 |
|
|
|
4748 |
#涵式說明:
|
|
|
4749 |
#插入資料到指定的資料表裡面,插入資料完畢可以選擇是否要進行轉址。
|
|
|
4750 |
#回傳的數值:
|
|
|
4751 |
#$result["connectInformation"],爲連線到該mysql-server的資訊。
|
|
|
4752 |
#$result["connectStatus"],爲查詢是否成功,若爲0則成功,若爲1則表示失敗了
|
|
|
4753 |
#$result["error"],錯誤訊息
|
|
|
4754 |
#必填參數:
|
|
|
4755 |
$conf["db"]["insertData"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
4756 |
$conf["db"]["insertData"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
4757 |
$conf["db"]["insertData"]["selectedDataBaseName"]=$conf["dbName"];#要選取的資料庫名稱
|
|
|
4758 |
$conf["db"]["insertData"]["tableName"]="questionnaireQuest";#爲要插入資料的資料表名稱
|
|
|
4759 |
$conf["db"]["insertData"]["columnName"]=array("typeNo","questNo","questContent","questTypeCode","selectedQuestOptionMaxCount","choiceValue","null","perspective","indicator");#爲資料表的項目名稱,
|
|
|
4760 |
#例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);
|
|
|
4761 |
$conf["db"]["insertData"]["insertValue"]=array($questionnaireType["usableNumber"],$questFindUsableNumber["usableNumber"],$csvFileContent["csvFileContent"][$i][0],$csvFileContent["csvFileContent"][$i][1],$csvFileContent["csvFileContent"][$i][2],$csvFileContent["csvFileContent"][$i][3],$csvFileContent["csvFileContent"][$i][4],$csvFileContent["csvFileContent"][$i][5],$csvFileContent["csvFileContent"][$i][6]);#爲要插入度數值,
|
|
|
4762 |
#例如:$conf["insertValue"]=array("insertValue1","insertValue2","insertValue3",...);
|
|
|
4763 |
#可以省略的變數:
|
|
|
4764 |
$conf["db"]["insertData"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
4765 |
$db["insertData"]=db::insertData($conf["db"]["insertData"]);
|
|
|
4766 |
unset($conf["db"]["insertData"]);
|
|
|
4767 |
|
|
|
4768 |
#如果 $db["insertData"]["status"] 等於 "false"
|
|
|
4769 |
if($db["insertData"]["status"]=="false"){
|
|
|
4770 |
|
|
|
4771 |
#設置執行錯誤
|
|
|
4772 |
$result["status"]="false";
|
|
|
4773 |
|
|
|
4774 |
#設置錯誤訊息
|
|
|
4775 |
$result["error"]=$db["insertData"];
|
|
|
4776 |
|
|
|
4777 |
#回傳結果
|
|
|
4778 |
return $result;
|
|
|
4779 |
|
|
|
4780 |
}#if end
|
|
|
4781 |
|
|
|
4782 |
}#for end
|
|
|
4783 |
|
|
|
4784 |
#根據每個 $csvFileContent["csvFileContent"] 的數量,從 $csvFileContent["csvFileContent"][4] 開始建立每一KPI題項預測的KRI題項資料。
|
|
|
4785 |
for($i=4;$i<count($csvFileContent["csvFileContent"]);$i++){
|
|
|
4786 |
|
|
|
4787 |
#設定$j為7
|
|
|
4788 |
$j=7;
|
|
|
4789 |
|
|
|
4790 |
#然後執行無窮迴圈
|
|
|
4791 |
while(true){
|
|
|
4792 |
|
|
|
4793 |
#如果 $csvFileContent["csvFileContent"][i][$j] 存在
|
|
|
4794 |
if(isset($csvFileContent["csvFileContent"][$i][$j])){
|
|
|
4795 |
|
|
|
4796 |
#如果 $csvFileContent["csvFileContent"][i][$j] 不等於 ""
|
|
|
4797 |
if($csvFileContent["csvFileContent"][$i][$j]!=""){
|
|
|
4798 |
|
|
|
4799 |
#尋找該題的題號
|
|
|
4800 |
#涵式說明:
|
|
|
4801 |
#一次取得資料庫、表的資料
|
|
|
4802 |
#回傳的結果
|
|
|
4803 |
#$result["status"],執行結果"true"為成功;"false"為執行失敗。
|
|
|
4804 |
#$result["error"],錯誤訊息陣列。
|
|
|
4805 |
#$result["dataColumnName"],抓取的資料欄位名稱陣列.
|
|
|
4806 |
#$result["dataColumnName"][$i]代表第$i+1個欄位名稱
|
|
|
4807 |
#$result["dataContent"],爲資料的內容。
|
|
|
4808 |
#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
|
|
|
4809 |
#$dataSetNum 爲第$dataSetNum+1筆資料
|
|
|
4810 |
#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
|
|
|
4811 |
#$result["dataCount"],爲取得的資料筆數。
|
|
|
4812 |
#$result["sql"],執行的sql字串.
|
|
|
4813 |
#必填參數:
|
|
|
4814 |
$conf["db"]["fastGetDbData"]["dbAddress"]=$conf["dbAddress"];#爲dbServer的位置。
|
|
|
4815 |
$conf["db"]["fastGetDbData"]["dbAccount"]=$conf["dbAccount"];#爲登入dbServer的帳號。
|
|
|
4816 |
$conf["db"]["fastGetDbData"]["dbName"]=$dbName;#爲要存取的資料庫名稱
|
|
|
4817 |
$conf["db"]["fastGetDbData"]["tableName"]="questionnaireQuest";#爲要存取的資料表名稱
|
|
|
4818 |
$conf["db"]["fastGetDbData"]["columnYouWant"]=array("questNo");#你想要的欄位!,若設為「array("*")」則代表全部欄位.
|
|
|
4819 |
#可省略參數:
|
|
|
4820 |
$conf["db"]["fastGetDbData"]["dbPassword"]=$conf["dbPassword"];#爲要存取dbServer的密碼
|
|
|
4821 |
$conf["db"]["fastGetDbData"]["WhereColumnName"]=array("typeNo","questContent");#用於判斷語句的欄位項目陣列。
|
|
|
4822 |
$conf["db"]["fastGetDbData"]["WhereColumnValue"]=array($questionnaireType["usableNumber"],$csvFileContent["csvFileContent"][i][0]);#用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
|
|
|
4823 |
#$conf["db"]["fastGetDbData"]["WhereColumnCombine"]=array("");#用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
|
|
|
4824 |
#$conf["db"]["fastGetDbData"]["WhereColumnOperator"]=array("");#用於判斷語句的比較符號陣列,可以用的符號有「"="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
|
|
|
4825 |
#$conf["db"]["fastGetDbData"]["WhereColumnAndOr"]=array("");#用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
|
|
|
4826 |
#$conf["db"]["fastGetDbData"]["orderItem"]="";#爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
|
|
|
4827 |
#$conf["db"]["fastGetDbData"]["ascORdesc"]="";#爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
|
|
|
4828 |
#$conf["db"]["fastGetDbData"]["numberStart"]="0";#為從第幾筆開始讀取,預設為0,代筆第一筆。
|
|
|
4829 |
#$conf["db"]["fastGetDbData"]["numLimit"]="30";#為要取幾筆資料,可以省略,省略則表示不限制數目。
|
|
|
4830 |
#$conf["db"]["fastGetDbData"]["groupBy"]=array("");#爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
|
|
|
4831 |
$getQuestNoResult=db::fastGetDbData($conf["db"]["fastGetDbData"]);
|
|
|
4832 |
unset($conf["db"]["fastGetDbData"]);
|
|
|
4833 |
|
|
|
4834 |
#如果 $getQuestNoResult["status"] 等於 "false"
|
|
|
4835 |
if($getQuestNoResult["status"]=="false"){
|
|
|
4836 |
|
|
|
4837 |
#設置執行錯誤
|
|
|
4838 |
$result["status"]="false";
|
|
|
4839 |
|
|
|
4840 |
#設置錯誤訊息
|
|
|
4841 |
$result["error"]=$getQuestNoResult;
|
|
|
4842 |
|
|
|
4843 |
#回傳結果
|
|
|
4844 |
return $result;
|
|
|
4845 |
|
|
|
4846 |
}#if end
|
|
|
4847 |
|
|
|
4848 |
#如果 $getQuestNoResult["dataCount"] 為 0
|
|
|
4849 |
if($getQuestNoResult["dataCount"]==0){
|
|
|
4850 |
|
|
|
4851 |
#設置警告訊息
|
|
|
4852 |
$result["warning"][]="找不名為".$csvFileContent["csvFileContent"][i][0]."的題項";
|
|
|
4853 |
|
|
|
4854 |
#代表沒表沒有該題目
|
|
|
4855 |
continue;
|
|
|
4856 |
|
|
|
4857 |
}#if end
|
|
|
4858 |
|
|
|
4859 |
#依據問卷編號、題號建立指標預測關西
|
|
|
4860 |
#涵式說明:
|
|
|
4861 |
#插入資料到指定的資料表裡面,插入資料完畢可以選擇是否要進行轉址。
|
|
|
4862 |
#回傳的數值:
|
|
|
4863 |
#$result["status"],爲查詢是否成功,若爲"true"則成功,若爲"false"則表示失敗了.
|
|
|
4864 |
#$result["error"],錯誤訊息.
|
|
|
4865 |
#$result["sql"],執行的sql語法.
|
|
|
4866 |
#必填參數:
|
|
|
4867 |
$conf["db"]["insertData"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
4868 |
$conf["db"]["insertData"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
4869 |
$conf["db"]["insertData"]["selectedDataBaseName"]=$dbName;#要選取的資料庫名稱
|
|
|
4870 |
$conf["db"]["insertData"]["tableName"]="KRIforecast";#爲要插入資料的資料表名稱
|
|
|
4871 |
$conf["db"]["insertData"]["columnName"]=array("questionnaireNo","questNo","questNoTarget");#爲資料表的項目名稱,
|
|
|
4872 |
#例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);
|
|
|
4873 |
$conf["db"]["insertData"]["insertValue"]=array($questionnaireType["usableNumber"],$csvFileContent["csvFileContent"][i][0],$getQuestNoResult["dataContent"]["questNo"][0]);#爲要插入度數值,
|
|
|
4874 |
#例如:$conf["insertValue"]=array("insertValue1","insertValue2","insertValue3",...);
|
|
|
4875 |
#可以省略的變數:
|
|
|
4876 |
$conf["db"]["insertData"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
4877 |
$insertKRIforecastResult=db::insertData($conf["db"]["insertData"]);
|
|
|
4878 |
unset($conf["db"]["insertData"]);
|
|
|
4879 |
|
|
|
4880 |
#如果 $insertKRIforecastResult["status"] 等於 "false"
|
|
|
4881 |
if($insertKRIforecastResult["status"]=="false"){
|
|
|
4882 |
|
|
|
4883 |
#設置執行錯誤
|
|
|
4884 |
$result["status"]="false";
|
|
|
4885 |
|
|
|
4886 |
#設置錯誤訊息
|
|
|
4887 |
$result["error"]=$insertKRIforecastResult;
|
|
|
4888 |
|
|
|
4889 |
#回傳結果
|
|
|
4890 |
return $result;
|
|
|
4891 |
|
|
|
4892 |
}#if end
|
|
|
4893 |
|
|
|
4894 |
}#if end
|
|
|
4895 |
|
|
|
4896 |
#反之不存在要預測的KRI題項
|
|
|
4897 |
else{
|
|
|
4898 |
|
|
|
4899 |
#跳出while
|
|
|
4900 |
break;
|
|
|
4901 |
|
|
|
4902 |
}#else end
|
|
|
4903 |
|
|
|
4904 |
}#if end
|
|
|
4905 |
|
|
|
4906 |
#反之不存在要預測的KRI題項
|
|
|
4907 |
else{
|
|
|
4908 |
|
|
|
4909 |
#跳出while
|
|
|
4910 |
break;
|
|
|
4911 |
|
|
|
4912 |
}#else end
|
|
|
4913 |
|
|
|
4914 |
}#while end
|
|
|
4915 |
|
|
|
4916 |
}#for end
|
|
|
4917 |
|
|
|
4918 |
#如果 $conf["delFileAfterImport"]存在
|
|
|
4919 |
if(isset($conf["delFileAfterImport"])){
|
|
|
4920 |
|
|
|
4921 |
#如果 $conf["delFileAfterImport"] 為 "true"
|
|
|
4922 |
if($conf["delFileAfterImport"]=="true"){
|
|
|
4923 |
|
|
|
4924 |
#移除要匯入的csv檔案
|
|
|
4925 |
#涵式說明:
|
|
|
4926 |
#移除檔案
|
|
|
4927 |
#回傳的結果:
|
|
|
4928 |
#$result["status"],"true"代表移除成功,"false"代表移除失敗.
|
|
|
4929 |
#必填參數:
|
|
|
4930 |
$conf["fileAccess"]["delFile"]["fileAddress"]=$conf["questionnaireSetupCsvPath"];#要移除檔案的位置
|
|
|
4931 |
$eraseFileResult=fileAccess::delFile($conf["fileAccess"]["delFile"]);
|
|
|
4932 |
unset($conf["fileAccess"]["delFile"]);
|
|
|
4933 |
|
|
|
4934 |
#如果 $eraseFileResult["status"] 等於 "false"
|
|
|
4935 |
if($eraseFileResult["status"]=="false"){
|
|
|
4936 |
|
|
|
4937 |
#設置執行錯誤
|
|
|
4938 |
$result["status"]="false";
|
|
|
4939 |
|
|
|
4940 |
#設置錯誤訊息
|
|
|
4941 |
$result["error"][]="移除要匯入的問卷資訊csv檔失敗";
|
|
|
4942 |
|
|
|
4943 |
#回傳結果
|
|
|
4944 |
return $result;
|
|
|
4945 |
|
|
|
4946 |
}#if end
|
|
|
4947 |
|
|
|
4948 |
}#if end
|
|
|
4949 |
|
|
|
4950 |
}#if end
|
|
|
4951 |
|
|
|
4952 |
#值行到這邊代表正常
|
|
|
4953 |
$result["status"]="true";
|
|
|
4954 |
|
|
|
4955 |
#回傳結果
|
|
|
4956 |
return $result;
|
|
|
4957 |
|
|
|
4958 |
}#function importQuestionnaire end
|
|
|
4959 |
|
|
|
4960 |
/*
|
|
|
4961 |
#函式說明:
|
|
|
4962 |
#將csv檔,特定欄位的內容結尾加上特定的字串,並下載處理好的csv檔案
|
|
|
4963 |
#回傳的結果:
|
|
|
4964 |
#$result["status"],執行是否正確,"true"代表正確,"false"代表不正常.
|
|
|
4965 |
#$result["error"],錯誤訊息陣列.
|
|
|
4966 |
#$result["function"],當前執行的函數名稱.
|
|
|
4967 |
#$result["content"],輸出後的csv檔案位置.
|
|
|
4968 |
#必填參數:
|
|
|
4969 |
#$conf["csvFileAddress"],字串,要處理的csv檔案位置與名稱.
|
|
|
4970 |
$conf["csvFileAddress"]="";
|
|
|
4971 |
#$conf["selectedColumn"],字串陣列,要處理的欄位名稱(第一列的內容為欄位名稱)
|
|
|
4972 |
$conf["selectedColumn"]="";
|
|
|
4973 |
#$conf["stringAdded"],字串,要增加的字串內容
|
|
|
4974 |
$conf["stringAdded"]="";
|
|
|
4975 |
#可省略參數:
|
|
|
4976 |
#$conf["outputCsvFilePathAndName"],字串,輸出的csv檔案路徑與名稱,預設檔名爲系統時間,副檔名"csv"會自動加上.
|
|
|
4977 |
#$conf["outputCsvFilePathAndName"]="";
|
|
|
4978 |
#$conf["noDownload"],字串,是否不要自動開始下載,"true"代表不要自動下載.預設為自動下載.
|
|
|
4979 |
#$conf["noDownload"]="true";
|
|
|
4980 |
#參考資料:
|
|
|
4981 |
#無.
|
|
|
4982 |
#備註:
|
|
|
4983 |
#無.
|
|
|
4984 |
*/
|
|
|
4985 |
public static function addStringInTailOnSelectedColumnFormCsv($conf){
|
|
|
4986 |
|
|
|
4987 |
#初始化要回傳的變數
|
|
|
4988 |
$result=array();
|
|
|
4989 |
|
|
|
4990 |
#取得當前執行的函數名稱
|
|
|
4991 |
$result["function"]=__FUNCTION__;
|
|
|
4992 |
|
|
|
4993 |
#如果 $conf 不為陣列
|
|
|
4994 |
if(gettype($conf)!="array"){
|
|
|
4995 |
|
|
|
4996 |
#設置執行失敗
|
|
|
4997 |
$result["status"]="false";
|
|
|
4998 |
|
|
|
4999 |
#設置執行錯誤訊息
|
|
|
5000 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
5001 |
|
|
|
5002 |
#如果傳入的參數為 null
|
|
|
5003 |
if($conf==null){
|
|
|
5004 |
|
|
|
5005 |
#設置執行錯誤訊息
|
|
|
5006 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
5007 |
|
|
|
5008 |
}#if end
|
|
|
5009 |
|
|
|
5010 |
#回傳結果
|
|
|
5011 |
return $result;
|
|
|
5012 |
|
|
|
5013 |
}#if end
|
|
|
5014 |
|
|
|
5015 |
#檢查參數
|
|
|
5016 |
#涵式說明:
|
|
|
5017 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
5018 |
#回傳的結果:
|
|
|
5019 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5020 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
5021 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
5022 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
5023 |
#必填參數:
|
|
|
5024 |
$conf["variableCheck"]["isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
5025 |
$conf["variableCheck"]["isexistMulti"]["variableCheck"]=array("csvFileAddress","selectedColumn","stringAdded");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
5026 |
#可以省略的參數:
|
|
|
5027 |
$conf["variableType"]=array("string","array","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
|
|
5028 |
$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
5029 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMulti"]);
|
|
|
5030 |
unset($conf["variableCheck"]["isexistMulti"]);
|
|
|
5031 |
|
|
|
5032 |
#如果檢查不通過
|
|
|
5033 |
if($checkResult["status"]=="false"){
|
|
|
5034 |
|
|
|
5035 |
#設置錯誤識別
|
|
|
5036 |
$result["status"]="false";
|
|
|
5037 |
|
|
|
5038 |
#設置錯誤訊息
|
|
|
5039 |
$result["error"]=$checkResult;
|
|
|
5040 |
|
|
|
5041 |
#回傳結果
|
|
|
5042 |
return $result;
|
|
|
5043 |
|
|
|
5044 |
}#if end
|
|
|
5045 |
|
|
|
5046 |
#如果檢查不通過
|
|
|
5047 |
if($checkResult["passed"]=="false"){
|
|
|
5048 |
|
|
|
5049 |
#設置錯誤識別
|
|
|
5050 |
$result["status"]="false";
|
|
|
5051 |
|
|
|
5052 |
#設置錯誤訊息
|
|
|
5053 |
$result["error"]=$checkResult;
|
|
|
5054 |
|
|
|
5055 |
#回傳結果
|
|
|
5056 |
return $result;
|
|
|
5057 |
|
|
|
5058 |
}#if end
|
|
|
5059 |
|
|
|
5060 |
#var_dump($conf["csvFileAddress"]);
|
|
|
5061 |
|
|
|
5062 |
#讀取csv檔
|
|
|
5063 |
#涵式說明:
|
|
|
5064 |
#讀取csv檔案的內容
|
|
|
5065 |
#回傳得結果:
|
|
|
5066 |
#$result["status"],執行是否正常,"true"代表正常;"false"代表不正常.
|
|
|
5067 |
#$result["error"],錯誤訊息陣列.
|
|
|
5068 |
#$result["csvFileContent"],csv檔案內容的陣列
|
|
|
5069 |
#$result["csvFileContent"]["$i"]["$j"]代表第$i+1列第$j+1欄位的內容.
|
|
|
5070 |
#如果 $conf["firstLineVarName"]爲"true"的話則會回傳 $result["csvFileContent"]["第幾列"]["第一列各個欄位的名稱"]
|
|
|
5071 |
#$result["lineArray"],csv檔案逐列內容的陣列.
|
|
|
5072 |
#$result["lineArrayCount"],總共幾列資料
|
|
|
5073 |
#必填參數:
|
|
|
5074 |
$conf["csv"]["loadCsvFile"]["csvFilePositionAndName"]=$conf["csvFileAddress"];#csv檔案的位置
|
|
|
5075 |
#可省略參數:
|
|
|
5076 |
$conf["csv"]["loadCsvFile"]["firstLineVarName"]="true";#第一行是否爲變數名稱(各個欄位的名稱)
|
|
|
5077 |
#參考資料來源:
|
|
|
5078 |
#http://www.php.net/manual/en/function.str-split.php
|
|
|
5079 |
#參考資料來源
|
|
|
5080 |
#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)
|
|
|
5081 |
$readCsv=csv::loadCsvFile($conf["csv"]["loadCsvFile"]);
|
|
|
5082 |
unset($conf["csv"]["loadCsvFile"]);
|
|
|
5083 |
|
|
|
5084 |
#如果 $readCsv["status"] 等於 "false"
|
|
|
5085 |
if($readCsv["status"]=="false"){
|
|
|
5086 |
|
|
|
5087 |
#設置錯誤識別
|
|
|
5088 |
$result["status"]="false";
|
|
|
5089 |
|
|
|
5090 |
#設置錯誤訊息
|
|
|
5091 |
$result["error"]=$readCsv;
|
|
|
5092 |
|
|
|
5093 |
#回傳結果
|
|
|
5094 |
return $result;
|
|
|
5095 |
|
|
|
5096 |
}#if end
|
|
|
5097 |
|
|
|
5098 |
#依據每筆資料,$i=1是因為不含標題攔
|
|
|
5099 |
for($i=1;$i<$readCsv["lineArrayCount"];$i++){
|
|
|
5100 |
|
|
|
5101 |
#針對要處理的欄位
|
|
|
5102 |
foreach($conf["selectedColumn"] as $columnName){
|
|
|
5103 |
|
|
|
5104 |
#在結尾加上字串
|
|
|
5105 |
$readCsv["csvFileContent"][$i][$columnName]=$readCsv["csvFileContent"][$i][$columnName].$conf["stringAdded"];
|
|
|
5106 |
|
|
|
5107 |
}#foreache end
|
|
|
5108 |
|
|
|
5109 |
}#for end
|
|
|
5110 |
|
|
|
5111 |
#建立csv檔案
|
|
|
5112 |
#涵式說明:
|
|
|
5113 |
#快速建立一個csv檔案,並且要求使用者下載。
|
|
|
5114 |
#回傳的結果:
|
|
|
5115 |
#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
|
|
|
5116 |
#$result["error"],錯誤訊息陣列.
|
|
|
5117 |
#$result["content"],輸出的csv檔案位置.
|
|
|
5118 |
#如果有設置$conf["noDownload"]爲"true"的話,則會回傳檔案的位置
|
|
|
5119 |
#必填參數:
|
|
|
5120 |
$conf["csv"]["create"]["dataArray"]=$readCsv["csvFileContent"];#要寫入的文字,$conf["dataArray"][$i],代表第 $i 行的內容。
|
|
|
5121 |
#可省略參數:
|
|
|
5122 |
|
|
|
5123 |
#如果 $conf["outputCsvFilePathAndName"] 有設置
|
|
|
5124 |
if(isset($conf["outputCsvFilePathAndName"])){
|
|
|
5125 |
|
|
|
5126 |
$conf["csv"]["create"]["csvFilePathAndName"]=$conf["outputCsvFilePathAndName"];#輸出的csv檔案路徑與名稱,預設爲系統時間,副檔名"csv"會自動加上.
|
|
|
5127 |
|
|
|
5128 |
}#if end
|
|
|
5129 |
|
|
|
5130 |
#如果 $conf["csv"]["create"]["noDownload"] 有設置
|
|
|
5131 |
if(isset($conf["csv"]["create"]["noDownload"])){
|
|
|
5132 |
|
|
|
5133 |
#如果 $conf["csv"]["create"]["noDownload"] 等於 "true"
|
|
|
5134 |
if($conf["csv"]["create"]["noDownload"]=="true"){
|
|
|
5135 |
|
|
|
5136 |
$conf["csv"]["create"]["noDownload"]="true";#如果爲"true"則代表不要讓使用者下載,但會回傳檔案的相對位置
|
|
|
5137 |
|
|
|
5138 |
}#if end
|
|
|
5139 |
|
|
|
5140 |
}#if end
|
|
|
5141 |
|
|
|
5142 |
#參考資料來源:
|
|
|
5143 |
#http://php.net/manual/en/function.str-split.php
|
|
|
5144 |
$createCsvResult=csv::create($conf["csv"]["create"]);
|
|
|
5145 |
unset($conf["csv"]["create"]);
|
|
|
5146 |
|
|
|
5147 |
#var_dump($createCsvResult);
|
|
|
5148 |
|
|
|
5149 |
#如果 $createCsvResult["status"] 等於 "false"
|
|
|
5150 |
if($createCsvResult["status"]=="false"){
|
|
|
5151 |
|
|
|
5152 |
#設置錯誤識別
|
|
|
5153 |
$result["status"]="false";
|
|
|
5154 |
|
|
|
5155 |
#設置錯誤訊息
|
|
|
5156 |
$result["error"]=$createCsvResult;
|
|
|
5157 |
|
|
|
5158 |
#回傳結果
|
|
|
5159 |
return $result;
|
|
|
5160 |
|
|
|
5161 |
}#if end
|
|
|
5162 |
|
|
|
5163 |
#取得輸出的csv檔案位置與名稱
|
|
|
5164 |
$result["content"]=$createCsvResult["content"];
|
|
|
5165 |
|
|
|
5166 |
#設置執行正常的識別
|
|
|
5167 |
$result["status"]="true";
|
|
|
5168 |
|
|
|
5169 |
#回傳結果
|
|
|
5170 |
return $result;
|
|
|
5171 |
|
|
|
5172 |
}#function addStringInTailOnSelectedColumnFormCsv end
|
|
|
5173 |
|
|
|
5174 |
/*
|
|
|
5175 |
#函式說明:
|
|
|
5176 |
#將問卷樣本從以逗號間隔的數字編號代表的填寫內容轉換成用「;」間隔的實際填寫的內容,結尾也要一個「;」
|
|
|
5177 |
#也就是將傳統問卷樣本轉換成問卷系統匯入樣本時專用的格式.
|
|
|
5178 |
# 原始樣本格式
|
|
|
5179 |
# A B C
|
|
|
5180 |
# 1,2,3 2,4 3
|
|
|
5181 |
# 3 1,3 2,4
|
|
|
5182 |
# 各題目選項的對應
|
|
|
5183 |
# A 台北 嘉義 臺東 高雄
|
|
|
5184 |
# B ~17 18~25 26~50 51~
|
|
|
5185 |
# C 金 木 水 火
|
|
|
5186 |
# 轉換好的結果
|
|
|
5187 |
# A B C
|
|
|
5188 |
# 台北;嘉義;臺東; 18~25;51~; 水;
|
|
|
5189 |
# 臺東; ~17;26~50; 木;火;
|
|
|
5190 |
#樣本csv檔案的位置的第一列為各欄位的題目.
|
|
|
5191 |
#樣本csv檔案的位置的第一列過後為每筆樣本各欄位題目對應的填答數字代號.數字代號間用半型的逗號「,」間隔.
|
|
|
5192 |
#儲存題目對應的選項內容的csv檔案的第一欄每一列為每個題目的名稱.
|
|
|
5193 |
#儲存題目對應的選項內容的csv檔案的第一欄後面每欄每一列為每個題目對應的選項內容,一個選項佔用一欄.
|
|
|
5194 |
#回傳結果:
|
|
|
5195 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
5196 |
#$result["error"],錯誤訊息陣列.
|
|
|
5197 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
5198 |
#$result["content"],處理好的檔案所在位置.
|
|
|
5199 |
#必填參數:
|
|
|
5200 |
#$conf["samplesCsvFile"],字串,樣本csv檔案的位置.
|
|
|
5201 |
$conf["samplesCsvFile"]="";
|
|
|
5202 |
#$conf["questAndOptionCsvFile"],字串,儲存題目對應的選項內容的csv檔案.
|
|
|
5203 |
$conf["questAndOptionCsvFile"]="";
|
|
|
5204 |
#$conf["outputFilePathAndName"],字串,轉換好的檔案要存到哪邊,名稱為何,副檔名會自動加上.
|
|
|
5205 |
$conf["outputFilePathAndName"]="";
|
|
|
5206 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
5207 |
$conf["fileArgu"]=__FILE__;
|
|
|
5208 |
#可省略參數:
|
|
|
5209 |
#無.
|
|
|
5210 |
#參考資料:
|
|
|
5211 |
#無.
|
|
|
5212 |
#備註:
|
|
|
5213 |
#無.
|
|
|
5214 |
*/
|
|
|
5215 |
public static function numSampleToStr(&$conf){
|
|
|
5216 |
|
|
|
5217 |
#設置要回傳的變數
|
|
|
5218 |
$result=array();
|
|
|
5219 |
|
|
|
5220 |
#取得當前執行的涵式名稱
|
|
|
5221 |
$resutl["function"]=__FUNCTION__;
|
|
|
5222 |
|
|
|
5223 |
#如果 $conf 不為陣列
|
|
|
5224 |
if(gettype($conf)!="array"){
|
|
|
5225 |
|
|
|
5226 |
#設置執行失敗
|
|
|
5227 |
$result["status"]="false";
|
|
|
5228 |
|
|
|
5229 |
#設置執行錯誤訊息
|
|
|
5230 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
5231 |
|
|
|
5232 |
#如果傳入的參數為 null
|
|
|
5233 |
if($conf==null){
|
|
|
5234 |
|
|
|
5235 |
#設置執行錯誤訊息
|
|
|
5236 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
5237 |
|
|
|
5238 |
}#if end
|
|
|
5239 |
|
|
|
5240 |
#回傳結果
|
|
|
5241 |
return $result;
|
|
|
5242 |
|
|
|
5243 |
}#if end
|
|
|
5244 |
|
|
|
5245 |
#檢查參數
|
|
|
5246 |
#函式說明:
|
|
|
5247 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
5248 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5249 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
5250 |
#$result["function"],當前執行的函式名稱.
|
|
|
5251 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
5252 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
5253 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
5254 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
5255 |
#必填參數:
|
|
|
5256 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
5257 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
5258 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
5259 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("samplesCsvFile","questAndOptionCsvFile","outputFilePathAndName","fileArgu");
|
|
|
5260 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
5261 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string");
|
|
|
5262 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
5263 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
5264 |
#可以省略的參數:
|
|
|
5265 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
5266 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
5267 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
5268 |
#$conf["skipableVariableName"]=array();
|
|
|
5269 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
5270 |
#$conf["skipableVariableType"]=array();
|
|
|
5271 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
5272 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
5273 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
5274 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
5275 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
5276 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
5277 |
|
|
|
5278 |
#如果檢查參數失敗
|
|
|
5279 |
if($checkResult["status"]=="false"){
|
|
|
5280 |
|
|
|
5281 |
#設置執行失敗
|
|
|
5282 |
$result["status"]="false";
|
|
|
5283 |
|
|
|
5284 |
#設置錯誤訊息
|
|
|
5285 |
$result["error"]=$checkResult;
|
|
|
5286 |
|
|
|
5287 |
#回傳結果
|
|
|
5288 |
return $result;
|
|
|
5289 |
|
|
|
5290 |
}#if end
|
|
|
5291 |
|
|
|
5292 |
#如果檢查不通過
|
|
|
5293 |
if($checkResult["passed"]=="false"){
|
|
|
5294 |
|
|
|
5295 |
#設置執行失敗
|
|
|
5296 |
$result["status"]="false";
|
|
|
5297 |
|
|
|
5298 |
#設置錯誤訊息
|
|
|
5299 |
$result["error"]=$checkResult;
|
|
|
5300 |
|
|
|
5301 |
#回傳結果
|
|
|
5302 |
return $result;
|
|
|
5303 |
|
|
|
5304 |
}#if end
|
|
|
5305 |
|
|
|
5306 |
#檢查檔案是否存在
|
|
|
5307 |
#涵式說明:檢查多個檔案與資料夾是否存在.
|
|
|
5308 |
#回傳的結果:
|
|
|
5309 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
5310 |
#$result["error"],錯誤訊息陣列.
|
|
|
5311 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
5312 |
#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
|
|
|
5313 |
#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
|
|
|
5314 |
#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
|
|
|
5315 |
#必填參數:
|
|
|
5316 |
$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["samplesCsvFile"],$conf["questAndOptionCsvFile"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
|
|
|
5317 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
5318 |
$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
|
|
|
5319 |
#參考資料來源:
|
|
|
5320 |
#http://php.net/manual/en/function.file-exists.php
|
|
|
5321 |
#http://php.net/manual/en/control-structures.foreach.php
|
|
|
5322 |
$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
|
|
|
5323 |
unset($conf["fileAccess::checkMultiFileExist"]);
|
|
|
5324 |
|
|
|
5325 |
#如果檢查失敗
|
|
|
5326 |
if($checkMultiFileExist["status"]=="false"){
|
|
|
5327 |
|
|
|
5328 |
#設置執行失敗
|
|
|
5329 |
$result["status"]="false";
|
|
|
5330 |
|
|
|
5331 |
#設置錯誤訊息
|
|
|
5332 |
$result["error"]=$checkMultiFileExist;
|
|
|
5333 |
|
|
|
5334 |
#回傳結果
|
|
|
5335 |
return $result;
|
|
|
5336 |
|
|
|
5337 |
}#if end
|
|
|
5338 |
|
|
|
5339 |
#如果檔案沒有都找到
|
|
|
5340 |
if($checkMultiFileExist["allExist"]=="false"){
|
|
|
5341 |
|
|
|
5342 |
#設置執行失敗
|
|
|
5343 |
$result["status"]="false";
|
|
|
5344 |
|
|
|
5345 |
#設置錯誤訊息
|
|
|
5346 |
$result["error"]=$checkMultiFileExist;
|
|
|
5347 |
|
|
|
5348 |
#回傳結果
|
|
|
5349 |
return $result;
|
|
|
5350 |
|
|
|
5351 |
}#if end
|
|
|
5352 |
|
|
|
5353 |
#讀取 $conf["questAndOptionCsvFile"] 檔案的內容
|
|
|
5354 |
#涵式說明:
|
|
|
5355 |
#讀取csv檔案的內容
|
|
|
5356 |
#回傳得結果:
|
|
|
5357 |
#$result["status"],執行是否正常,"true"代表正常;"false"代表不正常.
|
|
|
5358 |
#$result["error"],錯誤訊息陣列.
|
|
|
5359 |
#$result["csvFileContent"],csv檔案內容的陣列
|
|
|
5360 |
#$result["csvFileContent"]["$i"]["$j"]代表第$i+1列第$j+1欄位的內容.
|
|
|
5361 |
#如果 $conf["firstLineVarName"]爲"true"的話則會多回傳 $result["csvFileContent"]["第幾列"]["第一列各個欄位的名稱"]
|
|
|
5362 |
#$result["lineArray"],csv檔案逐列內容的陣列.
|
|
|
5363 |
#$result["lineArrayCount"],總共幾列資料
|
|
|
5364 |
#必填參數:
|
|
|
5365 |
$conf["csv::loadCsvFile"]["csvFilePositionAndName"]=$conf["questAndOptionCsvFile"];#csv檔案的位置
|
|
|
5366 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
5367 |
$conf["csv::loadCsvFile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
5368 |
#可省略參數:
|
|
|
5369 |
$conf["csv::loadCsvFile"]["firstLineVarName"]="false";#第一行是否爲變數名稱(各個欄位的名稱)
|
|
|
5370 |
#參考資料來源:
|
|
|
5371 |
#http://www.php.net/manual/en/function.str-split.php
|
|
|
5372 |
#參考資料來源
|
|
|
5373 |
#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)
|
|
|
5374 |
#http://php.net/manual/en/function.fgetcsv.php
|
|
|
5375 |
#備註:
|
|
|
5376 |
#可用fgetcsv函數替代
|
|
|
5377 |
$getQuestAndOptionCsvFile=csv::loadCsvFile($conf["csv::loadCsvFile"]);
|
|
|
5378 |
unset($conf["csv::loadCsvFile"]);
|
|
|
5379 |
|
|
|
5380 |
#如果讀取檔案失敗
|
|
|
5381 |
if($getQuestAndOptionCsvFile["status"]=="false"){
|
|
|
5382 |
|
|
|
5383 |
#設置執行失敗
|
|
|
5384 |
$result["status"]="false";
|
|
|
5385 |
|
|
|
5386 |
#設置錯誤訊息
|
|
|
5387 |
$result["error"]=$getQuestAndOptionCsvFile;
|
|
|
5388 |
|
|
|
5389 |
#回傳結果
|
|
|
5390 |
return $result;
|
|
|
5391 |
|
|
|
5392 |
}#if end
|
|
|
5393 |
|
|
|
5394 |
#初始化儲存題目與選項的陣列
|
|
|
5395 |
$questWithOptionArray=array();
|
|
|
5396 |
|
|
|
5397 |
#有幾列資料就執行幾次
|
|
|
5398 |
for($i=0;$i<$getQuestAndOptionCsvFile["lineArrayCount"];$i++){
|
|
|
5399 |
|
|
|
5400 |
#有幾個選項欄位就執行幾次
|
|
|
5401 |
for($j=1;$j<count($getQuestAndOptionCsvFile["csvFileContent"][$i]);$j++){
|
|
|
5402 |
|
|
|
5403 |
#用題目作為key來儲存選項
|
|
|
5404 |
$questWithOptionArray[$getQuestAndOptionCsvFile["csvFileContent"][$i][0]][]=$getQuestAndOptionCsvFile["csvFileContent"][$i][$j];
|
|
|
5405 |
|
|
|
5406 |
}#for end
|
|
|
5407 |
|
|
|
5408 |
}#for end
|
|
|
5409 |
|
|
|
5410 |
#讀取 $conf["samplesCsvFile"] 檔案
|
|
|
5411 |
#涵式說明:
|
|
|
5412 |
#讀取csv檔案的內容
|
|
|
5413 |
#回傳得結果:
|
|
|
5414 |
#$result["status"],執行是否正常,"true"代表正常;"false"代表不正常.
|
|
|
5415 |
#$result["error"],錯誤訊息陣列.
|
|
|
5416 |
#$result["csvFileContent"],csv檔案內容的陣列
|
|
|
5417 |
#$result["csvFileContent"]["$i"]["$j"]代表第$i+1列第$j+1欄位的內容.
|
|
|
5418 |
#如果 $conf["firstLineVarName"]爲"true"的話則會多回傳 $result["csvFileContent"]["第幾列"]["第一列各個欄位的名稱"]
|
|
|
5419 |
#$result["lineArray"],csv檔案逐列內容的陣列.
|
|
|
5420 |
#$result["lineArrayCount"],總共幾列資料
|
|
|
5421 |
#必填參數:
|
|
|
5422 |
$conf["csv::loadCsvFile"]["csvFilePositionAndName"]=$conf["samplesCsvFile"];#csv檔案的位置
|
|
|
5423 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
5424 |
$conf["csv::loadCsvFile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
5425 |
#可省略參數:
|
|
|
5426 |
$conf["csv::loadCsvFile"]["firstLineVarName"]="true";#第一行是否爲變數名稱(各個欄位的名稱)
|
|
|
5427 |
#參考資料來源:
|
|
|
5428 |
#http://www.php.net/manual/en/function.str-split.php
|
|
|
5429 |
#參考資料來源
|
|
|
5430 |
#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)
|
|
|
5431 |
#http://php.net/manual/en/function.fgetcsv.php
|
|
|
5432 |
#備註:
|
|
|
5433 |
#可用fgetcsv函數替代
|
|
|
5434 |
$getSamplesCsvFile=csv::loadCsvFile($conf["csv::loadCsvFile"]);
|
|
|
5435 |
unset($conf["csv::loadCsvFile"]);
|
|
|
5436 |
|
|
|
5437 |
#如果讀取檔案失敗
|
|
|
5438 |
if($getSamplesCsvFile["status"]=="false"){
|
|
|
5439 |
|
|
|
5440 |
#設置執行失敗
|
|
|
5441 |
$result["status"]="false";
|
|
|
5442 |
|
|
|
5443 |
#設置錯誤訊息
|
|
|
5444 |
$result["error"]=$getSamplesCsvFile;
|
|
|
5445 |
|
|
|
5446 |
#回傳結果
|
|
|
5447 |
return $result;
|
|
|
5448 |
|
|
|
5449 |
}#if end
|
|
|
5450 |
|
|
|
5451 |
#初始化儲存轉成實際填寫內容的陣列
|
|
|
5452 |
$converedSamplesArray=array();
|
|
|
5453 |
|
|
|
5454 |
#儲存第一列的題目
|
|
|
5455 |
$converedSamplesArray[]=$getSamplesCsvFile["csvFileContent"][0];
|
|
|
5456 |
|
|
|
5457 |
#有幾列資料就執行幾次
|
|
|
5458 |
for($i=1;$i<$getSamplesCsvFile["lineArrayCount"];$i++){
|
|
|
5459 |
|
|
|
5460 |
#有幾題目就執行幾次
|
|
|
5461 |
foreach($getSamplesCsvFile["csvFileContent"][$i] as $questName => $filledNumSpiltedByComma){
|
|
|
5462 |
|
|
|
5463 |
#分隔用逗號分隔的填寫編號
|
|
|
5464 |
#涵式說明:
|
|
|
5465 |
#將多個固定格式的字串分開,並回傳分開的結果
|
|
|
5466 |
#回傳的參數:
|
|
|
5467 |
#$result["status"],執行成功與否,若爲0,代表執行成功,若爲1代表執失敗。
|
|
|
5468 |
#$result["error"],錯誤訊息陣列.
|
|
|
5469 |
#$result["function"],當前執行的函數名稱.
|
|
|
5470 |
#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容
|
|
|
5471 |
#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列
|
|
|
5472 |
#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j)段內容
|
|
|
5473 |
#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段
|
|
|
5474 |
#必填參數:
|
|
|
5475 |
$conf["stringProcess::spiltMutiString"]["stringIn"]=array($filledNumSpiltedByComma);#要處理的字串陣列。
|
|
|
5476 |
$conf["stringProcess::spiltMutiString"]["spiltSymbol"]=",";#爲要以哪個符號作爲分割。
|
|
|
5477 |
$spiltNumStr=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);
|
|
|
5478 |
unset($conf["stringProcess::spiltMutiString"]);
|
|
|
5479 |
|
|
|
5480 |
#如果分隔字串失敗
|
|
|
5481 |
if($spiltNumStr["status"]==1){
|
|
|
5482 |
|
|
|
5483 |
#設置執行失敗
|
|
|
5484 |
$result["status"]="false";
|
|
|
5485 |
|
|
|
5486 |
#設置錯誤訊息
|
|
|
5487 |
$result["error"]=$spiltNumStr;
|
|
|
5488 |
|
|
|
5489 |
#回傳結果
|
|
|
5490 |
return $result;
|
|
|
5491 |
|
|
|
5492 |
}#if end
|
|
|
5493 |
|
|
|
5494 |
#初始化暫存填寫的選項字串
|
|
|
5495 |
$filledStr="";
|
|
|
5496 |
|
|
|
5497 |
#分割成幾個數字就執行幾次
|
|
|
5498 |
for($j=0;$j<$spiltNumStr["spiltString"][0]["dataCounts"];$j++){
|
|
|
5499 |
|
|
|
5500 |
#如果選項內容為0
|
|
|
5501 |
if(!isset($questWithOptionArray[$questName][$spiltNumStr["spiltString"][0]["dataArray"][$j]-1])){
|
|
|
5502 |
|
|
|
5503 |
#代表為空值
|
|
|
5504 |
|
|
|
5505 |
#轉換為""
|
|
|
5506 |
$questWithOptionArray[$questName][$spiltNumStr["spiltString"][0]["dataArray"][$j]-1]="";
|
|
|
5507 |
|
|
|
5508 |
}#if end
|
|
|
5509 |
|
|
|
5510 |
#從數字轉換成選項內容
|
|
|
5511 |
$filledStr=$filledStr.$questWithOptionArray[$questName][$spiltNumStr["spiltString"][0]["dataArray"][$j]-1].";";
|
|
|
5512 |
|
|
|
5513 |
}#for end
|
|
|
5514 |
|
|
|
5515 |
#儲存該筆樣本該題填寫的內容
|
|
|
5516 |
$converedSamplesArray[$i][]=$filledStr;
|
|
|
5517 |
|
|
|
5518 |
}#for end
|
|
|
5519 |
|
|
|
5520 |
}#for end
|
|
|
5521 |
|
|
|
5522 |
#將 $converedSamplesArray 的內容寫入到轉換好的檔案裡面
|
|
|
5523 |
#涵式說明:
|
|
|
5524 |
#快速建立一個csv檔案,並且要求使用者下載。
|
|
|
5525 |
#回傳的結果:
|
|
|
5526 |
#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
|
|
|
5527 |
#$result["error"],錯誤訊息陣列.
|
|
|
5528 |
#$result["content"],輸出的csv檔案位置.
|
|
|
5529 |
#如果有設置$conf["noDownload"]爲"true"的話,則會回傳檔案的位置
|
|
|
5530 |
#必填參數:
|
|
|
5531 |
$conf["csv::create"]["dataArray"]=$converedSamplesArray;#要寫入的文字,
|
|
|
5532 |
#$conf["dataArray"][$i],代表第 $i 行的內容,
|
|
|
5533 |
#$conf["dataArray"][$i][$j],代表第 $i 第 $j個欄位的內容.
|
|
|
5534 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
5535 |
$conf["csv::create"]["fileArgu"]=$conf["fileArgu"];
|
|
|
5536 |
#可省略參數:
|
|
|
5537 |
$conf["csv::create"]["csvFilePathAndName"]=$conf["outputFilePathAndName"];#輸出的csv檔案路徑與名稱,預設爲系統時間,副檔名"csv"會自動加上.
|
|
|
5538 |
$conf["csv::create"]["noDownload"]="true";#如果爲"true"則代表不要讓使用者下載,但會回傳檔案的相對位置
|
|
|
5539 |
#參考資料來源:
|
|
|
5540 |
#http://php.net/manual/en/function.str-split.php
|
|
|
5541 |
#http://php.net/manual/en/function.fputcsv.php
|
|
|
5542 |
#備註:
|
|
|
5543 |
#可用fputcsv涵式替代
|
|
|
5544 |
#建議增加自動判斷是否要建立csv檔路徑所需的資料夾
|
|
|
5545 |
$createCsv=csv::create($conf["csv::create"]);
|
|
|
5546 |
unset($conf["csv::create"]);
|
|
|
5547 |
|
|
|
5548 |
#如果建立csv檔案失敗
|
|
|
5549 |
if($createCsv["status"]=="false"){
|
|
|
5550 |
|
|
|
5551 |
#設置執行失敗
|
|
|
5552 |
$result["status"]="false";
|
|
|
5553 |
|
|
|
5554 |
#設置錯誤訊息
|
|
|
5555 |
$result["error"]=$createCsv;
|
|
|
5556 |
|
|
|
5557 |
#回傳結果
|
|
|
5558 |
return $result;
|
|
|
5559 |
|
|
|
5560 |
}#if end
|
|
|
5561 |
|
|
|
5562 |
#儲存處理好的問卷樣本csv檔案位置與名稱
|
|
|
5563 |
$result["content"]=$createCsv["content"];
|
|
|
5564 |
|
|
|
5565 |
#執行到這邊代表執行正常
|
|
|
5566 |
$result["status"]="true";
|
|
|
5567 |
|
|
|
5568 |
#回傳結果
|
|
|
5569 |
return $result;
|
|
|
5570 |
|
|
|
5571 |
}#function numSampleToStr end
|
|
|
5572 |
|
|
|
5573 |
}#class analyse end
|
|
|
5574 |
|
|
|
5575 |
?>
|