| 1: | <?php
|
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: |
|
| 18: | defined('XOOPS_ROOT_PATH') || exit('Restricted access');
|
| 19: |
|
| 20: | |
| 21: | |
| 22: | |
| 23: |
|
| 24: |
|
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: |
|
| 33: | class XoopsImagecategory extends XoopsObject
|
| 34: | {
|
| 35: | public $_imageCount;
|
| 36: |
|
| 37: | public $imgcat_id;
|
| 38: | public $imgcat_name;
|
| 39: | public $imgcat_display;
|
| 40: | public $imgcat_weight;
|
| 41: | public $imgcat_maxsize;
|
| 42: | public $imgcat_maxwidth;
|
| 43: | public $imgcat_maxheight;
|
| 44: | public $imgcat_type;
|
| 45: | public $imgcat_storetype;
|
| 46: |
|
| 47: | |
| 48: | |
| 49: |
|
| 50: | public function __construct()
|
| 51: | {
|
| 52: | parent::__construct();
|
| 53: | $this->initVar('imgcat_id', XOBJ_DTYPE_INT, null, false);
|
| 54: | $this->initVar('imgcat_name', XOBJ_DTYPE_TXTBOX, null, true, 100);
|
| 55: | $this->initVar('imgcat_display', XOBJ_DTYPE_INT, 1, false);
|
| 56: | $this->initVar('imgcat_weight', XOBJ_DTYPE_INT, 0, false);
|
| 57: | $this->initVar('imgcat_maxsize', XOBJ_DTYPE_INT, 0, false);
|
| 58: | $this->initVar('imgcat_maxwidth', XOBJ_DTYPE_INT, 0, false);
|
| 59: | $this->initVar('imgcat_maxheight', XOBJ_DTYPE_INT, 0, false);
|
| 60: | $this->initVar('imgcat_type', XOBJ_DTYPE_OTHER, null, false);
|
| 61: | $this->initVar('imgcat_storetype', XOBJ_DTYPE_OTHER, null, false);
|
| 62: | }
|
| 63: |
|
| 64: | |
| 65: | |
| 66: | |
| 67: | |
| 68: |
|
| 69: | public function id($format = 'N')
|
| 70: | {
|
| 71: | return $this->getVar('imgcat_id', $format);
|
| 72: | }
|
| 73: |
|
| 74: | |
| 75: | |
| 76: | |
| 77: | |
| 78: |
|
| 79: | public function imgcat_id($format = '')
|
| 80: | {
|
| 81: | return $this->getVar('imgcat_id', $format);
|
| 82: | }
|
| 83: |
|
| 84: | |
| 85: | |
| 86: | |
| 87: | |
| 88: |
|
| 89: | public function imgcat_name($format = '')
|
| 90: | {
|
| 91: | return $this->getVar('imgcat_name', $format);
|
| 92: | }
|
| 93: |
|
| 94: | |
| 95: | |
| 96: | |
| 97: | |
| 98: |
|
| 99: | public function imgcat_display($format = '')
|
| 100: | {
|
| 101: | return $this->getVar('imgcat_display', $format);
|
| 102: | }
|
| 103: |
|
| 104: | |
| 105: | |
| 106: | |
| 107: | |
| 108: |
|
| 109: | public function imgcat_weight($format = '')
|
| 110: | {
|
| 111: | return $this->getVar('imgcat_weight', $format);
|
| 112: | }
|
| 113: |
|
| 114: | |
| 115: | |
| 116: | |
| 117: | |
| 118: |
|
| 119: | public function imgcat_maxsize($format = '')
|
| 120: | {
|
| 121: | return $this->getVar('imgcat_maxsize', $format);
|
| 122: | }
|
| 123: |
|
| 124: | |
| 125: | |
| 126: | |
| 127: | |
| 128: |
|
| 129: | public function imgcat_maxwidth($format = '')
|
| 130: | {
|
| 131: | return $this->getVar('imgcat_maxwidth', $format);
|
| 132: | }
|
| 133: |
|
| 134: | |
| 135: | |
| 136: | |
| 137: | |
| 138: |
|
| 139: | public function imgcat_maxheight($format = '')
|
| 140: | {
|
| 141: | return $this->getVar('imgcat_maxheight', $format);
|
| 142: | }
|
| 143: |
|
| 144: | |
| 145: | |
| 146: | |
| 147: | |
| 148: |
|
| 149: | public function imgcat_type($format = '')
|
| 150: | {
|
| 151: | return $this->getVar('imgcat_type', $format);
|
| 152: | }
|
| 153: |
|
| 154: | |
| 155: | |
| 156: | |
| 157: | |
| 158: |
|
| 159: | public function imgcat_storetype($format = '')
|
| 160: | {
|
| 161: | return $this->getVar('imgcat_storetype', $format);
|
| 162: | }
|
| 163: |
|
| 164: | |
| 165: | |
| 166: | |
| 167: | |
| 168: |
|
| 169: | public function setImageCount($value)
|
| 170: | {
|
| 171: | $this->_imageCount = (int)$value;
|
| 172: | }
|
| 173: |
|
| 174: | |
| 175: | |
| 176: | |
| 177: | |
| 178: |
|
| 179: | public function getImageCount()
|
| 180: | {
|
| 181: | return $this->_imageCount;
|
| 182: | }
|
| 183: | }
|
| 184: |
|
| 185: | |
| 186: | |
| 187: | |
| 188: | |
| 189: | |
| 190: | |
| 191: | |
| 192: |
|
| 193: | class XoopsImagecategoryHandler extends XoopsObjectHandler
|
| 194: | {
|
| 195: | |
| 196: | |
| 197: | |
| 198: | |
| 199: | |
| 200: |
|
| 201: | public function create($isNew = true)
|
| 202: | {
|
| 203: | $imgcat = new XoopsImagecategory();
|
| 204: | if ($isNew) {
|
| 205: | $imgcat->setNew();
|
| 206: | }
|
| 207: |
|
| 208: | return $imgcat;
|
| 209: | }
|
| 210: |
|
| 211: | |
| 212: | |
| 213: | |
| 214: | |
| 215: | |
| 216: | |
| 217: | |
| 218: |
|
| 219: | public function get($id)
|
| 220: | {
|
| 221: | $id = (int)$id;
|
| 222: | $imgcat = false;
|
| 223: | if ($id > 0) {
|
| 224: | $sql = 'SELECT * FROM ' . $this->db->prefix('imagecategory') . ' WHERE imgcat_id=' . $id;
|
| 225: | $result = $this->db->query($sql);
|
| 226: | if (!$this->db->isResultSet($result)) {
|
| 227: | return $imgcat;
|
| 228: | }
|
| 229: | $numrows = $this->db->getRowsNum($result);
|
| 230: | if ($numrows == 1) {
|
| 231: | $imgcat = new XoopsImagecategory();
|
| 232: | $imgcat->assignVars($this->db->fetchArray($result));
|
| 233: | }
|
| 234: | }
|
| 235: |
|
| 236: | return $imgcat;
|
| 237: | }
|
| 238: |
|
| 239: | |
| 240: | |
| 241: | |
| 242: | |
| 243: | |
| 244: | |
| 245: |
|
| 246: | public function insert(XoopsObject $imgcat)
|
| 247: | {
|
| 248: | $className = 'XoopsImageCategory';
|
| 249: | if (!($imgcat instanceof $className)) {
|
| 250: | return false;
|
| 251: | }
|
| 252: |
|
| 253: | if (!$imgcat->isDirty()) {
|
| 254: | return true;
|
| 255: | }
|
| 256: | if (!$imgcat->cleanVars()) {
|
| 257: | return false;
|
| 258: | }
|
| 259: | foreach ($imgcat->cleanVars as $k => $v) {
|
| 260: | ${$k} = $v;
|
| 261: | }
|
| 262: | if ($imgcat->isNew()) {
|
| 263: | $imgcat_id = $this->db->genId('imgcat_imgcat_id_seq');
|
| 264: | $sql = sprintf('INSERT INTO %s (imgcat_id, imgcat_name, imgcat_display, imgcat_weight, imgcat_maxsize, imgcat_maxwidth, imgcat_maxheight, imgcat_type, imgcat_storetype) VALUES (%u, %s, %u, %u, %u, %u, %u, %s, %s)', $this->db->prefix('imagecategory'), $imgcat_id, $this->db->quoteString($imgcat_name), $imgcat_display, $imgcat_weight, $imgcat_maxsize, $imgcat_maxwidth, $imgcat_maxheight, $this->db->quoteString($imgcat_type), $this->db->quoteString($imgcat_storetype));
|
| 265: | } else {
|
| 266: | $sql = sprintf('UPDATE %s SET imgcat_name = %s, imgcat_display = %u, imgcat_weight = %u, imgcat_maxsize = %u, imgcat_maxwidth = %u, imgcat_maxheight = %u, imgcat_type = %s WHERE imgcat_id = %u', $this->db->prefix('imagecategory'), $this->db->quoteString($imgcat_name), $imgcat_display, $imgcat_weight, $imgcat_maxsize, $imgcat_maxwidth, $imgcat_maxheight, $this->db->quoteString($imgcat_type), $imgcat_id);
|
| 267: | }
|
| 268: | if (!$result = $this->db->query($sql)) {
|
| 269: | return false;
|
| 270: | }
|
| 271: | if (empty($imgcat_id)) {
|
| 272: | $imgcat_id = $this->db->getInsertId();
|
| 273: | }
|
| 274: | $imgcat->assignVar('imgcat_id', $imgcat_id);
|
| 275: |
|
| 276: | return true;
|
| 277: | }
|
| 278: |
|
| 279: | |
| 280: | |
| 281: | |
| 282: | |
| 283: | |
| 284: | |
| 285: |
|
| 286: | public function delete(XoopsObject $imgcat)
|
| 287: | {
|
| 288: | $className = 'XoopsImageCategory';
|
| 289: | if (!($imgcat instanceof $className)) {
|
| 290: | return false;
|
| 291: | }
|
| 292: |
|
| 293: | $sql = sprintf('DELETE FROM %s WHERE imgcat_id = %u', $this->db->prefix('imagecategory'), $imgcat->getVar('imgcat_id'));
|
| 294: | if (!$result = $this->db->query($sql)) {
|
| 295: | return false;
|
| 296: | }
|
| 297: |
|
| 298: | return true;
|
| 299: | }
|
| 300: |
|
| 301: | |
| 302: | |
| 303: | |
| 304: | |
| 305: | |
| 306: | |
| 307: |
|
| 308: | public function getObjects(CriteriaElement $criteria = null, $id_as_key = false)
|
| 309: | {
|
| 310: | $ret = array();
|
| 311: | $limit = $start = 0;
|
| 312: | $sql = 'SELECT DISTINCT c.* FROM ' . $this->db->prefix('imagecategory') . ' c LEFT JOIN ' . $this->db->prefix('group_permission') . " l ON l.gperm_itemid=c.imgcat_id WHERE (l.gperm_name = 'imgcat_read' OR l.gperm_name = 'imgcat_write')";
|
| 313: | if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
|
| 314: | $where = $criteria->render();
|
| 315: | $sql .= ($where != '') ? ' AND ' . $where : '';
|
| 316: | $limit = $criteria->getLimit();
|
| 317: | $start = $criteria->getStart();
|
| 318: | }
|
| 319: | $sql .= ' ORDER BY imgcat_weight, imgcat_id ASC';
|
| 320: | $result = $this->db->query($sql, $limit, $start);
|
| 321: | if (!$this->db->isResultSet($result)) {
|
| 322: | return $ret;
|
| 323: | }
|
| 324: |
|
| 325: | while (false !== ($myrow = $this->db->fetchArray($result))) {
|
| 326: | $imgcat = new XoopsImagecategory();
|
| 327: | $imgcat->assignVars($myrow);
|
| 328: | if (!$id_as_key) {
|
| 329: | $ret[] = $imgcat;
|
| 330: | } else {
|
| 331: | $ret[$myrow['imgcat_id']] = $imgcat;
|
| 332: | }
|
| 333: | unset($imgcat);
|
| 334: | }
|
| 335: |
|
| 336: | return $ret;
|
| 337: | }
|
| 338: |
|
| 339: | |
| 340: | |
| 341: | |
| 342: | |
| 343: | |
| 344: |
|
| 345: | public function getCount(CriteriaElement $criteria = null)
|
| 346: | {
|
| 347: | $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('imagecategory') . ' i LEFT JOIN ' . $this->db->prefix('group_permission') . " l ON l.gperm_itemid=i.imgcat_id WHERE (l.gperm_name = 'imgcat_read' OR l.gperm_name = 'imgcat_write')";
|
| 348: | if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
|
| 349: | $where = $criteria->render();
|
| 350: | $sql .= ($where != '') ? ' AND ' . $where : '';
|
| 351: | }
|
| 352: | $result = $this->db->query($sql);
|
| 353: | if (!$this->db->isResultSet($result)) {
|
| 354: | return 0;
|
| 355: | }
|
| 356: | list($count) = $this->db->fetchRow($result);
|
| 357: |
|
| 358: | return (int)$count;
|
| 359: | }
|
| 360: |
|
| 361: | |
| 362: | |
| 363: | |
| 364: | |
| 365: | |
| 366: | |
| 367: | |
| 368: | |
| 369: | |
| 370: | |
| 371: |
|
| 372: | public function getList($groups = array(), $perm = 'imgcat_read', $display = null, $storetype = null)
|
| 373: | {
|
| 374: | $criteria = new CriteriaCompo();
|
| 375: | if (!empty($groups) && \is_array($groups)) {
|
| 376: | $criteriaTray = new CriteriaCompo();
|
| 377: | foreach ($groups as $gid) {
|
| 378: | $criteriaTray->add(new Criteria('gperm_groupid', $gid), 'OR');
|
| 379: | }
|
| 380: | $criteria->add($criteriaTray);
|
| 381: | if ($perm === 'imgcat_read' || $perm === 'imgcat_write') {
|
| 382: | $criteria->add(new Criteria('gperm_name', $perm));
|
| 383: | $criteria->add(new Criteria('gperm_modid', 1));
|
| 384: | }
|
| 385: | }
|
| 386: | if (isset($display)) {
|
| 387: | $criteria->add(new Criteria('imgcat_display', (int)$display));
|
| 388: | }
|
| 389: | if (isset($storetype)) {
|
| 390: | $criteria->add(new Criteria('imgcat_storetype', $storetype));
|
| 391: | }
|
| 392: | $categories = $this->getObjects($criteria, true);
|
| 393: | $ret = array();
|
| 394: | foreach (array_keys($categories) as $i) {
|
| 395: | $ret[$i] = $categories[$i]->getVar('imgcat_name');
|
| 396: | }
|
| 397: |
|
| 398: | return $ret;
|
| 399: | }
|
| 400: | }
|
| 401: | |