forked from bjrambo/attendance
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattendance.admin.model.php
More file actions
451 lines (420 loc) · 13 KB
/
attendance.admin.model.php
File metadata and controls
451 lines (420 loc) · 13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
<?php
/**
* @class 출석부 모듈의 attendanceAdminModel 클래스
* @author BJRambo ([email protected])
* @관리자가 건드리는 함수 기록
*
*
**/
class attendanceAdminModel extends attendance
{
/**
* @brief 초기화
**/
function init()
{
}
/**
* @brief 회원 목록을 구함
**/
function getAttendanceMemberList($list, $new_type)
{
/*attendance model 객체 생성*/
$oAttendanceModel = getModel('attendance');
// 검색 옵션 정리
$args = new stdClass;
$args->is_admin = Context::get('is_admin')=='Y'?'Y':'';
$args->is_denied = Context::get('is_denied')=='Y'?'Y':'';
$args->selected_group_srl = Context::get('selected_group_srl');
$args->unjoined_members = Context::get('unjoined_members')=='Y'?'Y':'';
$type = $new_type;
if(!$type) $type=Context::get('type');
$args->year = substr(Context::get('selected_date'),0,4);
$args->year_month = substr(Context::get('selected_date'),0,6);
$week = $oAttendanceModel->getWeek(Context::get('selected_date'));
$args->monday = $week->monday;
$args->sunday = $week->sunday;
//날짜정보가 없으면 오늘로 초기화
if(!$args->year)
{
$args->year=zDate(date('YmdHis'),"Y");
}
if(!$args->year_month)
{
$args->year_month=zDate(date('YmdHis'),"Ym");
}
if(!$week->monday || !$week->sunday)
{
$week=$oAttendanceModel->getWeek(zDate(date('YmdHis'),"Ymd"));
$args->monday = $week->monday;
$args->sunday = $week->sunday;
}
$search_target = trim(Context::get('search_target'));
$search_keyword = trim(Context::get('search_keyword'));
if($search_target && $search_keyword)
{
switch($search_target)
{
case 'user_id' :
if($search_keyword) $search_keyword = str_replace(' ','%',$search_keyword);
$args->s_user_id = $search_keyword;
break;
case 'user_name' :
if($search_keyword) $search_keyword = str_replace(' ','%',$search_keyword);
$args->s_user_name = $search_keyword;
break;
case 'nick_name' :
if($search_keyword) $search_keyword = str_replace(' ','%',$search_keyword);
$args->s_nick_name = $search_keyword;
break;
case 'email_address' :
if($search_keyword) $search_keyword = str_replace(' ','%',$search_keyword);
$args->s_email_address = $search_keyword;
break;
case 'regdate' :
$args->s_regdate = preg_replace("/[^0-9]/","",$search_keyword);
break;
case 'regdate_more' :
$args->s_regdate_more = substr(preg_replace("/[^0-9]/","",$search_keyword) . '00000000000000',0,14);
break;
case 'regdate_less' :
$args->s_regdate_less = substr(preg_replace("/[^0-9]/","",$search_keyword) . '00000000000000',0,14);
break;
case 'last_login' :
$args->s_last_login = $search_keyword;
break;
case 'last_login_more' :
$args->s_last_login_more = substr(preg_replace("/[^0-9]/","",$search_keyword) . '00000000000000',0,14);
break;
case 'last_login_less' :
$args->s_last_login_less = substr(preg_replace("/[^0-9]/","",$search_keyword) . '00000000000000',0,14);
break;
case 'extra_vars' :
$args->s_extra_vars = preg_replace("/[^0-9]/","",$search_keyword);
break;
}
}
if($type=='day' || $type=='speed_search')
{
// selected_group_srl이 있으면 query id를 변경 (table join때문에)
if($args->selected_group_srl)
{
$query_id = 'member.getMemberListWithinGroup';
$args->sort_index = "member.member_srl";
$args->sort_order = "desc";
}
else
{
$query_id = 'member.getMemberList';
$args->sort_index = "member_srl";
$args->sort_order = "desc";
}
}
else if($type=='rank_total')
{
// selected_group_srl이 있으면 query id를 변경 (table join때문에)
if($args->selected_group_srl)
{
$query_id = 'attendance.getMemberListWithinGroup';
$args->sort_index = "attendance_total.total";
}
else
{
$query_id = 'attendance.getMemberList';
$args->sort_index = "attendance_total.total";
}
//탈퇴한 회원 정보 찾기 위한 쿼리 수정
if($args->unjoined_members)
{
$query_id = 'attendance.getUnJoinedMemberList';
$args->sort_index = 'attendance_total.total';
}
}
else if($type=='rank_yearly')
{
// selected_group_srl이 있으면 query id를 변경 (table join때문에)
if($args->selected_group_srl)
{
$query_id = 'attendance.getMemberListWithinGroupYearly';
$args->sort_index = "attendance_yearly.yearly";
}
else
{
$query_id = 'attendance.getMemberListYearly';
$args->sort_index = "attendance_yearly.yearly";
}
//탈퇴한 회원 정보 찾기 위한 쿼리 수정
if($args->unjoined_members)
{
$query_id = 'attendance.getUnJoinedMemberListYearly';
$args->sort_index = 'attendance_yearly.yearly';
}
}
else if($type=='rank_monthly')
{
// selected_group_srl이 있으면 query id를 변경 (table join때문에)
if($args->selected_group_srl)
{
$query_id = 'attendance.getMemberListWithinGroupMonthly';
$args->sort_index = "attendance_monthly.monthly";
}
else
{
$query_id = 'attendance.getMemberListMonthly';
$args->sort_index = "attendance_monthly.monthly";
}
//탈퇴한 회원 정보 찾기 위한 쿼리 수정
if($args->unjoined_members)
{
$query_id = 'attendance.getUnJoinedMemberListMonthly';
$args->sort_index = 'attendance_monthly.monthly';
}
}
else if($type=='rank_weekly')
{
// selected_group_srl이 있으면 query id를 변경 (table join때문에)
if($args->selected_group_srl)
{
$query_id = 'attendance.getMemberListWithinGroupWeekly';
$args->sort_index = "attendance_weekly.weekly";
}
else
{
$query_id = 'attendance.getMemberListWeekly';
$args->sort_index = "attendance_weekly.weekly";
}
//탈퇴한 회원 정보 찾기 위한 쿼리 수정
if($args->unjoined_members)
{
$query_id = 'attendance.getUnJoinedMemberListWeekly';
$args->sort_index = 'attendance_weekly.weekly';
}
}
// 기타 변수들 정리
$args->page = Context::get('page');
$args->list_count = $list;
$args->page_count = 10;
return executeQuery($query_id, $args);
}
/**
* @brief 오늘 총 출석인원 계산
**/
function getTodayTotalCount($today){
$arg = new stdClass;
$arg->today = $today;
$output = executeQuery("attendance.getTodayTotalCount",$arg);
return (int)$output->data->count;
}
/**
* @brief 시간대별 계산
**/
function getTodayTimeCount($today_time)
{
$arg = new stdClass;
$arg->today_time = $today_time;
$output = executeQuery("attendance.getTodayTimeCount",$arg);
return (int)$output->data->count;
}
/**
* @brief attendance테이블의 개인데이터 모두 삭제
**/
function deleteAllAttendanceData($member_srl)
{
//등록된 인사말을 모두 지우기 위한 작업
$oAttendanceModel = getModel('attendance');
$oDocumentController = getController('document');
$memberAttendanceInfo = $oAttendanceModel->getGreetingsList($member_srl);
//등록된 인사말 모두 제거
if(!$memberAttendanceInfo->data->greetings)
{
foreach($memberAttendanceInfo->data as $data)
{
if(substr($data->greetings,0,1) == '#')
{
$length = strlen($data->greetings) -1;
$document_srl = substr($data->greetings, 1, $length);
$oDocumentController->deleteDocument($document_srl,true);
}
}
}
$args = new stdClass;
$args->member_srl = $member_srl;
$output = executeQuery("attendance.deleteAllAttendanceData",$args);
}
/**
* @brief attendance_total 테이블의 개인데이터 모두 삭제
**/
function deleteAllAttendanceTotalData($member_srl)
{
$args = new stdClass;
$args->member_srl = $member_srl;
$output = executeQuery("attendance.deleteAllAttendanceTotalData",$args);
}
/**
* @brief attendance_yearly 테이블의 개인데이터 모두 삭제
**/
function deleteAllAttendanceYearlyData($member_srl)
{
$args = new stdClass;
$args->member_srl = $member_srl;
$output = executeQuery("attendance.deleteAllAttendanceYearlyData",$args);
}
/**
* @brief attendance_monthly 테이블의 개인데이터 모두 삭제
**/
function deleteAllAttendanceMonthlyData($member_srl)
{
$args = new stdClass;
$args->member_srl = $member_srl;
$output = executeQuery("attendance.deleteAllAttendanceMonthlyData",$args);
}
/**
* @brief attendance_weekly 테이블의 개인데이터 모두 삭제
**/
function deleteAllAttendanceWeeklyData($member_srl)
{
$args = new stdClass;
$args->member_srl = $member_srl;
$output = executeQuery("attendance.deleteAllAttendanceWeeklyData",$args);
}
/**
* @brief attendance_weekly 테이블의 개인데이터 삭제
**/
function deleteAttendanceWeeklyData($member_srl, $week)
{
$args = new stdClass;
$args->monday = $week->monday;
$args->sunday = $week->sunday;
$args->member_srl = $member_srl;
$output = executeQuery("attendance.deleteAttendanceWeeklyData",$args);
}
/**
* @brief attendance_monthly 테이블의 개인데이터 삭제
**/
function deleteAttendanceMonthlyData($member_srl, $monthly)
{
$args = new stdClass;
$args->monthly = $monthly;
$args->member_srl = $member_srl;
$output = executeQuery("attendance.deleteAttendanceMonthlyData",$args);
}
/**
* @brief attendance_yearly 테이블의 개인데이터 삭제
**/
function deleteAttendanceYearlyData($member_srl, $year)
{
$args = new stdClass;
$args->year = $year;
$args->member_srl = $member_srl;
$output = executeQuery("attendance.deleteAttendanceYearlyData",$args);
}
/**
* @brief 주간 획득포인트 구하는 쿼리
**/
function getWeeklyPoint($member_srl, $week)
{
$args = new stdClass;
$args->member_srl = $member_srl;
$args->monday = $week->monday;
$args->sunday = $week->sunday;
$output = executeQueryArray("attendance.getWeeklyPoint",$args);
if(!$output->data) $output->data = array();
return $output;
}
/**
* @brief 월간 획득포인트 구하는 쿼리
**/
function getMonthlyPoint($member_srl, $monthly)
{
$args = new stdClass;
$args->member_srl = $member_srl;
$args->monthly = $monthly;
$output = executeQueryArray("attendance.getMonthlyPoint",$args);
if(!$output->data) $output->data = array();
return $output;
}
/**
* @brief 연간 획득포인트 구하는 쿼리
**/
function getYearlyPoint($member_srl, $year)
{
$args = new stdClass;
$args->member_srl = $member_srl;
$args->year = $year;
$output = executeQueryArray("attendance.getYearlyPoint",$args);
if(!$output->data) $output->data = array();
return $output;
}
/**
* @brief 총 출석포인트 구하는 쿼리(연간 획득포인트 쿼리 이용)
**/
function getTotalPoint($member_srl)
{
$args = new stdClass;
$args->member_srl = $member_srl;
$output = executeQueryArray("attendance.getYearlyPoint",$args);
if(!$output->data) $output->data = array();
return $output;
}
/**
* @brief 중복 출석정보 구하는 쿼리
**/
function getDuplicatedData($member_srl,$selected_date)
{
$args = new stdClass;
$args->member_srl = $member_srl;
$args->selected_date = $selected_date;
$output = executeQueryArray("attendance.getDuplicatedData",$args);
if(!$output->data) $output->data = array();
return $output;
}
/**
* @brief attendance 테이블의 중복출석데이터 삭제(deleteAllAttendanceData 쿼리 이용)
**/
function deleteDuplicatedData($member_srl, $selected_date)
{
$args = new stdClass;
$args->member_srl = $member_srl;
$args->selected_date = $selected_date;
$output = executeQuery("attendance.deleteAllAttendanceData",$args);
return $output;
}
/**
* @brief 연/월/주간 출석정보 fix
**/
function fixYearMonthWeek($obj)
{
$oAttendanceModel = getModel('attendance');
$oAttendanceAdminModel = getAdminModel('attendance');
$year = substr($obj->selected_date,0,4);
$oAttendanceAdminModel->deleteAttendanceYearlyData($obj->member_srl, $year);
$points = $oAttendanceAdminModel->getWeeklyPoint($obj->member_srl, $year);
$sum=0;
foreach($points->data as $val)
{
$sum+=$val->today_point;
}
$attendance = $oAttendanceModel->getYearlyData($year,$obj->member_srl);
$oAttendanceModel->insertYearly($obj->member_srl, $attendance, $sum, $obj->selected_date.'000000');
$monthly = substr($obj->selected_date,0,6);
$oAttendanceAdminModel->deleteAttendanceMonthlyData($obj->member_srl, $monthly);
$points = $oAttendanceAdminModel->getMonthlyPoint($obj->member_srl, $monthly);
$sum=0;
foreach($points->data as $val)
{
$sum+=$val->today_point;
}
$attendance = $oAttendanceModel->getMonthlyData($monthly,$obj->member_srl);
$oAttendanceModel->insertMonthly($obj->member_srl, $attendance, $sum, $obj->selected_date.'000000');
$week = $oAttendanceModel->getWeek($obj->selected_date);
$oAttendanceAdminModel->deleteAttendanceWeeklyData($obj->member_srl, $week);
$points = $oAttendanceAdminModel->getWeeklyPoint($obj->member_srl, $week);
$sum=0;
foreach($points->data as $val)
{
$sum+=$val->today_point;
}
$attendance = $oAttendanceModel->getWeeklyAttendance($obj->member_srl, $week);
$oAttendanceModel->insertWeekly($obj->member_srl, $attendance, $sum, $obj->selected_date.'000000');
}
}