From 9e1e242dd8d0dfdecc0308bb6a7390ec8478d9f6 Mon Sep 17 00:00:00 2001 From: Louis Jeckel Date: Mon, 28 Sep 2020 11:20:22 +0200 Subject: [PATCH] reorder ads, revamp agenda + prev/next btns --- app/Http/Controllers/AdCampaignController.php | 6 +-- .../Admin/AdCampaignController.php | 3 +- app/Http/Controllers/EnPlusController.php | 7 ++-- app/Models/WeeklyAgenda.php | 40 ++++++++++++++++++- ...28_084558_add_position_to_ad_campaigns.php | 32 +++++++++++++++ resources/views/actu-labos/index.blade.php | 2 +- resources/views/en-plus/agenda/show.blade.php | 24 ++++++++--- resources/views/en-plus/index.blade.php | 31 +++++++++----- 8 files changed, 119 insertions(+), 26 deletions(-) create mode 100644 database/migrations/2020_09_28_084558_add_position_to_ad_campaigns.php diff --git a/app/Http/Controllers/AdCampaignController.php b/app/Http/Controllers/AdCampaignController.php index 854c0a1..28797e2 100644 --- a/app/Http/Controllers/AdCampaignController.php +++ b/app/Http/Controllers/AdCampaignController.php @@ -15,13 +15,13 @@ class AdCampaignController extends Controller } /** + * @param AdCampaignRepository $repository * @return \Illuminate\View\View - * */ - public function index() + public function index(AdCampaignRepository $repository) { $campaigns = AdCampaign::query() - ->orderByDesc('id') + ->orderBy('position') ->take(3) ->published() ->visible() diff --git a/app/Http/Controllers/Admin/AdCampaignController.php b/app/Http/Controllers/Admin/AdCampaignController.php index 4d80a3e..d76612f 100644 --- a/app/Http/Controllers/Admin/AdCampaignController.php +++ b/app/Http/Controllers/Admin/AdCampaignController.php @@ -11,8 +11,9 @@ class AdCampaignController extends ModuleController protected $permalinkBase = 'campagnes-et-communication'; protected $indexOptions = [ -// 'reorder' => true + 'reorder' => true ]; + } diff --git a/app/Http/Controllers/EnPlusController.php b/app/Http/Controllers/EnPlusController.php index 8e95ac1..200496b 100644 --- a/app/Http/Controllers/EnPlusController.php +++ b/app/Http/Controllers/EnPlusController.php @@ -13,11 +13,12 @@ class EnPlusController extends Controller public function index() { \View::share('humeur', Humeur::query()->orderByDesc('id')->firstOrFail()); - $agenda = WeeklyAgenda::query() + $agendas = WeeklyAgenda::query() ->orderBy('start_date') ->where('start_date', '>=', now()->addDay()->startof('week')) - ->first(); - \View::share('agenda', $agenda); + ->take(4) + ->get(); + \View::share('agendas', $agendas); \View::share('title', "Agenda et Humeur"); return view('en-plus.index'); diff --git a/app/Models/WeeklyAgenda.php b/app/Models/WeeklyAgenda.php index 97d5320..78d5f62 100644 --- a/app/Models/WeeklyAgenda.php +++ b/app/Models/WeeklyAgenda.php @@ -12,6 +12,7 @@ use Carbon\Carbon; * @package App\Models * @property Carbon $start_date * @property-read Carbon $end_date + * @property int $id */ class WeeklyAgenda extends Model { @@ -43,14 +44,28 @@ class WeeklyAgenda extends Model return $this->startDateCarbon()->format('d/m/Y'); } + /** + * @return string + */ public function getFullTitle() { - return "Semaine du {$this->startDateCarbon()->format('d/m/Y')} au {$this->endDateCarbon()->format('d/m/Y')}"; + return "Semaine du ".$this->getDatesString(); + } + + /** + * @return string + */ + public function getDatesString() + { + return "{$this->startDateCarbon()->format('d/m/Y')} au {$this->endDateCarbon()->format('d/m/Y')}"; } + /* + * + */ public function getUrlAttribute() { - return route('agenda.show', ['agenda' => $this->id]); + return route('agenda.show', ['agenda' => $this->start_date]); } @@ -70,6 +85,27 @@ class WeeklyAgenda extends Model return $this->startDateCarbon()->addWeek(); } + /** + * @return WeeklyAgenda|null + */ + public function nextWeek(): ?WeeklyAgenda + { + return self::query() + ->orderBy('start_date') + ->where('start_date', '>', $this->start_date) + ->first(); + } + + /** + * @return WeeklyAgenda|null + */ + public function previousWeek(): ?WeeklyAgenda + { + return self::query() + ->orderByDesc('start_date') + ->where('start_date', '<', $this->start_date) + ->first(); + } /** * @return string|null diff --git a/database/migrations/2020_09_28_084558_add_position_to_ad_campaigns.php b/database/migrations/2020_09_28_084558_add_position_to_ad_campaigns.php new file mode 100644 index 0000000..77639a9 --- /dev/null +++ b/database/migrations/2020_09_28_084558_add_position_to_ad_campaigns.php @@ -0,0 +1,32 @@ +

L'actu des labos

-

Une séléction de nos articles publiés cette semaine

+

Une sélection de nos articles publiés récemment

diff --git a/resources/views/en-plus/agenda/show.blade.php b/resources/views/en-plus/agenda/show.blade.php index a60f1a7..044cde2 100644 --- a/resources/views/en-plus/agenda/show.blade.php +++ b/resources/views/en-plus/agenda/show.blade.php @@ -13,12 +13,12 @@ @foreach($agenda->imageObjects('events') as $event)
@if(!empty($url = $event->getMetadata('url'))) - - @endif + + @endif - - @if(!empty($url)) - + + @if(!empty($url)) + @endif
@@ -28,6 +28,20 @@
+
+
+ @if(null !== $a = $agenda->previousWeek()) + ❮ Semaine précédente + @endif +
+
+ @if(null !== $a = $agenda->nextWeek()) + Semaine suivante ❯ + @endif +
+
+ + diff --git a/resources/views/en-plus/index.blade.php b/resources/views/en-plus/index.blade.php index 6768b60..3966aa3 100644 --- a/resources/views/en-plus/index.blade.php +++ b/resources/views/en-plus/index.blade.php @@ -20,20 +20,29 @@

L’AGENDA DES ACTEURS DU MÉDICAMENT

- @if($agenda === null) + @if(count($agendas) === 0)

Aucun événement pour cette semaine...

@else - @if($event = $agenda->imageObject('events')) - @if(!empty($url = $event->getMetadata('url'))) - - @endif - - @if(!empty($url)) +

+ Les Conférences de presse, les Colloques, les Rendez-Vous et les Dates essentielles des acteurs du Médicament et de leurs Partenaires +

+ + +

Les Rendez-Vous de la Pharma du

+
+ @endif
-- 2.39.5