XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
tplset.php
Go to the documentation of this file.
1 <?php
20 defined('XOOPS_ROOT_PATH') or die('Restricted access');
21 
30 class XoopsTplset extends XoopsObject
31 {
35  function XoopsTplset()
36  {
37  $this->XoopsObject();
38  $this->initVar('tplset_id', XOBJ_DTYPE_INT, null, false);
39  $this->initVar('tplset_name', XOBJ_DTYPE_OTHER, null, false);
40  $this->initVar('tplset_desc', XOBJ_DTYPE_TXTBOX, null, false, 255);
41  $this->initVar('tplset_credits', XOBJ_DTYPE_TXTAREA, null, false);
42  $this->initVar('tplset_created', XOBJ_DTYPE_INT, 0, false);
43  }
44 
48  function id($format = 'N')
49  {
50  return $this->getVar('tplset_id', $format);
51  }
52 
56  function tplset_id($format = '')
57  {
58  return $this->getVar('tplset_id', $format);
59  }
60 
64  function tplset_name($format = '')
65  {
66  return $this->getVar('tplset_name', $format);
67  }
68 
72  function tplset_desc($format = '')
73  {
74  return $this->getVar('tplset_desc', $format);
75  }
76 
80  function tplset_credits($format = '')
81  {
82  return $this->getVar('tplset_credits', $format);
83  }
84 
88  function tplset_created($format = '')
89  {
90  return $this->getVar('tplset_created', $format);
91  }
92 
93 }
94 
103 {
111  function &create($isNew = true)
112  {
113  $tplset = new XoopsTplset();
114  if ($isNew) {
115  $tplset->setNew();
116  }
117  return $tplset;
118  }
119 
127  function &get($id)
128  {
129  $tplset = false;
130  $id = intval($id);
131  if ($id > 0) {
132  $sql = 'SELECT * FROM ' . $this->db->prefix('tplset') . ' WHERE tplset_id=' . $id;
133  if (!$result = $this->db->query($sql)) {
134  return $tplset;
135  }
136  $numrows = $this->db->getRowsNum($result);
137  if ($numrows == 1) {
138  $tplset = new XoopsTplset();
139  $tplset->assignVars($this->db->fetchArray($result));
140  }
141  }
142  return $tplset;
143  }
144 
152  function &getByName($tplset_name)
153  {
154  $tplset = false;
155  $tplset_name = trim($tplset_name);
156  if ($tplset_name != '') {
157  $sql = 'SELECT * FROM ' . $this->db->prefix('tplset') . ' WHERE tplset_name=' . $this->db->quoteString($tplset_name);
158  if (!$result = $this->db->query($sql)) {
159  return $tplset;
160  }
161  $numrows = $this->db->getRowsNum($result);
162  if ($numrows == 1) {
163  $tplset = new XoopsTplset();
164  $tplset->assignVars($this->db->fetchArray($result));
165  }
166  }
167  return $tplset;
168  }
169 
176  function insert(&$tplset)
177  {
181  if (!is_a($tplset, 'xoopstplset')) {
182  return false;
183  }
184  if (!$tplset->isDirty()) {
185  return true;
186  }
187  if (!$tplset->cleanVars()) {
188  return false;
189  }
190  foreach ($tplset->cleanVars as $k => $v) {
191  ${$k} = $v;
192  }
193  if ($tplset->isNew()) {
194  $tplset_id = $this->db->genId('tplset_tplset_id_seq');
195  $sql = sprintf("INSERT INTO %s (tplset_id, tplset_name, tplset_desc, tplset_credits, tplset_created) VALUES (%u, %s, %s, %s, %u)", $this->db->prefix('tplset'), $tplset_id, $this->db->quoteString($tplset_name), $this->db->quoteString($tplset_desc), $this->db->quoteString($tplset_credits), $tplset_created);
196  } else {
197  $sql = sprintf("UPDATE %s SET tplset_name = %s, tplset_desc = %s, tplset_credits = %s, tplset_created = %u WHERE tplset_id = %u", $this->db->prefix('tplset'), $this->db->quoteString($tplset_name), $this->db->quoteString($tplset_desc), $this->db->quoteString($tplset_credits), $tplset_created, $tplset_id);
198  }
199  if (!$result = $this->db->query($sql)) {
200  return false;
201  }
202  if (empty($tplset_id)) {
203  $tplset_id = $this->db->getInsertId();
204  }
205  $tplset->assignVar('tplset_id', $tplset_id);
206  return true;
207  }
208 
215  function delete(&$tplset)
216  {
220  if (!is_a($tplset, 'xoopstplset')) {
221  return false;
222  }
223  $sql = sprintf("DELETE FROM %s WHERE tplset_id = %u", $this->db->prefix('tplset'), $tplset->getVar('tplset_id'));
224  if (!$result = $this->db->query($sql)) {
225  return false;
226  }
227  $sql = sprintf("DELETE FROM %s WHERE tplset_name = %s", $this->db->prefix('imgset_tplset_link'), $this->db->quoteString($tplset->getVar('tplset_name')));
228  $this->db->query($sql);
229  return true;
230  }
231 
239  function getObjects($criteria = null, $id_as_key = false)
240  {
241  $ret = array();
242  $limit = $start = 0;
243  $sql = 'SELECT * FROM ' . $this->db->prefix('tplset');
244  if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
245  $sql .= ' ' . $criteria->renderWhere() . ' ORDER BY tplset_id';
246  $limit = $criteria->getLimit();
247  $start = $criteria->getStart();
248  }
249  $result = $this->db->query($sql, $limit, $start);
250  if (!$result) {
251  return $ret;
252  }
253  while ($myrow = $this->db->fetchArray($result)) {
254  $tplset = new XoopsTplset();
255  $tplset->assignVars($myrow);
256  if (!$id_as_key) {
257  $ret[] =& $tplset;
258  } else {
259  $ret[$myrow['tplset_id']] =& $tplset;
260  }
261  unset($tplset);
262  }
263  return $ret;
264  }
265 
272  function getCount($criteria = null)
273  {
274  $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('tplset');
275  if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
276  $sql .= ' ' . $criteria->renderWhere();
277  }
278  if (!$result =& $this->db->query($sql)) {
279  return 0;
280  }
281  list ($count) = $this->db->fetchRow($result);
282  return $count;
283  }
284 
291  function getList($criteria = null)
292  {
293  $ret = array();
294  $tplsets = $this->getObjects($criteria, true);
295  foreach(array_keys($tplsets) as $i) {
296  $ret[$tplsets[$i]->getVar('tplset_name')] = $tplsets[$i]->getVar('tplset_name');
297  }
298  return $ret;
299  }
300 }
301 ?>