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