XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
configcategory.php
1<?php
12
13if (!defined('XOOPS_ROOT_PATH')) {
14 exit();
15}
16
17
18class XoopsConfigCategory extends XoopsObject
19{
20
21 public function __construct()
22 {
23 parent::__construct();
24 $this->initVar('confcat_id', XOBJ_DTYPE_INT, null);
25 $this->initVar('confcat_name', XOBJ_DTYPE_OTHER, null);
26 $this->initVar('confcat_order', XOBJ_DTYPE_INT, 0);
27 }
28 public function XoopsConfigCategory()
29 {
30 return self::__construct();
31 }
32
36 public function getName()
37 {
38 return defined($this->get('confcat_name')) ? constant($this->get('confcat_name')) : $this->get('confcat_name');
39 }
40}
41
42
56{
57
65 public function &create($isNew = true)
66 {
67 $confcat =new XoopsConfigCategory();
68 if ($isNew) {
69 $confcat->setNew();
70 }
71 return $confcat;
72 }
73
81 public function &get($id)
82 {
83 $ret = false;
84 $id = (int)$id;
85 if ($id > 0) {
86 $sql = 'SELECT * FROM '.$this->db->prefix('configcategory').' WHERE confcat_id='.$id;
87 if ($result = $this->db->query($sql)) {
88 $numrows = $this->db->getRowsNum($result);
89 if (1 == $numrows) {
90 $confcat =new XoopsConfigCategory();
91 $confcat->assignVars($this->db->fetchArray($result), false);
92 $ret =& $confcat;
93 }
94 }
95 }
96 return $ret;
97 }
98
106 public function insert(&$confcat)
107 {
108 $confcat_name = null;
109 $confcat_order = null;
110 $confcat_id = null;
111 if ('xoopsconfigcategory' != strtolower(get_class($confcat))) {
112 return false;
113 }
114 if (!$confcat->isDirty()) {
115 return true;
116 }
117 if (!$confcat->cleanVars()) {
118 return false;
119 }
120 foreach ($confcat->cleanVars as $k => $v) {
121 ${$k} = $v;
122 }
123 if ($confcat->isNew()) {
124 $confcat_id = $this->db->genId('configcategory_confcat_id_seq');
125 $sql = sprintf('INSERT INTO %s (confcat_id, confcat_name, confcat_order) VALUES (%u, %s, %u)', $this->db->prefix('configcategory'), $confcat_id, $this->db->quoteString($confcat_name), $confcat_order);
126 } else {
127 $sql = sprintf('UPDATE %s SET confcat_name = %s, confcat_order = %u WHERE confcat_id = %u', $this->db->prefix('configcategory'), $this->db->quoteString($confcat_name), $confcat_order, $confcat_id);
128 }
129 if (!$result = $this->db->query($sql)) {
130 return false;
131 }
132 if (empty($confcat_id)) {
133 $confcat_id = $this->db->getInsertId();
134 }
135 $confcat->assignVar('confcat_id', $confcat_id);
136 return $confcat_id;
137 }
138
146 public function delete(&$confcat)
147 {
148 if ('xoopsconfigcategory' != strtolower(get_class($confcat))) {
149 return false;
150 }
151 $sql = sprintf('DELETE FROM %s WHERE confcat_id = %u', $this->db->prefix('configcategory'), $confcat->getVar('confcat_id'));
152 if (!$result = $this->db->query($sql)) {
153 return false;
154 }
155 return true;
156 }
157
166 public function &getObjects($criteria = null, $id_as_key = false)
167 {
168 $ret = [];
169 $limit = $start = 0;
170 $sql = 'SELECT * FROM '.$this->db->prefix('configcategory');
171 if (isset($criteria) && $criteria instanceof \criteriaelement) {
172 $sql .= ' '.$criteria->renderWhere();
173 $sort = !in_array($criteria->getSort(), ['confcat_id', 'confcat_name', 'confcat_order']) ? 'confcat_order' : $criteria->getSort();
174 $sql .= ' ORDER BY '.$sort.' '.$criteria->getOrder();
175 $limit = $criteria->getLimit();
176 $start = $criteria->getStart();
177 }
178 $result = $this->db->query($sql, $limit, $start);
179 if (!$result) {
180 return $ret;
181 }
182 while ($myrow = $this->db->fetchArray($result)) {
183 $confcat =new XoopsConfigCategory();
184 $confcat->assignVars($myrow, false);
185 if (!$id_as_key) {
186 $ret[] =& $confcat;
187 } else {
188 $ret[$myrow['confcat_id']] =& $confcat;
189 }
190 unset($confcat);
191 }
192 return $ret;
193 }
194}
& getObjects($criteria=null, $id_as_key=false)
initVar($key, $data_type, $value=null, $required=false, $maxlength=null, $options='')
Definition object.php:206