XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
configoption.php
Go to the documentation of this file.
1 <?php
19 defined('XOOPS_ROOT_PATH') or die('Restricted access');
20 
30 {
34  function XoopsConfigOption()
35  {
36  $this->XoopsObject();
37  $this->initVar('confop_id', XOBJ_DTYPE_INT, null);
38  $this->initVar('confop_name', XOBJ_DTYPE_TXTBOX, null, true, 255);
39  $this->initVar('confop_value', XOBJ_DTYPE_TXTBOX, null, true, 255);
40  $this->initVar('conf_id', XOBJ_DTYPE_INT, 0);
41  }
42 
46  function id($format = 'N')
47  {
48  return $this->getVar('confop_id', $format);
49  }
50 
54  function confop_id($format = '')
55  {
56  return $this->getVar('confop_id', $format);
57  }
58 
62  function confop_name($format = '')
63  {
64  return $this->getVar('confop_name', $format);
65  }
66 
70  function confop_value($format = '')
71  {
72  return $this->getVar('confop_value', $format);
73  }
74 
78  function conf_id($format = '')
79  {
80  return $this->getVar('conf_id', $format);
81  }
82 
83 }
84 
97 {
105  function &create($isNew = true)
106  {
107  $confoption = new XoopsConfigOption();
108  if ($isNew) {
109  $confoption->setNew();
110  }
111  return $confoption;
112  }
113 
121  function &get($id)
122  {
123  $confoption = false;
124  $id = intval($id);
125  if ($id > 0) {
126  $sql = 'SELECT * FROM ' . $this->db->prefix('configoption') . ' WHERE confop_id=' . $id;
127  if (!$result = $this->db->query($sql)) {
128  return $confoption;
129  }
130  $numrows = $this->db->getRowsNum($result);
131  if ($numrows == 1) {
132  $confoption = new XoopsConfigOption();
133  $confoption->assignVars($this->db->fetchArray($result));
134  }
135  }
136  return $confoption;
137  }
138 
145  function insert(&$confoption)
146  {
150  if (!is_a($confoption, 'xoopsconfigoption')) {
151  return false;
152  }
153  if (!$confoption->isDirty()) {
154  return true;
155  }
156  if (!$confoption->cleanVars()) {
157  return false;
158  }
159  foreach ($confoption->cleanVars as $k => $v) {
160  ${$k} = $v;
161  }
162  if ($confoption->isNew()) {
163  $confop_id = $this->db->genId('configoption_confop_id_seq');
164  $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);
165  } else {
166  $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);
167  }
168  if (!$result = $this->db->query($sql)) {
169  return false;
170  }
171  if (empty($confop_id)) {
172  $confop_id = $this->db->getInsertId();
173  }
174  $confoption->assignVar('confop_id', $confop_id);
175  return $confop_id;
176  }
177 
184  function delete(&$confoption)
185  {
189  if (!is_a($confoption, 'xoopsconfigoption')) {
190  return false;
191  }
192  $sql = sprintf("DELETE FROM %s WHERE confop_id = %u", $this->db->prefix('configoption'), $confoption->getVar('confop_id'));
193  if (!$result = $this->db->query($sql)) {
194  return false;
195  }
196  return true;
197  }
198 
207  function getObjects($criteria = null, $id_as_key = false)
208  {
209  $ret = array();
210  $limit = $start = 0;
211  $sql = 'SELECT * FROM ' . $this->db->prefix('configoption');
212  if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
213  $sql .= ' ' . $criteria->renderWhere() . ' ORDER BY confop_id ' . $criteria->getOrder();
214  $limit = $criteria->getLimit();
215  $start = $criteria->getStart();
216  }
217  $result = $this->db->query($sql, $limit, $start);
218  if (!$result) {
219  return $ret;
220  }
221  while ($myrow = $this->db->fetchArray($result)) {
222  $confoption = new XoopsConfigOption();
223  $confoption->assignVars($myrow);
224  if (!$id_as_key) {
225  $ret[] =& $confoption;
226  } else {
227  $ret[$myrow['confop_id']] = & $confoption;
228  }
229  unset($confoption);
230  }
231  return $ret;
232  }
233 }
234 ?>