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_CONSTANTS_INCLUDED')) { |
23
|
|
|
exit(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
// require_once XHELP_CLASS_PATH . '/BaseObjectHandler.php'; |
27
|
|
|
// $helper->LoadLanguage('admin'); |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* class TicketValuesHandler |
31
|
|
|
*/ |
32
|
|
|
class TicketValuesHandler extends BaseObjectHandler |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* Name of child class |
36
|
|
|
* |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
public $classname = TicketValues::class; |
40
|
|
|
/** |
41
|
|
|
* DB Table Name |
42
|
|
|
* |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
public $dbtable = 'xhelp_ticket_values'; |
46
|
|
|
public $id = 'ticketid'; |
47
|
|
|
public $idfield = 'ticketid'; |
48
|
|
|
|
49
|
|
|
private const TABLE = 'xhelp_ticket_values'; |
50
|
|
|
private const ENTITY = TicketValues::class; |
51
|
|
|
private const ENTITYNAME = 'TicketValues'; |
52
|
|
|
private const KEYNAME = 'ticketid'; |
53
|
|
|
private const IDENTIFIER = 'ticketid'; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Constructor |
57
|
|
|
* |
58
|
|
|
* @param \XoopsMySQLDatabase|null $db reference to a xoopsDB object |
59
|
|
|
*/ |
60
|
|
|
public function __construct(\XoopsMySQLDatabase $db = null) |
61
|
|
|
{ |
62
|
|
|
$this->init($db); |
63
|
|
|
$this->helper = Helper::getInstance(); |
64
|
|
|
parent::__construct($db, static::TABLE, static::ENTITY, static::KEYNAME, static::IDENTIFIER); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param \XoopsObject $object |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
public function insertQuery(\XoopsObject $object): string |
72
|
|
|
{ |
73
|
|
|
//TODO mb replace with individual variables |
74
|
|
|
// Copy all object vars into local variables |
75
|
|
|
foreach ($object->cleanVars as $k => $v) { // Assumes cleanVars has already been called |
76
|
|
|
${$k} = $v; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$myFields = $object->getTicketFields(); // Returns array[$fieldname] = %s or %d for all custom fields |
|
|
|
|
80
|
|
|
|
81
|
|
|
$count = 1; |
82
|
|
|
$sqlFields = ''; |
83
|
|
|
$sqlVars = ''; |
84
|
|
|
foreach ($myFields as $myField => $datatype) { // Create sql name and value pairs |
85
|
|
|
if (null !== ${$myField}) { |
86
|
|
|
if ($count > 1) { // If we have been through the loop already |
87
|
|
|
$sqlVars .= ', '; |
88
|
|
|
$sqlFields .= ', '; |
89
|
|
|
} |
90
|
|
|
$sqlFields .= $myField; |
91
|
|
|
if ('%s' === $datatype) { // If this field is a string |
92
|
|
|
$sqlVars .= $this->db->quoteString(${$myField}); // Add text to sqlVars string |
93
|
|
|
} else { // If this field is a number |
94
|
|
|
$sqlVars .= ${$myField}; // Add text to sqlVars string |
95
|
|
|
} |
96
|
|
|
++$count; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
// Create sql statement |
100
|
|
|
$sql = 'INSERT INTO ' . $this->db->prefix($this->dbtable) . ' (' . $sqlFields . ') VALUES (' . $sqlVars . ')'; |
101
|
|
|
|
102
|
|
|
return $sql; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param \XoopsObject $object |
107
|
|
|
* @return string |
108
|
|
|
*/ |
109
|
|
|
public function updateQuery(\XoopsObject $object): string |
110
|
|
|
{ |
111
|
|
|
//TODO mb replace with individual variables |
112
|
|
|
// Copy all object vars into local variables |
113
|
|
|
foreach ($object->cleanVars as $k => $v) { |
114
|
|
|
${$k} = $v; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
$myFields = $object->getTicketFields(); // Returns array[$fieldname] = %s or %u for all custom fields |
118
|
|
|
$count = 1; |
119
|
|
|
$sqlVars = ''; |
120
|
|
|
foreach ($myFields as $myField => $datatype) { // Used to create sql field and value substrings |
121
|
|
|
if (null !== ${$myField}) { |
122
|
|
|
if ($count > 1) { // If we have been through the loop already |
123
|
|
|
$sqlVars .= ', '; |
124
|
|
|
} |
125
|
|
|
if ('%s' === $datatype) { // If this field is a string |
126
|
|
|
$sqlVars .= $myField . ' = ' . $this->db->quoteString(${$myField}); // Add text to sqlVars string |
127
|
|
|
} else { // If this field is a number |
128
|
|
|
$sqlVars .= $myField . ' = ' . ${$myField}; // Add text to sqlVars string |
129
|
|
|
} |
130
|
|
|
++$count; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
// Create update statement |
135
|
|
|
$sql = 'UPDATE ' . $this->db->prefix($this->dbtable) . ' SET ' . $sqlVars . ' WHERE ticketid = ' . $object->getVar('ticketid'); |
136
|
|
|
|
137
|
|
|
return $sql; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @param \XoopsObject $object |
142
|
|
|
* @return string |
143
|
|
|
*/ |
144
|
|
|
public function deleteQuery(\XoopsObject $object): string |
145
|
|
|
{ |
146
|
|
|
$sql = \sprintf('DELETE FROM `%s` WHERE ticketid = %u', $this->db->prefix($this->dbtable), $object->getVar($this->id)); |
|
|
|
|
147
|
|
|
|
148
|
|
|
return $sql; |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|