1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: use Xoops\Core\Database\Connection;
13: use Xoops\Core\Kernel\Criteria;
14: use Xoops\Core\Kernel\CriteriaCompo;
15: use Xoops\Core\Kernel\CriteriaElement;
16: use Xoops\Core\Kernel\XoopsObject;
17: use Xoops\Core\Kernel\XoopsPersistableObjectHandler;
18:
19: 20: 21: 22: 23: 24: 25:
26:
27: class ImagesCategory extends XoopsObject
28: {
29: 30: 31:
32: public function __construct()
33: {
34: $this->initVar('imgcat_id', XOBJ_DTYPE_INT, 0, false, 5);
35: $this->initVar('imgcat_name', XOBJ_DTYPE_TXTBOX, '', true, 100);
36: $this->initVar('imgcat_maxsize', XOBJ_DTYPE_INT, 100000, false, 8);
37: $this->initVar('imgcat_maxwidth', XOBJ_DTYPE_INT, 128, false, 3);
38: $this->initVar('imgcat_maxheight', XOBJ_DTYPE_INT, 128, false, 3);
39: $this->initVar('imgcat_display', XOBJ_DTYPE_INT, 1, false, 1);
40: $this->initVar('imgcat_weight', XOBJ_DTYPE_INT, 0, false, 3);
41: $this->initVar('imgcat_type', XOBJ_DTYPE_TXTBOX, '', true, 1);
42: $this->initVar('imgcat_storetype', XOBJ_DTYPE_TXTBOX, 'file', true, 5);
43: }
44: }
45:
46: class ImagesCategoryHandler extends XoopsPersistableObjectHandler
47: {
48: 49: 50: 51: 52:
53: public function __construct(Connection $db = null)
54: {
55: parent::__construct($db, 'imagecategory', 'ImagesCategory', 'imgcat_id', 'imgcat_name');
56: }
57:
58: 59: 60: 61: 62: 63:
64: public function getPermittedObjects($criteria = null, $start = 0, $limit = 0, $id_as_key = false, $asobject = true)
65: {
66: $this->table_link = $this->db2->prefix('system_permission');
67:
68: if (isset($criteria)) {
69: $criteria = new CriteriaCompo($criteria);
70: } else {
71: $criteria = new CriteriaCompo();
72: }
73: $criteria->setSort('o.imgcat_weight, o.imgcat_id');
74: $criteria->setOrder('ASC');
75: $criteria->setStart($start);
76: $criteria->setLimit($limit);
77:
78: return parent::getByLink($criteria, null, $asobject, 'gperm_itemid', 'imgcat_id');
79: }
80:
81: 82: 83: 84: 85: 86: 87: 88: 89: 90:
91: public function getListByPermission($groups = array(), $perm = 'imgcat_read', $display = null, $storetype = null)
92: {
93: $xoops = Xoops::getInstance();
94: $criteria = new CriteriaCompo();
95: if (is_array($groups) && !empty($groups)) {
96: $criteriaTray = new CriteriaCompo();
97: foreach ($groups as $gid) {
98: $criteriaTray->add(new Criteria('gperm_groupid', $gid), 'OR');
99: }
100: $criteria->add($criteriaTray);
101: if ($perm === 'imgcat_read' || $perm === 'imgcat_write') {
102: $criteria->add(new Criteria('gperm_name', $perm));
103: $mid = $xoops->getModuleByDirname('images')->getVar('mid');
104: $criteria->add(new Criteria('gperm_modid', $mid));
105: }
106: }
107: if (isset($display)) {
108: $criteria->add(new Criteria('imgcat_display', (int)($display)));
109: }
110: if (isset($storetype)) {
111: $criteria->add(new Criteria('imgcat_storetype', $storetype));
112: }
113: $categories = $this->getPermittedObjects($criteria, 0, 0, true);
114: $ret = array();
115: foreach (array_keys($categories) as $i) {
116: $ret[$i] = $categories[$i]->getVar('imgcat_name');
117: }
118: return $ret;
119: }
120: }
121: