]> git.immae.eu Git - perso/Immae/Config/Nix.git/commitdiff
To merge in nicecoop-installation
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Fri, 18 Nov 2022 23:55:04 +0000 (00:55 +0100)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Sun, 9 Apr 2023 15:16:31 +0000 (17:16 +0200)
modules/private/websites/nicecoop/gestion-compte.nix
modules/private/websites/nicecoop/gestion-compte/AmbassadorShiftTimeLogCommand.php [new file with mode: 0644]
modules/private/websites/nicecoop/gestion-compte/default.nix
modules/private/websites/nicecoop/gestion-compte/php-packages.nix
modules/private/websites/nicecoop/gestion-compte/shift_late_alerts_default.html.twig [new file with mode: 0644]

index a82fde2e22eb8b629511d6376b1967f494ae0b88..9ab54c4c9d66dfd8f49509d7daddf282f07b7693 100644 (file)
@@ -78,23 +78,26 @@ in {
         prefix = "${config.services.httpd.Prod.user} cd ${app} && ./bin/console --env=prod";
       in [
         ''
-          # generate shifts in 27 days (same weekday as yesterday)
-          55 5 * * * ${prefix} app:shift:generate $(date -d "+27 days" +\%Y-\%m-\%d)
+          # generate shifts in 80 to 90 days
+          55 5 * * * ${prefix} app:shift:generate --quiet $(date -d "+80 days" +\%Y-\%m-\%d) --to $(date -d "+90 days" +\%Y-\%m-\%d)
 
           # free pre-booked shifts
-          55 5 * * * ${prefix} app:shift:free $(date -d "+21 days" +\%Y-\%m-\%d)
+          55 5 * * * ${prefix} app:shift:free --quiet $(date -d "+21 days" +\%Y-\%m-\%d)
 
           # send reminder 2 days before shift
-          #0 6 * * * ${prefix} app:shift:reminder $(date -d "+2 days" +\%Y-\%m-\%d)
+          #0 6 * * * ${prefix} app:shift:reminder --quiet $(date -d "+2 days" +\%Y-\%m-\%d)
 
           # execute routine for cycle_end/cycle_start, everyday
-          5 6 * * * ${prefix} app:user:cycle_start
+          5 6 * * * ${prefix} app:user:cycle_start --quiet
+
+          # Reports the list of late shifters to RH
+          0 0 1 * * ${prefix} app:shift:send_late_shifters --quiet --emails=cebayle@gmail.com
 
           # send alert on shifts booking (low)
-          #0 10 * * * ${prefix} app:shift:send_alerts --emails creneaux@nicecoop.fr $(date -d "+2 days" +\%Y-\%m-\%d) 1
+          #0 10 * * * ${prefix} app:shift:send_alerts --quiet --emails creneaux@nicecoop.fr $(date -d "+2 days" +\%Y-\%m-\%d) 1
 
           # send a reminder mail to the user who generate the last code but did not validate the change.
-          #45 21 * * * ${prefix} app:code:verify_change --last_run 24
+          #45 21 * * * ${prefix} app:code:verify_change --quiet --last_run 24
         ''
       ];
     };
