From: Louis Jeckel Date: Mon, 14 Sep 2020 13:52:21 +0000 (+0200) Subject: labo article + adcampaigns subscriber only X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=2b327b3a3291dc6a94eaf627bec70dac3cf82762;p=psq.git labo article + adcampaigns subscriber only --- diff --git a/app/Models/AdCampaign.php b/app/Models/AdCampaign.php index eb8110c..49054d1 100644 --- a/app/Models/AdCampaign.php +++ b/app/Models/AdCampaign.php @@ -17,7 +17,7 @@ use Laravel\Scout\Searchable; */ class AdCampaign extends Model implements Sortable, PillBoxContract { - use HasSlug, HasMedias, HasPosition; + use HasSlug, HasMedias, HasPosition, HasSubscriberOnlyContent; use Searchable; protected $fillable = [ @@ -32,6 +32,7 @@ class AdCampaign extends Model implements Sortable, PillBoxContract 'box_title', 'box_content', 'box_link', + 'subscriber_only' ]; public $appends = [ diff --git a/app/Models/HasSubscriberOnlyContent.php b/app/Models/HasSubscriberOnlyContent.php index bb8e135..4e7c9d0 100644 --- a/app/Models/HasSubscriberOnlyContent.php +++ b/app/Models/HasSubscriberOnlyContent.php @@ -15,26 +15,16 @@ use HtmlTruncator\Truncator; trait HasSubscriberOnlyContent { + protected int $maxContentWords = 100; + /** * @return string * @throws InvalidHtmlException */ public function getTruncatedContent(): string { - return Truncator::truncate($this->content, 100); + return Truncator::truncate($this->content, $this->maxContentWords); } - /** - * @param User|null $user - * @return bool - */ - public function isVisibleByUser(User $user = null) - { - $user ??= \Auth::user(); - - return !$this->subscriber_only || - ($user !== null && $user->hasValidSubscription()); - - } } diff --git a/app/Models/LaboArticle.php b/app/Models/LaboArticle.php index 3b1c15c..fcb674a 100644 --- a/app/Models/LaboArticle.php +++ b/app/Models/LaboArticle.php @@ -18,7 +18,7 @@ use Laravel\Scout\Searchable; */ class LaboArticle extends Model implements Sortable, PillBoxContract { - use HasSlug, HasMedias, HasPosition; + use HasSlug, HasMedias, HasPosition, HasSubscriberOnlyContent; protected $fillable = [ 'publish_start_date', @@ -31,6 +31,7 @@ class LaboArticle extends Model implements Sortable, PillBoxContract 'box_title', 'box_content', 'box_link', + 'subscriber_only' ]; public $slugAttributes = [ diff --git a/app/Policies/AdCampaignPolicy.php b/app/Policies/AdCampaignPolicy.php new file mode 100644 index 0000000..75c5e52 --- /dev/null +++ b/app/Policies/AdCampaignPolicy.php @@ -0,0 +1,95 @@ +subscriber_only || + optional($user)->hasValidSubscription(); + } + + /** + * Determine whether the user can create models. + * + * @param \App\User $user + * @return mixed + */ + public function create(User $user) + { + // + } + + /** + * Determine whether the user can update the model. + * + * @param \App\User $user + * @param \App\Models\AdCampaign $adCampaign + * @return mixed + */ + public function update(User $user, AdCampaign $adCampaign) + { + // + } + + /** + * Determine whether the user can delete the model. + * + * @param \App\User $user + * @param \App\Models\AdCampaign $adCampaign + * @return mixed + */ + public function delete(User $user, AdCampaign $adCampaign) + { + // + } + + /** + * Determine whether the user can restore the model. + * + * @param \App\User $user + * @param \App\Models\AdCampaign $adCampaign + * @return mixed + */ + public function restore(User $user, AdCampaign $adCampaign) + { + // + } + + /** + * Determine whether the user can permanently delete the model. + * + * @param \App\User $user + * @param \App\Models\AdCampaign $adCampaign + * @return mixed + */ + public function forceDelete(User $user, AdCampaign $adCampaign) + { + // + } +} diff --git a/app/Policies/LaboArticlePolicy.php b/app/Policies/LaboArticlePolicy.php new file mode 100644 index 0000000..06d488d --- /dev/null +++ b/app/Policies/LaboArticlePolicy.php @@ -0,0 +1,95 @@ +subscriber_only || + optional($user)->hasValidSubscription(); + } + + /** + * Determine whether the user can create models. + * + * @param \App\User $user + * @return mixed + */ + public function create(User $user) + { + // + } + + /** + * Determine whether the user can update the model. + * + * @param \App\User $user + * @param \App\Models\LaboArticle $laboArticle + * @return mixed + */ + public function update(User $user, LaboArticle $laboArticle) + { + // + } + + /** + * Determine whether the user can delete the model. + * + * @param \App\User $user + * @param \App\Models\LaboArticle $laboArticle + * @return mixed + */ + public function delete(User $user, LaboArticle $laboArticle) + { + // + } + + /** + * Determine whether the user can restore the model. + * + * @param \App\User $user + * @param \App\Models\LaboArticle $laboArticle + * @return mixed + */ + public function restore(User $user, LaboArticle $laboArticle) + { + // + } + + /** + * Determine whether the user can permanently delete the model. + * + * @param \App\User $user + * @param \App\Models\LaboArticle $laboArticle + * @return mixed + */ + public function forceDelete(User $user, LaboArticle $laboArticle) + { + // + } +} diff --git a/app/Policies/SocialArticlePolicy.php b/app/Policies/SocialArticlePolicy.php new file mode 100644 index 0000000..d787ba4 --- /dev/null +++ b/app/Policies/SocialArticlePolicy.php @@ -0,0 +1,95 @@ +subscriber_only || + optional($user)->hasValidSubscription(); + } + + /** + * Determine whether the user can create models. + * + * @param User $user + * @return mixed + */ + public function create(User $user) + { + // + } + + /** + * Determine whether the user can update the model. + * + * @param User $user + * @param \App\Models\SocialArticle $socialArticle + * @return mixed + */ + public function update(User $user, SocialArticle $socialArticle) + { + // + } + + /** + * Determine whether the user can delete the model. + * + * @param User $user + * @param \App\Models\SocialArticle $socialArticle + * @return mixed + */ + public function delete(User $user, SocialArticle $socialArticle) + { + // + } + + /** + * Determine whether the user can restore the model. + * + * @param User $user + * @param \App\Models\SocialArticle $socialArticle + * @return mixed + */ + public function restore(User $user, SocialArticle $socialArticle) + { + // + } + + /** + * Determine whether the user can permanently delete the model. + * + * @param User $user + * @param \App\Models\SocialArticle $socialArticle + * @return mixed + */ + public function forceDelete(User $user, SocialArticle $socialArticle) + { + // + } +} diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 3049068..43a00b8 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -2,6 +2,7 @@ namespace App\Providers; + use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Gate; @@ -13,7 +14,9 @@ class AuthServiceProvider extends ServiceProvider * @var array */ protected $policies = [ - // 'App\Model' => 'App\Policies\ModelPolicy', + \App\Models\SocialArticle::class => \App\Policies\SocialArticlePolicy::class, + \App\Models\LaboArticle::class => \App\Policies\LaboArticlePolicy::class, + \App\Models\AdCampaign::class => \App\Policies\AdCampaignPolicy::class, ]; /** diff --git a/app/View/Components/SubscriberOnlyContent.php b/app/View/Components/SubscriberOnlyContent.php new file mode 100644 index 0000000..330a12c --- /dev/null +++ b/app/View/Components/SubscriberOnlyContent.php @@ -0,0 +1,40 @@ +article = $article; + } + + /** + * Get the view / contents that represent the component. + * + * @return \Illuminate\View\View|string + */ + public function render() + { + return view('components.subscriber-only-content'); + } +} diff --git a/database/migrations/2020_09_14_133836_add_subscriber_only_to_labo_articles.php b/database/migrations/2020_09_14_133836_add_subscriber_only_to_labo_articles.php new file mode 100644 index 0000000..059de2c --- /dev/null +++ b/database/migrations/2020_09_14_133836_add_subscriber_only_to_labo_articles.php @@ -0,0 +1,32 @@ +boolean('subscriber_only')->default(0); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('labo_articles', function (Blueprint $table) { + $table->dropColumn('subscriber_only'); + }); + } +} diff --git a/database/migrations/2020_09_14_134440_add_subscriber_only_to_ad_campaigns.php b/database/migrations/2020_09_14_134440_add_subscriber_only_to_ad_campaigns.php new file mode 100644 index 0000000..2e5a1f6 --- /dev/null +++ b/database/migrations/2020_09_14_134440_add_subscriber_only_to_ad_campaigns.php @@ -0,0 +1,32 @@ +boolean('subscriber_only')->default(0); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('ad_campaigns', function (Blueprint $table) { + $table->dropColumn('subscriber_only'); + }); + } +} diff --git a/resources/views/actu-labos/show.blade.php b/resources/views/actu-labos/show.blade.php index 7acca18..2c146e1 100644 --- a/resources/views/actu-labos/show.blade.php +++ b/resources/views/actu-labos/show.blade.php @@ -15,7 +15,7 @@ {{--

{{$actu->title}}

--}} {{--
{{$actu->chapo}}
--}}
- {!! $actu->content !!} +
diff --git a/resources/views/admin/adCampaigns/form.blade.php b/resources/views/admin/adCampaigns/form.blade.php index 6d8cfce..3712a7d 100644 --- a/resources/views/admin/adCampaigns/form.blade.php +++ b/resources/views/admin/adCampaigns/form.blade.php @@ -24,6 +24,23 @@ 'label' => 'Image', ]) + @formField('radios', [ + 'name' => 'subscriber_only', + 'label' => 'Article réservé aux abonnés', + 'default' => false, + 'inline' => true, + 'options' => [ + [ + 'value' => false, + 'label' => 'Non' + ], + [ + 'value' => true, + 'label' => 'Oui' + ], + ] + ]) + @formField('ckeditor', [ 'name' => 'content', 'label' => 'Article complet', diff --git a/resources/views/admin/laboArticles/form.blade.php b/resources/views/admin/laboArticles/form.blade.php index 012c00b..7f17c73 100644 --- a/resources/views/admin/laboArticles/form.blade.php +++ b/resources/views/admin/laboArticles/form.blade.php @@ -15,6 +15,23 @@ ]) + @formField('radios', [ + 'name' => 'subscriber_only', + 'label' => 'Article réservé aux abonnés', + 'default' => false, + 'inline' => true, + 'options' => [ + [ + 'value' => false, + 'label' => 'Non' + ], + [ + 'value' => true, + 'label' => 'Oui' + ], + ] + ]) + @formField('ckeditor', [ 'label' => 'Article complet', 'name' => 'content', diff --git a/resources/views/com-campaigns/show.blade.php b/resources/views/com-campaigns/show.blade.php index 618b44d..64162d0 100644 --- a/resources/views/com-campaigns/show.blade.php +++ b/resources/views/com-campaigns/show.blade.php @@ -12,7 +12,7 @@
- {!! $campaign->content !!} +
diff --git a/resources/views/components/subscriber-only-content.blade.php b/resources/views/components/subscriber-only-content.blade.php new file mode 100644 index 0000000..2b40656 --- /dev/null +++ b/resources/views/components/subscriber-only-content.blade.php @@ -0,0 +1,14 @@ +
+ @can('view', $article) + {!! $article->content !!} + @else +
+ {!! $article->getTruncatedContent() !!} +
+
+ Cet article est réservé aux abonnés ! Pour y accéder merci de vous connecter, ou + cliquez ici pour découvrir nos formules d'abonnement. +
+ @endif + +
diff --git a/resources/views/social-articles/show.blade.php b/resources/views/social-articles/show.blade.php index 759214a..db4a58e 100644 --- a/resources/views/social-articles/show.blade.php +++ b/resources/views/social-articles/show.blade.php @@ -2,35 +2,25 @@ @section('content') -
+
-
+

{{$article->title}}

{!! $article->chapo !!}
-
- @if($article->isVisibleByUser()) - {!! $article->content !!} - @else -
- {!! $article->getTruncatedContent() !!} -
-
- Cet article est réservé aux abonnés ! Pour y accéder merci de vous connecter, ou - cliquez ici pour découvrir nos formules d'abonnement. -
- @endif +
+
-
+
-
+ @endsection