-
Notifications
You must be signed in to change notification settings - Fork 0
/
experience.model.php
256 lines (221 loc) · 5.32 KB
/
experience.model.php
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
<?php
/**
* @class experienceModel
* @author CONORY (http://www.conory.com)
* @brief The model class fo the experience module
**/
class experienceModel extends experience
{
protected $experienceList = array();
/**
* @brief Initialization
*/
function init()
{
}
/**
* @brief 모듈설정
**/
function getModuleConfig()
{
return $this->getConfig();
}
/**
* @brief 경험치 정보 존재확인
*/
function isExistsExperience($member_srl)
{
$member_srl = abs($member_srl);
if ($this->experienceList[$member_srl])
{
return true;
}
$args = new stdClass;
$args->member_srl = $member_srl;
$output = executeQuery('experience.getExperience', $args);
if ($output->data->member_srl == $member_srl)
{
if (!$this->experienceList[$member_srl])
{
$this->experienceList[$member_srl] = (int)$output->data->experience;
}
return true;
}
return false;
}
/**
* @brief 경험치 가져오기
*/
function getExperience($member_srl, $from_db = false)
{
$member_srl = abs($member_srl);
if (!$from_db && $this->experienceList[$member_srl])
{
return $this->experienceList[$member_srl];
}
//캐시 뒤짐.
$path = sprintf(_XE_PATH_ . 'files/member_extra_info/experience/%s', getNumberingPath($member_srl));
$cache_filename = sprintf('%s%d.cache.txt', $path, $member_srl);
if (!$from_db && file_exists($cache_filename))
{
return $this->experienceList[$member_srl] = trim(FileHandler::readFile($cache_filename));
}
//DB에서...
$args = new stdClass;
$args->member_srl = $member_srl;
$output = executeQuery('experience.getExperience', $args);
if (isset($output->data->member_srl))
{
$experience = (int)$output->data->experience;
$this->experienceList[$member_srl] = $experience;
if (!is_dir($path))
{
FileHandler::makeDir($path);
}
FileHandler::writeFile($cache_filename, $experience);
return $experience;
}
return 0;
}
/**
* @brief 레벨 가져오기
*/
function getLevel($experience, $level_step)
{
$level_count = count($level_step);
for ($level = 0; $level <= $level_count; $level++)
{
if ($experience < $level_step[$level])
{
break;
}
}
$level--;
return $level;
}
/**
* @brief 레벨 도달 퍼센트 계산
*/
function getLevelPer($experience, $config)
{
$per = '';
$level = $this->getLevel($experience, $config->level_step);
if ($level < $config->max_level)
{
$next_experience = $config->level_step[$level + 1];
$present_experience = $config->level_step[$level];
if ($next_experience > 0)
{
$per = (int)(($experience - $present_experience) / ($next_experience - $present_experience) * 100);
$per = $per . '%';
}
}
if (!$per)
{
$per = '100%';
}
return $per;
}
/**
* @brief 경험치 회원 목록
*/
function getMemberList($args = null, $columnList = array())
{
if ($args == null)
{
$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');
$search_target = trim(Context::get('search_target'));
$search_keyword = trim(Context::get('search_keyword'));
if (!$search_keyword)
{
unset($args->is_admin, $args->is_denied, $args->selected_group_srl, $search_target);
}
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 = $search_keyword;
break;
case 'last_login' :
$args->s_last_login = $search_keyword;
break;
case 'extra_vars' :
$args->s_extra_vars = $search_keyword;
break;
}
}
if ($args->selected_group_srl)
{
$query_id = 'experience.getMemberListWithinGroup';
}
else
{
$query_id = 'experience.getMemberList';
}
$output = executeQuery($query_id, $args, $columnList);
if ($output->total_count)
{
$config = moduleModel::getInstance()->getModuleConfig('experience');
foreach ($output->data as $key => $val)
{
$output->data[$key]->level = $this->getLevel($val->experience, $config->level_step);
}
}
return $output;
}
function getMonthExperience($member_srl, $date)
{
if (!$member_srl)
{
return false;
}
$args = new stdClass();
$args->regdate = $date;
$args->member_srl = $member_srl;
$output = executeQuery('experience.getMonthExperienceByMemberSrl', $args);
return $output->data;
}
function getMedalByMemberSrl($member_srl)
{
if (!$member_srl)
{
return false;
}
$args = new stdClass();
$args->member_srl = $member_srl;
return executeQuery('experience.getMedalByMemberSrl', $args)->data;
}
}