]> Raphaƫl G. Git Repositories - airbundle/blobdiff - Command/Calendar2Command.php
Pass google client and default markdown to constructor
[airbundle] / Command / Calendar2Command.php
index 0ddcd3ff3213a5d4c1a42e4a05df29c4a62dc9a4..257d2e313d4fe8a30554dbcef41eff6bfe9eac0a 100644 (file)
@@ -33,49 +33,54 @@ use Rapsys\AirBundle\Entity\Session;
 
 use Rapsys\PackBundle\Util\SluggerUtil;
 
 
 use Rapsys\PackBundle\Util\SluggerUtil;
 
+/**
+ * {@inheritdoc}
+ *
+ * Synchronize sessions in users' calendar
+ */
 class Calendar2Command extends Command {
        /**
 class Calendar2Command extends Command {
        /**
-        * Set google client scopes
+        * Set description
+        *
+        * Shown with bin/console list
         */
         */
-       private array $scopes = [
-               Calendar::CALENDAR_EVENTS,
-               Calendar::CALENDAR,
-               Oauth2::USERINFO_EMAIL
-       ];
+       protected string $description = 'Synchronize sessions in users\' calendar';
 
        /**
 
        /**
-        * Set google client instance
+        * Set help
+        *
+        * Shown with bin/console --help rapsysair:calendar2
         */
         */
-       private Client $client;
+       protected string $help = 'This command synchronize sessions in users\' google calendar';
 
        /**
         * Set markdown instance
         */
 
        /**
         * Set markdown instance
         */
-       private DefaultMarkdown $markdown;
+       #private DefaultMarkdown $markdown;
 
        /**
         * Set date period instance
         */
 
        /**
         * Set date period instance
         */
-       private \DatePeriod $period;
+       #private \DatePeriod $period;
 
        /**
         * {@inheritdoc}
 
        /**
         * {@inheritdoc}
-        *
-        * @param string $project The google project
-        * @param string $client The google client
-        * @param string $secret The google secret
         */
         */
-       public function __construct(ManagerRegistry $doctrine, RouterInterface $router, SluggerUtil $slugger, TranslatorInterface $translator, string $locale, string $project, string $client, string $secret) {
+       public function __construct(protected ManagerRegistry $doctrine, protected string $locale, protected RouterInterface $router, protected SluggerUtil $slugger, protected TranslatorInterface $translator, protected Client $google, protected DefaultMarkdown $markdown) {
                //Call parent constructor
                //Call parent constructor
-               parent::__construct($doctrine, $router, $slugger, $translator, $locale);
+               parent::__construct($this->doctrine, $this->locale, $this->router, $this->slugger, $this->translator);
 
 
+               //Replace google client redirect uri
+               $this->google->setRedirectUri($this->router->generate($this->google->getRedirectUri(), [], UrlGeneratorInterface::ABSOLUTE_URL));
+
+               /*
                //Set google client
                $this->client = new Client(
                        [
                //Set google client
                $this->client = new Client(
                        [
-                               'application_name' => $project,
-                               'client_id' => $client,
-                               'client_secret' => $secret,
-                               'redirect_uri' => $this->router->generate('rapsys_air_google_callback', [], UrlGeneratorInterface::ABSOLUTE_URL),
+                               'application_name' => $_ENV['RAPSYSAIR_GOOGLE_PROJECT'],
+                               'client_id' => $_ENV['GOOGLE_CLIENT_ID'],
+                               'client_secret' => $_ENV['GOOGLE_CLIENT_SECRET'],
+                               'redirect_uri' => $this->router->generate('rapsysair_google_callback', [], UrlGeneratorInterface::ABSOLUTE_URL),
                                'scopes' => $this->scopes,
                                'access_type' => 'offline',
                                #'login_hint' => $user->getMail(),
                                'scopes' => $this->scopes,
                                'access_type' => 'offline',
                                #'login_hint' => $user->getMail(),
@@ -86,13 +91,13 @@ class Calendar2Command extends Command {
                );
 
                //Set Markdown instance
                );
 
                //Set Markdown instance
-               $this->markdown = new DefaultMarkdown;
+               $this->markdown = new DefaultMarkdown;*/
        }
 
        /**
         * Configure attribute command
         */
        }
 
        /**
         * Configure attribute command
         */
-       protected function configure() {
+       /*protected function configure() {
                //Configure the class
                $this
                        //Set name
                //Configure the class
                $this
                        //Set name
@@ -101,26 +106,26 @@ class Calendar2Command extends Command {
                        ->setDescription('Synchronize sessions in users\' calendar')
                        //Set description shown with bin/console --help airlibre:attribute
                        ->setHelp('This command synchronize sessions in users\' google calendar');
                        ->setDescription('Synchronize sessions in users\' calendar')
                        //Set description shown with bin/console --help airlibre:attribute
                        ->setHelp('This command synchronize sessions in users\' google calendar');
-       }
+       }*/
 
        /**
         * Process the attribution
         */
        protected function execute(InputInterface $input, OutputInterface $output): int {
 
        /**
         * Process the attribution
         */
        protected function execute(InputInterface $input, OutputInterface $output): int {
+               //Set period
+               $period = new \DatePeriod(
+                       //Start from last week
+                       new \DateTime('-1 week'),
+                       //Iterate on each day
+                       new \DateInterval('P1D'),
+                       //End with next 2 week
+                       new \DateTime('+2 week')
+               );
+
                //Iterate on google tokens
                foreach($tokens = $this->doctrine->getRepository(GoogleToken::class)->findAllIndexed() as $tid => $token) {
                        //Iterate on google calendars
                        foreach($calendars = $token['calendars'] as $cid => $calendar) {
                //Iterate on google tokens
                foreach($tokens = $this->doctrine->getRepository(GoogleToken::class)->findAllIndexed() as $tid => $token) {
                        //Iterate on google calendars
                        foreach($calendars = $token['calendars'] as $cid => $calendar) {
-                               //Set period
-                               $this->period = new \DatePeriod(
-                                       //Start from last week
-                                       new \DateTime('-1 week'),
-                                       //Iterate on each day
-                                       new \DateInterval('P1D'),
-                                       //End with next 2 week
-                                       new \DateTime('+2 week')
-                               );
-
                                #$calendar['synchronized']
                                var_dump($token);
 
                                #$calendar['synchronized']
                                var_dump($token);