PSMList 0.4.0 PSM-040-044
| Ordre affichage : | 42 | Création : | 26/06/2023 13h08 |
| Index BL : | 44 | Modification : | 26/06/2023 21h28 |
| BL : | PSM-040-044 | ||
| Source : | Aucune | Soeurs : | - |
| Fin dev : | D (Done) | Ticket : | - |
| Contrôle dev effectué : | Fiche : | - | |
| C.Qualif. : | #000000 | ||
| Activé : | Icône FA : | Par défaut | |
| Contact : | ARS - Arshellan | Qualification : | Nouveauté |
| Répartition : | - | Module : | Data |
| Dev : | ARS - Arshellan | Sous module : | - |
| Provenance : | 0.4.0 New | Constat : | - |
| Début : | S.26 | Charge j. : | - |
| Fin : | S.26 | Délai j. : | - |
| Priorité : | - | Pokercard : | - |
| Estimatif j. : | - | ||
| Description : | Create a parameter table to store various things, start with the values from the discord psm server and an expiration date. | ||
| Texte Commit : | - | ||
| Description client : | Create a parameter table to store various things, start with the values from the discord psm server and an expiration date. | ||
| Fascicule : | Ne pas communiquer : | ||
| Alerte Mailing : |
| Statut PreP : | OK - Validé | Testeur : | ARS - Arshellan |
in CacheValuesgeneric entity<br/><br/><br/><?php<br/><br/>namespace App\Entity;<br/><br/>use App\Repository\CacheValuesGenericRepository;<br/>use DateTime;<br/>use Doctrine\ORM\Mapping as ORM;<br/><br/>/**<br/> * @ORM\Entity(repositoryClass=CacheValuesGenericRepository::class)<br/> */<br/>class CacheValuesGeneric<br/>{<br/> /**<br/> * @ORM\Id<br/> * @ORM\GeneratedValue<br/> * @ORM\Column(type="integer")<br/> */<br/> private $id;<br/> <br/> /**<br/> * @ORM\Column(type="string", length=127, nullable=true)<br/> */<br/> private $discordservername;<br/><br/> /**<br/> * @ORM\Column(type="string", length=254, nullable=true)<br/> */<br/> private $discordservericon;<br/><br/> /**<br/> * @ORM\Column(type="integer", nullable=true)<br/> */<br/> private $discordmembercount;<br/><br/> /**<br/> * @ORM\Column(type="datetime", nullable=true)<br/> */<br/> private $discordcacheexpiration;<br/><br/><br/><br/> <br/> <br/> <br/> <br/> <br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> public function getId(): ?int {<br/> return $this->id;<br/> }<br/> <br/> <br/> public function getDiscordservername(): ?string {<br/> return $this->discordservername;<br/> }<br/> public function setDiscordservername(?string $discordservername): self {<br/> $this->discordservername = $discordservername;<br/> return $this;<br/> }<br/> <br/> <br/> public function getDiscordservericon(): ?string {<br/> return $this->discordservericon;<br/> }<br/> public function setDiscordservericon(?string $discordservericon): self {<br/> $this->discordservericon = $discordservericon;<br/> return $this;<br/> }<br/> <br/> <br/> public function getDiscordmembercount(): ?int {<br/> return $this->discordmembercount;<br/> }<br/> public function setDiscordmembercount(?int $discordmembercount): self {<br/> $this->discordmembercount = $discordmembercount;<br/> return $this;<br/> }<br/> <br/> <br/> public function getDiscordcacheexpiration(): ?DateTime {<br/> return $this->discordcacheexpiration;<br/> }<br/> public function setDiscordcacheexpiration(?DateTime $discordcacheexpiration): self {<br/> $this->discordcacheexpiration = $discordcacheexpiration;<br/> return $this;<br/> }<br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/>}
the reworked route in MainController<br/><br/><br/> <br/> <br/> /**<br/> * @Route("/", name="home")<br/> */<br/> public function home(EntityManagerInterface $em): Response<br/> {<br/> $cacheGenRepo = $this->doctrine->getRepository(CacheValuesGeneric::class);<br/> $cacheValues = $cacheGenRepo->findOneBy(array());<br/><br/> // if the cache isn't expired yet<br/> if ($cacheValues->getDiscordcacheexpiration() > new DateTime() || $cacheValues->getDiscordservername() != 'Unknown') {<br/> $discordServerName = $cacheValues->getDiscordservername();<br/> $discordServerIcon = $cacheValues->getDiscordservericon();<br/> $discordUserCount = $cacheValues->getDiscordmembercount();<br/><br/> } else { // the cache is expired<br/> // Discord server ID and bot token<br/> $serverId = "468973063325876234";<br/> $botToken = "ODE2NzQxMjAyNjAxNzA1NTEy.GEvWCR.lPJtGvX4ATvy9ijV5T4P9ebx_4TTVGJJtWqyQ0";<br/><br/> // Discord API endpoint to fetch server information<br/> $url = "https://discord.com/api/v10/guilds/" . $serverId . "?with_counts=true";<br/><br/> // Create an HTTP client instance<br/> $client = HttpClient::create();<br/><br/> // Set the headers for the API request<br/> $headers = [<br/> 'Authorization' => 'Bot ' . $botToken,<br/> 'Content-Type' => 'application/json',<br/> ];<br/><br/> // Make the API request<br/> $response = $client->request('GET', $url, [<br/> 'headers' => $headers,<br/> ]);<br/><br/> // Process the response<br/> if ($response->getStatusCode() === 200) {<br/> $data = $response->toArray();<br/><br/> // Extract the desired information<br/> $discordServerName = $data['name'];<br/> $discordServerIcon = $data['icon'];<br/> $discordUserCount = $data['approximate_member_count'];<br/> } else {<br/> $discordServerName = 'Unknown';<br/> $discordServerIcon = '';<br/> $discordUserCount = '?';<br/> }<br/><br/> // Put the updated values in the cache<br/> $cacheValues->setDiscordcacheexpiration((new DateTime())->modify('+3 days'));<br/> $cacheValues->setDiscordservername($discordServerName);<br/> $cacheValues->setDiscordservericon($discordServerIcon);<br/> $cacheValues->setDiscordmembercount($discordUserCount);<br/> $em->persist($cacheValues);<br/> $em->flush();<br/> }<br/> <br/><br/> return $this->render('default/home.html.twig', [<br/> 'discordServerName' => $discordServerName,<br/> 'discordServerIcon' => $discordServerIcon,<br/> 'discordUserCount' => $discordUserCount,<br/> ]);<br/> }