StaffReviewHandler::updateQuery()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 15
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 23
rs 9.7666
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Xhelp;
4
5
/*
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
15
/**
16
 * @copyright    {@link https://xoops.org/ XOOPS Project}
17
 * @license      {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
18
 * @author       Eric Juden <[email protected]>
19
 * @author       XOOPS Development Team
20
 */
21
22
if (!\defined('XHELP_CLASS_PATH')) {
23
    exit();
24
}
25
26
// require_once XHELP_CLASS_PATH . '/BaseObjectHandler.php';
27
28
/**
29
 * StaffReviewHandler class
30
 *
31
 * StaffReview Handler for StaffReview class
32
 *
33
 * @author  Eric Juden <[email protected]> &
34
 */
35
class StaffReviewHandler extends BaseObjectHandler
36
{
37
    /**
38
     * Name of child class
39
     *
40
     * @var string
41
     */
42
    public $classname = StaffReview::class;
43
    /**
44
     * DB table name
45
     *
46
     * @var string
47
     */
48
    public $dbtable = 'xhelp_staffreview';
49
50
    private const TABLE = 'xhelp_staffreview';
51
    private const ENTITY = StaffReview::class;
52
    private const ENTITYNAME = 'StaffReview';
53
    private const KEYNAME = 'id';
54
    private const IDENTIFIER = 'staffid';
55
56
    /**
57
     * Constructor
58
     *
59
     * @param \XoopsMySQLDatabase|null $db reference to a xoopsDB object
60
     */
61
    public function __construct(\XoopsMySQLDatabase $db = null)
62
    {
63
        $this->init($db);
64
        $this->helper = Helper::getInstance();
65
        parent::__construct($db, static::TABLE, static::ENTITY, static::KEYNAME, static::IDENTIFIER);
66
    }
67
68
    /**
69
     * retrieve a StaffReview object meeting certain criteria
70
     * @param int $ticketid    ID of ticket
71
     * @param int $responseid  ID of response
72
     * @param int $submittedBy UID of ticket submitter
73
     * @return array|bool (@link StaffReview}
74
     */
75
    public function getReview(int $ticketid, int $responseid, int $submittedBy)
76
    {
77
        $ticketid    = $ticketid;
78
        $responseid  = $responseid;
79
        $submittedBy = $submittedBy;
80
81
        $criteria = new \CriteriaCompo(new \Criteria('ticketid', (string)$ticketid));
82
        $criteria->add(new \Criteria('submittedBy', (string)$submittedBy));
83
        $criteria->add(new \Criteria('responseid', (string)$responseid));
84
        $review = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $review is dead and can be removed.
Loading history...
85
        if (!$review = $this->getObjects($criteria)) {
86
            return false;
87
        }
88
89
        return $review;
90
    }
91
92
    /**
93
     * @param \XoopsObject $object
94
     * @return string
95
     */
96
    public function insertQuery(\XoopsObject $object): string
97
    {
98
        //TODO mb replace with individual variables
99
        // Copy all object vars into local variables
100
        foreach ($object->cleanVars as $k => $v) {
101
            ${$k} = $v;
102
        }
103
104
        $sql = \sprintf(
105
            'INSERT INTO `%s` (id, staffid, rating, ticketid, responseid, comments, submittedBy, userIP)
106
            VALUES (%u, %u, %u, %u, %u, %s, %u, %s)',
107
            $this->db->prefix($this->dbtable),
108
            $id,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $id seems to be never defined.
Loading history...
109
            $staffid,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $staffid seems to be never defined.
Loading history...
110
            $rating,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $rating seems to be never defined.
Loading history...
111
            $ticketid,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $ticketid seems to be never defined.
Loading history...
112
            $responseid,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $responseid seems to be never defined.
Loading history...
113
            $this->db->quoteString($comments),
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $comments seems to be never defined.
Loading history...
114
            $submittedBy,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $submittedBy seems to be never defined.
Loading history...
115
            $this->db->quoteString($userIP)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $userIP seems to be never defined.
Loading history...
116
        );
117
118
        return $sql;
119
    }
120
121
    /**
122
     * @param \XoopsObject $object
123
     * @return string
124
     */
125
    public function updateQuery(\XoopsObject $object): string
126
    {
127
        //TODO mb replace with individual variables
128
        // Copy all object vars into local variables
129
        foreach ($object->cleanVars as $k => $v) {
130
            ${$k} = $v;
131
        }
132
133
        $sql = \sprintf(
134
            'UPDATE `%s` SET staffid = %u, rating = %u, ticketid = %u, responseid = %u, comments = %s, submittedBy = %u, userIP = %s
135
                WHERE id = %u',
136
            $this->db->prefix($this->dbtable),
137
            $staffid,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $staffid seems to be never defined.
Loading history...
138
            $rating,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $rating seems to be never defined.
Loading history...
139
            $ticketid,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $ticketid seems to be never defined.
Loading history...
140
            $responseid,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $responseid seems to be never defined.
Loading history...
141
            $this->db->quoteString($comments),
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $comments seems to be never defined.
Loading history...
142
            $submittedBy,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $submittedBy seems to be never defined.
Loading history...
143
            $this->db->quoteString($userIP),
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $userIP seems to be never defined.
Loading history...
144
            $id
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $id seems to be never defined.
Loading history...
145
        );
146
147
        return $sql;
148
    }
149
150
    /**
151
     * @param \XoopsObject $object
152
     * @return string
153
     */
154
    public function deleteQuery(\XoopsObject $object): string
155
    {
156
        $sql = \sprintf('DELETE FROM `%s` WHERE id = %u', $this->db->prefix($this->dbtable), $object->getVar('id'));
0 ignored issues
show
Bug introduced by
It seems like $object->getVar('id') can also be of type array and array; however, parameter $values of sprintf() does only seem to accept double|integer|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

156
        $sql = \sprintf('DELETE FROM `%s` WHERE id = %u', $this->db->prefix($this->dbtable), /** @scrutinizer ignore-type */ $object->getVar('id'));
Loading history...
157
158
        return $sql;
159
    }
160
}
161