| 1: | <?php
|
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: |
|
| 18: |
|
| 19: | defined('XOOPS_ROOT_PATH') || exit('Restricted access');
|
| 20: |
|
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: |
|
| 29: | class XoopsTplset extends XoopsObject
|
| 30: | {
|
| 31: | |
| 32: | |
| 33: |
|
| 34: | public function __construct()
|
| 35: | {
|
| 36: | parent::__construct();
|
| 37: | $this->initVar('tplset_id', XOBJ_DTYPE_INT, null, false);
|
| 38: | $this->initVar('tplset_name', XOBJ_DTYPE_OTHER, null, false);
|
| 39: | $this->initVar('tplset_desc', XOBJ_DTYPE_TXTBOX, null, false, 255);
|
| 40: | $this->initVar('tplset_credits', XOBJ_DTYPE_TXTAREA, null, false);
|
| 41: | $this->initVar('tplset_created', XOBJ_DTYPE_INT, 0, false);
|
| 42: | }
|
| 43: |
|
| 44: | |
| 45: | |
| 46: | |
| 47: | |
| 48: |
|
| 49: | public function id($format = 'N')
|
| 50: | {
|
| 51: | return $this->getVar('tplset_id', $format);
|
| 52: | }
|
| 53: |
|
| 54: | |
| 55: | |
| 56: | |
| 57: | |
| 58: |
|
| 59: | public function tplset_id($format = '')
|
| 60: | {
|
| 61: | return $this->getVar('tplset_id', $format);
|
| 62: | }
|
| 63: |
|
| 64: | |
| 65: | |
| 66: | |
| 67: | |
| 68: |
|
| 69: | public function tplset_name($format = '')
|
| 70: | {
|
| 71: | return $this->getVar('tplset_name', $format);
|
| 72: | }
|
| 73: |
|
| 74: | |
| 75: | |
| 76: | |
| 77: | |
| 78: |
|
| 79: | public function tplset_desc($format = '')
|
| 80: | {
|
| 81: | return $this->getVar('tplset_desc', $format);
|
| 82: | }
|
| 83: |
|
| 84: | |
| 85: | |
| 86: | |
| 87: | |
| 88: |
|
| 89: | public function tplset_credits($format = '')
|
| 90: | {
|
| 91: | return $this->getVar('tplset_credits', $format);
|
| 92: | }
|
| 93: |
|
| 94: | |
| 95: | |
| 96: | |
| 97: | |
| 98: |
|
| 99: | public function tplset_created($format = '')
|
| 100: | {
|
| 101: | return $this->getVar('tplset_created', $format);
|
| 102: | }
|
| 103: | }
|
| 104: |
|
| 105: | |
| 106: | |
| 107: | |
| 108: | |
| 109: | |
| 110: | |
| 111: | |
| 112: | |
| 113: |
|
| 114: | class XoopsTplsetHandler extends XoopsObjectHandler
|
| 115: | {
|
| 116: | |
| 117: | |
| 118: | |
| 119: | |
| 120: | |
| 121: | |
| 122: |
|
| 123: | public function create($isNew = true)
|
| 124: | {
|
| 125: | $tplset = new XoopsTplset();
|
| 126: | if ($isNew) {
|
| 127: | $tplset->setNew();
|
| 128: | }
|
| 129: |
|
| 130: | return $tplset;
|
| 131: | }
|
| 132: |
|
| 133: | |
| 134: | |
| 135: | |
| 136: | |
| 137: | |
| 138: | |
| 139: |
|
| 140: | public function get($id)
|
| 141: | {
|
| 142: | $tplset = false;
|
| 143: | $id = (int)$id;
|
| 144: | if ($id > 0) {
|
| 145: | $sql = 'SELECT * FROM ' . $this->db->prefix('tplset') . ' WHERE tplset_id=' . $id;
|
| 146: | $result = $this->db->query($sql);
|
| 147: | if (!$this->db->isResultSet($result)) {
|
| 148: | return $tplset;
|
| 149: | }
|
| 150: | $numrows = $this->db->getRowsNum($result);
|
| 151: | if ($numrows == 1) {
|
| 152: | $tplset = new XoopsTplset();
|
| 153: | $tplset->assignVars($this->db->fetchArray($result));
|
| 154: | }
|
| 155: | }
|
| 156: |
|
| 157: | return $tplset;
|
| 158: | }
|
| 159: |
|
| 160: | |
| 161: | |
| 162: | |
| 163: | |
| 164: | |
| 165: | |
| 166: | |
| 167: | |
| 168: | |
| 169: |
|
| 170: | public function getByName($tplset_name)
|
| 171: | {
|
| 172: | $tplset = false;
|
| 173: | $tplset_name = trim($tplset_name);
|
| 174: | if ($tplset_name != '') {
|
| 175: | $sql = 'SELECT * FROM ' . $this->db->prefix('tplset') . ' WHERE tplset_name=' . $this->db->quoteString($tplset_name);
|
| 176: | $result = $this->db->query($sql);
|
| 177: | if (!$this->db->isResultSet($result)) {
|
| 178: | return $tplset;
|
| 179: | }
|
| 180: | $numrows = $this->db->getRowsNum($result);
|
| 181: | if ($numrows == 1) {
|
| 182: | $tplset = new XoopsTplset();
|
| 183: | $tplset->assignVars($this->db->fetchArray($result));
|
| 184: | }
|
| 185: | }
|
| 186: |
|
| 187: | return $tplset;
|
| 188: | }
|
| 189: |
|
| 190: | |
| 191: | |
| 192: | |
| 193: | |
| 194: | |
| 195: | |
| 196: |
|
| 197: | public function insert(XoopsObject $tplset)
|
| 198: | {
|
| 199: | $className = 'XoopsTplset';
|
| 200: | if (!($tplset instanceof $className)) {
|
| 201: | return false;
|
| 202: | }
|
| 203: | if (!$tplset->isDirty()) {
|
| 204: | return true;
|
| 205: | }
|
| 206: | if (!$tplset->cleanVars()) {
|
| 207: | return false;
|
| 208: | }
|
| 209: | foreach ($tplset->cleanVars as $k => $v) {
|
| 210: | ${$k} = $v;
|
| 211: | }
|
| 212: | if ($tplset->isNew()) {
|
| 213: | $tplset_id = $this->db->genId('tplset_tplset_id_seq');
|
| 214: | $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);
|
| 215: | } else {
|
| 216: | $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);
|
| 217: | }
|
| 218: | if (!$result = $this->db->query($sql)) {
|
| 219: | return false;
|
| 220: | }
|
| 221: | if (empty($tplset_id)) {
|
| 222: | $tplset_id = $this->db->getInsertId();
|
| 223: | }
|
| 224: | $tplset->assignVar('tplset_id', $tplset_id);
|
| 225: |
|
| 226: | return true;
|
| 227: | }
|
| 228: |
|
| 229: | |
| 230: | |
| 231: | |
| 232: | |
| 233: | |
| 234: | |
| 235: |
|
| 236: | public function delete(XoopsObject $tplset)
|
| 237: | {
|
| 238: | $className = 'XoopsTplset';
|
| 239: | if (!($tplset instanceof $className)) {
|
| 240: | return false;
|
| 241: | }
|
| 242: | $sql = sprintf('DELETE FROM %s WHERE tplset_id = %u', $this->db->prefix('tplset'), $tplset->getVar('tplset_id'));
|
| 243: | if (!$result = $this->db->query($sql)) {
|
| 244: | return false;
|
| 245: | }
|
| 246: | $sql = sprintf('DELETE FROM %s WHERE tplset_name = %s', $this->db->prefix('imgset_tplset_link'), $this->db->quoteString($tplset->getVar('tplset_name')));
|
| 247: | $this->db->query($sql);
|
| 248: |
|
| 249: | return true;
|
| 250: | }
|
| 251: |
|
| 252: | |
| 253: | |
| 254: | |
| 255: | |
| 256: | |
| 257: | |
| 258: |
|
| 259: | public function getObjects(CriteriaElement $criteria = null, $id_as_key = false)
|
| 260: | {
|
| 261: | $ret = array();
|
| 262: | $limit = $start = 0;
|
| 263: | $sql = 'SELECT * FROM ' . $this->db->prefix('tplset');
|
| 264: | if (isset($criteria) && \method_exists($criteria, 'renderWhere')) {
|
| 265: | $sql .= ' ' . $criteria->renderWhere() . ' ORDER BY tplset_id';
|
| 266: | $limit = $criteria->getLimit();
|
| 267: | $start = $criteria->getStart();
|
| 268: | }
|
| 269: | $result = $this->db->query($sql, $limit, $start);
|
| 270: | if (!$this->db->isResultSet($result)) {
|
| 271: | return $ret;
|
| 272: | }
|
| 273: |
|
| 274: | while (false !== ($myrow = $this->db->fetchArray($result))) {
|
| 275: | $tplset = new XoopsTplset();
|
| 276: | $tplset->assignVars($myrow);
|
| 277: | if (!$id_as_key) {
|
| 278: | $ret[] =& $tplset;
|
| 279: | } else {
|
| 280: | $ret[$myrow['tplset_id']] =& $tplset;
|
| 281: | }
|
| 282: | unset($tplset);
|
| 283: | }
|
| 284: |
|
| 285: | return $ret;
|
| 286: | }
|
| 287: |
|
| 288: | |
| 289: | |
| 290: | |
| 291: | |
| 292: | |
| 293: |
|
| 294: | public function getCount(CriteriaElement $criteria = null)
|
| 295: | {
|
| 296: | $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('tplset');
|
| 297: | if (isset($criteria) && \method_exists($criteria, 'renderWhere')) {
|
| 298: | $sql .= ' ' . $criteria->renderWhere();
|
| 299: | }
|
| 300: | $result = $this->db->query($sql);
|
| 301: | if (!$this->db->isResultSet($result)) {
|
| 302: | return 0;
|
| 303: | }
|
| 304: | list($count) = $this->db->fetchRow($result);
|
| 305: |
|
| 306: | return (int)$count;
|
| 307: | }
|
| 308: |
|
| 309: | |
| 310: | |
| 311: | |
| 312: | |
| 313: | |
| 314: |
|
| 315: | public function getList(CriteriaElement $criteria = null)
|
| 316: | {
|
| 317: | $ret = array();
|
| 318: | $tplsets = $this->getObjects($criteria, true);
|
| 319: | foreach (array_keys($tplsets) as $i) {
|
| 320: | $temp = $tplsets[$i]->getVar('tplset_name');
|
| 321: | $ret[$temp] = $temp;
|
| 322: | }
|
| 323: |
|
| 324: | return $ret;
|
| 325: | }
|
| 326: | }
|
| 327: | |