Completed
Push — master ( a4e09c...825da9 )
by Michael
01:51
created

PageHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php namespace Xoopsmodules\instruction;
2
3
//if (!defined("XOOPS_ROOT_PATH")) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
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':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
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':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
48
                if ($uid && $status) {
49
                    $user          = new \XoopsUser($uid);
50
                    $memberHandler = xoops_getHandler('member');
51
                    // Декримент комментов
52
                    //$user->setVar( 'posts', $user->getVar( 'posts' ) - 1 );
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

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.

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