diff --git a/modules/private/websites/nicecoop/gestion-compte/AmbassadorShiftTimeLogCommand.php b/modules/private/websites/nicecoop/gestion-compte/AmbassadorShiftTimeLogCommand.php
new file mode 100644 (file)
index 0000000..e91a0a3
--- /dev/null
@@ -0,0 +1,92 @@
+<?php
+// src/AppBundle/Command/AmbassadorShiftTimeLogCommand.php
+namespace AppBundle\Command;
+
+use Swift_Message;
+use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+use Doctrine\ORM\Query\Expr\Join;
+
+class AmbassadorShiftTimeLogCommand extends ContainerAwareCommand
+{
+    protected function configure()
+    {
+        $this
+          ->setName('app:shift:send_late_shifters')
+          ->setDescription('Send shifters which are too late')
+          ->setHelp('This command allows you to send alerts for shifters that are too late')
+            ->addOption('emails', null, InputOption::VALUE_OPTIONAL, 'Email recipients (comma separated)')
+            ->addOption('emailTemplate', null, InputOption::VALUE_OPTIONAL, 'Template used in email alerts', 'SHIFT_LATE_ALERT_EMAIL');
+    }
+
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        $email_template = $input->getOption('emailTemplate');
+
+        $alerts = $this->computeAlerts();
+        $nbAlerts = count($alerts);
+        if ($nbAlerts > 0) {
+            $output->writeln('<fg=cyan;>Found ' . $nbAlerts . ' alerts to send</>');
+            $this->sendAlertsByEmail($input, $output, $alerts, $email_template);
+        } else {
+            $output->writeln('<fg=cyan;>No shift alert to send</>');
+        }
+    }
+
+    private function computeAlerts() {
+        $time_after_which_members_are_late_with_shifts = $this->getContainer()->getParameter('time_after_which_members_are_late_with_shifts');
+
+        $em = $this->getContainer()->get('doctrine')->getManager();
+        $qb = $em->getRepository("AppBundle:Membership")->createQueryBuilder('o');
+        $qb = $qb->leftJoin("o.beneficiaries", "b")
+            ->leftJoin("b.user", "u")
+            ->leftJoin("o.registrations", "r")->addSelect("r");
+        $qb = $qb->andWhere('o.member_number > 0'); //do not include admin user
+        $qb = $qb->leftJoin("o.registrations", "lr", Join::WITH,'lr.date > r.date')->addSelect("lr")
+            ->where('lr.id IS NULL') //registration is the last one registere
+            ->leftJoin("o.timeLogs", "c")->addSelect("c")
+            ->addSelect("(SELECT SUM(ti.time) FROM AppBundle\Entity\TimeLog ti WHERE ti.membership = o.id) AS HIDDEN time");
+        $qb = $qb->andWhere('o.withdrawn = 0');
+        $qb = $qb->andWhere('o.frozen = 0');
+        $qb = $qb->andWhere('b.membership IN (SELECT IDENTITY(t.membership) FROM AppBundle\Entity\TimeLog t GROUP BY t.membership HAVING SUM(t.time) < :compteurlt * 60)')
+            ->setParameter('compteurlt', $time_after_which_members_are_late_with_shifts);
+        $alerts = $qb->getQuery()->getResult();
+        return $alerts;
+    }
+
+    private function sendAlertsByEmail(InputInterface $input, OutputInterface $output, $alerts, $template) {
+        $mailer = $this->getContainer()->get('mailer');
+        $recipients = $input->getOption('emails') ? explode(',', $input->getOption('emails')) : null;
+        if ($recipients) {
+            setlocale(LC_TIME, 'fr_FR.UTF8');
+            $subject = '[ALERTE RETARDS] Membres en retard de shifts';
+
+            $shiftEmail = $this->getContainer()->getParameter('emails.shift');
+
+            $em = $this->getContainer()->get('doctrine')->getManager();
+            $dynamicContent = null;
+            //$dynamicContent = $em->getRepository('AppBundle:DynamicContent')->findOneByCode($template);
+            $template = null;
+            if ($dynamicContent) {
+                $template = $this->getContainer()->get('twig')->createTemplate($dynamicContent->getContent());
+            } else {
+                $template = 'emails/shift_late_alerts_default.html.twig';
+            }
+
+            $email = (new Swift_Message($subject))
+                ->setFrom($shiftEmail['address'], $shiftEmail['from_name'])
+                ->setTo($recipients)
+                ->setBody(
+                    $this->getContainer()->get('twig')->render(
+                        $template,
+                        array('alerts' => $alerts)
+                    ),
+                    'text/html'
+                );
+            $mailer->send($email);
+            $output->writeln('<fg=cyan;>Email(s) sent</>');
+        }
+    }
+}
index 090f1351333a1d52e265383470eefbaa49da6117..9250f9b6c6722f3d131efd4ee282012a95a05605 100644 (file)
@@ -6,14 +6,14 @@ let
   app = composerEnv'.buildPackage (
     import ./php-packages.nix { composerEnv = composerEnv'; inherit fetchurl fetchgit; } //
     rec {
-      version = "1.32.3";
+      version = "1.41.2";
       pname = "gestion-compte";
       name = "${pname}-${version}";
       src = fetchFromGitHub {
         owner = "elefan-grenoble";
         repo = "gestion-compte";
         rev = "v${version}";
-        sha256 = "16pwp4pqdf85ziryzvcj9ryk9jlz56ja07p8kj7pldghnk9pmkwm";
+        sha256 = "0w2j515vacmyic4isbflxzsh5406md1nl053ag5412jnlha9nlcy";
       };
       noDev = true;
       preInstall = ''
@@ -21,6 +21,8 @@ let
         sed -i -e "/database_password: /a\    database_version: 5.5" app/config/parameters.yml.dist
         export APP_ENV="prod"
         export SYMFONY_ENV="prod"
+        cp ${./AmbassadorShiftTimeLogCommand.php} src/AppBundle/Command/AmbassadorShiftTimeLogCommand.php
+        cp ${./shift_late_alerts_default.html.twig} app/Resources/views/emails/shift_late_alerts_default.html.twig
       '';
       postInstall = ''
         cd $out
index dce22d3bf8b47ada177f48ea061b87e7b4970c36..7a1bb2ca1c07c021b6f6a080e1177c9b48d08c90 100644 (file)
         };
       };
     };
+    "beberlei/doctrineextensions" = {
+      targetDir = "";
+      src = composerEnv.buildZipPackage {
+        name = "beberlei-doctrineextensions-008f162f191584a6c37c03a803f718802ba9dd9a";
+        src = fetchurl {
+          url = "https://api.github.com/repos/beberlei/DoctrineExtensions/zipball/008f162f191584a6c37c03a803f718802ba9dd9a";
+          sha256 = "1z56h15z3k1bhrnghys24pwd5ra5b5cngyfnkk342cyzpn5a7qpk";
+        };
+      };
+    };
     "behat/transliterator" = {
       targetDir = "";
       src = composerEnv.buildZipPackage {
diff --git a/modules/private/websites/nicecoop/gestion-compte/shift_late_alerts_default.html.twig b/modules/private/websites/nicecoop/gestion-compte/shift_late_alerts_default.html.twig
new file mode 100644 (file)
index 0000000..3fdc112
--- /dev/null
@@ -0,0 +1,5 @@
+{% for alert in alerts %}
+<strong>Compteur de
+  {% for user in alert.beneficiaries %}{{ user.firstname }} {{ user.lastname }}{% endfor %} :
+  {{ alert.timeCount | duration_from_minutes }}</strong><br>
+{% endfor %}