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