XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
tplset.php
1<?php
13
14
15if (!defined('XOOPS_ROOT_PATH')) {
16 exit();
17}
18class XoopsTplset extends XoopsObject
19{
20
21 public function __construct()
22 {
23 static $initVars;
24 if (isset($initVars)) {
25 $this->vars = $initVars;
26 return;
27 }
28 parent::__construct();
29 $this->initVar('tplset_id', XOBJ_DTYPE_INT, null, false);
30 $this->initVar('tplset_name', XOBJ_DTYPE_OTHER, null, false);
31 $this->initVar('tplset_desc', XOBJ_DTYPE_TXTBOX, null, false, 191);
32 $this->initVar('tplset_credits', XOBJ_DTYPE_TXTAREA, null, false);
33 $this->initVar('tplset_created', XOBJ_DTYPE_INT, 0, false);
34 $initVars = $this->vars;
35 }
36 public function XoopsTplset()
37 {
38 return self::__construct();
39 }
40}
41
49
51{
52
53 public function &create($isNew = true)
54 {
55 $tplset =new XoopsTplset();
56 if ($isNew) {
57 $tplset->setNew();
58 }
59 return $tplset;
60 }
61
62 public function &get($id)
63 {
64 $ret = false;
65 $id = (int)$id;
66 if ($id > 0) {
67 $sql = 'SELECT * FROM '.$this->db->prefix('tplset').' WHERE tplset_id='.$id;
68 if ($result = $this->db->query($sql)) {
69 $numrows = $this->db->getRowsNum($result);
70 if (1 == $numrows) {
71 $tplset = new XoopsTplset();
72 $tplset->assignVars($this->db->fetchArray($result));
73 $ret =& $tplset;
74 }
75 }
76 }
77 return $ret;
78 }
79
80 public function &getByName($tplset_name)
81 {
82 $ret = false;
83 $tplset_name = trim($tplset_name);
84 if ('' != $tplset_name) {
85 $sql = 'SELECT * FROM '.$this->db->prefix('tplset').' WHERE tplset_name='.$this->db->quoteString($tplset_name);
86 if ($result = $this->db->query($sql)) {
87 $numrows = $this->db->getRowsNum($result);
88 if (1 == $numrows) {
89 $tplset =new XoopsTplset();
90 $tplset->assignVars($this->db->fetchArray($result));
91 $ret =& $tplset;
92 }
93 }
94 }
95 return $ret;
96 }
97
98 public function insert(&$tplset)
99 {
100 $tplset_name = null;
101 $tplset_desc = null;
102 $tplset_credits = null;
103 $tplset_created = null;
104 $tplset_id = null;
105 if ('xoopstplset' != strtolower(get_class($tplset))) {
106 return false;
107 }
108 if (!$tplset->isDirty()) {
109 return true;
110 }
111 if (!$tplset->cleanVars()) {
112 return false;
113 }
114 foreach ($tplset->cleanVars as $k => $v) {
115 ${$k} = $v;
116 }
117 if ($tplset->isNew()) {
118 $tplset_id = $this->db->genId('tplset_tplset_id_seq');
119 $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);
120 } else {
121 $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);
122 }
123 if (!$result = $this->db->query($sql)) {
124 return false;
125 }
126 if (empty($tplset_id)) {
127 $tplset_id = $this->db->getInsertId();
128 }
129 $tplset->assignVar('tplset_id', $tplset_id);
130 return true;
131 }
132
133 public function delete(&$tplset)
134 {
135 if ('xoopstplset' != strtolower(get_class($tplset))) {
136 return false;
137 }
138 $sql = sprintf('DELETE FROM %s WHERE tplset_id = %u', $this->db->prefix('tplset'), $tplset->getVar('tplset_id'));
139 if (!$result = $this->db->query($sql)) {
140 return false;
141 }
142 $sql = sprintf('DELETE FROM %s WHERE tplset_name = %s', $this->db->prefix('imgset_tplset_link'), $this->db->quoteString($tplset->getVar('tplset_name')));
143 $this->db->query($sql);
144 return true;
145 }
146
147 public function &getObjects($criteria = null, $id_as_key = false)
148 {
149 $ret = [];
150 $limit = $start = 0;
151 $sql = 'SELECT * FROM '.$this->db->prefix('tplset');
152 if (isset($criteria) && $criteria instanceof \criteriaelement) {
153 $sql .= ' '.$criteria->renderWhere().' ORDER BY tplset_id';
154 $limit = $criteria->getLimit();
155 $start = $criteria->getStart();
156 }
157 $result = $this->db->query($sql, $limit, $start);
158 if (!$result) {
159 return $ret;
160 }
161 while ($myrow = $this->db->fetchArray($result)) {
162 $tplset =new XoopsTplset();
163 $tplset->assignVars($myrow);
164 if (!$id_as_key) {
165 $ret[] =& $tplset;
166 } else {
167 $ret[$myrow['tplset_id']] =& $tplset;
168 }
169 unset($tplset);
170 }
171 return $ret;
172 }
173
174
175 public function getCount($criteria = null)
176 {
177 $sql = 'SELECT COUNT(*) FROM '.$this->db->prefix('tplset');
178 if (isset($criteria) && $criteria instanceof \criteriaelement) {
179 $sql .= ' '.$criteria->renderWhere();
180 }
181 if (!$result =& $this->db->query($sql)) {
182 return 0;
183 }
184 [$count] = $this->db->fetchRow($result);
185 return $count;
186 }
187
188 public function &getList($criteria = null)
189 {
190 $ret = [];
191 $tplsets =& $this->getObjects($criteria, true);
192 foreach ($tplsets as $tpl) {
193 $name = $tpl->getVar('tplset_name');
194 $ret[$name] = $name;
195 }
196 return $ret;
197 }
198}
initVar($key, $data_type, $value=null, $required=false, $maxlength=null, $options='')
Definition object.php:206
insert(&$tplset)
Definition tplset.php:98
__construct()
Definition tplset.php:21