Subversion Repositories php-qbpwcf

Rev

Rev 226 | Details | Compare with Previous | Last modification | View Log | RSS feed

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