GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — develop (#1929)
by
unknown
11:46
created

pointController::triggerInsertComment()   C

Complexity

Conditions 7
Paths 4

Size

Total Lines 26
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 18
nc 4
nop 1
dl 0
loc 26
rs 6.7272
c 0
b 0
f 0
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'];
0 ignored issues
show
Unused Code introduced by
$point is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
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
		$module_srl = $obj->module_srl;
191
		$member_srl = $obj->member_srl;
192
		// The process related to clearing the post object
193
		if(!$module_srl || !$member_srl) return new Object();
194
		// Run only when logged in
195
		$logged_info = Context::get('logged_info');
196
		if(!$logged_info->member_srl) return new Object();
197
		// Get the points of the member
198
		$oPointModel = getModel('point');
199
		$cur_point = $oPointModel->getPoint($member_srl, true);
200
		// Get the point module information
201
		$oModuleModel = getModel('module');
202
		$config = $oModuleModel->getModuleConfig('point');
203
		$module_config = $oModuleModel->getModulePartConfig('point', $module_srl);
204
205
		$point = $module_config['insert_document'];
206
		if(strlen($point) == 0 && !is_int($point)) $point = $config->insert_document;
207
		// if the point is set to decrease when writing a document, make sure it does not increase the points when deleting an article
208
		if($point < 0) return new Object();
209
		$cur_point -= $point;
210
		// Add points related to deleting an attachment
211
		$point = $module_config['upload_file'];
212
		if(strlen($point) == 0 && !is_int($point)) $point = $config->upload_file;
213
		if($obj->uploaded_count) $cur_point -= $point * $obj->uploaded_count;
214
		// Increase the point
215
		$this->setPoint($member_srl,$cur_point);
216
217
		return new Object();
218
	}
219
220
	/**
221
	 * @brief A trigger which gives points for entering a comment
222
	 */
223
	function triggerInsertComment(&$obj)
224
	{
225
		$module_srl = $obj->module_srl;
226
		$member_srl = $obj->member_srl;
227
		if(!$module_srl || !$member_srl) return new Object();
228
		// Do not increase the points if the member is the author of the post
229
		$document_srl = $obj->document_srl;
230
		$oDocumentModel = getModel('document');
231
		$oDocument = $oDocumentModel->getDocument($document_srl);
232
		if(!$oDocument->isExists() || abs($oDocument->get('member_srl'))==abs($member_srl)) return new Object();
233
		// Get the point module information
234
		$oModuleModel = getModel('module');
235
		$config = $oModuleModel->getModuleConfig('point');
236
		$module_config = $oModuleModel->getModulePartConfig('point', $module_srl);
237
		// Get the points of the member
238
		$oPointModel = getModel('point');
239
		$cur_point = $oPointModel->getPoint($member_srl, true);
240
241
		$point = $module_config['insert_comment'];
242
		if(strlen($point) == 0 && !is_int($point)) $point = $config->insert_comment;
243
		// Increase the point
244
		$cur_point += $point;
245
		$this->setPoint($member_srl,$cur_point);
246
247
		return new Object();
248
	}
249
250
	/**
251
	 * @brief A trigger which gives points for deleting a comment
252
	 */
253
	function triggerDeleteComment(&$obj)
254
	{
255
		$oModuleModel = getModel('module');
256
		$oPointModel = getModel('point');
257
		$oDocumentModel = getModel('document');
258
259
		$module_srl = $obj->module_srl;
260
		$member_srl = abs($obj->member_srl);
261
		$document_srl = $obj->document_srl;
262
		if(!$module_srl || !$member_srl) return new Object();
263
		// Get the original article (if the original article is missing or if the member is its author, do not apply the points)
264
		$oDocument = $oDocumentModel->getDocument($document_srl);
265
		if(!$oDocument->isExists()) return new Object();
266
		if($oDocument->get('member_srl')==$member_srl) return new Object();
267
		// Get the point module information
268
		$config = $oModuleModel->getModuleConfig('point');
269
		$module_config = $oModuleModel->getModulePartConfig('point', $module_srl);
270
		// Get the points of the member
271
		$cur_point = $oPointModel->getPoint($member_srl, true);
272
273
		$point = $module_config['insert_comment'];
274
		if(strlen($point) == 0 && !is_int($point)) $point = $config->insert_comment;
275
		// if the point is set to decrease when writing a comment, make sure it does not increase the points when deleting a comment
276
		if($point < 0) return new Object();
277
		// Increase the point
278
		$cur_point -= $point;
279
		$this->setPoint($member_srl,$cur_point);
280
281
		return new Object();
282
	}
