file.class.php 2.0KB

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