]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5732 @0.75
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 14 Feb 2023 18:34:30 +0000 (19:34 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 14 Feb 2023 18:34:30 +0000 (19:34 +0100)
app/Http/Controllers/Admin/Operations/FluidbookPublication/PreviewOperation.php
app/Models/FluidbookPublication.php
app/Slack/Slack.php

index dd1af655fa69e1d265478e99dd083a4c927ab851..e94fb9007c8f6b2e8c80af24c7e364e303ba21e1 100644 (file)
@@ -180,6 +180,7 @@ html,body{height:100%;cursor: wait;font-family: "Open Sans", Arial;background-co
 
         $dest = $fluidbook->getFinalPath($theme, $isScorm);
         if ($path === 'index.html') {
+            $fluidbook->incrementPreviewVisit();
             $compiler = new FluidbookCompiler($fluidbook, $isScorm, theme: $theme);
             $compiler->handle();
         }
index 2a5b5e36828f3c9436513f323c3e067a5868bf2a..cedb02cb7c08f152c35b376e06ef4327c6e0b957 100644 (file)
@@ -19,6 +19,7 @@ use App\Jobs\FluidbookImagesPreprocess;
 use App\Models\Base\ToolboxSettingsModel;
 use App\Models\Traits\PublicationSettings;
 use App\Models\Traits\SCORMVersionTrait;
+use App\Slack\Slack;
 use Backpack\CRUD\app\Http\Controllers\Operations\CloneOperation;
 use Backpack\CRUD\app\Library\Widget;
 use Cubist\Backpack\Magic\Fields\FormBigSection;
@@ -119,7 +120,7 @@ class FluidbookPublication extends ToolboxSettingsModel
 
         $this->addField('hash', Hidden::class);
         $this->addField('cid', Hidden::class);
-        $this->addField('visits_counter', Integer::class, 'Compteur de visites', ['read_only' => true]);
+        $this->addField('visits_counter', Integer::class, 'Compteur de visites', ['read_only' => true, 'default' => 0]);
 
         $this->addField('extranet_task', Hidden::class, __('Tâche de l\'extranet'));
         $this->addField('export_data', Hidden::class, __('Paramètres d\'export'));
@@ -357,7 +358,7 @@ class FluidbookPublication extends ToolboxSettingsModel
 
     public function asset_path($path)
     {
-        return $this->getAssetDir() . ltrim($path,'/');
+        return $this->getAssetDir() . ltrim($path, '/');
     }
 
     public function getCompositionUpdate(): int
@@ -458,6 +459,7 @@ class FluidbookPublication extends ToolboxSettingsModel
         $new->status = -1;
         $new->title = __('Copie de :title', ['title' => $new->title]);
         $new->composition = [];
+        $new->visits_counter = 0;
         $new->save();
         return $new;
     }
@@ -472,5 +474,29 @@ class FluidbookPublication extends ToolboxSettingsModel
         `cp -r $from $to`;
     }
 
+    public function incrementPreviewVisit()
+    {
+        if (!backpack_user()) {
+            $this->visits_counter++;
+            $this->saveQuietly();
+            if ($this->visits_counter % 20 === 0) {
+                /** @var \App\Models\User $owner */
+                $owner = \App\Models\User::withoutGlobalScopes()->find($this->owner);
+
+                $actions = [];
+                if ($this->stats) {
+                    $actions['Voir les stats'] = backpack_url('/fluidbook-publication/stats/' . $this->id . '_' . $this->hash . '/');
+                }
+
+                Slack::send(Slack::fluidbookPreviewAlertsChannel,
+                    'Fluidbook #' . $this->id . ' : ' . $this->visits_counter . ' visites',
+                    'Le lien de preview de _' . $this->title . '_ a été utilisé à *' . $this->visits_counter . '* reprises par des visiteurs non authentifiés sur la toolbox. Le fluidbook se trouve sur le compte de ' . $owner->getNameWithCompanyAttribute() . '.',
+                    $actions,
+                    false
+                );
+            }
+        }
+    }
+
 
 }
index 7af07bb6b917cfdc49d189b6631ae2929b904e47..8e02bbd7b038d4d38522a01abf70b2128cf9c226 100644 (file)
@@ -8,6 +8,7 @@ use JoliCode\Slack\ClientFactory;
 class Slack
 {
     const fluidbookQuoteChannel = 'C045CH0UB47';
+    const fluidbookPreviewAlertsChannel = 'C04Q9LZNPT2';
 
     /**
      * @var \JoliCode\Slack\Client|null