283
284
	/**
285
	 * @brief Add the file registration trigger
286
	 * To prevent taking points for invalid file registration this method wlil return a null object
287
	 */
288
	function triggerInsertFile(&$obj)
0 ignored issues
show
Unused Code introduced by
The parameter $obj is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
289
	{
290
		return new Object();
291
	}
292
293
	/**
294
	 * @brief A trigger to give points for deleting a file
295
	 * Remove points only in case an invalid file is being deleted
296
	 */
297
	function triggerDeleteFile(&$obj)
298
	{
299
		if($obj->isvalid != 'Y') return new Object();
300
301
		$module_srl = $obj->module_srl;
302
		$member_srl = $obj->member_srl;
303
		if(!$module_srl || !$member_srl) return new Object();
304
		// Get the point module information
305
		$oModuleModel = getModel('module');
306
		$config = $oModuleModel->getModuleConfig('point');
307
		$module_config = $oModuleModel->getModulePartConfig('point', $module_srl);
308
		// Get the points of the member
309
		$oPointModel = getModel('point');
310
		$cur_point = $oPointModel->getPoint($member_srl, true);
311
312
		$point = $module_config['upload_file'];
313
		if(strlen($point) == 0 && !is_int($point)) $point = $config->upload_file;
314
		// Increase the point
315
		$cur_point -= $point;
316
		$this->setPoint($member_srl,$cur_point);
317
318
		return new Object();
319
	}
320
321
	/**
322
	 * @brief The trigger called before a file is downloaded
323
	 */
324
	function triggerBeforeDownloadFile(&$obj)
325
	{
326
		$logged_info = Context::get('logged_info');
327
		$member_srl = $logged_info->member_srl;
328
		$module_srl = $obj->module_srl;
329
		if(!$module_srl) return new Object();
330
		// Pass if it is your file
331
		if(abs($obj->member_srl) == abs($member_srl)) return new Object();
332
333
		$oModuleModel = getModel('module');
334
		$config = $oModuleModel->getModuleConfig('point');
335
		$module_config = $oModuleModel->getModulePartConfig('point', $module_srl);
336
		// If it is set not to allow downloading for non-logged in users, do not permit
337
		if(!Context::get('is_logged'))
338
		{
339
			if($config->disable_download == 'Y' && strlen($module_config['download_file']) == 0 && !is_int($module_config['download_file'])) return new Object(-1,'msg_not_permitted_download');
340
			else return new Object();
341
		}
342
		// Get the points of the member
343
		$oPointModel = getModel('point');
344
		$cur_point = $oPointModel->getPoint($member_srl, true);
345
		// Get the points
346
		$point = $module_config['download_file'];
347
		if(strlen($point) == 0 && !is_int($point)) $point = $config->download_file;
348
		// If points are less than 0, and if downloading a file is not allowed in this case, give an errors
349
		if($cur_point + $point < 0 && $config->disable_download == 'Y') return new Object(-1,'msg_cannot_download');
350
351
		return new Object();
352
	}
353
354
	/**
355
	 * @brief The trigger to give points for downloading the file
356
	 */
357
	function triggerDownloadFile(&$obj)
358
	{
359
		// Run only when logged in
360
		$logged_info = Context::get('logged_info');
361
		if(!$logged_info->member_srl) return new Object();
362
		$module_srl = $obj->module_srl;
363
		$member_srl = $logged_info->member_srl;
364
		if(!$module_srl) return new Object();
365
		// Pass if it is your file
366
		if(abs($obj->member_srl) == abs($member_srl)) return new Object();
367
		// Get the point module information
368
		$oModuleModel = getModel('module');
369
		$config = $oModuleModel->getModuleConfig('point');
370
		$module_config = $oModuleModel->getModulePartConfig('point', $module_srl);
371
		// Get the points of the member
372
		$oPointModel = getModel('point');
373
		$cur_point = $oPointModel->getPoint($member_srl, true);
374
		// Get the points
375
		$point = $module_config['download_file'];
376
		if(strlen($point) == 0 && !is_int($point)) $point = $config->download_file;
377
		// Increase the point
378
		$cur_point += $point;
379
		$this->setPoint($member_srl,$cur_point);
380
381
		return new Object();
382
	}
