diff --git a/ProjetProgWeb/class/dump.php b/ProjetProgWeb/class/dump.php index 99c391c..468d1f3 100644 --- a/ProjetProgWeb/class/dump.php +++ b/ProjetProgWeb/class/dump.php @@ -10,25 +10,29 @@ class dump { $this->these = $these; } + public static function convertDate($old_date) : string { + return date("Y-m-d", strtotime($old_date)); + } + public function sendThese() { $data = [ 'author' => $this->these->getAuthor(), - 'id_author' => $this->these->getIdAuthor(), + 'id_author' => empty($this->these->getIdAuthor()) ? NULL : $this->these->getIdAuthor(), 'these_director' => $this->these->getTheseDirector(), 'title' => $this->these->getTitle(), 'these_director_name_lastname' => $this->these->getTheseDirectorNameLastname(), - 'id_director' => $this->these->getIdDirector(), + 'id_director' => empty($this->these->getIdDirector()) ? NULL : $this->these->getIdDirector(), 'soutenance_establishment' => $this->these->getSoutenanceEstablishment(), - 'id_establishment' => $this->these->getIdEstablishment(), + 'id_establishment' => empty($this->these->getIdEstablishment()) ? NULL : $this->these->getIdEstablishment(), 'discipline' => $this->these->getDiscipline(), 'status' => $this->these->getStatus(), - 'date_first_registration' => $this->these->getDateFirstRegistration(), - 'date_soutenance' => $this->these->getDateSoutenance(), - 'language' => $this->these->getLanguage(), - 'id_these' => $this->these->getIdThese(), + 'date_first_registration' => empty($this->these->getDateFirstRegistration()) ? NULL : $this->these->getDateFirstRegistration(), + 'date_soutenance' => empty($this->these->getDateSoutenance()) ? NULL : $this->these->getDateSoutenance(), + 'language' => empty($this->these->getLanguage()) ? NULL : $this->these->getLanguage(), + 'id_these' => empty($this->these->getIdThese()) ? NULL : $this->these->getIdThese(), 'online' => $this->these->isOnline() ? "yes" : "no", - 'date_publication' => $this->these->getDatePublication(), - 'date_update' => $this->these->getDateUpdate() + 'date_publication' => empty($this->these->getDatePublication()) ? NULL : $this->these->getDatePublication(), + 'date_update' => empty($this->these->getDateUpdate()) ? NULL : $this->these->getDateUpdate() ]; $sql = "INSERT INTO theses (author, id_author, these_director, title, these_director_name_lastname, id_director, soutenance_establishment, id_establishment, discipline, status, date_first_registration, date_soutenance, language, id_these, online, date_publication, date_update) VALUES (:author, :id_author, :these_director, :title, :these_director_name_lastname, :id_director, :soutenance_establishment, :id_establishment, :discipline, :status, :date_first_registration, :date_soutenance, :language, :id_these, :online, :date_publication, :date_update)"; $pdo = new PDO('mysql:host=localhost;dbname=projet_prog_web', 'root', 'root'); diff --git a/ProjetProgWeb/class/these.php b/ProjetProgWeb/class/these.php index 1d4ef2e..a7db8de 100644 --- a/ProjetProgWeb/class/these.php +++ b/ProjetProgWeb/class/these.php @@ -1,5 +1,7 @@ author = $author; - $this->id_author = $id_author; - $this->title = $title; - $this->these_director = $these_director; - $this->these_director_name_lastname = $these_director_name_lastname; - $this->id_director = $id_director; - $this->soutenance_establishment = $soutenance_establishment; - $this->id_establishment = $id_establishment; - $this->discipline = $discipline; - $this->status = $status; - $this->date_first_registration = $date_first_registration; - $this->date_soutenance = $date_soutenance; - $this->language = $language; - $this->id_these = $id_these; - $this->online = $online; - $this->date_publication = $date_publication; - $this->date_update = $date_update; + #[Pure] public static function emptyThese(): these + { + return new self(); + } + + public static function fullThese(string $author, string $id_author, string $title, string $these_director, string $these_director_name_lastname, string $id_director, string $soutenance_establishment, string $id_establishment, string $discipline, string $status, string $date_first_registration, string $date_soutenance, string $language, string $id_these, bool $online, string $date_publication, string $date_update) { + $these = these::emptyThese(); + $these->setAuthor($author); + $these->setIdAuthor($id_author); + $these->setTitle($title); + $these->setTheseDirector($these_director); + $these->setTheseDirectorNameLastname($these_director_name_lastname); + $these->setIdDirector($id_director); + $these->setSoutenanceEstablishment($soutenance_establishment); + $these->setIdEstablishment($id_establishment); + $these->setDiscipline($discipline); + $these->setStatus($status); + $these->setDateFirstRegistration($date_first_registration); + $these->setDateSoutenance($date_soutenance); + $these->setLanguage($language); + $these->setIdThese($id_these); + $these->setOnline($online); + $these->setDatePublication($date_publication); + $these->setDateUpdate($date_update); + return $these; + } + + public function insertField($field, $index) { + switch ($index) { + case 0: $this->setAuthor($field); break; + case 1: $this->setIdAuthor($field); break; + case 2: $this->setTitle($field); break; + case 3: $this->setTheseDirector($field); break; + case 4: $this->setTheseDirectorNameLastname($field); break; + case 5: $this->setIdDirector($field); break; + case 6: $this->setSoutenanceEstablishment($field); break; + case 7: $this->setIdEstablishment($field); break; + case 8: $this->setDiscipline($field); break; + case 9: $this->setStatus($field); break; + case 10: $this->setDateFirstRegistration(dump::convertDate($field)); break; + case 11: $this->setDateSoutenance(dump::convertDate($field)); break; + case 12: $this->setLanguage($field); break; + case 13: $this->setIdThese($field); break; + case 14: $this->setOnline($field); break; + case 15: $this->setDatePublication(dump::convertDate($field)); break; + case 16: $this->setDateUpdate(dump::convertDate($field)); break; + } } /**