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;
$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'));
public function asset_path($path)
{
- return $this->getAssetDir() . ltrim($path,'/');
+ return $this->getAssetDir() . ltrim($path, '/');
}
public function getCompositionUpdate(): int
$new->status = -1;
$new->title = __('Copie de :title', ['title' => $new->title]);
$new->composition = [];
+ $new->visits_counter = 0;
$new->save();
return $new;
}
`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
+ );
+ }
+ }
+ }
+
}