$web_coupons Array of web coupons * @property array $notification_emails Array of email to notify when there's a winnner * @property boolean $winning_proof Is the winning proof needed * @property-read \Illuminate\Support\Carbon $created_at Creation Date. * @property-read \Illuminate\Support\Carbon $updated_at Last update Date. * * @property-read boolean $game_is_open Le jeu est ouvert ? * @property-read boolean $game_has_begun Le jeu à démarré ? * @property-read boolean $game_has_ended Le jeu est terminé ? * @property-read boolean $should_display_teaser_page Doit afficher la page de teaser ? * @property-read boolean $should_display_end_page Doit afficher la page fin de jeu ? */ class Settings extends Model { use IsCachedAsCollection; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'name', 'company', 'start_date', 'end_date', 'nb_participation_player', 'nb_participation_ip', 'nb_unique_code_use', 'use_ean_codes', 'activated_teaser', 'activated_close_page', 'close_page_active_date', 'redirect_close', 'discounts_activated', 'discounts_site', 'discounts_campaign', 'web_coupons', 'notification_emails', 'winning_proof', 'analytics', ]; /** * The attributes that should be cast to native types. * * @var array */ protected $casts = [ 'use_ean_codes' => 'bool', 'activated_teaser' => 'bool', 'activated_close_page' => 'bool', 'discounts_activated' => 'bool', 'winning_proof' => 'bool', 'start_date' => 'datetime', 'end_date' => 'datetime', 'close_page_active_date' => 'datetime', 'web_coupons' => AsArrayOfDiscount::class, 'notification_emails' => 'array', ]; /** * Perform any actions required after the model boots. * * @return void */ protected static function booted() { static::created(function () { self::removeCached(); }); static::updated(function (self $model) { self::removeCached(); FileStorageHelper::removeOldFiles( $model->fetchCouponsPictures(true), $model->fetchCouponsPictures() ); }); static::deleted(function () { self::removeCached(); }); } // * METHODS /** * Fetch all widget Files * * @param boolean $useOldAttribute * @return array */ public function fetchCouponsPictures(bool $useOldAttribute = false): array { $files = []; \collect(!$useOldAttribute ? $this->web_coupons : $this->getOriginal('web_coupons')) ->each(function (Discount $coupon) use (&$files) { $files = \array_merge($files, [$coupon->picture]); }); return FileStorageHelper::onlyUploadedFilesWithFileStorageHelper(collect($files)->filter()->all()); } // * GETTERS /** * Get game_has_begun attribute * * The game has started ? * * @return boolean */ public function getGameHasBegunAttribute(): bool { return $this->start_date->lte(now()); } /** * Get game_has_ended attribute * * The game has ended ? * * @return boolean */ public function getGameHasEndedAttribute(): bool { return $this->game_has_begun and $this->end_date->lte(now()); } /** * Get game_is_open attribute * * The game is oppen ? * * @return boolean */ public function getGameIsOpenAttribute(): bool { return $this->game_has_begun and !$this->game_has_ended; } /** * Get should_display_teaser_page attribute * * The teaser page has to be displayed ? * * @return boolean */ public function getShouldDisplayTeaserPageAttribute(): bool { return !$this->game_has_begun and !$this->game_has_ended and $this->activated_teaser; } /** * Get should_display_end_page attribute * * The end page has to be displayed ? * * @return boolean */ public function getShouldDisplayEndPageAttribute(): bool { return $this->game_has_begun and $this->game_has_ended and $this->activated_close_page and $this->close_page_active_date->gte(now()); } }