diff --git a/src/Contracts/CalendarDataProviderInterface.php b/src/Contracts/CalendarDataProviderInterface.php index eb1db8e..eb2ca54 100644 --- a/src/Contracts/CalendarDataProviderInterface.php +++ b/src/Contracts/CalendarDataProviderInterface.php @@ -16,6 +16,8 @@ namespace Wdelfuego\NovaCalendar\Contracts; +use Wdelfuego\NovaCalendar\View\AbstractView as View; + interface CalendarDataProviderInterface { public function __construct(); @@ -31,4 +33,7 @@ public function daysOfTheWeek() : array; // A multi-dimensional array of event styles, see documentation public function eventStyles() : array; + + // Allows the data provider to customize the data view just before sending it to the front-end + public function customizeView(View $view) : View; } diff --git a/src/DataProvider/AbstractCalendarDataProvider.php b/src/DataProvider/AbstractCalendarDataProvider.php index ab8df1e..0f400a7 100644 --- a/src/DataProvider/AbstractCalendarDataProvider.php +++ b/src/DataProvider/AbstractCalendarDataProvider.php @@ -62,6 +62,11 @@ public function initialize(): void } + public function customizeView(View $view) : View + { + return $view; + } + public function setConfig(array $config) { $this->config = $config; diff --git a/src/Http/Controllers/CalendarController.php b/src/Http/Controllers/CalendarController.php index 70095a4..e6f86cb 100644 --- a/src/Http/Controllers/CalendarController.php +++ b/src/Http/Controllers/CalendarController.php @@ -78,6 +78,7 @@ public function getCalendarData(string $view = 'month') $view = View::get($view); $view->initFromRequest($this->request); + $view = $dataProvider->customizeView($this); return $view->calendarData($this->request, $dataProvider); } diff --git a/src/View/AbstractView.php b/src/View/AbstractView.php index dca9451..70400d0 100644 --- a/src/View/AbstractView.php +++ b/src/View/AbstractView.php @@ -47,7 +47,8 @@ public static function get(string $view) : ViewInterface abstract public function specifier() : string; abstract public function initFromRequest(NovaRequest $request); abstract public function viewData(CalendarDataProviderInterface $dataProvider) : array; - + abstract public function forceShowDate(Carbon $date); + // The general Range is the date range that the user is interested in. // The Calendar range is the date range that will be shown in the front-end. // The Range can be shorter than the Calendar, not the other way around. diff --git a/src/View/Month.php b/src/View/Month.php index 01eb11d..c6e8c3b 100644 --- a/src/View/Month.php +++ b/src/View/Month.php @@ -49,6 +49,11 @@ public function viewData(CalendarDataProviderInterface $dataProvider) : array ]; } + public function forceShowDate(Carbon $date) + { + $this->setYearAndMonth($date->year, $date->month); + } + public function setYearAndMonth($year, $month) : self { $year = is_null($year) || !is_numeric($year) ? now()->year : intval($year);