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