Configuration.class.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. class Configuration extends SQLiteEntity{
  3. protected $id,$key,$value,$confTab;
  4. protected $TABLE_NAME = 'configuration';
  5. protected $CLASS_NAME = 'Configuration';
  6. protected $object_fields =
  7. array(
  8. 'id'=>'key',
  9. 'key'=>'longstring',
  10. 'value'=>'longstring'
  11. );
  12. function __construct(){
  13. parent::__construct();
  14. }
  15. public function getAll(){
  16. if(!isset($_SESSION['configuration'])){
  17. $configurationManager = new Configuration();
  18. $configsQuery = $configurationManager->customQuery('SELECT key,value FROM configuration');
  19. $confTab = array();
  20. while($config = $configsQuery->fetchArray() ){
  21. $this->confTab[$config['key']] = $config['value'];
  22. }
  23. $_SESSION['configuration'] = serialize($this->confTab);
  24. }else{
  25. $this->confTab = unserialize($_SESSION['configuration']);
  26. }
  27. }
  28. public function get($key){
  29. return (isset($this->confTab[$key])?$this->confTab[$key]:'');
  30. }
  31. public function put($key,$value){
  32. $configurationManager = new Configuration();
  33. $configurationManager->change(array('value'=>$value),array('key'=>$key));
  34. $this->confTab[$key] = $value;
  35. unset($_SESSION['configuration']);
  36. }
  37. public function add($key,$value){
  38. $config = new Configuration();
  39. $config->setKey($key);
  40. $config->setValue($value);
  41. $config->save();
  42. }
  43. function getId(){
  44. return $this->id;
  45. }
  46. function getKey(){
  47. return $this->key;
  48. }
  49. function setKey($key){
  50. $this->key = $key;
  51. }
  52. function getValue(){
  53. return $this->value;
  54. }
  55. function setValue($value){
  56. $this->value = $value;
  57. }
  58. }
  59. ?>