diff --git a/app/Http/Requests/StoreCalendar.php b/app/Http/Requests/StoreCalendar.php
index 6d7ea3a6e4..b454a6b212 100644
--- a/app/Http/Requests/StoreCalendar.php
+++ b/app/Http/Requests/StoreCalendar.php
@@ -44,6 +44,7 @@ public function rules()
'moon_name' => 'nullable|array',
'epoch_name' => 'nullable|array',
'season_name' => 'nullable|array',
+ 'show_birthdays' => 'boolean',
'template_id' => 'nullable',
'format' => ['nullable', new CalendarFormat(), 'string', 'max:20'],
'moon_offset' => [
diff --git a/app/Models/Calendar.php b/app/Models/Calendar.php
index caad6a5750..20256e1ac8 100644
--- a/app/Models/Calendar.php
+++ b/app/Models/Calendar.php
@@ -32,6 +32,7 @@
* @property int $calendar_id
* @property array $parameters
* @property bool $skip_year_zero
+ * @property bool $show_birthdays
*/
class Calendar extends MiscModel
{
@@ -66,6 +67,7 @@ class Calendar extends MiscModel
'reset',
'is_incrementing',
'format',
+ 'show_birthdays',
// Leap year
'has_leap_year',
diff --git a/app/Renderers/CalendarRenderer.php b/app/Renderers/CalendarRenderer.php
index d8c1b465cc..031b512d04 100644
--- a/app/Renderers/CalendarRenderer.php
+++ b/app/Renderers/CalendarRenderer.php
@@ -5,6 +5,7 @@
use App\Models\Calendar;
use App\Models\CalendarWeather;
use App\Models\EntityEvent;
+use App\Models\EntityEventType;
use App\Traits\CampaignAware;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
@@ -54,6 +55,16 @@ class CalendarRenderer
*/
protected array $weeks = [];
+ /**
+ * Death events
+ */
+ protected array $deaths = [];
+
+ /**
+ * Birthday events
+ */
+ protected array $births = [];
+
/**
* Array of weirdly recurring events
*/
@@ -777,6 +788,7 @@ protected function events(): array
$reminders = $this->getReminders($this->calendar->calendar);
$this->parseReminders($reminders);
}
+ //dd($this->events);
return $this->events;
}
@@ -807,6 +819,18 @@ protected function getReminders(Calendar $calendar)
->where('is_recurring', true);
}
})
+ ->orWhere(function ($sub) {
+ if ($this->calendar->show_birthdays) {
+ $sub->where('year', '<=', $this->getYear());
+
+ if ($this->isYearlyLayout()) {
+ $sub->whereIn('type_id', [EntityEventType::BIRTH, EntityEventType::DEATH]);
+ } else {
+ $sub->where('month', $this->getMonth())
+ ->whereIn('type_id', [EntityEventType::BIRTH, EntityEventType::DEATH]);
+ }
+ }
+ })
// Events from previous year or month that spill over
->orWhere(function ($sub) {
$previousYear = $this->getYear(-1);
@@ -846,7 +870,7 @@ protected function parseReminders(Collection $reminders): void
// If the event is recurring, get the year to make sure it should start showing. This was previously
// done in the query, but it didn't work on all systems.
- if ($event->is_recurring) {
+ if ($event->is_recurring || $event->type_id == EntityEventType::BIRTH) {
if ($event->year > $this->getYear()) {
continue;
}
@@ -878,11 +902,24 @@ protected function parseReminders(Collection $reminders): void
$this->recurring[$event->recurring_periodicity][] = $event;
}
} else {
+ if ($event->type_id == EntityEventType::DEATH) {
+ $this->deaths[$event->entity_id] = $event;
+ } elseif ($event->type_id == EntityEventType::BIRTH) {
+ $this->births[$event->entity_id] = $event;
+ continue;
+ }
// Only add it once
$this->events[$date][] = $event;
$this->addMultidayEvent($event, $date);
}
}
+
+ foreach ($this->births as $key => $birth) {
+ if (!isset($this->deaths[$key]) || ($this->deaths[$key]->month > $birth->month || ($this->deaths[$key]->month == $birth->month && $this->deaths[$key]->day > $birth->day))) {
+ $date = $this->getYear() . '-' . $birth->month . '-' . $birth->day;
+ $this->events[$date][] = $birth;
+ }
+ }
//should end the first day of the month
}
diff --git a/database/migrations/2023_11_21_215234_update_calendars_add_show_birthdays.php b/database/migrations/2023_11_21_215234_update_calendars_add_show_birthdays.php
new file mode 100644
index 0000000000..2bf231048b
--- /dev/null
+++ b/database/migrations/2023_11_21_215234_update_calendars_add_show_birthdays.php
@@ -0,0 +1,28 @@
+boolean('show_birthdays')->default(true);
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::table('calendars', function (Blueprint $table) {
+ $table->dropColumn('show_birthdays');
+ });
+ }
+};
diff --git a/lang/en/calendars.php b/lang/en/calendars.php
index acb0ced23b..1ff857ab79 100644
--- a/lang/en/calendars.php
+++ b/lang/en/calendars.php
@@ -90,6 +90,7 @@
'recurring_until' => 'Recurring Until Year',
'reset' => 'Weekly Reset',
'seasons' => 'Seasons',
+ 'show_birthdays' => 'Show Birthdays',
'skip_year_zero' => 'Skip Year Zero',
'start_offset' => 'Start Offset',
'suffix' => 'Suffix',
@@ -117,6 +118,7 @@
'reset' => 'Always start the beginning of the month or year on the first week day.',
'seasons' => 'Create seasons for your calendar by providing when each of them start. Kanka will take care of the rest.',
'skip_year_zero' => 'By default, the calendar\'s first year is year zero. Enable this option to skip year zero.',
+ 'show_birthdays' => 'Show the yearly birthdays of characters that have a birthday reminder on this calendar up to their death date.',
'weekdays' => 'Set your weekday names. At least 2 weekdays are required.',
'weeks' => 'Define some names for the more important weeks of your calendar.',
'years' => 'Some years are so important that they have their own name.',
diff --git a/resources/views/calendars/form/_calendar.blade.php b/resources/views/calendars/form/_calendar.blade.php
index 5d23b3eb34..98b5a0371c 100644
--- a/resources/views/calendars/form/_calendar.blade.php
+++ b/resources/views/calendars/form/_calendar.blade.php
@@ -44,6 +44,13 @@
{!! Form::checkbox('is_incrementing', 1, FormCopy::field('is_incrementing')->string()) !!}
+
+