Subversion Repositories php-qbpwcf

Rev

Rev 3 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3 Rev 226
Line 1... Line 1...
1
<?php
1
<?php
2
 
2
 
3
/*
3
/*
4
 
4
 
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
6
    Copyright (C) 2015~2025 Min-Jhin,Chen
6
    Copyright (C) 2014~2025 MIN ZHI, CHEN
7
 
7
 
8
    This file is part of QBPWCF.
8
    This file is part of QBPWCF.
9
 
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
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
11
    it under the terms of the GNU General Public License as published by
Line 28... Line 28...
28
跟考試應用相關的類別.
28
跟考試應用相關的類別.
29
備註:
29
備註:
30
無.
30
無.
31
*/
31
*/
32
class exam{
32
class exam{
33
	
33
 
34
	/*
34
	/*
35
	#函式說明:
35
	#函式說明:
36
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
36
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
37
	#回傳結果:
37
	#回傳結果:
38
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
38
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 43... Line 43...
43
	#$arguments,陣列,為呼叫方法時所用的參數.
43
	#$arguments,陣列,為呼叫方法時所用的參數.
44
	#參考資料:
44
	#參考資料:
45
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
45
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
46
	*/
46
	*/
47
	public function __call($method,$arguments){
47
	public function __call($method,$arguments){
48
		
48
 
49
		#取得當前執行的函式
49
		#取得當前執行的函式
50
		$result["function"]=__FUNCTION__;
50
		$result["function"]=__FUNCTION__;
51
		
51
 
52
		#設置執行不正常
52
		#設置執行不正常
53
		$result["status"]="false";
53
		$result["status"]="false";
54
		
54
 
55
		#設置執行錯誤
55
		#設置執行錯誤
56
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
56
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
57
		
57
 
58
		#設置所丟入的參數
58
		#設置所丟入的參數
59
		$result["error"][]=$arguments;
59
		$result["error"][]=$arguments;
60
		
60
 
61
		#回傳結果
61
		#回傳結果
62
		return $result;
62
		return $result;
63
		
63
 
64
		}#function __call end
64
		}#function __call end
65
		
65
 
66
	/*
66
	/*
67
	#函式說明:
67
	#函式說明:
68
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
68
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
69
	#回傳結果:
69
	#回傳結果:
70
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
70
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 75... Line 75...
75
	#$arguments,陣列,為呼叫方法時所用的參數.
75
	#$arguments,陣列,為呼叫方法時所用的參數.
76
	#參考資料:
76
	#參考資料:
77
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
77
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
78
	*/
78
	*/
79
	public static function __callStatic($method,$arguments){
79
	public static function __callStatic($method,$arguments){
80
		
80
 
81
		#取得當前執行的函式
81
		#取得當前執行的函式
82
		$result["function"]=__FUNCTION__;
82
		$result["function"]=__FUNCTION__;
83
		
83
 
84
		#設置執行不正常
84
		#設置執行不正常
85
		$result["status"]="false";
85
		$result["status"]="false";
86
		
86
 
87
		#設置執行錯誤
87
		#設置執行錯誤
88
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
88
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
89
		
89
 
90
		#設置所丟入的參數
90
		#設置所丟入的參數
91
		$result["error"][]=$arguments;
91
		$result["error"][]=$arguments;
92
		
92
 
93
		#回傳結果
93
		#回傳結果
94
		return $result;
94
		return $result;
95
		
95
 
96
		}#function __callStatic end
96
		}#function __callStatic end
97
	
97
 
98
	/*
98
	/*
99
	#函式說明:
99
	#函式說明:
100
	#根據座位表csv檔與坐者csv檔來隨機安排座位,並自動下載安排好的座位表csv檔.
100
	#根據座位表csv檔與坐者csv檔來隨機安排座位,並自動下載安排好的座位表csv檔.
101
	#回傳結果:
101
	#回傳結果:
102
	#$result["status"],執行正常與否,"true"為正常,"false"為不正常.
102
	#$result["status"],執行正常與否,"true"為正常,"false"為不正常.
Line 107... Line 107...
107
	#$conf["seaterList"],字串,坐者的csv檔位置與名稱,單攔,每一列為坐者的代稱.
107
	#$conf["seaterList"],字串,坐者的csv檔位置與名稱,單攔,每一列為坐者的代稱.
108
	$conf["seaterList"]="";
108
	$conf["seaterList"]="";
109
	#$conf["seatMap"],字串,座位表示意csv檔位置與名稱,格子內容為0代表非座位,1為座位.
109
	#$conf["seatMap"],字串,座位表示意csv檔位置與名稱,格子內容為0代表非座位,1為座位.
110
	$conf["seatMap"]="";
110
	$conf["seatMap"]="";
111
	#$conf["outputAddress"],字串,csv檔要輸出到哪邊,不用加csv副檔名.
111
	#$conf["outputAddress"],字串,csv檔要輸出到哪邊,不用加csv副檔名.
112
	$conf["outputAddress"]="";		
112
	$conf["outputAddress"]="";
113
	#$conf["fileArgu"],字串,__FILE__的內容.
113
	#$conf["fileArgu"],字串,__FILE__的內容.
114
	$conf["fileArgu"]=__FILE__;
114
	$conf["fileArgu"]=__FILE__;
115
	#可省略參數:
115
	#可省略參數:
116
	#$conf["emptySeatName"],字串,要空下來的座位,其代稱要用什麼?預設為empty.
116
	#$conf["emptySeatName"],字串,要空下來的座位,其代稱要用什麼?預設為empty.
117
	#$conf["emptySeatName"]="empty";
117
	#$conf["emptySeatName"]="empty";
Line 123... Line 123...
123
	#無.
123
	#無.
124
	#備註:
124
	#備註:
125
	#無.
125
	#無.
126
	*/
126
	*/
127
	public static function randomSeater(&$conf){
127
	public static function randomSeater(&$conf){
128
		
128
 
129
		#初始化要回傳的內容
129
		#初始化要回傳的內容
130
		$result=array();
130
		$result=array();
131
 
131
 
132
		#取得當前執行的函數名稱
132
		#取得當前執行的函數名稱
133
		$result["function"]=__FUNCTION__;
133
		$result["function"]=__FUNCTION__;
134
 
134
 
135
		#如果 $conf 不為陣列
135
		#如果 $conf 不為陣列
136
		if(gettype($conf)!="array"){
136
		if(gettype($conf)!="array"){
137
			
137
 
138
			#設置執行失敗
138
			#設置執行失敗
139
			$result["status"]="false";
139
			$result["status"]="false";
140
			
140
 
141
			#設置執行錯誤訊息
141
			#設置執行錯誤訊息
142
			$result["error"][]="\$conf變數須為陣列形態";
142
			$result["error"][]="\$conf變數須為陣列形態";
143
 
143
 
144
			#如果傳入的參數為 null
144
			#如果傳入的參數為 null
145
			if($conf==null){
145
			if($conf==null){
146
				
146
 
147
				#設置執行錯誤訊息
147
				#設置執行錯誤訊息
148
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
148
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
149
				
149
 
150
				}#if end
150
				}#if end
151
 
151
 
152
			#回傳結果
152
			#回傳結果
153
			return $result;
153
			return $result;
154
			
154
 
155
			}#if end
155
			}#if end
156
		
156
 
157
		#檢查參數
157
		#檢查參數
158
		#函式說明:
158
		#函式說明:
159
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
159
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
160
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
160
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
161
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
161
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
Line 170... Line 170...
170
		#必填寫的參數:
170
		#必填寫的參數:
171
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
171
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
172
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
172
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
173
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
173
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
174
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("seaterList","seatMap","outputAddress","fileArgu");
174
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("seaterList","seatMap","outputAddress","fileArgu");
175
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double"); 
175
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
176
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string");
176
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string");
177
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
177
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
178
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
178
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
179
		#可以省略的參數:
179
		#可以省略的參數:
180
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
180
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
181
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
181
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
182
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
182
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
183
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("emptySeatName","noDownload","repeat");
183
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("emptySeatName","noDownload","repeat");
184
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
184
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
185
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
185
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
186
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
186
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
187
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("empty","true","false");
187
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("empty","true","false");
188
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
188
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
189
		#$conf["arrayCountEqualCheck"][]=array();
189
		#$conf["arrayCountEqualCheck"][]=array();
190
		#參考資料來源:
190
		#參考資料來源:
191
		#array_keys=>http://php.net/manual/en/function.array-keys.php
191
		#array_keys=>http://php.net/manual/en/function.array-keys.php
192
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
192
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
193
		unset($conf["variableCheck::checkArguments"]);
193
		unset($conf["variableCheck::checkArguments"]);
194
		
194
 
195
		#如果 $checkResult["status"] 等於 "false"
195
		#如果 $checkResult["status"] 等於 "false"
196
		if($checkResult["status"]=="false"){
196
		if($checkResult["status"]=="false"){
197
			
197
 
198
			#設置執行錯誤
198
			#設置執行錯誤
199
			$result["status"]="false";
199
			$result["status"]="false";
200
			
200
 
201
			#設置錯誤訊息
201
			#設置錯誤訊息
202
			$result["error"]=$checkResult;
202
			$result["error"]=$checkResult;
203
			
203
 
204
			#回傳結果
204
			#回傳結果
205
			return $result;
205
			return $result;
206
			
206
 
207
			}#if end
207
			}#if end
208
			
208
 
209
		#如果 $checkResult["passed"] 等於 "false"
209
		#如果 $checkResult["passed"] 等於 "false"
210
		if($checkResult["passed"]=="false"){
210
		if($checkResult["passed"]=="false"){
211
			
211
 
212
			#設置執行錯誤
212
			#設置執行錯誤
213
			$result["status"]="false";
213
			$result["status"]="false";
214
			
214
 
215
			#設置錯誤訊息
215
			#設置錯誤訊息
216
			$result["error"]=$checkResult;
216
			$result["error"]=$checkResult;
217
			
217
 
218
			#回傳結果
218
			#回傳結果
219
			return $result;
219
			return $result;
220
			
220
 
221
			}#if end
221
			}#if end
222
						
222
 
223
		#讀座位表csv檔
223
		#讀座位表csv檔
224
		#涵式說明:
224
		#涵式說明:
225
		#讀取csv檔案的內容
225
		#讀取csv檔案的內容
226
		#回傳得結果:
226
		#回傳得結果:
227
		#$result["status"],執行是否正常,"true"代表正常;"false"代表不正常.
227
		#$result["status"],執行是否正常,"true"代表正常;"false"代表不正常.
Line 240... Line 240...
240
		#http://www.php.net/manual/en/function.str-split.php
240
		#http://www.php.net/manual/en/function.str-split.php
241
		#參考資料來源
241
		#參考資料來源
242
		#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)
242
		#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)
243
		$seatMap=csv::loadCsvFile($conf["csv"]["loadCsvFile"]);
243
		$seatMap=csv::loadCsvFile($conf["csv"]["loadCsvFile"]);
244
		unset($conf["csv"]["loadCsvFile"]);
244
		unset($conf["csv"]["loadCsvFile"]);
245
		
245
 
246
		#如果 $seatMap["status"] 等於 "false"
246
		#如果 $seatMap["status"] 等於 "false"
247
		if($seatMap["status"]=="false"){
247
		if($seatMap["status"]=="false"){
248
 
248
 
249
			#設置執行錯誤
249
			#設置執行錯誤
250
			$result["status"]="false";
250
			$result["status"]="false";
251
			
251
 
252
			#設置錯誤訊息
252
			#設置錯誤訊息
253
			$result["error"]=$seatMap;
253
			$result["error"]=$seatMap;
254
			
254
 
255
			#回傳結果
255
			#回傳結果
256
			return $result;
256
			return $result;
257
			
257
 
258
			}#if end
258
			}#if end
259
			
259
 
260
		#讀取坐者csv檔
260
		#讀取坐者csv檔
261
		#涵式說明:
261
		#涵式說明:
262
		#讀取csv檔案的內容
262
		#讀取csv檔案的內容
263
		#回傳得結果:
263
		#回傳得結果:
264
		#$result["status"],執行是否正常,"true"代表正常;"false"代表不正常.
264
		#$result["status"],執行是否正常,"true"代表正常;"false"代表不正常.
Line 277... Line 277...
277
		#http://www.php.net/manual/en/function.str-split.php
277
		#http://www.php.net/manual/en/function.str-split.php
278
		#參考資料來源
278
		#參考資料來源
279
		#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)
279
		#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)
280
		$seaterList=csv::loadCsvFile($conf["csv"]["loadCsvFile"]);
280
		$seaterList=csv::loadCsvFile($conf["csv"]["loadCsvFile"]);
281
		unset($conf["csv"]["loadCsvFile"]);
281
		unset($conf["csv"]["loadCsvFile"]);
282
		
282
 
283
		#如果 $seaterList["status"] 等於 "false"
283
		#如果 $seaterList["status"] 等於 "false"
284
		if($seaterList["status"]=="false"){
284
		if($seaterList["status"]=="false"){
285
 
285
 
286
			#設置執行錯誤
286
			#設置執行錯誤
287
			$result["status"]="false";
287
			$result["status"]="false";
288
			
288
 
289
			#設置錯誤訊息
289
			#設置錯誤訊息
290
			$result["error"]=$seaterList;
290
			$result["error"]=$seaterList;
291
			
291
 
292
			#回傳結果
292
			#回傳結果
293
			return $result;
293
			return $result;
294
			
294
 
295
			}#if end
295
			}#if end
296
			
296
 
297
		#取得坐者的數量
297
		#取得坐者的數量
298
		$seaterCount=$seaterList["lineArrayCount"];
298
		$seaterCount=$seaterList["lineArrayCount"];
299
		
299
 
300
		#取得座位表的空位數
300
		#取得座位表的空位數
301
		#函式說明:
301
		#函式說明:
302
		#計屬csv檔裡面的關鍵字.
302
		#計屬csv檔裡面的關鍵字.
303
		#回傳的結果:
303
		#回傳的結果:
304
		#$result["status"],執行正常與否,"true"為正常,"false"為不正常.
304
		#$result["status"],執行正常與否,"true"為正常,"false"為不正常.
Line 308... Line 308...
308
		#$conf["csvFileAddress"],字串,csv檔案的位置與名稱.
308
		#$conf["csvFileAddress"],字串,csv檔案的位置與名稱.
309
		$conf["csv"]["keyWordsCount"]["csvFileAddress"]=$conf["seatMap"];
309
		$conf["csv"]["keyWordsCount"]["csvFileAddress"]=$conf["seatMap"];
310
		#$conf["keyWord"],字串,要尋找的關鍵字.
310
		#$conf["keyWord"],字串,要尋找的關鍵字.
311
		$conf["csv"]["keyWordsCount"]["keyWord"]="1";
311
		$conf["csv"]["keyWordsCount"]["keyWord"]="1";
312
		$conf["csv"]["keyWordsCount"]["fileArgu"]=$conf["fileArgu"];
312
		$conf["csv"]["keyWordsCount"]["fileArgu"]=$conf["fileArgu"];
313
		#可省略的參數: 
313
		#可省略的參數:
314
		$conf["csv"]["keyWordsCount"]["firstLineVarName"]="false";#第一行是否爲變數名稱(各個欄位的名稱),"true"表示第一列不在搜尋範圍裡.
314
		$conf["csv"]["keyWordsCount"]["firstLineVarName"]="false";#第一行是否爲變數名稱(各個欄位的名稱),"true"表示第一列不在搜尋範圍裡.
315
		$seatCount=csv::keyWordsCount($conf["csv"]["keyWordsCount"]);
315
		$seatCount=csv::keyWordsCount($conf["csv"]["keyWordsCount"]);
316
		unset($conf["csv"]["keyWordsCount"]);
316
		unset($conf["csv"]["keyWordsCount"]);
317
		
317
 
318
		#如果 $seatCount["status"] 等於 "false" 
318
		#如果 $seatCount["status"] 等於 "false"
319
		if($seatCount["status"]=="false"){
319
		if($seatCount["status"]=="false"){
320
			
320
 
321
			#設置執行錯誤
321
			#設置執行錯誤
322
			$result["status"]="false";
322
			$result["status"]="false";
323
			
323
 
324
			#設置錯誤訊息
324
			#設置錯誤訊息
325
			$result["error"]=$seatCount;
325
			$result["error"]=$seatCount;
326
			
326
 
327
			#回傳結果
327
			#回傳結果
328
			return $result;
328
			return $result;
329
			
329
 
330
			}#if end
330
			}#if end
331
			
331
 
332
		#如果空座位數小於坐者
332
		#如果空座位數小於坐者
333
		if($seatCount["content"]<$seaterCount){
333
		if($seatCount["content"]<$seaterCount){
334
			
334
 
335
			#設置執行錯誤
335
			#設置執行錯誤
336
			$result["status"]="false";
336
			$result["status"]="false";
337
			
337
 
338
			#設置錯誤訊息
338
			#設置錯誤訊息
339
			$result["error"][]="座位數量不足,至少需要".$seaterCount."個座位";
339
			$result["error"][]="座位數量不足,至少需要".$seaterCount."個座位";
340
			
340
 
341
			#回傳結果
341
			#回傳結果
342
			return $result;
342
			return $result;
343
			
343
 
344
			}#if end
344
			}#if end
345
			
345
 
346
		#初始化儲存坐者清單的一維陣列
346
		#初始化儲存坐者清單的一維陣列
347
		$seaterListArray=array();
347
		$seaterListArray=array();
348
		
348
 
349
		#根據坐者csv檔清單裡每列內容
349
		#根據坐者csv檔清單裡每列內容
350
		foreach($seaterList["csvFileContent"] as $row){
350
		foreach($seaterList["csvFileContent"] as $row){
351
			
351
 
352
			#根據每列的欄元素
352
			#根據每列的欄元素
353
			foreach($row as $col){
353
			foreach($row as $col){
354
			
354
 
355
				#取得每個元素內容
355
				#取得每個元素內容
356
				$seaterListArray[]=$col;
356
				$seaterListArray[]=$col;
357
			
357
 
358
				}#foreach end
358
				}#foreach end
359
			
359
 
360
			}#foreach end
360
			}#foreach end
361
		
361
 
362
		#取得座位表跟坐者的差
362
		#取得座位表跟坐者的差
363
		$range=$seatCount["content"]-$seaterCount;	
363
		$range=$seatCount["content"]-$seaterCount;
364
			
364
 
365
		#將坐者清單加上代表沒人坐的名單,讓其數量跟座位數一樣
365
		#將坐者清單加上代表沒人坐的名單,讓其數量跟座位數一樣
366
		#缺幾個名單就執行幾次
366
		#缺幾個名單就執行幾次
367
		for($i=0;$i<$range;$i++){
367
		for($i=0;$i<$range;$i++){
368
			
368
 
369
			#將沒有要坐的名稱設為$conf["emptySeatName"]
369
			#將沒有要坐的名稱設為$conf["emptySeatName"]
370
			$seaterListArray[]=$conf["emptySeatName"];
370
			$seaterListArray[]=$conf["emptySeatName"];
371
			
371
 
372
			}#for end
372
			}#for end
373
		
373
 
374
		#根據座位表csv檔裡每列內容
374
		#根據座位表csv檔裡每列內容
375
		foreach($seatMap["csvFileContent"] as $rowKey=>$rowValue){
375
		foreach($seatMap["csvFileContent"] as $rowKey=>$rowValue){
376
			
376
 
377
			#根據每列的欄元素
377
			#根據每列的欄元素
378
			foreach($rowValue as $colKey=>$colValue){
378
			foreach($rowValue as $colKey=>$colValue){
379
				
379
 
380
				#初始化沒有上一位坐者
380
				#初始化沒有上一位坐者
381
				$lastSeat=null;
381
				$lastSeat=null;
382
				
382
 
383
				#如果該地方是座位(等於1)
383
				#如果該地方是座位(等於1)
384
				if($colValue=="1"){
384
				if($colValue=="1"){
385
					
385
 
386
					#隨機安排坐者						
386
					#隨機安排坐者
387
					#函式說明: 
387
					#函式說明:
388
					#亂數產生特定陣列裡面的內容
388
					#亂數產生特定陣列裡面的內容
389
					#回傳的結果:
389
					#回傳的結果:
390
					#$result["status"],執行正常與否,"true"為正常,"false"為不正常.
390
					#$result["status"],執行正常與否,"true"為正常,"false"為不正常.
391
					#$result["error"],錯誤訊息陣列.
391
					#$result["error"],錯誤訊息陣列.
392
					#$result["content"]["name"],產生的元素在$conf["randomArray"]裡面的key是?
392
					#$result["content"]["name"],產生的元素在$conf["randomArray"]裡面的key是?
Line 396... Line 396...
396
					$conf["math"]["randomFromArray"]["randomArray"]=$seaterListArray;
396
					$conf["math"]["randomFromArray"]["randomArray"]=$seaterListArray;
397
					#可省略參數:
397
					#可省略參數:
398
					#無
398
					#無
399
					$randomResult=math::randomFromArray($conf["math"]["randomFromArray"]);
399
					$randomResult=math::randomFromArray($conf["math"]["randomFromArray"]);
400
					unset($conf["math"]["randomFromArray"]);
400
					unset($conf["math"]["randomFromArray"]);
401
					
401
 
402
					#如果 $randomResult["status"] 等於 "false" 
402
					#如果 $randomResult["status"] 等於 "false"
403
					if($randomResult["status"]=="false"){
403
					if($randomResult["status"]=="false"){
404
						
404
 
405
						#設置執行錯誤
405
						#設置執行錯誤
406
						$result["status"]="false";
406
						$result["status"]="false";
407
						
407
 
408
						#設置錯誤訊息
408
						#設置錯誤訊息
409
						$result["error"]=$randomResult;
409
						$result["error"]=$randomResult;
410
						
410
 
411
						#回傳結果
411
						#回傳結果
412
						return $result;
412
						return $result;
413
						
413
 
414
						}#if end
414
						}#if end
415
					
415
 
416
					#如果座位不能重複
416
					#如果座位不能重複
417
					if($conf["repeat"]=="false"){
417
					if($conf["repeat"]=="false"){
418
						
418
 
419
						#如果上一位坐者不為 null
419
						#如果上一位坐者不為 null
420
						if($lastSeat!=null){
420
						if($lastSeat!=null){
421
							
421
 
422
							#如果抽出來的坐者是連續的
422
							#如果抽出來的坐者是連續的
423
							while($randomResult["content"]["value"]==$lastSeat){
423
							while($randomResult["content"]["value"]==$lastSeat){
424
								
424
 
425
								#若這是最後一個坐者了
425
								#若這是最後一個坐者了
426
								if(count($seaterListArray)==1){
426
								if(count($seaterListArray)==1){
427
									
427
 
428
									#跳出
428
									#跳出
429
									break;
429
									break;
430
									
430
 
431
									}#if end
431
									}#if end
432
								
432
 
433
								#初始化是否要繼續執行的辨別變數
433
								#初始化是否要繼續執行的辨別變數
434
								$continue="false";
434
								$continue="false";
435
								
435
 
436
								#若剩下坐者全部跟 $lastSeat(上一個坐者) 一樣
436
								#若剩下坐者全部跟 $lastSeat(上一個坐者) 一樣
437
								foreach($seaterListArray as $seaterName){
437
								foreach($seaterListArray as $seaterName){
438
									
438
 
439
									#如果剩下的坐者有跟 $lastSeat(上一個坐者) 不一樣
439
									#如果剩下的坐者有跟 $lastSeat(上一個坐者) 不一樣
440
									if($seaterName!=$lastSeat){
440
									if($seaterName!=$lastSeat){
441
										
441
 
442
										#設置繼續執行
442
										#設置繼續執行
443
										$continue="true";
443
										$continue="true";
444
										
444
 
445
										#跳出 foreach
445
										#跳出 foreach
446
										break;
446
										break;
447
										
447
 
448
										}#if end
448
										}#if end
449
									
449
 
450
									}#foreach end
450
									}#foreach end
451
									
451
 
452
								#如果不繼續執行
452
								#如果不繼續執行
453
								if($continue=="false"){
453
								if($continue=="false"){
454
									
454
 
455
									#跳出 while
455
									#跳出 while
456
									break;
456
									break;
457
									
457
 
458
									}#if end
458
									}#if end
459
								
459
 
460
								#隨機安排坐者						
460
								#隨機安排坐者
461
								#函式說明: 
461
								#函式說明:
462
								#亂數產生特定陣列裡面的內容
462
								#亂數產生特定陣列裡面的內容
463
								#回傳的結果:
463
								#回傳的結果:
464
								#$result["status"],執行正常與否,"true"為正常,"false"為不正常.
464
								#$result["status"],執行正常與否,"true"為正常,"false"為不正常.
465
								#$result["error"],錯誤訊息陣列.
465
								#$result["error"],錯誤訊息陣列.
466
								#$result["content"]["name"],產生的元素在$conf["randomArray"]裡面的key是?
466
								#$result["content"]["name"],產生的元素在$conf["randomArray"]裡面的key是?
Line 470... Line 470...
470
								$conf["math"]["randomFromArray"]["randomArray"]=$seaterListArray;
470
								$conf["math"]["randomFromArray"]["randomArray"]=$seaterListArray;
471
								#可省略參數:
471
								#可省略參數:
472
								#無
472
								#無
473
								$randomResult=math::randomFromArray($conf["math"]["randomFromArray"]);
473
								$randomResult=math::randomFromArray($conf["math"]["randomFromArray"]);
474
								unset($conf["math"]["randomFromArray"]);
474
								unset($conf["math"]["randomFromArray"]);
475
								
475
 
476
								#如果 $randomResult["status"] 等於 "false" 
476
								#如果 $randomResult["status"] 等於 "false"
477
								if($randomResult["status"]=="false"){
477
								if($randomResult["status"]=="false"){
478
									
478
 
479
									#設置執行錯誤
479
									#設置執行錯誤
480
									$result["status"]="false";
480
									$result["status"]="false";
481
									
481
 
482
									#設置錯誤訊息
482
									#設置錯誤訊息
483
									$result["error"]=$randomResult;
483
									$result["error"]=$randomResult;
484
									
484
 
485
									#回傳結果
485
									#回傳結果
486
									return $result;
486
									return $result;
487
									
487
 
488
									}#if end
488
									}#if end
489
								
489
 
490
								}#while end
490
								}#while end
491
							
491
 
492
							}#if end
492
							}#if end
493
						
493
 
494
						}#if end
494
						}#if end
495
											
495
 
496
					#將其欄位內容置換為坐者代稱
496
					#將其欄位內容置換為坐者代稱
497
					$seatMap["csvFileContent"][$rowKey][$colKey]=$randomResult["content"]["value"];
497
					$seatMap["csvFileContent"][$rowKey][$colKey]=$randomResult["content"]["value"];
498
					
498
 
499
					#涵式說明:
499
					#涵式說明:
500
					#將陣列中特定元素剔除,並重新按照順序排序
500
					#將陣列中特定元素剔除,並重新按照順序排序
501
					#回傳的結果:
501
					#回傳的結果:
502
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
502
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
503
					#$result["error"],錯誤訊息
503
					#$result["error"],錯誤訊息
504
					#$result["function"],當前執行的函數
504
					#$result["function"],當前執行的函數
505
					#$result["content"]["byName"],剔除掉特定元素的陣列,使用原來陣列的key來儲存.
505
					#$result["content"]["byName"],剔除掉特定元素的陣列,使用原來陣列的key來儲存.
506
					#$result["content"]["byNumber"],剔除掉特定元素的陣列,使用從0開始的整數key來儲存.
506
					#$result["content"]["byNumber"],剔除掉特定元素的陣列,使用從0開始的整數key來儲存.
507
					#必填的參數:
507
					#必填的參數:
508
					$conf["arrays"]["eraseElement"]["rawInputArray"]=$seaterListArray;#要處理的原始數字陣列
508
					$conf["arrays"]["eraseElement"]["rawInputArray"]=$seaterListArray;#要處理的原始數字陣列
509
					$conf["arrays"]["eraseElement"]["eraseElementKey"]=(string)$randomResult["content"]["key"];#要移除的元素key值  
509
					$conf["arrays"]["eraseElement"]["eraseElementKey"]=(string)$randomResult["content"]["key"];#要移除的元素key值
510
					$eraseElement=arrays::eraseElement($conf["arrays"]["eraseElement"]);
510
					$eraseElement=arrays::eraseElement($conf["arrays"]["eraseElement"]);
511
					unset($conf["arrays"]["eraseElement"]);
511
					unset($conf["arrays"]["eraseElement"]);
512
					
512
 
513
					#如果移除元素失敗
513
					#如果移除元素失敗
514
					if($eraseElement["status"]=="false"){
514
					if($eraseElement["status"]=="false"){
515
						
515
 
516
						#設置執行錯誤
516
						#設置執行錯誤
517
						$result["status"]="false";
517
						$result["status"]="false";
518
						
518
 
519
						#設置錯誤訊息
519
						#設置錯誤訊息
520
						$result["error"]=$eraseElement;
520
						$result["error"]=$eraseElement;
521
						
521
 
522
						#回傳結果
522
						#回傳結果
523
						return $result;
523
						return $result;
524
						
524
 
525
						}#if end
525
						}#if end
526
					
526
 
527
					}#if end
527
					}#if end
528
					
528
 
529
				#反之為 0(不是位置)
529
				#反之為 0(不是位置)
530
				else{
530
				else{
531
					
531
 
532
					#設為沒有上一位坐者
532
					#設為沒有上一位坐者
533
					$lastSeat=null;
533
					$lastSeat=null;
534
					
534
 
535
					}#else end
535
					}#else end
536
				
536
 
537
				}#foreach end
537
				}#foreach end
538
					
538
 
539
			}#foreach end
539
			}#foreach end
540
	
540
 
541
		#輸出排好的座位表csv檔
541
		#輸出排好的座位表csv檔
542
		#涵式說明:
542
		#涵式說明:
543
		#快速建立一個csv檔案,並且要求使用者下載。
543
		#快速建立一個csv檔案,並且要求使用者下載。
544
		#回傳的結果:
544
		#回傳的結果:
545
		#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
545
		#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
Line 551... Line 551...
551
			#$conf["dataArray"][$i],代表第 $i 行的內容,
551
			#$conf["dataArray"][$i],代表第 $i 行的內容,
552
			#$conf["dataArray"][$i][$j],代表第 $i 第 $j個欄位的內容.
552
			#$conf["dataArray"][$i][$j],代表第 $i 第 $j個欄位的內容.
553
		$conf["csv"]["create"]["fileArgu"]=$conf["fileArgu"];
553
		$conf["csv"]["create"]["fileArgu"]=$conf["fileArgu"];
554
		#可省略的參數:
554
		#可省略的參數:
555
		$conf["csv"]["create"]["csvFilePathAndName"]=$conf["outputAddress"];#輸出的csv檔案路徑與名稱,預設爲系統時間,副檔名"csv"會自動加上.
555
		$conf["csv"]["create"]["csvFilePathAndName"]=$conf["outputAddress"];#輸出的csv檔案路徑與名稱,預設爲系統時間,副檔名"csv"會自動加上.
556
		
556
 
557
		#如果 $conf["noDownload"] 存在
557
		#如果 $conf["noDownload"] 存在
558
		if(isset($conf["noDownload"])){
558
		if(isset($conf["noDownload"])){
559
			
559
 
560
			#如果 $conf["noDownload"] 等於 "true"
560
			#如果 $conf["noDownload"] 等於 "true"
561
			if($conf["noDownload"]=="true"){
561
			if($conf["noDownload"]=="true"){
562
				
562
 
563
				#設為 "true"
563
				#設為 "true"
564
				$conf["csv"]["create"]["noDownload"]="true";
564
				$conf["csv"]["create"]["noDownload"]="true";
565
				
565
 
566
				}#if end
566
				}#if end
567
			
567
 
568
			}#if end
568
			}#if end
569
		
569
 
570
		#參考資料來源:
570
		#參考資料來源:
571
		#http://php.net/manual/en/function.str-split.php
571
		#http://php.net/manual/en/function.str-split.php
572
		$createCsvResult=csv::create($conf["csv"]["create"]);
572
		$createCsvResult=csv::create($conf["csv"]["create"]);
573
		unset($conf["csv"]["create"]);
573
		unset($conf["csv"]["create"]);
574
			
574
 
575
		#如果 $createCsvResult["status"] 等於 "false"
575
		#如果 $createCsvResult["status"] 等於 "false"
576
		if($createCsvResult["status"]=="false"){
576
		if($createCsvResult["status"]=="false"){
577
			
577
 
578
			#設置執行錯誤
578
			#設置執行錯誤
579
			$result["status"]="false";
579
			$result["status"]="false";
580
			
580
 
581
			#設置錯誤訊息
581
			#設置錯誤訊息
582
			$result["error"]=$createCsvResult;
582
			$result["error"]=$createCsvResult;
583
			
583
 
584
			#回傳結果
584
			#回傳結果
585
			return $result;
585
			return $result;
586
			
586
 
587
			}#if end
587
			}#if end
588
			
588
 
589
		#設置執行正常
589
		#設置執行正常
590
		$result["status"]="true";
590
		$result["status"]="true";
591
		
591
 
592
		#設置建立的csv檔案位置
592
		#設置建立的csv檔案位置
593
		$result["content"]=$createCsvResult["content"];
593
		$result["content"]=$createCsvResult["content"];
594
		
594
 
595
		#回傳結果
595
		#回傳結果
596
		return $result;
596
		return $result;
597
								
597
 
598
		}#funtion randomSeater end
598
		}#funtion randomSeater end
599
	
599
 
600
	}#class exam end
600
	}#class exam end
601
 
601
 
602
?>
602
?>