ソースを参照

Finished Promo

Brendan Abolivier 9 年 前
コミット
3c4375de28
共有4 個のファイルを変更した97 個の追加9 個の削除を含む
  1. 1
    1
      models/connector.class.php
  2. 1
    1
      models/data.class.php
  3. 92
    4
      models/promo.class.php
  4. 3
    3
      test.php

+ 1
- 1
models/connector.class.php ファイルの表示

@@ -93,7 +93,7 @@ class Connector {
93 93
         foreach($values as $name=>$value) {
94 94
             $request .= $name.",";
95 95
             $valeurs .= "?,";
96
-                array_push($arrayVerif, $value);
96
+            array_push($arrayVerif, $value);
97 97
         }
98 98
 
99 99
         $request = substr($request, 0, -1).") ".substr($valeurs, 0, -1).")";

+ 1
- 1
models/data.class.php ファイルの表示

@@ -1,6 +1,6 @@
1 1
 <?php
2 2
 
3
-require_once(dirname(__DIR__) . "connector.class.php");
3
+require_once("connector.class.php");
4 4
 
5 5
 class Data
6 6
 {

+ 92
- 4
models/promo.class.php ファイルの表示

@@ -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
 }

+ 3
- 3
test.php ファイルの表示

@@ -1,8 +1,8 @@
1 1
 <?php
2 2
 try {
3
-    include("models/data.class.php");
4
-    $csv = Data::extract();
5
-    echo $csv;
3
+    include("models/promo.class.php");
4
+    $promo = new Promo("test");
5
+    $promo->erase();
6 6
 } catch(Exception $e) {
7 7
     echo $e;
8 8
 }