public static function addDocument($document, $options)
 {
     $filename = $document["name"];
     // Check for upload error
     if ($document["error"]) {
         throw new InvalidArgumentException("Une erreur s'est produite lors de l'envoi du fichier (" . $document["error"] . ")");
     }
     // Determining the folder to put the document in
     if (preg_match("/A[12]/", $options["promo"])) {
         $destination = "A12/" . $filename;
     } elseif (preg_match("/A[345]/", $options["promo"])) {
         $destination = "A345/" . $filename;
     } else {
         $destination = $filename;
     }
     if (!move_uploaded_file($document["tmp_name"], __DIR__ . "/../../pdf/" . $destination)) {
         error_log("Error when trying to write " . __DIR__ . "/../../pdf/" . $destination);
     }
     foreach ($options as $key => $value) {
         if (empty($value) && $key != "promo") {
             throw new InvalidArgumentException("La colonne `" . $key . "` doit être définie");
         }
     }
     $bdd = new Connector();
     $bdd->Insert("document", array("rang" => $options["rang"], "promo" => $options["promo"], "libelle" => $options["libelle"], "fichier" => $destination));
     $document = $bdd->Select("*", "document", array("where" => array(array("fichier", "=", $destination))))[0];
     return array("path" => $destination, "id" => $document["id"]);
 }
示例#2
0
 public static function addPromo($promo)
 {
     $bdd = new Connector();
     $bdd->Insert("promo", array("id_promo" => $promo["id"], "libelle" => $promo["libelle"]));
 }