1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace XoopsModules\Suico; |
||
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 suico |
||
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 | * Protection against inclusion outside the site |
||
30 | */ |
||
31 | if (!\defined('XOOPS_ROOT_PATH')) { |
||
32 | die('XOOPS root path not defined'); |
||
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 | // constructor |
||
52 | |||
53 | /** |
||
54 | * Image constructor. |
||
55 | * @param null $id |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
56 | */ |
||
57 | public function __construct($id = null) |
||
58 | { |
||
59 | /** @var Helper $helper */ |
||
60 | $this->helper = Helper::getInstance(); |
||
61 | $this->permHelper = new Permission(); |
||
62 | $this->db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
63 | $this->initVar('image_id', \XOBJ_DTYPE_INT, null, false, 10); |
||
64 | $this->initVar('title', \XOBJ_DTYPE_TXTBOX, null, false); |
||
65 | $this->initVar('caption', \XOBJ_DTYPE_TXTBOX, null, false); |
||
66 | $this->initVar('date_created', \XOBJ_DTYPE_INT, 0, false); |
||
67 | $this->initVar('date_updated', \XOBJ_DTYPE_INT, 0, false); |
||
68 | $this->initVar('uid_owner', \XOBJ_DTYPE_TXTBOX, null, false); |
||
69 | $this->initVar('filename', \XOBJ_DTYPE_OTHER, null, false); |
||
70 | $this->initVar('private', \XOBJ_DTYPE_TXTBOX, null, false); |
||
71 | if (!empty($id)) { |
||
72 | if (\is_array($id)) { |
||
73 | $this->assignVars($id); |
||
74 | } else { |
||
75 | $this->load((int)$id); |
||
76 | } |
||
77 | } else { |
||
78 | $this->setNew(); |
||
79 | } |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * @param $id |
||
84 | */ |
||
85 | public function load($id) |
||
86 | { |
||
87 | $sql = 'SELECT * FROM ' . $this->db->prefix('suico_images') . ' WHERE image_id=' . $id; |
||
88 | $myrow = $this->db->fetchArray($this->db->query($sql)); |
||
89 | $this->assignVars($myrow); |
||
90 | if (!$myrow) { |
||
91 | $this->setNew(); |
||
92 | } |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * @param array $criteria |
||
97 | * @param bool $asobject |
||
98 | * @param string $sort |
||
99 | * @param string $order |
||
100 | * @param int $limit |
||
101 | * @param int $start |
||
102 | * @return array |
||
103 | */ |
||
104 | public function getAllImages( |
||
105 | $criteria = [], |
||
106 | $asobject = false, |
||
107 | $sort = 'image_id', |
||
108 | $order = 'ASC', |
||
109 | $limit = 0, |
||
110 | $start = 0 |
||
111 | ) { |
||
112 | $db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
113 | $ret = []; |
||
114 | $whereQuery = ''; |
||
115 | if (\is_array($criteria) && \count($criteria) > 0) { |
||
116 | $whereQuery = ' WHERE'; |
||
117 | foreach ($criteria as $c) { |
||
118 | $whereQuery .= " ${c} AND"; |
||
119 | } |
||
120 | $whereQuery = mb_substr($whereQuery, 0, -4); |
||
121 | } elseif (!\is_array($criteria) && $criteria) { |
||
122 | $whereQuery = ' WHERE ' . $criteria; |
||
123 | } |
||
124 | if (!$asobject) { |
||
125 | $sql = 'SELECT image_id FROM ' . $db->prefix('suico_images') . "${whereQuery} ORDER BY ${sort} ${order}"; |
||
126 | $result = $db->query($sql, $limit, $start); |
||
127 | while (false !== ($myrow = $db->fetchArray($result))) { |
||
128 | $ret[] = $myrow['suico_images_id']; |
||
129 | } |
||
130 | } else { |
||
131 | $sql = 'SELECT * FROM ' . $db->prefix('suico_images') . "${whereQuery} ORDER BY ${sort} ${order}"; |
||
132 | $result = $db->query($sql, $limit, $start); |
||
133 | while (false !== ($myrow = $db->fetchArray($result))) { |
||
134 | $ret[] = new self($myrow); |
||
135 | } |
||
136 | } |
||
137 | return $ret; |
||
138 | } |
||
139 | |||
140 | /** |
||
141 | * Get form |
||
142 | * |
||
143 | * @return \XoopsModules\Suico\Form\ImagesForm |
||
144 | */ |
||
145 | public function getForm() |
||
146 | { |
||
147 | return new Form\ImagesForm($this); |
||
148 | } |
||
149 | |||
150 | /** |
||
151 | * @return array|null |
||
152 | */ |
||
153 | public function getGroupsRead() |
||
154 | { |
||
155 | //$permHelper = new \Xmf\Module\Helper\Permission(); |
||
156 | return $this->permHelper->getGroupsForItem( |
||
157 | 'sbcolumns_read', |
||
158 | $this->getVar('image_id') |
||
159 | ); |
||
160 | } |
||
161 | |||
162 | /** |
||
163 | * @return array|null |
||
164 | */ |
||
165 | public function getGroupsSubmit() |
||
166 | { |
||
167 | //$permHelper = new \Xmf\Module\Helper\Permission(); |
||
168 | return $this->permHelper->getGroupsForItem( |
||
169 | 'sbcolumns_submit', |
||
170 | $this->getVar('image_id') |
||
171 | ); |
||
172 | } |
||
173 | |||
174 | /** |
||
175 | * @return array|null |
||
176 | */ |
||
177 | public function getGroupsModeration() |
||
178 | { |
||
179 | //$permHelper = new \Xmf\Module\Helper\Permission(); |
||
180 | return $this->permHelper->getGroupsForItem( |
||
181 | 'sbcolumns_moderation', |
||
182 | $this->getVar('image_id') |
||
183 | ); |
||
184 | } |
||
185 | } |
||
186 |