src/Twig/CvsExtension.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Twig;
  3. use App\Services\Core\Core;
  4. use App\Services\Core\Tools;
  5. use App\Services\Core\Users;
  6. use App\Services\Cvs;
  7. use App\Services\Cvs\AppStoreLinksService;
  8. use App\Tools\Core\StatusSearchTool;
  9. use App\Tools\Cvs\AvailabilityTool;
  10. use Twig\Extension\AbstractExtension;
  11. use Twig\TwigFilter;
  12. use Twig\TwigFunction;
  13. class CvsExtension extends AbstractExtension
  14. {
  15.     private $core;
  16.     private $tool;
  17.     private $users;
  18.     private $cvs;
  19.     private $appStoreLinks;
  20.     public function __construct(Core $coreService,
  21.                                 Tools $toolService,
  22.                                 Users $usersService,
  23.                                 Cvs $cvsService,
  24.                                 AppStoreLinksService $appStoreLinksService
  25.     ){
  26.         $this->core $coreService;
  27.         $this->tool $toolService;
  28.         $this->users $usersService;
  29.         $this->cvs $cvsService;
  30.         $this->appStoreLinks $appStoreLinksService;
  31.     }
  32.     public function getFunctions(): array
  33.     {
  34.         return [
  35.             new TwigFunction('getCvsCandidateUser', [$this'getCvsCandidateUser']),
  36.             new TwigFunction('getCvsAvailabilityTool', [$this'getCvsAvailabilityTool']),
  37.             new TwigFunction('getCvsStatusSearchTool', [$this'getCvsStatusSearchTool']),
  38.             new TwigFunction('getCvsCompanyUser', [$this'getCvsCompanyUser']),
  39.             new TwigFunction('getCvsMobilesUser', [$this'getCvsMobilesUser']),
  40.             // Nouvelles fonctions liens stores
  41.             new TwigFunction('getAppStoreCountries', [$this'getAppStoreCountries']),
  42.             new TwigFunction('getAppStorePrimaryCountry', [$this'getAppStorePrimaryCountry']),
  43.         ];
  44.     }
  45.     public function getFilters()
  46.     {
  47.         return [];
  48.     }
  49.     public function getCvsMobilesUser($userID)
  50.     {
  51.         return $this->cvs->getCvsMobilesUser($userID);
  52.     }
  53.     public function getCvsCompanyUser($userID)
  54.     {
  55.         return $this->cvs->getCvsCompanyUser($userID);
  56.     }
  57.     public function getCvsCandidateUser($candidateID)
  58.     {
  59.         return $this->cvs->getCvsCandidateUser($candidateID);
  60.     }
  61.     public function getCvsAvailabilityTool($chain)
  62.     {
  63.         return AvailabilityTool::getStatus($chain);
  64.     }
  65.     public function getCvsStatusSearchTool($chain)
  66.     {
  67.         return StatusSearchTool::getStatus($chain);
  68.     }
  69.     /**
  70.      * Retourne tous les pays App Store / Play Store affichables.
  71.      * Format : ['primary' => [...], 'others' => [...]]
  72.      */
  73.     public function getAppStoreCountries(): array
  74.     {
  75.         return $this->appStoreLinks->getAppStoreCountries();
  76.     }
  77.     /**
  78.      * Retourne le pays "primary" pour un countryCode donné.
  79.      * Utilisé sur la version FR pour afficher un seul lien direct.
  80.      */
  81.     public function getAppStorePrimaryCountry(string $preferredCountryCode 'US'): ?array
  82.     {
  83.         return $this->appStoreLinks->getPrimaryCountry($preferredCountryCode);
  84.     }
  85. }