UserModel.php 788 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. require_once __DIR__.'/../app/data.php';
  3. class UserModel
  4. {
  5. protected $id;
  6. protected $data = array();
  7. protected $saved = false;
  8. public function getName()
  9. {
  10. return $this->data['name'];
  11. }
  12. function setName($name)
  13. {
  14. $this->data['name'] = 'Mr. '.$name;
  15. }
  16. function getId()
  17. {
  18. return $this->id;
  19. }
  20. function get($param)
  21. {
  22. if (!isset($this->data[$param])) throw new \Exception('Key does not exist!');
  23. return $this->data[$param];
  24. }
  25. function set($param, $value)
  26. {
  27. $this->data[$param] = $value;
  28. }
  29. function save()
  30. {
  31. if (!$this->id) $this->id = uniqid();
  32. data::set($this->id, $this->data);
  33. $this->saved = true;
  34. return true;
  35. }
  36. }