diff options
| author | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
| commit | bf6655a534a6775d30cafa67bd801276bda1d98d (patch) | |
| tree | c6381e3f6c81c33eab72508f410b165ba05f7e9c /src/functions.php | |
| parent | 94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff) | |
| download | AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.gz AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.bz2 AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip | |
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'src/functions.php')
| -rw-r--r-- | src/functions.php | 123 |
1 files changed, 0 insertions, 123 deletions
diff --git a/src/functions.php b/src/functions.php index 47cea42..d9fbfca 100644 --- a/src/functions.php +++ b/src/functions.php | |||
| @@ -1,7 +1,5 @@ | |||
| 1 | <?php | 1 | <?php |
| 2 | // src/functions.php | 2 | // src/functions.php |
| 3 | // | ||
| 4 | // utilisées par main.php et les fonctions de la boucle principale | ||
| 5 | 3 | ||
| 6 | 4 | ||
| 7 | // commande pour lancer une application graphique en ouvrant un fichier | 5 | // commande pour lancer une application graphique en ouvrant un fichier |
| @@ -20,124 +18,3 @@ function windowAppCommand(string $app, string $path = ''): string | |||
| 20 | // stderr > stdout pour cacher un message inutile | 18 | // stderr > stdout pour cacher un message inutile |
| 21 | return $command; | 19 | return $command; |
| 22 | } | 20 | } |
| 23 | |||
| 24 | function enterCustomer($Client): bool | ||
| 25 | { | ||
| 26 | // fenêtre | ||
| 27 | $NouveauClient = new ZenityForms(ZenitySetup::$nouveau_client['text'], ZenitySetup::$nouveau_client['entrees']); | ||
| 28 | |||
| 29 | $input = exec($NouveauClient->get()); | ||
| 30 | if($input == '') | ||
| 31 | { | ||
| 32 | echo "debug: annulation lors de l'enregistrement d'un nouveau client\n"; | ||
| 33 | return false; | ||
| 34 | } | ||
| 35 | if(!$Client->hydrateFromForm($input)) | ||
| 36 | { | ||
| 37 | // messages d'erreur dans hydrateFromForm() | ||
| 38 | return false; | ||
| 39 | } | ||
| 40 | unset($input); | ||
| 41 | |||
| 42 | $Client->create(); // écrire dans la base | ||
| 43 | $Client->setId(); // sans paramètre, exécute un $this->db->lastInsertId() | ||
| 44 | |||
| 45 | return true; | ||
| 46 | } | ||
| 47 | |||
| 48 | function makeObjectClient() | ||
| 49 | { | ||
| 50 | // fenêtres | ||
| 51 | $RechercheClient = new zenityEntry(ZenitySetup::$recherche_client_text); | ||
| 52 | $ResultatsRechercheClient = new ZenityList(ZenitySetup::$resultats_recherche_client_text, []); | ||
| 53 | |||
| 54 | $Client = new Clients; | ||
| 55 | |||
| 56 | $input = exec($RechercheClient->get()); | ||
| 57 | if($input == '') | ||
| 58 | { | ||
| 59 | echo "debug: recherche annulée ou saisie vide\n"; | ||
| 60 | return 0; | ||
| 61 | } | ||
| 62 | |||
| 63 | echo "debug: recherche effectuée\n"; | ||
| 64 | $ResultatsRechercheClient->setListRows( | ||
| 65 | searchCustomer($input, $Client), | ||
| 66 | count(StructTablesDB::$structureOfTables[$Client->getTable()])); // 2è paramètre = nombre de colonnes | ||
| 67 | |||
| 68 | // sélection parmi les résultats | ||
| 69 | $input = exec($ResultatsRechercheClient->get()); // renvoie l'ID de la table 'clients' | ||
| 70 | $ResultatsRechercheClient->cleanCommand(); | ||
| 71 | |||
| 72 | if($input == '') | ||
| 73 | { | ||
| 74 | echo "debug: client pas trouvé ou pas sélectionné\n"; | ||
| 75 | return 0; | ||
| 76 | } | ||
| 77 | |||
| 78 | echo "debug: client sélectionné\n"; | ||
| 79 | $Client->setId($input); | ||
| 80 | $Client->hydrate($Client->findById()); | ||
| 81 | |||
| 82 | return $Client; | ||
| 83 | } | ||
| 84 | |||
| 85 | // NOTE 1: en PHP les objets sont passés aux fonctions par référence par défaut, toutefois ce n'est pas entièrement vrai | ||
| 86 | // NOTE 2: PHP n'a pas de pointeur mais des références, une référence est un alias qui ne contient pas l'objet lui-même | ||
| 87 | // NOTE 3: la variable créée lors d'un "new" est elle-même une référence contenant un identifiant (= le pointeur?) | ||
| 88 | // NOTE 4: l'objet est détruit lorsque la dernière référence est supprimée | ||
| 89 | |||
| 90 | function searchCustomer(string $input, Clients $Client): array | ||
| 91 | { | ||
| 92 | $input_array = explode(' ', $input); // si plusieurs mot, on les recherche tous l'un après l'autre | ||
| 93 | $result = $Client->findByKeywords($input_array, 'prenom_nom'); // on obtient un tableau à deux dimensions avec les entrées trouvées | ||
| 94 | //var_dump($result); | ||
| 95 | return($result); | ||
| 96 | } | ||
| 97 | |||
| 98 | |||
| 99 | function getServices(Clients $Client, string $type = '') | ||
| 100 | { | ||
| 101 | echo "debug: recherche d'une prestation\n"; | ||
| 102 | |||
| 103 | // on recherche les ID des prestas dans la table 'prestations' avec 'id_client' | ||
| 104 | $Presta = new Prestations($Client->getId()); | ||
| 105 | $Presta->setTypePresta($type); | ||
| 106 | $IDs = $Presta->getIdsByIdClient(); // comportement différent si le type est connu | ||
| 107 | unset($Presta); | ||
| 108 | |||
| 109 | // mettres toutes les données dans un tableau | ||
| 110 | $PrestaList = []; | ||
| 111 | foreach($IDs as $id) | ||
| 112 | { | ||
| 113 | $PrestaList[$id] = new Prestations($Client->getId()); // renseigne 'id_client' | ||
| 114 | $PrestaList[$id]->setId($id); // ID de la prestation = clé du tableau | ||
| 115 | $PrestaList[$id]->hydrate($PrestaList[$id]->findById()); // données copiés de la table à l'objet | ||
| 116 | } | ||
| 117 | |||
| 118 | // fenêtre | ||
| 119 | $entrees = []; | ||
| 120 | foreach($PrestaList as $Presta) | ||
| 121 | { | ||
| 122 | $id = $Presta->getId(); | ||
| 123 | $entrees[$id][] = $id; | ||
| 124 | $Date = new Dates((int)$Presta->getDate()); // envoi du timestamp, (int) est là par sécurité | ||
| 125 | $entrees[$id][] = $Date->getDate(); | ||
| 126 | $entrees[$id][] = $Presta->getTypePresta(); | ||
| 127 | $entrees[$id][] = $Presta->getCodePresta(); | ||
| 128 | } | ||
| 129 | $ResultatsRecherchePresta = new ZenityList(ZenitySetup::$resultats_recherche_presta_text, []); | ||
| 130 | $ResultatsRecherchePresta->setListRows($entrees, 4); | ||
| 131 | |||
| 132 | // choix de l'utilisateur | ||
| 133 | $input = exec($ResultatsRecherchePresta->get()); // $input est l'ID de la prestation | ||
| 134 | if($input == '') | ||
| 135 | { | ||
| 136 | echo "debug: recherche annulée ou saisie vide\n"; | ||
| 137 | return 0; | ||
| 138 | } | ||
| 139 | else | ||
| 140 | { | ||
| 141 | return $PrestaList[$input]; | ||
| 142 | } | ||
| 143 | } | ||
