1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace XoopsModules\Yogurt; |
6
|
|
|
|
7
|
|
|
/* |
8
|
|
|
You may not change or alter any portion of this comment or credits |
9
|
|
|
of supporting developers from this source code or any supporting source code |
10
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
11
|
|
|
|
12
|
|
|
This program is distributed in the hope that it will be useful, |
13
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
use Xmf\Module\Helper\Permission; |
18
|
|
|
use XoopsDatabaseFactory; |
19
|
|
|
use XoopsObject; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @category Module |
23
|
|
|
* @package yogurt |
24
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
25
|
|
|
* @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
26
|
|
|
* @author Marcello Brandão aka Suico, Mamba, LioMJ <https://xoops.org> |
27
|
|
|
*/ |
28
|
|
|
if (!\defined( |
29
|
|
|
'XOOPS_ROOT_PATH' |
30
|
|
|
)) { |
31
|
|
|
exit(); |
32
|
|
|
} |
33
|
|
|
require_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Ishot class. |
37
|
|
|
* $this class is responsible for providing data access mechanisms to the data source |
38
|
|
|
* of XOOPS user class objects. |
39
|
|
|
*/ |
40
|
|
|
class Ishot extends XoopsObject |
41
|
|
|
{ |
42
|
|
|
public $db; |
43
|
|
|
|
44
|
|
|
public $helper; |
45
|
|
|
|
46
|
|
|
public $permHelper; |
47
|
|
|
|
48
|
|
|
// constructor |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Ishot constructor. |
52
|
|
|
* @param null $id |
|
|
|
|
53
|
|
|
*/ |
54
|
|
|
|
55
|
|
|
public function __construct($id = null) |
56
|
|
|
{ |
57
|
|
|
/** @var Helper $helper */ |
58
|
|
|
|
59
|
|
|
$this->helper = Helper::getInstance(); |
60
|
|
|
|
61
|
|
|
$this->permHelper = new Permission(); |
62
|
|
|
|
63
|
|
|
$this->db = XoopsDatabaseFactory::getDatabaseConnection(); |
64
|
|
|
|
65
|
|
|
$this->initVar('cod_ishot', \XOBJ_DTYPE_INT, null, false, 10); |
66
|
|
|
|
67
|
|
|
$this->initVar('uid_voter', \XOBJ_DTYPE_INT, null, false, 10); |
68
|
|
|
|
69
|
|
|
$this->initVar('uid_voted', \XOBJ_DTYPE_INT, null, false, 10); |
70
|
|
|
|
71
|
|
|
$this->initVar('ishot', \XOBJ_DTYPE_INT, null, false, 10); |
72
|
|
|
|
73
|
|
|
$this->initVar('date_created', \XOBJ_DTYPE_INT, 0, false); |
74
|
|
|
|
75
|
|
|
if (!empty($id)) { |
76
|
|
|
if (\is_array($id)) { |
77
|
|
|
$this->assignVars($id); |
78
|
|
|
} else { |
79
|
|
|
$this->load((int)$id); |
80
|
|
|
} |
81
|
|
|
} else { |
82
|
|
|
$this->setNew(); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param $id |
88
|
|
|
*/ |
89
|
|
|
|
90
|
|
|
public function load($id) |
91
|
|
|
{ |
92
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('yogurt_ishot') . ' WHERE cod_ishot=' . $id; |
93
|
|
|
|
94
|
|
|
$myrow = $this->db->fetchArray($this->db->query($sql)); |
95
|
|
|
|
96
|
|
|
$this->assignVars($myrow); |
97
|
|
|
|
98
|
|
|
if (!$myrow) { |
99
|
|
|
$this->setNew(); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param array $criteria |
105
|
|
|
* @param bool $asobject |
106
|
|
|
* @param string $sort |
107
|
|
|
* @param string $order |
108
|
|
|
* @param int $limit |
109
|
|
|
* @param int $start |
110
|
|
|
* @return array |
111
|
|
|
*/ |
112
|
|
|
|
113
|
|
|
public function getAllHots( |
114
|
|
|
$criteria = [], |
115
|
|
|
$asobject = false, |
116
|
|
|
$sort = 'cod_ishot', |
117
|
|
|
$order = 'ASC', |
118
|
|
|
$limit = 0, |
119
|
|
|
$start = 0 |
120
|
|
|
) { |
121
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
122
|
|
|
|
123
|
|
|
$ret = []; |
124
|
|
|
|
125
|
|
|
$whereQuery = ''; |
126
|
|
|
|
127
|
|
|
if (\is_array($criteria) && \count($criteria) > 0) { |
128
|
|
|
$whereQuery = ' WHERE'; |
129
|
|
|
|
130
|
|
|
foreach ($criteria as $c) { |
131
|
|
|
$whereQuery .= " ${c} AND"; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
$whereQuery = mb_substr($whereQuery, 0, -4); |
135
|
|
|
} elseif (!\is_array($criteria) && $criteria) { |
136
|
|
|
$whereQuery = ' WHERE ' . $criteria; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
if (!$asobject) { |
140
|
|
|
$sql = 'SELECT cod_ishot FROM ' . $db->prefix( |
141
|
|
|
'yogurt_ishot' |
142
|
|
|
) . "${whereQuery} ORDER BY ${sort} ${order}"; |
143
|
|
|
|
144
|
|
|
$result = $db->query($sql, $limit, $start); |
145
|
|
|
|
146
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
147
|
|
|
$ret[] = $myrow['yogurt_ishot_id']; |
148
|
|
|
} |
149
|
|
|
} else { |
150
|
|
|
$sql = 'SELECT * FROM ' . $db->prefix('yogurt_ishot') . "${whereQuery} ORDER BY ${sort} ${order}"; |
151
|
|
|
|
152
|
|
|
$result = $db->query($sql, $limit, $start); |
153
|
|
|
|
154
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
155
|
|
|
$ret[] = new self($myrow); |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
return $ret; |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
|