XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
configoption.php
1<?php
12
13
14if (!defined('XOOPS_ROOT_PATH')) {
15 exit();
16}
17
18
20{
21
22 public function __construct()
23 {
24 static $initVars;
25 if (isset($initVars)) {
26 $this->vars = $initVars;
27 return;
28 }
29 parent::__construct();
30 $this->initVar('confop_id', XOBJ_DTYPE_INT, null);
31 $this->initVar('confop_name', XOBJ_DTYPE_TXTBOX, null, true, 255);
32 $this->initVar('confop_value', XOBJ_DTYPE_TXTBOX, null, true, 255);
33 $this->initVar('conf_id', XOBJ_DTYPE_INT, 0);
34 $initVars = $this->vars;
35 }
36
40 public function getOptionKey()
41 {
42 return defined($this->get('confop_value')) ? constant($this->get('confop_value')) : $this->get('confop_value');
43 }
44
48 public function getOptionLabel()
49 {
50 return defined($this->get('confop_name')) ? constant($this->get('confop_name')) : $this->get('confop_name');
51 }
52
60 public function isEqual(&$option)
61 {
62 $flag = true;
63
64 $flag &= ($this->get('confop_name') == $option->get('confop_name'));
65 $flag &= ($this->get('confop_value') == $option->get('confop_value'));
66
67 return $flag;
68 }
69}
70
83{
84
92 public function &create($isNew = true)
93 {
94 $confoption =new XoopsConfigOption();
95 if ($isNew) {
96 $confoption->setNew();
97 }
98 return $confoption;
99 }
100
108 public function &get($id)
109 {
110 $ret = false;
111 $id = (int)$id;
112 if ($id > 0) {
113 $sql = 'SELECT * FROM '.$this->db->prefix('configoption').' WHERE confop_id='.$id;
114 if ($result = $this->db->query($sql)) {
115 $numrows = $this->db->getRowsNum($result);
116 if (1 == $numrows) {
117 $confoption =new XoopsConfigOption();
118 $confoption->assignVars($this->db->fetchArray($result));
119 $ret =& $confoption;
120 }
121 }
122 }
123 return $ret;
124 }
125
132 public function insert(&$confoption)
133 {
134 $confop_name = null;
135 $confop_value = null;
136 $conf_id = null;
137 $confop_id = null;
138 if ('xoopsconfigoption' != strtolower(get_class($confoption))) {
139 return false;
140 }
141 if (!$confoption->isDirty()) {
142 return true;
143 }
144 if (!$confoption->cleanVars()) {
145 return false;
146 }
147 foreach ($confoption->cleanVars as $k => $v) {
148 ${$k} = $v;
149 }
150 if ($confoption->isNew()) {
151 $confop_id = $this->db->genId('configoption_confop_id_seq');
152 $sql = sprintf('INSERT INTO %s (confop_id, confop_name, confop_value, conf_id) VALUES (%u, %s, %s, %u)', $this->db->prefix('configoption'), $confop_id, $this->db->quoteString($confop_name), $this->db->quoteString($confop_value), $conf_id);
153 } else {
154 $sql = sprintf('UPDATE %s SET confop_name = %s, confop_value = %s WHERE confop_id = %u', $this->db->prefix('configoption'), $this->db->quoteString($confop_name), $this->db->quoteString($confop_value), $confop_id);
155 }
156 if (!$result = $this->db->query($sql)) {
157 return false;
158 }
159 if (empty($confop_id)) {
160 $confop_id = $this->db->getInsertId();
161 }
162 $confoption->assignVar('confop_id', $confop_id);
163 return $confop_id;
164 }
165
172 public function delete(&$confoption)
173 {
174 if ('xoopsconfigoption' != strtolower(get_class($confoption))) {
175 return false;
176 }
177 $sql = sprintf('DELETE FROM %s WHERE confop_id = %u', $this->db->prefix('configoption'), $confoption->getVar('confop_id', 'n'));
178 if (!$result = $this->db->query($sql)) {
179 return false;
180 }
181 return true;
182 }
183
192 public function &getObjects($criteria = null, $id_as_key = false)
193 {
194 $ret = [];
195 $limit = $start = 0;
196 $sql = 'SELECT * FROM '.$this->db->prefix('configoption');
197 if (isset($criteria) && $criteria instanceof \criteriaelement) {
198 $sql .= ' '.$criteria->renderWhere().' ORDER BY confop_id '.$criteria->getOrder();
199 $limit = $criteria->getLimit();
200 $start = $criteria->getStart();
201 }
202 $result = $this->db->query($sql, $limit, $start);
203 if (!$result) {
204 return $ret;
205 }
206 while ($myrow = $this->db->fetchArray($result)) {
207 $confoption =new XoopsConfigOption();
208 $confoption->assignVars($myrow);
209 if (!$id_as_key) {
210 $ret[] =& $confoption;
211 } else {
212 $ret[$myrow['confop_id']] =& $confoption;
213 }
214 unset($confoption);
215 }
216 return $ret;
217 }
218}
& getObjects($criteria=null, $id_as_key=false)
initVar($key, $data_type, $value=null, $required=false, $maxlength=null, $options='')
Definition object.php:206