383
384
	/**
385
	 * @brief Give points for hits increase
386
	 * Run it even if there are no points
387
	 */
388
	function triggerUpdateReadedCount(&$obj)
389
	{
390
		$oModuleModel = getModel('module');
391
		$oPointModel = getModel('point');
392
		// Get visitor information
393
		$logged_info = Context::get('logged_info');
394
		$member_srl = $logged_info->member_srl;
395
		// Get the original author number
396
		$target_member_srl = abs($obj->get('member_srl'));
397
		// Pass without increasing the hits if the viewer is the same as the author
398
		if($target_member_srl == $member_srl) return new Object();
399
		// Get the point information for each module
400
		$config = $oModuleModel->getModuleConfig('point');
401
		$module_config = $oModuleModel->getModulePartConfig('point', $obj->get('module_srl'));
402
		// Get hits points
403
		$point = $module_config['read_document'];
404
		if(strlen($point) == 0 && !is_int($point)) $point = $config->read_document;
405
		// Pass if there are no requested points
406
		if(!$point) return new Object();
407
		// In case of a registered member, if it is read but cannot just pass, then get the current points
408
		if($member_srl)
409
		{
410
			$args->member_srl = $member_srl;
0 ignored issues
show
Bug introduced by
The variable $args does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
411
			$args->document_srl = $obj->document_srl;
412
			$output = executeQuery('document.getDocumentReadedLogInfo', $args);
413
			if($output->data->count) return new Object();
414
			$cur_point = $oPointModel->getPoint($member_srl, true);
415
		}
416
		else
417
		{
418
			$cur_point = 0;
419
		}
420
		// Get the defaul configurations of the Point Module
421
		$config = $oModuleModel->getModuleConfig('point');
422
		// When the requested points are negative, compared it with the current point
423
		$_SESSION['banned_document'][$obj->document_srl] = false;
424
		if($config->disable_read_document == 'Y' && $point < 0 && abs($point)>$cur_point)
425
		{
426
			$message = sprintf(Context::getLang('msg_disallow_by_point'), abs($point), $cur_point);
427
			$obj->add('content', $message);
428
			$_SESSION['banned_document'][$obj->document_srl] = true;
429
			return new Object(-1, $message);
430
		}
431
		// If not logged in, pass
432
		if(!$logged_info->member_srl) return new Object();
433
		// Pass, if there are no requested points
434
		if(!$point) return new Object();
435
		// If the read record is missing, leave it
436
		$output = executeQuery('document.insertDocumentReadedLog', $args);
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
437
		// Increase the point
438
		$cur_point += $point;
439
		$this->setPoint($member_srl,$cur_point);
440
441
		return new Object();
442
	}
443
444
	/**
445
	 * @brief Points for voting up or down
446
	 */
447
	function triggerUpdateVotedCount(&$obj)
448
	{
449
		$module_srl = $obj->module_srl;
450
		$member_srl = $obj->member_srl;
451
		if(!$module_srl || !$member_srl) return new Object();
452
453
		$oModuleModel = getModel('module');
454
		$config = $oModuleModel->getModuleConfig('point');
455
		$module_config = $oModuleModel->getModulePartConfig('point', $module_srl);
456
457
		$oPointModel = getModel('point');
458
		$cur_point = $oPointModel->getPoint($member_srl, true);
459
460
		if( $obj->point > 0 )
461
		{
462
			$point = $module_config['voted'];
463
			if(strlen($point) == 0 && !is_int($point)) $point = $config->voted;
464
		}
465
		else
466
		{
467
			$point = $module_config['blamed'];
468
			if(strlen($point) == 0 && !is_int($point)) $point = $config->blamed;
469
		}
470
471
		if(!$point) return new Object();
472
		// Increase the point
473
		$cur_point += $point;
474
		$this->setPoint($member_srl,$cur_point);
475
476
		return new Object();
477
	}
