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