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
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Protection against inclusion outside the site |
31
|
|
|
*/ |
32
|
|
|
if (!\defined('XOOPS_ROOT_PATH')) { |
33
|
|
|
die('XOOPS root path not defined'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Includes of form objects and uploader |
38
|
|
|
*/ |
39
|
|
|
require_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
40
|
|
|
require_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
41
|
|
|
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Image class. |
45
|
|
|
* $this class is responsible for providing data access mechanisms to the data source |
46
|
|
|
* of XOOPS user class objects. |
47
|
|
|
*/ |
48
|
|
|
class Image extends XoopsObject |
49
|
|
|
{ |
50
|
|
|
public $db; |
51
|
|
|
public $helper; |
52
|
|
|
public $permHelper; |
53
|
|
|
|
54
|
|
|
// constructor |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Image constructor. |
58
|
|
|
* @param null $id |
|
|
|
|
59
|
|
|
*/ |
60
|
|
|
public function __construct($id = null) |
61
|
|
|
{ |
62
|
|
|
/** @var Helper $helper */ |
63
|
|
|
$this->helper = Helper::getInstance(); |
64
|
|
|
$this->permHelper = new Permission(); |
65
|
|
|
$this->db = XoopsDatabaseFactory::getDatabaseConnection(); |
66
|
|
|
$this->initVar('cod_img', \XOBJ_DTYPE_INT, null, false, 10); |
67
|
|
|
$this->initVar('title', \XOBJ_DTYPE_TXTBOX, null, false); |
68
|
|
|
$this->initVar('caption', \XOBJ_DTYPE_TXTBOX, null, false); |
69
|
|
|
$this->initVar('date_created', \XOBJ_DTYPE_INT, 0, false); |
70
|
|
|
$this->initVar('date_updated', \XOBJ_DTYPE_INT, 0, false); |
71
|
|
|
$this->initVar('uid_owner', \XOBJ_DTYPE_TXTBOX, null, false); |
72
|
|
|
$this->initVar('filename', \XOBJ_DTYPE_OTHER, null, false); |
73
|
|
|
$this->initVar('private', \XOBJ_DTYPE_TXTBOX, null, false); |
74
|
|
|
if (!empty($id)) { |
75
|
|
|
if (\is_array($id)) { |
76
|
|
|
$this->assignVars($id); |
77
|
|
|
} else { |
78
|
|
|
$this->load((int)$id); |
79
|
|
|
} |
80
|
|
|
} else { |
81
|
|
|
$this->setNew(); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param $id |
87
|
|
|
*/ |
88
|
|
|
public function load($id) |
89
|
|
|
{ |
90
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('yogurt_images') . ' WHERE cod_img=' . $id; |
91
|
|
|
$myrow = $this->db->fetchArray($this->db->query($sql)); |
92
|
|
|
$this->assignVars($myrow); |
93
|
|
|
if (!$myrow) { |
94
|
|
|
$this->setNew(); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param array $criteria |
100
|
|
|
* @param bool $asobject |
101
|
|
|
* @param string $sort |
102
|
|
|
* @param string $order |
103
|
|
|
* @param int $limit |
104
|
|
|
* @param int $start |
105
|
|
|
* @return array |
106
|
|
|
*/ |
107
|
|
|
public function getAllImages( |
108
|
|
|
$criteria = [], |
109
|
|
|
$asobject = false, |
110
|
|
|
$sort = 'cod_img', |
111
|
|
|
$order = 'ASC', |
112
|
|
|
$limit = 0, |
113
|
|
|
$start = 0 |
114
|
|
|
) { |
115
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
116
|
|
|
$ret = []; |
117
|
|
|
$whereQuery = ''; |
118
|
|
|
if (\is_array($criteria) && \count($criteria) > 0) { |
119
|
|
|
$whereQuery = ' WHERE'; |
120
|
|
|
foreach ($criteria as $c) { |
121
|
|
|
$whereQuery .= " ${c} AND"; |
122
|
|
|
} |
123
|
|
|
$whereQuery = mb_substr($whereQuery, 0, -4); |
124
|
|
|
} elseif (!\is_array($criteria) && $criteria) { |
125
|
|
|
$whereQuery = ' WHERE ' . $criteria; |
126
|
|
|
} |
127
|
|
|
if (!$asobject) { |
128
|
|
|
$sql = 'SELECT cod_img FROM ' . $db->prefix('yogurt_images') . "${whereQuery} ORDER BY ${sort} ${order}"; |
129
|
|
|
$result = $db->query($sql, $limit, $start); |
130
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
131
|
|
|
$ret[] = $myrow['yogurt_images_id']; |
132
|
|
|
} |
133
|
|
|
} else { |
134
|
|
|
$sql = 'SELECT * FROM ' . $db->prefix('yogurt_images') . "${whereQuery} ORDER BY ${sort} ${order}"; |
135
|
|
|
$result = $db->query($sql, $limit, $start); |
136
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
137
|
|
|
$ret[] = new self($myrow); |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
return $ret; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Get form |
146
|
|
|
* |
147
|
|
|
* @return \XoopsModules\Yogurt\Form\ImagesForm |
148
|
|
|
*/ |
149
|
|
|
public function getForm() |
150
|
|
|
{ |
151
|
|
|
return new Form\ImagesForm($this); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @return array|null |
156
|
|
|
*/ |
157
|
|
|
public function getGroupsRead() |
158
|
|
|
{ |
159
|
|
|
//$permHelper = new \Xmf\Module\Helper\Permission(); |
160
|
|
|
return $this->permHelper->getGroupsForItem( |
161
|
|
|
'sbcolumns_read', |
162
|
|
|
$this->getVar('cod_img') |
163
|
|
|
); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @return array|null |
168
|
|
|
*/ |
169
|
|
|
public function getGroupsSubmit() |
170
|
|
|
{ |
171
|
|
|
//$permHelper = new \Xmf\Module\Helper\Permission(); |
172
|
|
|
return $this->permHelper->getGroupsForItem( |
173
|
|
|
'sbcolumns_submit', |
174
|
|
|
$this->getVar('cod_img') |
175
|
|
|
); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @return array|null |
180
|
|
|
*/ |
181
|
|
|
public function getGroupsModeration() |
182
|
|
|
{ |
183
|
|
|
//$permHelper = new \Xmf\Module\Helper\Permission(); |
184
|
|
|
return $this->permHelper->getGroupsForItem( |
185
|
|
|
'sbcolumns_moderation', |
186
|
|
|
$this->getVar('cod_img') |
187
|
|
|
); |
188
|
|
|
} |
189
|
|
|
} |
190
|
|
|
|