478
479
	/**
480
	 * @brief Set points
481
	 */
482
	function setPoint($member_srl, $point, $mode = null)
483
	{
484
		$member_srl = abs($member_srl);
485
		$mode_arr = array('add', 'minus', 'update', 'signup');
486
		if(!$mode || !in_array($mode,$mode_arr)) $mode = 'update';
487
488
		// Get configuration information
489
		$oMemberModel = getModel('member');
490
		$oModuleModel = getModel('module');
491
		$oPointModel = getModel('point');
492
		$config = $oModuleModel->getModuleConfig('point');
493
494
		// Get the default configuration information
495
		$current_point = $oPointModel->getPoint($member_srl, true);
496
		$current_level = $oPointModel->getLevel($current_point, $config->level_step);
497
498
		// Change points
499
		$args = new stdClass();
500
		$args->member_srl = $member_srl;
501
		$args->point = $current_point;
502
503
		switch($mode)
504
		{
505
			case 'add' :
506
				$args->point += $point;
507
				break;
508
			case 'minus' :
509
				$args->point -= $point;
510
				break;
511
			case 'update' :
512
			case 'signup' :
513
				$args->point = $point;
514
				break;
515
		}
516
		if($args->point < 0) $args->point = 0;
517
		$point = $args->point;
518
519
		// Call a trigger (before)
520
		$trigger_obj = new stdClass();
521
		$trigger_obj->member_srl = $args->member_srl;
522
		$trigger_obj->mode = $mode;
523
		$trigger_obj->current_point = $current_point;
524
		$trigger_obj->current_level = $current_level;
525
		$trigger_obj->set_point = $point;
526
		$trigger_output = ModuleHandler::triggerCall('point.setPoint', 'before', $trigger_obj);
527
		if(!$trigger_output->toBool())
528
		{
529
			return $trigger_output;
530
		}
531
532
		// begin transaction
533
		$oDB = &DB::getInstance();
534
		$oDB->begin();
535
536
		// If there are points, update, if no, insert
537
		$oPointModel = getModel('point');
538
		if($oPointModel->isExistsPoint($member_srl)) executeQuery("point.updatePoint", $args);
539
		else executeQuery("point.insertPoint", $args);
540
541
		// Get a new level
542
		$level = $oPointModel->getLevel($point, $config->level_step);
543
544
		// If existing level and a new one are different attempt to set a point group
545
		if($level != $current_level)
546
		{
547
			// Check if the level, for which the current points are prepared, is calculate and set the correct group
548
			$point_group = $config->point_group;
549
			// If the point group exists
550
			if($point_group && is_array($point_group) && count($point_group) )
551
			{
552
				// Get the default group
553
				$default_group = $oMemberModel->getDefaultGroup();
554
				// Get the removed group and the newly granted group
555
				$del_group_list = array();
556
				$new_group_list = array();
557
558
				asort($point_group);
559
				// Reset group after initialization
560
				if($config->group_reset != 'N')
561
				{
562
					// If the new level is in the right group
563
					if(in_array($level, $point_group))
564
					{
565
						// Delete all groups except the one which the current level belongs to
566 View Code Duplication
						foreach($point_group as $group_srl => $target_level)
567
						{
568
							$del_group_list[] = $group_srl;
569
							if($target_level == $level) $new_group_list[] = $group_srl;
570
						}
571
					}
572
					// Otherwise, in case the level is reduced, add the recent group
573
					else
574
					{
575
						$i = $level;
576
						while($i > 0)
577
						{
578
							if(in_array($i, $point_group))
579
							{
580
								foreach($point_group as $group_srl => $target_level)
581
								{
582
									if($target_level == $i)
583
									{
584
										$new_group_list[] = $group_srl;
585
									}
586
								}
587
								$i = 0;
588
							}
589
							$i--;
590
						}
591
					}
592
					// Delete the group of a level which is higher than the current level
593
					foreach($point_group as $group_srl => $target_level)
594
					{
595
						if($target_level > $level) $del_group_list[] = $group_srl;
596
					}
597
					$del_group_list[] = $default_group->group_srl;
598
				}
599
				// Grant a new group
600
				else
601
				{
602
					// Check until the current level by rotating setting the configurations of the point groups
603 View Code Duplication
					foreach($point_group as $group_srl => $target_level)
604
					{
605
						$del_group_list[] = $group_srl;
606
						if($target_level <= $level) $new_group_list[] = $group_srl;
607
					}
608
				}
609
				// If there is no a new group, granted the default group
610
				if(!$new_group_list[0]) $new_group_list[0] = $default_group->group_srl;
611
				// Remove linkage group
612
				if($del_group_list && count($del_group_list))
0 ignored issues
show
Bug Best Practice introduced by
The expression $del_group_list of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
613
				{
614
					$del_group_args = new stdClass;
615
					$del_group_args->member_srl = $member_srl;
616
					$del_group_args->group_srl = implode(',', $del_group_list);
617
					$del_group_output = executeQuery('point.deleteMemberGroup', $del_group_args);
0 ignored issues
show
Unused Code introduced by
$del_group_output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
618
				}
619
				// Grant a new group
620
				foreach($new_group_list as $group_srl)
621
				{
622
					$new_group_args = new stdClass;
623
					$new_group_args->member_srl = $member_srl;
624
					$new_group_args->group_srl = $group_srl;
625
					executeQuery('member.addMemberToGroup', $new_group_args);
626
				}
627
			}
628
		}
629
630
		// Call a trigger (after)
631
		$trigger_obj->new_group_list = $new_group_list;
0 ignored issues
show
Bug introduced by
The variable $new_group_list does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
632
		$trigger_obj->del_group_list = $del_group_list;
0 ignored issues
show
Bug introduced by
The variable $del_group_list does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
633
		$trigger_obj->new_level = $level;
634
		$trigger_output = ModuleHandler::triggerCall('point.setPoint', 'after', $trigger_obj);
635
		if(!$trigger_output->toBool())
636
		{
637
			$oDB->rollback();
638
			return $trigger_output;
639
		}
640
641
		$oDB->commit();
642
643
		// Cache Settings
644
		$cache_path = sprintf('./files/member_extra_info/point/%s/', getNumberingPath($member_srl));
645
		FileHandler::makedir($cache_path);
646
647
		$cache_filename = sprintf('%s%d.cache.txt', $cache_path, $member_srl);
648
		FileHandler::writeFile($cache_filename, $point);
649
650
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
651 View Code Duplication
		if($new_group_list && $del_group_list && $oCacheHandler->isSupport())
0 ignored issues
show
Bug Best Practice introduced by
The expression $new_group_list of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
Bug Best Practice introduced by
The expression $del_group_list of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
652
		{
653
			$object_key = 'member_groups:' . getNumberingPath($member_srl) . $member_srl . '_0';
654
			$cache_key = $oCacheHandler->getGroupKey('member', $object_key);
655
			$oCacheHandler->delete($cache_key);
656
		}
657
658
		$oCacheHandler = CacheHandler::getInstance('object');
659 View Code Duplication
		if($new_group_list && $del_group_list && $oCacheHandler->isSupport())
0 ignored issues
show
Bug Best Practice introduced by
The expression $new_group_list of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
Bug Best Practice introduced by
The expression $del_group_list of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
660
		{
661
			$object_key = 'member_info:' . getNumberingPath($member_srl) . $member_srl;
662
			$cache_key = $oCacheHandler->getGroupKey('member', $object_key);
663
			$oCacheHandler->delete($cache_key);
664
		}
665
666
		return $output;
0 ignored issues
show
Bug introduced by
The variable $output does not exist. Did you mean $trigger_output?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
667
	}
668
669 View Code Duplication
	function triggerCopyModule(&$obj)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
670
	{
671
		$oModuleModel = getModel('module');
672
		$pointConfig = $oModuleModel->getModulePartConfig('point', $obj->originModuleSrl);
673
674
		$oModuleController = getController('module');
675
		if(is_array($obj->moduleSrlList))
676
		{
677
			foreach($obj->moduleSrlList AS $key=>$moduleSrl)
678
			{
679
				$oModuleController->insertModulePartConfig('point', $moduleSrl, $pointConfig);
680
			}
681
		}
682
	}
683
}
684
/* End of file point.controller.php */
685
/* Location: ./modules/point/point.controller.php */
686