src/Entity/Cvs/AppStoreLink.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Cvs;
  3. use Doctrine\ORM\Mapping as ORM;
  4. /**
  5. * Liens vers les stores (App Store / Google Play) par pays.
  6. *
  7. * Affichage :
  8. * - Version FR du site → 1 seul lien (countryCode=FR, isPrimary=true)
  9. * - Version EN du site → bouton avec dropdown listant tous les pays actifs
  10. * (isPrimary=true en haut, puis les autres triés par position)
  11. *
  12. * Règle : si une ligne n'existe pas en BDD, le pays ne s'affiche pas.
  13. * La table peut être pré-remplie avec ~150 pays (isActive=false par défaut),
  14. * puis on active au fur et à mesure que les apps sont publiées.
  15. *
  16. * @ORM\Table("cvs_app_store_links", indexes={
  17. * @ORM\Index(name="idx_appstore_platform_active", columns={"platform", "is_active"}),
  18. * @ORM\Index(name="idx_appstore_country", columns={"country_code"}),
  19. * @ORM\Index(name="idx_appstore_position", columns={"position"})
  20. * },
  21. * uniqueConstraints={
  22. * @ORM\UniqueConstraint(name="uniq_appstore_platform_country", columns={"platform", "country_code"})
  23. * })
  24. * @ORM\Entity(repositoryClass="App\Repository\Cvs\AppStoreLinkRepository")
  25. * @ORM\HasLifecycleCallbacks()
  26. */
  27. class AppStoreLink
  28. {
  29. public const PLATFORM_IOS = 'ios';
  30. public const PLATFORM_ANDROID = 'android';
  31. /**
  32. * @ORM\Column(name="id", type="integer")
  33. * @ORM\Id
  34. * @ORM\GeneratedValue(strategy="AUTO")
  35. */
  36. protected $id;
  37. /**
  38. * Plateforme : 'ios' ou 'android'.
  39. *
  40. * @ORM\Column(name="platform", type="string", length=16)
  41. */
  42. protected $platform;
  43. /**
  44. * Code pays ISO 3166-1 alpha-2 (US, FR, GB, DE, ES, IT, CA...).
  45. *
  46. * @ORM\Column(name="country_code", type="string", length=2)
  47. */
  48. protected $countryCode;
  49. /**
  50. * Nom du pays affiché (en anglais par défaut, ex: "United States", "France").
  51. *
  52. * @ORM\Column(name="country_label", type="string", length=100)
  53. */
  54. protected $countryLabel;
  55. /**
  56. * Emoji du drapeau (🇺🇸, 🇫🇷, 🇬🇧...).
  57. * Optionnel mais sympa pour l'UI.
  58. *
  59. * @ORM\Column(name="country_flag", type="string", length=16, nullable=true)
  60. */
  61. protected $countryFlag;
  62. /**
  63. * URL vers le store du pays.
  64. * Si null → on n'affiche pas, même si isActive=true.
  65. *
  66. * @ORM\Column(name="url", type="string", length=500, nullable=true)
  67. */
  68. protected $url;
  69. /**
  70. * Si true → le pays est mis en avant (en haut du dropdown, gros bouton sur la version FR).
  71. *
  72. * @ORM\Column(name="is_primary", type="boolean", options={"default":false})
  73. */
  74. protected $isPrimary = false;
  75. /**
  76. * Si true → on affiche ce lien.
  77. * Permet d'avoir tous les pays en BDD mais d'activer au fur et à mesure.
  78. *
  79. * @ORM\Column(name="is_active", type="boolean", options={"default":false})
  80. */
  81. protected $isActive = false;
  82. /**
  83. * Ordre d'affichage dans le dropdown (croissant).
  84. *
  85. * @ORM\Column(name="position", type="integer", options={"default":100})
  86. */
  87. protected $position = 100;
  88. /**
  89. * @ORM\Column(name="created_at", type="datetime", nullable=true)
  90. */
  91. protected $createdAt;
  92. /**
  93. * @ORM\Column(name="updated_at", type="datetime", nullable=true)
  94. */
  95. protected $updatedAt;
  96. /**
  97. * @ORM\PrePersist
  98. */
  99. public function onPrePersist(): void
  100. {
  101. $now = new \DateTime();
  102. if (!$this->createdAt) {
  103. $this->createdAt = $now;
  104. }
  105. $this->updatedAt = $now;
  106. }
  107. /**
  108. * @ORM\PreUpdate
  109. */
  110. public function onPreUpdate(): void
  111. {
  112. $this->updatedAt = new \DateTime();
  113. }
  114. public function getId(): ?int { return $this->id; }
  115. public function getPlatform(): ?string { return $this->platform; }
  116. public function setPlatform(string $platform): self { $this->platform = $platform; return $this; }
  117. public function getCountryCode(): ?string { return $this->countryCode; }
  118. public function setCountryCode(string $code): self { $this->countryCode = strtoupper($code); return $this; }
  119. public function getCountryLabel(): ?string { return $this->countryLabel; }
  120. public function setCountryLabel(string $label): self { $this->countryLabel = $label; return $this; }
  121. public function getCountryFlag(): ?string { return $this->countryFlag; }
  122. public function setCountryFlag(?string $flag): self { $this->countryFlag = $flag; return $this; }
  123. public function getUrl(): ?string { return $this->url; }
  124. public function setUrl(?string $url): self { $this->url = $url; return $this; }
  125. public function getIsPrimary(): bool { return (bool) $this->isPrimary; }
  126. public function setIsPrimary(bool $v): self { $this->isPrimary = $v; return $this; }
  127. public function getIsActive(): bool { return (bool) $this->isActive; }
  128. public function setIsActive(bool $v): self { $this->isActive = $v; return $this; }
  129. public function getPosition(): int { return $this->position ?? 100; }
  130. public function setPosition(int $p): self { $this->position = $p; return $this; }
  131. public function getCreatedAt(): ?\DateTime { return $this->createdAt; }
  132. public function setCreatedAt(?\DateTime $d): self { $this->createdAt = $d; return $this; }
  133. public function getUpdatedAt(): ?\DateTime { return $this->updatedAt; }
  134. public function setUpdatedAt(?\DateTime $d): self { $this->updatedAt = $d; return $this; }
  135. /**
  136. * Helper : un lien est affichable si il est actif ET a une URL.
  137. */
  138. public function isDisplayable(): bool
  139. {
  140. return $this->getIsActive() && !empty($this->getUrl());
  141. }
  142. }