|
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
|
|
|
* StatusHandler class |
|
30
|
|
|
* |
|
31
|
|
|
* Status Handler for Status class |
|
32
|
|
|
* |
|
33
|
|
|
* @author Eric Juden <[email protected]> & |
|
34
|
|
|
*/ |
|
35
|
|
|
class StatusHandler extends BaseObjectHandler |
|
36
|
|
|
{ |
|
37
|
|
|
/** |
|
38
|
|
|
* Name of child class |
|
39
|
|
|
* |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
public $classname = Status::class; |
|
43
|
|
|
/** |
|
44
|
|
|
* DB table name |
|
45
|
|
|
* |
|
46
|
|
|
* @var string |
|
47
|
|
|
*/ |
|
48
|
|
|
public $dbtable = 'xhelp_status'; |
|
49
|
|
|
|
|
50
|
|
|
private const TABLE = 'xhelp_status'; |
|
51
|
|
|
private const ENTITY = Status::class; |
|
52
|
|
|
private const ENTITYNAME = 'Status'; |
|
53
|
|
|
private const KEYNAME = 'id'; |
|
54
|
|
|
private const IDENTIFIER = 'state'; |
|
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
|
|
|
* @param \XoopsObject $object |
|
70
|
|
|
* @return string |
|
71
|
|
|
*/ |
|
72
|
|
|
public function insertQuery(\XoopsObject $object): string |
|
73
|
|
|
{ |
|
74
|
|
|
//TODO mb replace with individual variables |
|
75
|
|
|
// Copy all object vars into local variables |
|
76
|
|
|
foreach ($object->cleanVars as $k => $v) { |
|
77
|
|
|
${$k} = $v; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
$sql = \sprintf('INSERT INTO `%s` (id, state, description) VALUES (%u, %u, %s)', $this->db->prefix($this->dbtable), $id, $state, $this->db->quoteString($description)); |
|
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
return $sql; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param \XoopsObject $object |
|
87
|
|
|
* @return string |
|
88
|
|
|
*/ |
|
89
|
|
|
public function updateQuery(\XoopsObject $object): string |
|
90
|
|
|
{ |
|
91
|
|
|
//TODO mb replace with individual variables |
|
92
|
|
|
// Copy all object vars into local variables |
|
93
|
|
|
foreach ($object->cleanVars as $k => $v) { |
|
94
|
|
|
${$k} = $v; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
$sql = \sprintf('UPDATE `%s` SET state = %u, description = %s WHERE id = %u', $this->db->prefix($this->dbtable), $state, $this->db->quoteString($description), $id); |
|
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
return $sql; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @param \XoopsObject $object |
|
104
|
|
|
* @return string |
|
105
|
|
|
*/ |
|
106
|
|
|
public function deleteQuery(\XoopsObject $object): string |
|
107
|
|
|
{ |
|
108
|
|
|
$sql = \sprintf('DELETE FROM `%s` WHERE ID = %u', $this->db->prefix($this->dbtable), $object->getVar('id')); |
|
|
|
|
|
|
109
|
|
|
|
|
110
|
|
|
return $sql; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @param int $state |
|
115
|
|
|
* @return array |
|
116
|
|
|
*/ |
|
117
|
|
|
public function &getStatusesByState(int $state): array |
|
118
|
|
|
{ |
|
119
|
|
|
$aStatuses = []; |
|
|
|
|
|
|
120
|
|
|
$state = $state; |
|
121
|
|
|
$criteria = new \Criteria('state', $state); |
|
122
|
|
|
$aStatuses = $this->getObjects($criteria, true); |
|
123
|
|
|
|
|
124
|
|
|
return $aStatuses; |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|