diff options
Diffstat (limited to 'php/Model.php')
| -rw-r--r-- | php/Model.php | 51 |
1 files changed, 2 insertions, 49 deletions
diff --git a/php/Model.php b/php/Model.php index f3f1fe7..d26b081 100644 --- a/php/Model.php +++ b/php/Model.php | |||
| @@ -4,18 +4,15 @@ | |||
| 4 | class Model extends Connection | 4 | class Model extends Connection |
| 5 | { | 5 | { |
| 6 | private $db; // instance de connexion | 6 | private $db; // instance de connexion |
| 7 | private $date = ''; | 7 | public $date; |
| 8 | static public $date_format; // dates européennes jj-mm-aaaa | ||
| 9 | // pourquoi ne pas mettre les fonctions concernées dans une interface? | ||
| 10 | 8 | ||
| 11 | public function __construct() | 9 | public function __construct() |
| 12 | { | 10 | { |
| 13 | $this->db = parent::getInstance(); // connexion | 11 | $this->db = parent::getInstance(); // connexion |
| 14 | self::create_tables(); | ||
| 15 | } | 12 | } |
| 16 | 13 | ||
| 17 | // code SQL | 14 | // code SQL |
| 18 | function create_tables() | 15 | public function create_tables() |
| 19 | { | 16 | { |
| 20 | // la table prestations est liée à la table clients | 17 | // la table prestations est liée à la table clients |
| 21 | // les tables devis_factures, cesu et locations sont liées à la table prestations | 18 | // les tables devis_factures, cesu et locations sont liées à la table prestations |
| @@ -42,48 +39,4 @@ class Model extends Connection | |||
| 42 | 39 | ||
| 43 | // pour les dates, on stockera à priori le timestamp | 40 | // pour les dates, on stockera à priori le timestamp |
| 44 | } | 41 | } |
| 45 | |||
| 46 | |||
| 47 | // date jour/mois/année (string) -> timestamp (int) | ||
| 48 | private function get_timestamp(): int | ||
| 49 | { | ||
| 50 | if(self::$date_format == 'EU') | ||
| 51 | { | ||
| 52 | // change jj/mm/aaaa en jj-mm-aaaa | ||
| 53 | $this->date = preg_replace('#/#', '-', $this->date); | ||
| 54 | } | ||
| 55 | elseif(self::$date_format == 'US') | ||
| 56 | { | ||
| 57 | // change mm-dd.yyyy en mm/dd/yyyy | ||
| 58 | $this->date = preg_replace('#[-\.]#', '/', $this->date); | ||
| 59 | } | ||
| 60 | else | ||
| 61 | { | ||
| 62 | echo('Le fichier config.php comporte une erreur. La variable $date_format doit avoir pour valeur "EU" ou "US"'); | ||
| 63 | die(); // brutal | ||
| 64 | } | ||
| 65 | return(strtotime($this->date)); | ||
| 66 | // strtotime() devine le format en analysant la chaîne en entrée, on l'aide un peu | ||
| 67 | // avec des /, php considère que la date est américaine | ||
| 68 | // avec des - ou des ., php considère que la date est européenne | ||
| 69 | } | ||
| 70 | |||
| 71 | // timestamp (int) -> date jj-mm-aaaa (string) | ||
| 72 | private function get_date(): string | ||
| 73 | { | ||
| 74 | if(self::$date_format == 'EU') | ||
| 75 | { | ||
| 76 | return(date("j-m-Y", $this->date)); | ||
| 77 | } | ||
| 78 | elseif(self::$date_format == 'US') | ||
| 79 | { | ||
| 80 | return(date("m/d/Y", $this->date)); | ||
| 81 | } | ||
| 82 | else | ||
| 83 | { | ||
| 84 | echo('Le fichier config.php comporte une erreur. La variable $date_format doit avoir pour valeur "EU" ou "US"'); | ||
| 85 | die(); // brutal | ||
| 86 | } | ||
| 87 | } | ||
| 88 | |||
| 89 | } | 42 | } |
