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