promo.class.php 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. require_once("connector.class.php");
  3. class Promo
  4. {
  5. private $id_promo;
  6. private $libelle;
  7. function __construct($id)
  8. {
  9. $bdd = new Connector();
  10. $promo = $bdd->Select("*", "promo", array(
  11. "where" => array(
  12. array("id_promo", "=", $id)
  13. )
  14. ))[0];
  15. $this->id_promo = $promo["id_promo"];
  16. $this->libelle = $promo["libelle"];
  17. }
  18. public static function getAll()
  19. {
  20. $bdd = new Connector();
  21. return $bdd->Select("*", "promo");
  22. }
  23. /**
  24. * @return mixed
  25. */
  26. public function getIdPromo()
  27. {
  28. return $this->id_promo;
  29. }
  30. /**
  31. * @return mixed
  32. */
  33. public function getLibelle()
  34. {
  35. return $this->libelle;
  36. }
  37. /**
  38. * @param mixed $id_promo
  39. */
  40. public function setIdPromo($id_promo)
  41. {
  42. $this->id_promo = $id_promo;
  43. }
  44. /**
  45. * @param mixed $libelle
  46. */
  47. public function setLibelle($libelle)
  48. {
  49. $this->libelle = $libelle;
  50. }
  51. function write()
  52. {
  53. $bdd = new Connector();
  54. $promo = $bdd->Select("*", "promo", array(
  55. "where" => array(
  56. array("id_promo", "=", $this->id_promo)
  57. )
  58. ))[0];
  59. $attrs = get_object_vars($this);
  60. $toUpdate = array();
  61. foreach ($attrs as $key => $value) {
  62. if ($value != $promo[$key]) {
  63. $toUpdate[$key] = $value;
  64. }
  65. }
  66. $bdd->Update("promo", array(
  67. "set" => $toUpdate,
  68. "where" => array(array("id_promo", "=", $this->id_promo))
  69. ));
  70. }
  71. function erase()
  72. {
  73. $bdd = new Connector();
  74. $bdd->Delete("promo", array(array("id_promo", "=", $this->id_promo)));
  75. }
  76. public static function addPromo($id, $libelle)
  77. {
  78. $bdd = new Connector();
  79. $bdd->Insert("promo", array(
  80. "id_promo" => $id,
  81. "libelle" => $libelle
  82. ));
  83. }
  84. }