1
|
|
|
<?php namespace Xoopsmodules\instruction; |
2
|
|
|
|
3
|
|
|
//if (!defined("XOOPS_ROOT_PATH")) { |
|
|
|
|
4
|
|
|
// die("XOOPS root path not defined"); |
5
|
|
|
//} |
6
|
|
|
|
7
|
|
|
include_once $GLOBALS['xoops']->path('include/common.php'); |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class PageHandler |
11
|
|
|
* @package Xoopsmodules\instruction |
12
|
|
|
*/ |
13
|
|
|
class PageHandler extends \XoopsPersistableObjectHandler |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @param null|mixed $db |
17
|
|
|
*/ |
18
|
|
|
public function __construct(\XoopsDatabase $db = null) |
19
|
|
|
{ |
20
|
|
|
parent::__construct($db, 'instruction_page', Page::class, 'pageid', 'title'); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Generate function for update user post |
25
|
|
|
* |
26
|
|
|
* @ Update user post count after send approve content |
27
|
|
|
* @ Update user post count after change status content |
28
|
|
|
* @ Update user post count after delete content |
29
|
|
|
* @param $uid |
30
|
|
|
* @param $status |
31
|
|
|
* @param $action |
32
|
|
|
*/ |
33
|
|
|
public function updateposts($uid, $status, $action) |
34
|
|
|
{ |
35
|
|
|
// |
36
|
|
|
switch ($action) { |
37
|
|
|
// Добавление страницы |
38
|
|
View Code Duplication |
case 'add': |
|
|
|
|
39
|
|
|
if ($uid && $status) { |
40
|
|
|
$user = new \XoopsUser($uid); |
41
|
|
|
$memberHandler = xoops_getHandler('member'); |
42
|
|
|
// Добавялем +1 к комментам |
43
|
|
|
$memberHandler->updateUserByField($user, 'posts', $user->getVar('posts') + 1); |
44
|
|
|
} |
45
|
|
|
break; |
46
|
|
|
// Удаление страницы |
47
|
|
View Code Duplication |
case 'delete': |
|
|
|
|
48
|
|
|
if ($uid && $status) { |
49
|
|
|
$user = new \XoopsUser($uid); |
50
|
|
|
$memberHandler = xoops_getHandler('member'); |
51
|
|
|
// Декримент комментов |
52
|
|
|
//$user->setVar( 'posts', $user->getVar( 'posts' ) - 1 ); |
|
|
|
|
53
|
|
|
// Сохраняем |
54
|
|
|
$memberHandler->updateUserByField($user, 'posts', $user->getVar('posts') - 1); |
55
|
|
|
} |
56
|
|
|
break; |
57
|
|
|
|
58
|
|
|
case 'status': |
59
|
|
|
if ($uid) { |
60
|
|
|
$user = new \XoopsUser($uid); |
61
|
|
|
$memberHandler = xoops_getHandler('member'); |
62
|
|
|
if ($status) { |
63
|
|
|
$memberHandler->updateUserByField($user, 'posts', $user->getVar('posts') - 1); |
64
|
|
|
} else { |
65
|
|
|
$memberHandler->updateUserByField($user, 'posts', $user->getVar('posts') + 1); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
break; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.