|
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
|
|
|
// require_once XHELP_CLASS_PATH . '/BaseObjectHandler.php'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* xhelpResponseTemplatesHandler class |
|
29
|
|
|
* |
|
30
|
|
|
* ResponseTemplates Handler for xhelpResponseTemplates class |
|
31
|
|
|
* |
|
32
|
|
|
* @author Eric Juden <[email protected]> & |
|
33
|
|
|
*/ |
|
34
|
|
|
class ResponseTemplatesHandler extends BaseObjectHandler |
|
35
|
|
|
{ |
|
36
|
|
|
/** |
|
37
|
|
|
* Name of child class |
|
38
|
|
|
* |
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
public $classname = ResponseTemplates::class; |
|
42
|
|
|
/** |
|
43
|
|
|
* DB table name |
|
44
|
|
|
* |
|
45
|
|
|
* @var string |
|
46
|
|
|
*/ |
|
47
|
|
|
public $dbtable = 'xhelp_responsetemplates'; |
|
48
|
|
|
|
|
49
|
|
|
private const TABLE = 'xhelp_responsetemplates'; |
|
50
|
|
|
private const ENTITY = ResponseTemplates::class; |
|
51
|
|
|
private const ENTITYNAME = 'ResponseTemplates'; |
|
52
|
|
|
private const KEYNAME = 'id'; |
|
53
|
|
|
private const IDENTIFIER = 'name'; |
|
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) { |
|
76
|
|
|
${$k} = $v; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
$sql = \sprintf( |
|
80
|
|
|
'INSERT INTO `%s` (id, uid, NAME, response) |
|
81
|
|
|
VALUES (%u, %u, %s, %s)', |
|
82
|
|
|
$this->db->prefix($this->dbtable), |
|
83
|
|
|
$id, |
|
|
|
|
|
|
84
|
|
|
$uid, |
|
|
|
|
|
|
85
|
|
|
$this->db->quoteString($name), |
|
|
|
|
|
|
86
|
|
|
$this->db->quoteString($response) |
|
|
|
|
|
|
87
|
|
|
); |
|
88
|
|
|
|
|
89
|
|
|
return $sql; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @param \XoopsObject $object |
|
94
|
|
|
* @return string |
|
95
|
|
|
*/ |
|
96
|
|
|
public function updateQuery(\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('UPDATE `%s` SET uid = %u, NAME = %s, response = %s WHERE id = %u', $this->db->prefix($this->dbtable), $uid, $this->db->quoteString($name), $this->db->quoteString($response), $id); |
|
|
|
|
|
|
105
|
|
|
|
|
106
|
|
|
return $sql; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @param \XoopsObject $object |
|
111
|
|
|
* @return string |
|
112
|
|
|
*/ |
|
113
|
|
|
public function deleteQuery(\XoopsObject $object): string |
|
114
|
|
|
{ |
|
115
|
|
|
$sql = \sprintf('DELETE FROM `%s` WHERE id = %u', $this->db->prefix($this->dbtable), $object->getVar('id')); |
|
|
|
|
|
|
116
|
|
|
|
|
117
|
|
|
return $sql; |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|