Explorar el Código

Added File model, changed includes, and added a few exceptions

Brendan Abolivier hace 9 años
padre
commit
3567803076
Se han modificado 5 ficheros con 102 adiciones y 12 borrados
  1. 1
    1
      models/connector.class.php
  2. 5
    0
      models/data.class.php
  3. 88
    0
      models/file.class.php
  4. 8
    3
      models/promo.class.php
  5. 0
    8
      test.php

+ 1
- 1
models/connector.class.php Ver fichero

@@ -16,7 +16,7 @@
16 16
 *        Update()                                                              *
17 17
 *******************************************************************************/
18 18
 
19
-include(dirname(__DIR__)."../../DbIds.php");
19
+include(__DIR__."/../../DbIds.php");
20 20
 
21 21
 class Connector {
22 22
 

+ 5
- 0
models/data.class.php Ver fichero

@@ -23,6 +23,11 @@ class Data
23 23
             )
24 24
         ))[0];
25 25
 
26
+        if($data == NULL)
27
+        {
28
+            throw new Exception("Les données n'existent pas");
29
+        }
30
+
26 31
         // Chargement des informations
27 32
         $this->identifiant = $email;
28 33
         $this->nom_fils = $data["nom_fils"];

+ 88
- 0
models/file.class.php Ver fichero

@@ -0,0 +1,88 @@
1
+<?php
2
+
3
+require_once("connector.class.php");
4
+
5
+class File
6
+{
7
+    private $id;
8
+    private $rang;
9
+    private $promo;
10
+    private $libelle;
11
+    private $fichier;
12
+
13
+    function __construct($id)
14
+    {
15
+        $bdd = new Connector();
16
+        $document = $bdd->Select("*", "document", array(
17
+            "where" => array(
18
+                array("id", "=", $id)
19
+            )
20
+        ))[0];
21
+
22
+        if(!$document)
23
+        {
24
+            throw new Exception("Le fichier n'existe pas");
25
+        }
26
+
27
+        $this->id = $document["id"];
28
+        $this->rang = $document["rang"];
29
+        $this->promo = $document["promo"];
30
+        $this->libelle = $document["libelle"];
31
+        $this->fichier = $document["fichier"];
32
+    }
33
+
34
+    public static function addDocument($document)
35
+    {
36
+        $bdd = new Connector();
37
+        $bdd->Insert("document", array(
38
+            "id" => $document["id"],
39
+            "rang" => $document["rang"],
40
+            "promo" => $document["promo"],
41
+            "libelle" => $document["libelle"],
42
+            "fichier" => $document["fichier"]
43
+        ));
44
+    }
45
+
46
+    function erase()
47
+    {
48
+        $bdd = new Connector();
49
+        $bdd->Delete("document", array(array("id", "=", $this->id)));
50
+        unlink(__DIR__."/../../pdf/".$this->fichier);
51
+    }
52
+
53
+    function changePromo($newPromo)
54
+    {
55
+        $bdd = new Connector();
56
+
57
+        // Check if promo exists
58
+        $promo = $bdd->Select("*", "promo", array(
59
+            "where" => array(
60
+                array("promo_id", "=", $newPromo)
61
+            )
62
+        ))[0];
63
+
64
+        if(!$promo)
65
+        {
66
+            throw new Exception("La promo n'existe pas");
67
+        }
68
+
69
+        // Change promo in both object and BDD
70
+        $this->promo = $newPromo;
71
+
72
+        $bdd->Update("document", array(
73
+            "promo" => $this->promo
74
+        ));
75
+    }
76
+
77
+    function changeRank($newRank)
78
+    {
79
+        $bdd = new Connector();
80
+
81
+        // Change promo in both object and BDD
82
+        $this->rang = $newRank;
83
+
84
+        $bdd->Update("document", array(
85
+            "rang" => $this->rang
86
+        ));
87
+    }
88
+}

+ 8
- 3
models/promo.class.php Ver fichero

@@ -16,6 +16,11 @@ class Promo
16 16
             )
17 17
         ))[0];
18 18
 
19
+        if($promo == NULL)
20
+        {
21
+            throw new Exception("La promo n'existe pas");
22
+        }
23
+
19 24
         $this->id_promo = $promo["id_promo"];
20 25
         $this->libelle = $promo["libelle"];
21 26
     }
@@ -89,12 +94,12 @@ class Promo
89 94
         $bdd->Delete("promo", array(array("id_promo", "=", $this->id_promo)));
90 95
     }
91 96
 
92
-    public static function addPromo($id, $libelle)
97
+    public static function addPromo($promo)
93 98
     {
94 99
         $bdd = new Connector();
95 100
         $bdd->Insert("promo", array(
96
-            "id_promo" => $id,
97
-            "libelle" => $libelle
101
+            "id_promo" => $promo["id"],
102
+            "libelle" => $promo["libelle"]
98 103
         ));
99 104
     }
100 105
 }

+ 0
- 8
test.php Ver fichero

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