From bf6655a534a6775d30cafa67bd801276bda1d98d Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 13 Aug 2024 23:45:21 +0200 Subject: =?UTF-8?q?VERSION=200.2=20doctrine=20ORM=20et=20entit=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/entities/Prestation.php | 252 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 252 insertions(+) create mode 100644 src/model/entities/Prestation.php (limited to 'src/model/entities/Prestation.php') diff --git a/src/model/entities/Prestation.php b/src/model/entities/Prestation.php new file mode 100644 index 0000000..6d014d8 --- /dev/null +++ b/src/model/entities/Prestation.php @@ -0,0 +1,252 @@ +setClient($client); + } + } + + // getters + public function getId(): int + { + return $this->id; + } + public function getCodePresta(): string + { + return $this->code_presta; + } + public function getDate(): int + { + return $this->date; + } + public function getTypePresta(): string + { + return $this->type_presta; + } + public function getClient(): Client + { + return $this->client; + } + public function getAll(): array + { + // n'utiliser get_object_vars() qu'avec une entité parce qu'on maîtrise le nombre de propriétés + return get_object_vars($this); + } + + public function getAllWithWindowFields(): array // différent de Model::getAll() qui retourne get_object_vars($this) + { + $code_presta_tableau = explode('-', $this->code_presta); + $Date = new Dates($this->date); + + return [ + //"Numéro prestation:" => end($code_presta_tableau), // crée des conflits, calcul automatique par setCodePresta() + "Date:" => $Date->getDate(), + //"Type de Presta:" => $this->type_presta, // choix impossible pour le moment + "Mode de paiement:" => $this->mode_paiement, // non pertinent pour un devis + "Commentaires:" => $this->commentaires]; + } + + // setters + //~ public function setCodePresta(string $value) + //~ { + //~ $this->code_presta = $value; + //~ return $this; + //~ } + //public function setDate(int $value) + public function setDate(Dates $Date) + { + //$this->date = (int)$value; // attend un timestamp + $this->date = $Date->getTimestamp(); + return $this; + /*if($set_code_presta) + { + $code_presta_tableau = explode('-', $this->code_presta); + $Date = new Dates($value); + $code_presta_tableau[0] = $Date->getYear(); + $code_presta_tableau[1] = $Date->getMonth(); + $code_presta_tableau[2] = $Date->getDay(); + $this->code_presta = implode('-', $code_presta_tableau); + }*/ + } + + public function setTypePresta(string $value) // appelée dans la section 2 uniquement, pour la 3 on verra plus tard + { + $this->type_presta = $value; + return $this; + } + public function setModePaiement(string $value) + { + $this->mode_paiement = $value; + return $this; + } + public function setCommentaires(string $input) + { + $this->commentaires = $input; + } + /*public function setAll(array $input) + { + $this->code_presta = $input[0]; + $this->date = $input[1]; + $this->type_presta = $input[2]; + $this->mode_paiement = $input[3]; + $this->commentaires = $input[4]; + }*/ + + private function setClient(Client $input) // private? + { + $this->client = $input; + //$input->typeToClient(); // on modifie $client ici (merci les références PHP) + } + + public function set(string $entry, $input) // $input = chaîne ou entier + { + if(gettype($input) === 'string') + { + $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaine vide + } + switch($entry) + { + // pas de cas "code presta" qui généré par setCodePresta, on peut modifier la date (ici) et le code client (ailleurs) + //~ case "Numéro prestation:": + //~ $this->setNumeroPresta($input); + //~ // modifier le code presta en conséquence + //~ break; + case "Date:": // inutile, setDate() est appelé directement après choix fenêtre calendrier + $this->setDate($input); + break; + //~ case "Type de Presta:": // choix impossible pour le moment + //~ $this->setTypePresta($input); + //~ break; + case "Mode de paiement:": + $this->setModePaiement($input); + break; + case "Commentaires:": + $this->setCommentaires($input); + break; + } + } + + // code presta = année-mois-jour-codeclient-typedepresta-combientièmefois + public function setCodePresta(int $increment) // 0 pour modif, 1 pour nouvelle presta + { + $Date = new Dates($this->date); + $repository = self::$entityManager->getRepository('Prestation'); // prestas de tout type d'un client + // attention: il peut y avoir plusieurs prestations avec le même numéro au compteur, à améliorer + $combientieme_fois = count($repository->findBy(['client' => $this->client->getId()])) + $increment; + //var_dump($combientieme_fois); + $array_code = [$Date->getYear(), $Date->getMonth(), $Date->getDay(), $this->client->getCodeClient(), $this->type_presta, $combientieme_fois]; + //~ $array_code[0] = $Date->getYear(); + //~ $array_code[1] = $Date->getMonth(); + //~ $array_code[2] = $Date->getDay(); + //~ $array_code[3] = $this->client->getCodeClient(); // mise à jour éventuelle + //~ $array_code[4] = $this->type_presta; + $this->code_presta = implode('-', $array_code); + return $this; + } + // combientième fois au choix (ne fonctionne pas avec setCodePresta qui recalculera ce numéro automatiquement à la prochaine modification) + //~ public function setNumeroPresta($value) + //~ { + //~ // modifier le code presta, on pourrait aussi utiliser une regex + //~ $code_presta_tableau = explode('-', $this->code_presta); + //~ $code_presta_tableau[count($code_presta_tableau) - 1] = (int) $value; // dernière case du tableau + //~ $this->code_presta = implode('-', $code_presta_tableau); + //~ return $this; + //~ } + + public static function getServices(Client $Customer, string $type = '') + { + echo "debug: recherche d'une prestation\n"; + + // requête DQL qui fait la même chose que le findBy plus bas + /*$query = self::$entityManager->createQuery('SELECT u FROM Prestation u WHERE u.client = :id_client AND u.type_presta = :type_presta'); + $query->setParameter('id_client', $Customer->getId()); + $query->setParameter('type_presta', $type); + $query_result = $query->getResult(); + var_dump($query_result);die;*/ + + $repository = self::$entityManager->getRepository('Prestation'); + $find_by = ['client' => $Customer->getId()]; + if($type != '') + { + $find_by['type_presta'] = 'devis'; + } + $PrestaList = $repository->findBy($find_by); + + // le même tableau avec pour clés les id des objets + $PrestaListIdKeys = []; + foreach($PrestaList as $Presta) + { + $id = $Presta->getId(); + $PrestaListIdKeys[$id] = $Presta; + } + + // fenêtre + $entrees = []; + foreach($PrestaListIdKeys as $Presta) + { + $id = $Presta->getId(); + $entrees[$id][] = $id; + $Date = new Dates((int)$Presta->getDate()); // envoi du timestamp, (int) est là par sécurité + $entrees[$id][] = $Date->getDate(); + $entrees[$id][] = $Presta->getTypePresta(); + $entrees[$id][] = $Presta->getCodePresta(); + } + + // pas à la bonne place, couper la fonction en deux et mettre ça ailleurs! + $ResultatsRecherchePresta = new ZenityList(ZenitySetup::$resultats_recherche_presta['text'], []); + $ResultatsRecherchePresta->setListRows($entrees, 4); + + // choix de l'utilisateur + $input = exec($ResultatsRecherchePresta->get()); // $input est l'ID de la prestation + //echo "input = " . $input . "\n"; + if($input == '') + { + echo "debug: recherche annulée ou saisie vide\n"; + return 0; + } + else + { + return $PrestaListIdKeys[$input]; + } + } + + // à mettre plus tard dans une classe mère + private function cleanSpecialChars(string $data): string + { + $search = ['"']; + return str_replace($search, '', $data); + } +} -- cgit v1.2.3