diff options
Diffstat (limited to 'old/model version 0.1/Clients.php')
| -rw-r--r-- | old/model version 0.1/Clients.php | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/old/model version 0.1/Clients.php b/old/model version 0.1/Clients.php new file mode 100644 index 0000000..32cf0c5 --- /dev/null +++ b/old/model version 0.1/Clients.php | |||
| @@ -0,0 +1,168 @@ | |||
| 1 | <?php | ||
| 2 | // src/model/Clients.php | ||
| 3 | |||
| 4 | class Clients extends Model | ||
| 5 | { | ||
| 6 | // lecture des données ou hydratation | ||
| 7 | protected $id; // auto-incrémentée | ||
| 8 | protected $prenom_nom; | ||
| 9 | protected $code_client; | ||
| 10 | protected $adresse; | ||
| 11 | protected $code_postal; | ||
| 12 | protected $ville; | ||
| 13 | protected $telephone; | ||
| 14 | protected $courriel; | ||
| 15 | protected $apropos; | ||
| 16 | protected $type = 'prospect'; | ||
| 17 | |||
| 18 | public function __construct() | ||
| 19 | { | ||
| 20 | $this->table = strtolower(__CLASS__); // clients | ||
| 21 | } | ||
| 22 | |||
| 23 | // getters | ||
| 24 | public function getId(): int | ||
| 25 | { | ||
| 26 | return $this->id; | ||
| 27 | } | ||
| 28 | public function getCodeClient(): string | ||
| 29 | { | ||
| 30 | return $this->code_client; | ||
| 31 | } | ||
| 32 | public function getAllWithWindowFields(): array // différent de Model::getAll() qui retourne get_object_vars($this) | ||
| 33 | { | ||
| 34 | return [ | ||
| 35 | "Prénom Nom:" => $this->prenom_nom, | ||
| 36 | "Code client (J.C.Dusse):" => $this->code_client, | ||
| 37 | "Adresse:" => $this->adresse, | ||
| 38 | "Code postal:" => $this->code_postal, | ||
| 39 | "Ville:" => $this->ville, | ||
| 40 | "Telephone:" => $this->telephone, | ||
| 41 | "Courriel:" => $this->courriel, | ||
| 42 | "À propos:" => $this->apropos, | ||
| 43 | "Client ou Prospect?" => $this->type]; | ||
| 44 | } | ||
| 45 | public function set(string $entry, string $input) | ||
| 46 | { | ||
| 47 | $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaine vide | ||
| 48 | switch($entry) | ||
| 49 | { | ||
| 50 | case "Prénom Nom:": | ||
| 51 | $this->setPrenomNom($input); | ||
| 52 | break; | ||
| 53 | case "Code client (J.C.Dusse):": | ||
| 54 | $this->setCodeClient($input); | ||
| 55 | break; | ||
| 56 | case "Adresse:": | ||
| 57 | $this->setAdresse($input); | ||
| 58 | break; | ||
| 59 | case "Code postal:": | ||
| 60 | $this->setCodePostal($input); | ||
| 61 | break; | ||
| 62 | case "Ville:": | ||
| 63 | $this->setVille($input); | ||
| 64 | break; | ||
| 65 | case "Telephone:": | ||
| 66 | $this->setTelephone($input); | ||
| 67 | break; | ||
| 68 | case "Courriel:": | ||
| 69 | $this->setCourriel($input); | ||
| 70 | break; | ||
| 71 | case "À propos:": | ||
| 72 | $this->setApropos($input); | ||
| 73 | break; | ||
| 74 | case "Client ou Prospect?": | ||
| 75 | $this->setType($input); | ||
| 76 | break; | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | // setters | ||
| 81 | public function setPrenomNom($value) | ||
| 82 | { | ||
| 83 | $this->prenom_nom = (string) $value; | ||
| 84 | return $this; | ||
| 85 | } | ||
| 86 | public function setCodeClient($value) | ||
| 87 | { | ||
| 88 | $this->code_client = (string) $value; | ||
| 89 | return $this; | ||
| 90 | } | ||
| 91 | public function setAdresse($value) | ||
| 92 | { | ||
| 93 | $this->adresse = (string) $value; | ||
| 94 | return $this; | ||
| 95 | } | ||
| 96 | public function setCodePostal($value) | ||
| 97 | { | ||
| 98 | $this->code_postal = (string) $value; | ||
| 99 | return $this; | ||
| 100 | } | ||
| 101 | public function setVille($value) | ||
| 102 | { | ||
| 103 | $this->ville = (string) $value; | ||
| 104 | return $this; | ||
| 105 | } | ||
| 106 | public function setTelephone($value) | ||
| 107 | { | ||
| 108 | // type string parce que: | ||
| 109 | // - zenity renvoie une chaine | ||
| 110 | // - permet de garder le 0 au début et d'inscrire plusieurs numéros | ||
| 111 | $this->telephone = (string) $value; | ||
| 112 | return $this; | ||
| 113 | } | ||
| 114 | public function setCourriel($value) | ||
| 115 | { | ||
| 116 | $this->courriel = (string) $value; | ||
| 117 | return $this; | ||
| 118 | } | ||
| 119 | public function setApropos($value) | ||
| 120 | { | ||
| 121 | $this->apropos = (string) $value; | ||
| 122 | return $this; | ||
| 123 | } | ||
| 124 | public function setType($value) | ||
| 125 | { | ||
| 126 | $this->type = (string) $value; | ||
| 127 | return $this; | ||
| 128 | } | ||
| 129 | |||
| 130 | public function typeToClient(): bool | ||
| 131 | { | ||
| 132 | if($this->type != 'client') | ||
| 133 | { | ||
| 134 | $this->type = 'client'; | ||
| 135 | return true; | ||
| 136 | } | ||
| 137 | else | ||
| 138 | { | ||
| 139 | return false; | ||
| 140 | } | ||
| 141 | } | ||
| 142 | |||
| 143 | public function findByKeywords(array $keywords, string $field): array // n'hydrate pas les variables, on doit choisir un client et hydrater ensuite | ||
| 144 | { | ||
| 145 | $result = []; | ||
| 146 | for($i = 0; $i < count($keywords); $i++) | ||
| 147 | { | ||
| 148 | // tableau à deux dimensions obtenu pour un mot clé | ||
| 149 | $query_result = $this->execQuery('SELECT * FROM ' . $this->table . ' WHERE ' . $field . ' LIKE "%' . $keywords[$i] . '%"')->fetchAll(); | ||
| 150 | foreach($query_result as $one_array) // pour chaque sous tableau | ||
| 151 | { | ||
| 152 | $already_exist = false; | ||
| 153 | for($j = 0; $j < count($result); $j++) // pour chaque tableau déjà enregistré dans le tableau $result | ||
| 154 | { | ||
| 155 | if($result[$j]['id'] === $one_array['id']) | ||
| 156 | { | ||
| 157 | $already_exist = true; | ||
| 158 | } | ||
| 159 | } | ||
| 160 | if(!$already_exist) | ||
| 161 | { | ||
| 162 | $result[] = $one_array; | ||
| 163 | } | ||
| 164 | } | ||
| 165 | } | ||
| 166 | return $result; | ||
| 167 | } | ||
| 168 | } | ||
