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 ImagesImage extends XoopsObject
28: {
29: 30: 31:
32: public function __construct()
33: {
34: $this->initVar('image_id', XOBJ_DTYPE_INT, null, false, 8);
35: $this->initVar('image_name', XOBJ_DTYPE_TXTBOX, '', true, 30);
36: $this->initVar('image_nicename', XOBJ_DTYPE_TXTBOX, '', true, 255);
37: $this->initVar('image_mimetype', XOBJ_DTYPE_TXTBOX, '', true, 30);
38: $this->initVar('image_created', XOBJ_DTYPE_INT, time(), false, 10);
39: $this->initVar('image_display', XOBJ_DTYPE_INT, 1, false, 1);
40: $this->initVar('image_weight', XOBJ_DTYPE_INT, 0, false, 5);
41: $this->initVar('imgcat_id', XOBJ_DTYPE_INT, 0, false, 5);
42: }
43: }
44:
45: class ImagesImage_Body extends XoopsObject
46: {
47: 48: 49:
50: public function __construct()
51: {
52: $this->initVar('image_id', XOBJ_DTYPE_INT, null, false, 8);
53: $this->initVar('image_name', XOBJ_DTYPE_TXTBOX, '', true, 30);
54: $this->initVar('image_nicename', XOBJ_DTYPE_TXTBOX, '', true, 255);
55: $this->initVar('image_mimetype', XOBJ_DTYPE_TXTBOX, '', true, 30);
56: $this->initVar('image_created', XOBJ_DTYPE_INT, time(), false, 10);
57: $this->initVar('image_display', XOBJ_DTYPE_INT, 1, false, 1);
58: $this->initVar('image_weight', XOBJ_DTYPE_INT, 0, false, 5);
59: $this->initVar('imgcat_id', XOBJ_DTYPE_INT, 0, false, 5);
60:
61: $this->initVar('image_body', XOBJ_DTYPE_SOURCE, null, true);
62: }
63: }
64:
65: class ImagesImageHandler extends XoopsPersistableObjectHandler
66: {
67: 68: 69: 70: 71:
72: public function __construct(Connection $db = null)
73: {
74: parent::__construct($db, 'image', 'ImagesImage', 'image_id', 'image_name');
75: }
76:
77: public function getById($image_id, $asobject = true)
78: {
79: $this->table_link = $this->db2->prefix('imagebody');
80: $this->className = 'ImagesImage_Body';
81:
82:
83: $criteria = new CriteriaCompo();
84: $criteria->add(new Criteria('o.image_id', $image_id));
85:
86: return parent::getByLink($criteria, null, $asobject, 'image_id', 'image_id');
87: }
88:
89: public function getByCategory($imgcat_id, $start = 0, $limit = 0, $asobject = true)
90: {
91: $criteria = new CriteriaCompo();
92: $criteria->add(new Criteria('imgcat_id', $imgcat_id));
93: $criteria->setSort('image_weight');
94: $criteria->setOrder('ASC');
95: $criteria->setStart($start);
96: $criteria->setLimit($limit);
97:
98: return parent::getObjects($criteria, null, $asobject);
99: }
100:
101: public function countByCategory($imgcat_id)
102: {
103: $criteria = new CriteriaCompo();
104: $criteria->add(new Criteria('imgcat_id', $imgcat_id));
105:
106: return parent::getCount($criteria);
107: }
108: }
109: