option.inc.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. class Option {
  3. private $id = NULL;
  4. private $key = NULL;
  5. private $value = NULL;
  6. public function __construct($id, $key, $value) {
  7. $this->id = $id;
  8. $this->key = $key;
  9. $this->value = $value;
  10. }
  11. /**
  12. * Get the value of Id
  13. *
  14. *
  15. * @return int
  16. *
  17. */
  18. public function getID() {
  19. return $this->id;
  20. }
  21. /**
  22. * Set the value of Id
  23. *
  24. *
  25. * @param int id
  26. *
  27. */
  28. public function setID($id) {
  29. $this->id = $id;
  30. }
  31. /**
  32. * Get the value of Key
  33. *
  34. *
  35. * @return string
  36. *
  37. */
  38. public function getKey() {
  39. return $this->key;
  40. }
  41. /**
  42. * Set the value of Key
  43. *
  44. *
  45. * @param string key
  46. *
  47. */
  48. public function setKey($key) {
  49. $this->key = $key;
  50. }
  51. /**
  52. * Get the value of Value
  53. *
  54. *
  55. * @return string
  56. *
  57. */
  58. public function getValue() {
  59. return $this->value;
  60. }
  61. /**
  62. * Set the value of Value
  63. *
  64. *
  65. * @param string value
  66. *
  67. */
  68. public function setValue($value) {
  69. $this->value = $value;
  70. }
  71. /*
  72. *
  73. * Save current option
  74. *
  75. */
  76. public function save() {
  77. global $db;
  78. $db->insertQuery("INSERT INTO `options` (`id`, `key`, `value`) VALUES (" . $this->id . ", '" . $this->key . "', '" . $this->value . "') ON DUPLICATE KEY UPDATE `id` = " . $this->id . ", `key` = '" . $this->key . "', `value` = '" . $this->value . "';");
  79. }
  80. /**
  81. * Get Option by Key
  82. *
  83. * @param string $key Key
  84. *
  85. * @return Option Selected Option
  86. *
  87. */
  88. public static function getOptionByKey($key) {
  89. global $db;
  90. $option = $db->selectQuery("SELECT * FROM `options` WHERE `key` = '" . $key . "';");
  91. if(!$option) {
  92. return false;
  93. }
  94. return new Option($option[0]->id, $option[0]->key, $option[0]->value);
  95. }
  96. }
  97. ?>