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
|
|
|
|
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.