1
|
|
|
<?php |
2
|
|
|
/* Copyright (C) NAVER <http://www.navercorp.com> */ |
3
|
|
|
/** |
4
|
|
|
* @class pointController |
5
|
|
|
* @author NAVER ([email protected]) |
6
|
|
|
* @brief Controller class of point modules |
7
|
|
|
*/ |
8
|
|
|
class pointController extends point |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @brief Initialization |
12
|
|
|
*/ |
13
|
|
|
function init() |
14
|
|
|
{ |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @brief Membership point application trigger |
19
|
|
|
*/ |
20
|
|
|
function triggerInsertMember(&$obj) |
21
|
|
|
{ |
22
|
|
|
// Get the point module information |
23
|
|
|
$oModuleModel = getModel('module'); |
24
|
|
|
$config = $oModuleModel->getModuleConfig('point'); |
25
|
|
|
// Get the member_srl of the newly registered member |
26
|
|
|
$member_srl = $obj->member_srl; |
27
|
|
|
// Get the points of the member |
28
|
|
|
$oPointModel = getModel('point'); |
29
|
|
|
$cur_point = $oPointModel->getPoint($member_srl, true); |
30
|
|
|
|
31
|
|
|
$point = $config->signup_point; |
32
|
|
|
// Increase the point |
33
|
|
|
$cur_point += $point; |
34
|
|
|
$this->setPoint($member_srl,$cur_point, 'signup'); |
35
|
|
|
|
36
|
|
|
return new Object(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @brief A trigger to add points to the member for login |
41
|
|
|
*/ |
42
|
|
|
function triggerAfterLogin(&$obj) |
43
|
|
|
{ |
44
|
|
|
$member_srl = $obj->member_srl; |
45
|
|
|
if(!$member_srl) return new Object(); |
46
|
|
|
// If the last login is not today, give the points |
47
|
|
|
if(substr($obj->last_login,0,8)==date("Ymd")) return new Object(); |
48
|
|
|
// Get the point module information |
49
|
|
|
$oModuleModel = getModel('module'); |
50
|
|
|
$config = $oModuleModel->getModuleConfig('point'); |
51
|
|
|
// Get the points of the member |
52
|
|
|
$oPointModel = getModel('point'); |
53
|
|
|
$cur_point = $oPointModel->getPoint($member_srl, true); |
54
|
|
|
|
55
|
|
|
$point = $config->login_point; |
56
|
|
|
// Increase the point |
57
|
|
|
$cur_point += $point; |
58
|
|
|
$this->setPoint($member_srl,$cur_point); |
59
|
|
|
|
60
|
|
|
return new Object(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @brief A trigger to add points to the member for creating a post |
65
|
|
|
*/ |
66
|
|
|
function triggerInsertDocument(&$obj) |
67
|
|
|
{ |
68
|
|
|
$oDocumentModel = getModel('document'); |
69
|
|
|
if($obj->status != $oDocumentModel->getConfigStatus('temp')) |
70
|
|
|
{ |
71
|
|
|
$module_srl = $obj->module_srl; |
72
|
|
|
$member_srl = $obj->member_srl; |
73
|
|
|
if(!$module_srl || !$member_srl) return new Object(); |
74
|
|
|
// The fix to disable giving points for saving the document temporarily |
75
|
|
|
if($module_srl == $member_srl) return new Object(); |
76
|
|
|
// Get the point module information |
77
|
|
|
$oModuleModel = getModel('module'); |
78
|
|
|
$config = $oModuleModel->getModuleConfig('point'); |
79
|
|
|
$module_config = $oModuleModel->getModulePartConfig('point',$module_srl); |
80
|
|
|
// Get the points of the member |
81
|
|
|
$oPointModel = getModel('point'); |
82
|
|
|
$cur_point = $oPointModel->getPoint($member_srl, true); |
83
|
|
|
|
84
|
|
|
$point = $module_config['insert_document']; |
85
|
|
|
if(strlen($point) == 0 && !is_int($point)) $point = $config->insert_document; |
86
|
|
|
$cur_point += $point; |
87
|
|
|
// Add points for attaching a file |
88
|
|
|
$point = $module_config['upload_file']; |
89
|
|
|
if(strlen($point) == 0 && !is_int($point)) $point = $config->upload_file; |
90
|
|
|
if($obj->uploaded_count) $cur_point += $point * $obj->uploaded_count; |
91
|
|
|
// Increase the point |
92
|
|
|
$this->setPoint($member_srl,$cur_point); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return new Object(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @brief The trigger to give points for normal saving the temporarily saved document |
100
|
|
|
* Temporary storage at the point in 1.2.3 changed to avoid payment |
101
|
|
|
*/ |
102
|
|
|
function triggerUpdateDocument(&$obj) |
103
|
|
|
{ |
104
|
|
|
$oDocumentModel = getModel('document'); |
105
|
|
|
$document_srl = $obj->document_srl; |
106
|
|
|
$oDocument = $oDocumentModel->getDocument($document_srl); |
107
|
|
|
|
108
|
|
|
// if status is TEMP or PUBLIC... give not point, only status is empty |
109
|
|
|
if($oDocument->get('status') == $oDocumentModel->getConfigStatus('temp') && $obj->status != $oDocumentModel->getConfigStatus('temp')) |
110
|
|
|
{ |
111
|
|
|
$oModuleModel = getModel('module'); |
112
|
|
|
|
113
|
|
|
// Get the point module information |
114
|
|
|
$config = $oModuleModel->getModuleConfig('point'); |
115
|
|
|
$module_config = $oModuleModel->getModulePartConfig('point',$obj->module_srl); |
116
|
|
|
// Get the points of the member |
117
|
|
|
$oPointModel = getModel('point'); |
118
|
|
|
$cur_point = $oPointModel->getPoint($oDocument->get('member_srl'), true); |
119
|
|
|
|
120
|
|
|
$point = $module_config['insert_document']; |
121
|
|
|
if(strlen($point) == 0 && !is_int($point)) $point = $config->insert_document; |
122
|
|
|
$cur_point += $point; |
123
|
|
|
// Add points for attaching a file |
124
|
|
|
$point = $module_config['upload_file']; |
125
|
|
|
if(strlen($point) == 0 && !is_int($point)) $point = $config->upload_file; |
126
|
|
|
if($obj->uploaded_count) $cur_point += $point * $obj->uploaded_count; |
127
|
|
|
// Increase the point |
128
|
|
|
$this->setPoint($oDocument->get('member_srl'), $cur_point); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
return new Object(); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @brief The trigger which deducts the points related to post comments before deleting the post itself |
136
|
|
|
*/ |
137
|
|
|
function triggerBeforeDeleteDocument(&$obj) |
138
|
|
|
{ |
139
|
|
|
$document_srl = $obj->document_srl; |
140
|
|
|
$member_srl = $obj->member_srl; |
141
|
|
|
|
142
|
|
|
$oDocumentModel = getModel('document'); |
143
|
|
|
$oDocument = $oDocumentModel->getDocument($document_srl); |
144
|
|
|
if(!$oDocument->isExists()) return new Object(); |
145
|
|
|
// Get the point module information |
146
|
|
|
$oModuleModel = getModel('module'); |
147
|
|
|
$config = $oModuleModel->getModuleConfig('point'); |
148
|
|
|
$module_config = $oModuleModel->getModulePartConfig('point',$oDocument->get('module_srl')); |
149
|
|
|
// The process related to clearing the post comments |
150
|
|
|
$comment_point = $module_config['insert_comment']; |
151
|
|
|
if(strlen($comment_point) == 0 && !is_int($comment_point)) $comment_point = $config->insert_comment; |
152
|
|
|
// If there are comment points, attempt to deduct |
153
|
|
|
if($comment_point>0) return new Object(); |
154
|
|
|
// Get all the comments related to this post |
155
|
|
|
$cp_args = new stdClass(); |
156
|
|
|
$cp_args->document_srl = $document_srl; |
157
|
|
|
$output = executeQueryArray('point.getCommentUsers', $cp_args); |
158
|
|
|
// Return if there is no object |
159
|
|
|
if(!$output->data) return new Object(); |
160
|
|
|
// Organize the member number |
161
|
|
|
$member_srls = array(); |
162
|
|
|
$cnt = count($output->data); |
163
|
|
|
for($i=0;$i<$cnt;$i++) |
164
|
|
|
{ |
165
|
|
|
if($output->data[$i]->member_srl<1) continue; |
166
|
|
|
$member_srls[abs($output->data[$i]->member_srl)] = $output->data[$i]->count; |
167
|
|
|
} |
168
|
|
|
// Remove the member number who has written the original post |
169
|
|
|
if($member_srl) unset($member_srls[abs($member_srl)]); |
170
|
|
|
if(!count($member_srls)) return new Object(); |
171
|
|
|
// Remove all the points for each member |
172
|
|
|
$oPointModel = getModel('point'); |
173
|
|
|
// Get the points |
174
|
|
|
$point = $module_config['download_file']; |
|
|
|
|
175
|
|
|
foreach($member_srls as $member_srl => $cnt) |
176
|
|
|
{ |
177
|
|
|
$cur_point = $oPointModel->getPoint($member_srl, true); |
178
|
|
|
$cur_point -= $cnt * $comment_point; |
179
|
|
|
$this->setPoint($member_srl,$cur_point); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
return new Object(); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @brief A trigger to give points for deleting the post |
187
|
|
|
*/ |
188
|
|
|
function triggerDeleteDocument(&$obj) |
189
|
|
|
{ |
190
|
|
|
$oDocumentModel = getModel('document'); |
191
|
|
|
|
192
|
|
|
if($obj->status != $oDocumentModel->getConfigStatus('temp')) |
193
|
|
|
{ |
194
|
|
|
$module_srl = $obj->module_srl; |
195
|
|
|
$member_srl = $obj->member_srl; |
196
|
|
|
// The process related to clearing the post object |
197
|
|
|
if(!$module_srl || !$member_srl) return new Object(); |
198
|
|
|
// Run only when logged in |
199
|
|
|
$logged_info = Context::get('logged_info'); |
200
|
|
|
if(!$logged_info->member_srl) return new Object(); |
201
|
|
|
// Get the points of the member |
202
|
|
|
$oPointModel = getModel('point'); |
203
|
|
|
$cur_point = $oPointModel->getPoint($member_srl, true); |
204
|
|
|
// Get the point module information |
205
|
|
|
$oModuleModel = getModel('module'); |
206
|
|
|
$config = $oModuleModel->getModuleConfig('point'); |
207
|
|
|
$module_config = $oModuleModel->getModulePartConfig('point', $module_srl); |
208
|
|
|
|
209
|
|
|
$point = $module_config['insert_document']; |
210
|
|
|
if(strlen($point) == 0 && !is_int($point)) $point = $config->insert_document; |
211
|
|
|
// if the point is set to decrease when writing a document, make sure it does not increase the points when deleting an article |
212
|
|
|
if($point < 0) return new Object(); |
213
|
|
|
$cur_point -= $point; |
214
|
|
|
// Add points related to deleting an attachment |
215
|
|
|
$point = $module_config['upload_file']; |
216
|
|
|
if(strlen($point) == 0 && !is_int($point)) $point = $config->upload_file; |
217
|
|
|
if($obj->uploaded_count) $cur_point -= $point * $obj->uploaded_count; |
218
|
|
|
// Increase the point |
219
|
|
|
$this->setPoint($member_srl,$cur_point); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
return new Object(); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* @brief A trigger which gives points for entering a comment |
227
|
|
|
*/ |
228
|
|
|
function triggerInsertComment(&$obj) |
229
|
|
|
{ |
230
|
|
|
$module_srl = $obj->module_srl; |
231
|
|
|
$member_srl = $obj->member_srl; |
232
|
|
|
if(!$module_srl || !$member_srl) return new Object(); |
233
|
|
|
// Do not increase the points if the member is the author of the post |
234
|
|
|
$document_srl = $obj->document_srl; |
235
|
|
|
$oDocumentModel = getModel('document'); |
236
|
|
|
$oDocument = $oDocumentModel->getDocument($document_srl); |
237
|
|
|
if(!$oDocument->isExists() || abs($oDocument->get('member_srl'))==abs($member_srl)) return new Object(); |
238
|
|
|
// Get the point module information |
239
|
|
|
$oModuleModel = getModel('module'); |
240
|
|
|
$config = $oModuleModel->getModuleConfig('point'); |
241
|
|
|
$module_config = $oModuleModel->getModulePartConfig('point', $module_srl); |
242
|
|
|
// Get the points of the member |
243
|
|
|
$oPointModel = getModel('point'); |
244
|
|
|
$cur_point = $oPointModel->getPoint($member_srl, true); |
245
|
|
|
|
246
|
|
|
$point = $module_config['insert_comment']; |
247
|
|
|
if(strlen($point) == 0 && !is_int($point)) $point = $config->insert_comment; |
248
|
|
|
// Increase the point |
249
|
|
|
$cur_point += $point; |
250
|
|
|
$this->setPoint($member_srl,$cur_point); |
251
|
|
|
|
252
|
|
|
return new Object(); |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* @brief A trigger which gives points for deleting a comment |
257
|
|
|
*/ |
258
|
|
|
function triggerDeleteComment(&$obj) |
259
|
|
|
{ |
260
|
|
|
$oModuleModel = getModel('module'); |
261
|
|
|
$oPointModel = getModel('point'); |
262
|
|
|
$oDocumentModel = getModel('document'); |
263
|
|
|
|
264
|
|
|
$module_srl = $obj->module_srl; |
265
|
|
|
$member_srl = abs($obj->member_srl); |
266
|
|
|
$document_srl = $obj->document_srl; |
267
|
|
|
if(!$module_srl || !$member_srl) return new Object(); |
268
|
|
|
// Get the original article (if the original article is missing or if the member is its author, do not apply the points) |
269
|
|
|
$oDocument = $oDocumentModel->getDocument($document_srl); |
270
|
|
|
if(!$oDocument->isExists()) return new Object(); |
271
|
|
|
if($oDocument->get('member_srl')==$member_srl) return new Object(); |
272
|
|
|
// Get the point module information |
273
|
|
|
$config = $oModuleModel->getModuleConfig('point'); |
274
|
|
|
$module_config = $oModuleModel->getModulePartConfig('point', $module_srl); |
275
|
|
|
// Get the points of the member |
276
|
|
|
$cur_point = $oPointModel->getPoint($member_srl, true); |
277
|
|
|
|
278
|
|
|
$point = $module_config['insert_comment']; |
279
|
|
|
if(strlen($point) == 0 && !is_int($point)) $point = $config->insert_comment; |
280
|
|
|
// if the point is set to decrease when writing a comment, make sure it does not increase the points when deleting a comment |
281
|
|
|
if($point < 0) return new Object(); |
282
|
|
|
// Increase the point |
283
|
|
|
$cur_point -= $point; |
284
|
|
|
$this->setPoint($member_srl,$cur_point); |
285
|
|
|
|
286
|
|
|
return new Object(); |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
/** |
290
|
|
|
* @brief Add the file registration trigger |
291
|
|
|
* To prevent taking points for invalid file registration this method wlil return a null object |
292
|
|
|
*/ |
293
|
|
|
function triggerInsertFile(&$obj) |
|
|
|
|
294
|
|
|
{ |
295
|
|
|
return new Object(); |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* @brief A trigger to give points for deleting a file |
300
|
|
|
* Remove points only in case an invalid file is being deleted |
301
|
|
|
*/ |
302
|
|
|
function triggerDeleteFile(&$obj) |
303
|
|
|
{ |
304
|
|
|
if($obj->isvalid != 'Y') return new Object(); |
305
|
|
|
|
306
|
|
|
$module_srl = $obj->module_srl; |
307
|
|
|
$member_srl = $obj->member_srl; |
308
|
|
|
if(!$module_srl || !$member_srl) return new Object(); |
309
|
|
|
// Get the point module information |
310
|
|
|
$oModuleModel = getModel('module'); |
311
|
|
|
$config = $oModuleModel->getModuleConfig('point'); |
312
|
|
|
$module_config = $oModuleModel->getModulePartConfig('point', $module_srl); |
313
|
|
|
// Get the points of the member |
314
|
|
|
$oPointModel = getModel('point'); |
315
|
|
|
$cur_point = $oPointModel->getPoint($member_srl, true); |
316
|
|
|
|
317
|
|
|
$point = $module_config['upload_file']; |
318
|
|
|
if(strlen($point) == 0 && !is_int($point)) $point = $config->upload_file; |
319
|
|
|
// Increase the point |
320
|
|
|
$cur_point -= $point; |
321
|
|
|
$this->setPoint($member_srl,$cur_point); |
322
|
|
|
|
323
|
|
|
return new Object(); |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* @brief The trigger called before a file is downloaded |
328
|
|
|
*/ |
329
|
|
|
function triggerBeforeDownloadFile(&$obj) |
330
|
|
|
{ |
331
|
|
|
$logged_info = Context::get('logged_info'); |
332
|
|
|
$member_srl = $logged_info->member_srl; |
333
|
|
|
$module_srl = $obj->module_srl; |
334
|
|
|
if(!$module_srl) return new Object(); |
335
|
|
|
|
336
|
|
|
// Pass if it is your file |
337
|
|
|
if($member_srl && abs($obj->member_srl) == $member_srl) return new Object(); |
338
|
|
|
$oModuleModel = getModel('module'); |
339
|
|
|
$config = $oModuleModel->getModuleConfig('point'); |
340
|
|
|
$module_config = $oModuleModel->getModulePartConfig('point', $module_srl); |
341
|
|
View Code Duplication |
if (isset($module_config['download_file'])) |
342
|
|
|
{ |
343
|
|
|
$point = intval($module_config['download_file']); |
344
|
|
|
} |
345
|
|
|
else |
346
|
|
|
{ |
347
|
|
|
$point = intval($config->download_file); |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
// If the user is not logged in and download requires points, deny access. |
351
|
|
|
if(!Context::get('is_logged')) |
352
|
|
|
{ |
353
|
|
|
if($config->disable_download == 'Y' && $point) |
354
|
|
|
{ |
355
|
|
|
return new Object(-1,'msg_not_permitted_download'); |
356
|
|
|
} |
357
|
|
|
else |
358
|
|
|
{ |
359
|
|
|
return new Object(); |
360
|
|
|
} |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
// Get the points of the member |
364
|
|
|
$oPointModel = getModel('point'); |
365
|
|
|
$cur_point = $oPointModel->getPoint($member_srl, true); |
366
|
|
|
|
367
|
|
|
// If the member does not have enough points, deny access. |
368
|
|
|
if ($config->disable_download == 'Y' && $cur_point + $point < 0) |
369
|
|
|
{ |
370
|
|
|
return new Object(-1,'msg_cannot_download'); |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
// Otherwise, points will be adjusted after downloading (triggerDownloadFile). |
374
|
|
|
return new Object(); |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
/** |
378
|
|
|
* @brief The trigger to give or take points for downloading the file |
379
|
|
|
*/ |
380
|
|
|
function triggerDownloadFile(&$obj) |
381
|
|
|
{ |
382
|
|
|
// Run only when logged in |
383
|
|
|
$logged_info = Context::get('logged_info'); |
384
|
|
|
if(!$logged_info->member_srl) return new Object(); |
385
|
|
|
$module_srl = $obj->module_srl; |
386
|
|
|
$member_srl = $logged_info->member_srl; |
387
|
|
|
if(!$module_srl) return new Object(); |
388
|
|
|
|
389
|
|
|
// Pass if it is your file |
390
|
|
|
if($member_srl && abs($obj->member_srl) == $member_srl) return new Object(); |
391
|
|
|
|
392
|
|
|
// Get the point module information |
393
|
|
|
$oModuleModel = getModel('module'); |
394
|
|
|
$config = $oModuleModel->getModuleConfig('point'); |
395
|
|
|
$module_config = $oModuleModel->getModulePartConfig('point', $module_srl); |
396
|
|
View Code Duplication |
if (isset($module_config['download_file'])) |
397
|
|
|
{ |
398
|
|
|
$point = intval($module_config['download_file']); |
399
|
|
|
} |
400
|
|
|
else |
401
|
|
|
{ |
402
|
|
|
$point = intval($config->download_file); |
403
|
|
|
} |
404
|
|
|
|
405
|
|
|
// Get the points of the member |
406
|
|
|
$oPointModel = getModel('point'); |
407
|
|
|
$cur_point = $oPointModel->getPoint($member_srl, true); |
408
|
|
|
|
409
|
|
|
// Increase or decrease points. |
410
|
|
|
if ($point) |
411
|
|
|
{ |
412
|
|
|
$this->setPoint($member_srl, $cur_point += $point); |
413
|
|
|
} |
414
|
|
|
return new Object(); |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
/** |
418
|
|
|
* @brief Give points for hits increase |
419
|
|
|
* Run it even if there are no points |
420
|
|
|
*/ |
421
|
|
|
function triggerUpdateReadedCount(&$obj) |
422
|
|
|
{ |
423
|
|
|
$oModuleModel = getModel('module'); |
424
|
|
|
$oPointModel = getModel('point'); |
425
|
|
|
// Get visitor information |
426
|
|
|
$logged_info = Context::get('logged_info'); |
427
|
|
|
$member_srl = $logged_info->member_srl; |
428
|
|
|
// Get the original author number |
429
|
|
|
$target_member_srl = abs($obj->get('member_srl')); |
430
|
|
|
// Pass without increasing the hits if the viewer is the same as the author |
431
|
|
|
if($target_member_srl == $member_srl) return new Object(); |
432
|
|
|
// Get the point information for each module |
433
|
|
|
$config = $oModuleModel->getModuleConfig('point'); |
434
|
|
|
$module_config = $oModuleModel->getModulePartConfig('point', $obj->get('module_srl')); |
435
|
|
|
// Get hits points |
436
|
|
|
$point = $module_config['read_document']; |
437
|
|
|
if(strlen($point) == 0 && !is_int($point)) $point = $config->read_document; |
438
|
|
|
// Pass if there are no requested points |
439
|
|
|
if(!$point) return new Object(); |
440
|
|
|
// In case of a registered member, if it is read but cannot just pass, then get the current points |
441
|
|
|
if($member_srl) |
442
|
|
|
{ |
443
|
|
|
$args->member_srl = $member_srl; |
|
|
|
|
444
|
|
|
$args->document_srl = $obj->document_srl; |
445
|
|
|
$output = executeQuery('document.getDocumentReadedLogInfo', $args); |
446
|
|
|
if($output->data->count) return new Object(); |
447
|
|
|
$cur_point = $oPointModel->getPoint($member_srl, true); |
448
|
|
|
} |
449
|
|
|
else |
450
|
|
|
{ |
451
|
|
|
$cur_point = 0; |
452
|
|
|
} |
453
|
|
|
// Get the defaul configurations of the Point Module |
454
|
|
|
$config = $oModuleModel->getModuleConfig('point'); |
455
|
|
|
// When the requested points are negative, compared it with the current point |
456
|
|
|
$_SESSION['banned_document'][$obj->document_srl] = false; |
457
|
|
|
if($config->disable_read_document == 'Y' && $point < 0 && abs($point)>$cur_point) |
458
|
|
|
{ |
459
|
|
|
$message = sprintf(Context::getLang('msg_disallow_by_point'), abs($point), $cur_point); |
460
|
|
|
$obj->add('content', $message); |
461
|
|
|
$_SESSION['banned_document'][$obj->document_srl] = true; |
462
|
|
|
return new Object(-1, $message); |
463
|
|
|
} |
464
|
|
|
// If not logged in, pass |
465
|
|
|
if(!$logged_info->member_srl) return new Object(); |
466
|
|
|
// Pass, if there are no requested points |
467
|
|
|
if(!$point) return new Object(); |
468
|
|
|
// If the read record is missing, leave it |
469
|
|
|
$output = executeQuery('document.insertDocumentReadedLog', $args); |
|
|
|
|
470
|
|
|
// Increase the point |
471
|
|
|
$cur_point += $point; |
472
|
|
|
$this->setPoint($member_srl,$cur_point); |
473
|
|
|
|
474
|
|
|
return new Object(); |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
/** |
478
|
|
|
* @brief Points for voting up or down |
479
|
|
|
*/ |
480
|
|
|
function triggerUpdateVotedCount(&$obj) |
481
|
|
|
{ |
482
|
|
|
$module_srl = $obj->module_srl; |
483
|
|
|
$member_srl = $obj->member_srl; |
484
|
|
|
if(!$module_srl || !$member_srl) return new Object(); |
485
|
|
|
|
486
|
|
|
$oModuleModel = getModel('module'); |
487
|
|
|
$config = $oModuleModel->getModuleConfig('point'); |
488
|
|
|
$module_config = $oModuleModel->getModulePartConfig('point', $module_srl); |
489
|
|
|
|
490
|
|
|
$oPointModel = getModel('point'); |
491
|
|
|
$cur_point = $oPointModel->getPoint($member_srl, true); |
492
|
|
|
|
493
|
|
|
if( $obj->point > 0 ) |
494
|
|
|
{ |
495
|
|
|
$point = $module_config['voted']; |
496
|
|
|
if(strlen($point) == 0 && !is_int($point)) $point = $config->voted; |
497
|
|
|
} |
498
|
|
|
else |
499
|
|
|
{ |
500
|
|
|
$point = $module_config['blamed']; |
501
|
|
|
if(strlen($point) == 0 && !is_int($point)) $point = $config->blamed; |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
if(!$point) return new Object(); |
505
|
|
|
// Increase the point |
506
|
|
|
$cur_point += $point; |
507
|
|
|
$this->setPoint($member_srl,$cur_point); |
508
|
|
|
|
509
|
|
|
return new Object(); |
510
|
|
|
} |
511
|
|
|
|
512
|
|
|
/** |
513
|
|
|
* @brief Set points |
514
|
|
|
*/ |
515
|
|
|
function setPoint($member_srl, $point, $mode = null) |
516
|
|
|
{ |
517
|
|
|
$member_srl = abs($member_srl); |
518
|
|
|
$mode_arr = array('add', 'minus', 'update', 'signup'); |
519
|
|
|
if(!$mode || !in_array($mode,$mode_arr)) $mode = 'update'; |
520
|
|
|
|
521
|
|
|
// Get configuration information |
522
|
|
|
$oMemberModel = getModel('member'); |
523
|
|
|
$oModuleModel = getModel('module'); |
524
|
|
|
$oPointModel = getModel('point'); |
525
|
|
|
$config = $oModuleModel->getModuleConfig('point'); |
526
|
|
|
|
527
|
|
|
// Get the default configuration information |
528
|
|
|
$current_point = $oPointModel->getPoint($member_srl, true); |
529
|
|
|
$current_level = $oPointModel->getLevel($current_point, $config->level_step); |
530
|
|
|
|
531
|
|
|
// Change points |
532
|
|
|
$args = new stdClass(); |
533
|
|
|
$args->member_srl = $member_srl; |
534
|
|
|
$args->point = $current_point; |
535
|
|
|
|
536
|
|
|
switch($mode) |
537
|
|
|
{ |
538
|
|
|
case 'add' : |
539
|
|
|
$args->point += $point; |
540
|
|
|
break; |
541
|
|
|
case 'minus' : |
542
|
|
|
$args->point -= $point; |
543
|
|
|
break; |
544
|
|
|
case 'update' : |
545
|
|
|
case 'signup' : |
546
|
|
|
$args->point = $point; |
547
|
|
|
break; |
548
|
|
|
} |
549
|
|
|
if($args->point < 0) $args->point = 0; |
550
|
|
|
$point = $args->point; |
551
|
|
|
|
552
|
|
|
// Call a trigger (before) |
553
|
|
|
$trigger_obj = new stdClass(); |
554
|
|
|
$trigger_obj->member_srl = $args->member_srl; |
555
|
|
|
$trigger_obj->mode = $mode; |
556
|
|
|
$trigger_obj->current_point = $current_point; |
557
|
|
|
$trigger_obj->current_level = $current_level; |
558
|
|
|
$trigger_obj->set_point = $point; |
559
|
|
|
$trigger_output = ModuleHandler::triggerCall('point.setPoint', 'before', $trigger_obj); |
560
|
|
|
if(!$trigger_output->toBool()) |
561
|
|
|
{ |
562
|
|
|
return $trigger_output; |
563
|
|
|
} |
564
|
|
|
|
565
|
|
|
// begin transaction |
566
|
|
|
$oDB = &DB::getInstance(); |
567
|
|
|
$oDB->begin(); |
568
|
|
|
|
569
|
|
|
// If there are points, update, if no, insert |
570
|
|
|
$oPointModel = getModel('point'); |
571
|
|
|
if($oPointModel->isExistsPoint($member_srl)) executeQuery("point.updatePoint", $args); |
572
|
|
|
else executeQuery("point.insertPoint", $args); |
573
|
|
|
|
574
|
|
|
// Get a new level |
575
|
|
|
$level = $oPointModel->getLevel($point, $config->level_step); |
576
|
|
|
|
577
|
|
|
// If existing level and a new one are different attempt to set a point group |
578
|
|
|
if($level != $current_level) |
579
|
|
|
{ |
580
|
|
|
// Check if the level, for which the current points are prepared, is calculate and set the correct group |
581
|
|
|
$point_group = $config->point_group; |
582
|
|
|
// If the point group exists |
583
|
|
|
if($point_group && is_array($point_group) && count($point_group) ) |
584
|
|
|
{ |
585
|
|
|
// Get the default group |
586
|
|
|
$default_group = $oMemberModel->getDefaultGroup(); |
587
|
|
|
// Get the removed group and the newly granted group |
588
|
|
|
$del_group_list = array(); |
589
|
|
|
$new_group_list = array(); |
590
|
|
|
|
591
|
|
|
asort($point_group); |
592
|
|
|
// Reset group after initialization |
593
|
|
|
if($config->group_reset != 'N') |
594
|
|
|
{ |
595
|
|
|
// If the new level is in the right group |
596
|
|
|
if(in_array($level, $point_group)) |
597
|
|
|
{ |
598
|
|
|
// Delete all groups except the one which the current level belongs to |
599
|
|
View Code Duplication |
foreach($point_group as $group_srl => $target_level) |
600
|
|
|
{ |
601
|
|
|
$del_group_list[] = $group_srl; |
602
|
|
|
if($target_level == $level) $new_group_list[] = $group_srl; |
603
|
|
|
} |
604
|
|
|
} |
605
|
|
|
// Otherwise, in case the level is reduced, add the recent group |
606
|
|
|
else |
607
|
|
|
{ |
608
|
|
|
$i = $level; |
609
|
|
|
while($i > 0) |
610
|
|
|
{ |
611
|
|
|
if(in_array($i, $point_group)) |
612
|
|
|
{ |
613
|
|
|
foreach($point_group as $group_srl => $target_level) |
614
|
|
|
{ |
615
|
|
|
if($target_level == $i) |
616
|
|
|
{ |
617
|
|
|
$new_group_list[] = $group_srl; |
618
|
|
|
} |
619
|
|
|
} |
620
|
|
|
$i = 0; |
621
|
|
|
} |
622
|
|
|
$i--; |
623
|
|
|
} |
624
|
|
|
} |
625
|
|
|
// Delete the group of a level which is higher than the current level |
626
|
|
|
foreach($point_group as $group_srl => $target_level) |
627
|
|
|
{ |
628
|
|
|
if($target_level > $level) $del_group_list[] = $group_srl; |
629
|
|
|
} |
630
|
|
|
$del_group_list[] = $default_group->group_srl; |
631
|
|
|
} |
632
|
|
|
// Grant a new group |
633
|
|
|
else |
634
|
|
|
{ |
635
|
|
|
// Check until the current level by rotating setting the configurations of the point groups |
636
|
|
View Code Duplication |
foreach($point_group as $group_srl => $target_level) |
637
|
|
|
{ |
638
|
|
|
$del_group_list[] = $group_srl; |
639
|
|
|
if($target_level <= $level) $new_group_list[] = $group_srl; |
640
|
|
|
} |
641
|
|
|
} |
642
|
|
|
// If there is no a new group, granted the default group |
643
|
|
|
if(!$new_group_list[0]) $new_group_list[0] = $default_group->group_srl; |
644
|
|
|
// Remove linkage group |
645
|
|
|
if($del_group_list && count($del_group_list)) |
|
|
|
|
646
|
|
|
{ |
647
|
|
|
$del_group_args = new stdClass; |
648
|
|
|
$del_group_args->member_srl = $member_srl; |
649
|
|
|
$del_group_args->group_srl = implode(',', $del_group_list); |
650
|
|
|
$del_group_output = executeQuery('point.deleteMemberGroup', $del_group_args); |
|
|
|
|
651
|
|
|
} |
652
|
|
|
// Grant a new group |
653
|
|
|
foreach($new_group_list as $group_srl) |
654
|
|
|
{ |
655
|
|
|
$new_group_args = new stdClass; |
656
|
|
|
$new_group_args->member_srl = $member_srl; |
657
|
|
|
$new_group_args->group_srl = $group_srl; |
658
|
|
|
executeQuery('member.addMemberToGroup', $new_group_args); |
659
|
|
|
} |
660
|
|
|
} |
661
|
|
|
} |
662
|
|
|
|
663
|
|
|
// Call a trigger (after) |
664
|
|
|
$trigger_obj->new_group_list = $new_group_list; |
|
|
|
|
665
|
|
|
$trigger_obj->del_group_list = $del_group_list; |
|
|
|
|
666
|
|
|
$trigger_obj->new_level = $level; |
667
|
|
|
$trigger_output = ModuleHandler::triggerCall('point.setPoint', 'after', $trigger_obj); |
668
|
|
|
if(!$trigger_output->toBool()) |
669
|
|
|
{ |
670
|
|
|
$oDB->rollback(); |
671
|
|
|
return $trigger_output; |
672
|
|
|
} |
673
|
|
|
|
674
|
|
|
$oDB->commit(); |
675
|
|
|
|
676
|
|
|
// Cache Settings |
677
|
|
|
$cache_path = sprintf('./files/member_extra_info/point/%s/', getNumberingPath($member_srl)); |
678
|
|
|
FileHandler::makedir($cache_path); |
679
|
|
|
|
680
|
|
|
$cache_filename = sprintf('%s%d.cache.txt', $cache_path, $member_srl); |
681
|
|
|
FileHandler::writeFile($cache_filename, $point); |
682
|
|
|
|
683
|
|
|
$oCacheHandler = CacheHandler::getInstance('object', null, true); |
684
|
|
View Code Duplication |
if($new_group_list && $del_group_list && $oCacheHandler->isSupport()) |
|
|
|
|
685
|
|
|
{ |
686
|
|
|
$object_key = 'member_groups:' . getNumberingPath($member_srl) . $member_srl . '_0'; |
687
|
|
|
$cache_key = $oCacheHandler->getGroupKey('member', $object_key); |
688
|
|
|
$oCacheHandler->delete($cache_key); |
689
|
|
|
} |
690
|
|
|
|
691
|
|
|
$oCacheHandler = CacheHandler::getInstance('object'); |
692
|
|
View Code Duplication |
if($new_group_list && $del_group_list && $oCacheHandler->isSupport()) |
|
|
|
|
693
|
|
|
{ |
694
|
|
|
$object_key = 'member_info:' . getNumberingPath($member_srl) . $member_srl; |
695
|
|
|
$cache_key = $oCacheHandler->getGroupKey('member', $object_key); |
696
|
|
|
$oCacheHandler->delete($cache_key); |
697
|
|
|
} |
698
|
|
|
|
699
|
|
|
return $output; |
|
|
|
|
700
|
|
|
} |
701
|
|
|
|
702
|
|
View Code Duplication |
function triggerCopyModule(&$obj) |
|
|
|
|
703
|
|
|
{ |
704
|
|
|
$oModuleModel = getModel('module'); |
705
|
|
|
$pointConfig = $oModuleModel->getModulePartConfig('point', $obj->originModuleSrl); |
706
|
|
|
|
707
|
|
|
$oModuleController = getController('module'); |
708
|
|
|
if(is_array($obj->moduleSrlList)) |
709
|
|
|
{ |
710
|
|
|
foreach($obj->moduleSrlList AS $key=>$moduleSrl) |
711
|
|
|
{ |
712
|
|
|
$oModuleController->insertModulePartConfig('point', $moduleSrl, $pointConfig); |
713
|
|
|
} |
714
|
|
|
} |
715
|
|
|
} |
716
|
|
|
} |
717
|
|
|
/* End of file point.controller.php */ |
718
|
|
|
/* Location: ./modules/point/point.controller.php */ |
719
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.