From d8dabf085c572ae60a40a944c6193a248cbe4826 Mon Sep 17 00:00:00 2001 From: Lars Jansen Date: Tue, 23 May 2023 14:40:30 +0200 Subject: [PATCH] fix: force some items of CalendarItem to be an int --- LJPcCalendarModule/Entities/Calendar.php | 96 ++++++++++---------- LJPcCalendarModule/Entities/CalendarItem.php | 94 +++++++++---------- 2 files changed, 95 insertions(+), 95 deletions(-) diff --git a/LJPcCalendarModule/Entities/Calendar.php b/LJPcCalendarModule/Entities/Calendar.php index bfac381..2d6bb8c 100644 --- a/LJPcCalendarModule/Entities/Calendar.php +++ b/LJPcCalendarModule/Entities/Calendar.php @@ -6,54 +6,54 @@ use JsonSerializable; class Calendar extends Model implements JsonSerializable { - protected $table = 'calendars'; - protected $fillable = [ - 'name', - 'url', - 'synchronization_token', - ]; - - public function isVisible(): bool { - $calendarList = explode( "\n", base64_decode( config( 'ljpccalendarmodule.calendar_list' ) ) ); - - return in_array( $this->name, $calendarList, true ) || in_array( $this->url, $calendarList, true ); - } - - public function jsonSerialize(): array { - return [ - 'id' => $this->id, - 'name' => $this->name, - 'external' => $this->isExternal(), - 'colors' => $this->getColors(), + protected $table = 'calendars'; + protected $fillable = [ + 'name', + 'url', + 'synchronization_token', ]; - } - public function isExternal(): bool { - return ! empty( $this->url ); - } - - public function getColors(): array { - $colors = $this->calendarColors(); - $calendarColors = $colors[ ($this->id-1) % count( $colors ) ]; - - return [ - 'backgroundColor' => $calendarColors[0], - 'borderColor' => $calendarColors[1], - 'textColor' => $calendarColors[2], - ]; - } - - private function calendarColors(): array { - return [ - [ '#3498db', '#2980b9', '#ffffff' ], - [ '#e74c3c', '#c0392b', '#ffffff' ], - [ '#e67e22', '#d35400', '#ffffff' ], - [ '#1abc9c', '#16a085', '#ffffff' ], - [ '#9b59b6', '#8e44ad', '#ffffff' ], - [ '#2ecc71', '#27ae60', '#ffffff' ], - [ '#f1c40f', '#f39c12', '#000000' ], - [ '#833471', '#6F1E51', '#ffffff' ], - [ '#9980FA', '#5758BB', '#ffffff' ], - ]; - } + public function isVisible(): bool { + $calendarList = explode( "\n", base64_decode( config( 'ljpccalendarmodule.calendar_list' ) ) ); + + return in_array( $this->name, $calendarList, true ) || in_array( $this->url, $calendarList, true ); + } + + public function jsonSerialize(): array { + return [ + 'id' => $this->id, + 'name' => $this->name, + 'external' => $this->isExternal(), + 'colors' => $this->getColors(), + ]; + } + + public function isExternal(): bool { + return ! empty( $this->url ); + } + + public function getColors(): array { + $colors = $this->calendarColors(); + $calendarColors = $colors[ ( $this->id - 1 ) % count( $colors ) ]; + + return [ + 'backgroundColor' => $calendarColors[0], + 'borderColor' => $calendarColors[1], + 'textColor' => $calendarColors[2], + ]; + } + + private function calendarColors(): array { + return [ + [ '#3498db', '#2980b9', '#ffffff' ], + [ '#e74c3c', '#c0392b', '#ffffff' ], + [ '#e67e22', '#d35400', '#ffffff' ], + [ '#1abc9c', '#16a085', '#ffffff' ], + [ '#9b59b6', '#8e44ad', '#ffffff' ], + [ '#2ecc71', '#27ae60', '#ffffff' ], + [ '#f1c40f', '#f39c12', '#000000' ], + [ '#833471', '#6F1E51', '#ffffff' ], + [ '#9980FA', '#5758BB', '#ffffff' ], + ]; + } } diff --git a/LJPcCalendarModule/Entities/CalendarItem.php b/LJPcCalendarModule/Entities/CalendarItem.php index 2550e0b..69fa6d8 100644 --- a/LJPcCalendarModule/Entities/CalendarItem.php +++ b/LJPcCalendarModule/Entities/CalendarItem.php @@ -8,55 +8,55 @@ use JsonSerializable; class CalendarItem extends Model implements JsonSerializable { - public const ACTION_TYPE_ADD_TO_CALENDAR = 186; - - protected $table = 'calendar_items'; - protected $fillable = [ - 'calendar_id', - 'author_id', - 'is_all_day', - 'is_private', - 'is_read_only', - 'title', - 'body', - 'state', - 'location', - 'start', - 'end', - ]; - - public function calendar(): BelongsTo { - return $this->belongsTo( Calendar::class ); - } - - public function jsonSerialize(): array { - $retArr = [ - 'id' => $this->id, - 'title' => $this->title, - 'location' => $this->location, - 'body' => $this->body, - 'state' => $this->state, - 'start' => $this->start, - 'end' => $this->end, - 'isAllDay' => $this->is_all_day, - 'category' => $this->is_all_day ? 'allday' : 'time', - 'isPrivate' => $this->is_private, - 'isReadOnly' => $this->is_read_only, - 'calendarId' => $this->calendar_id, - 'raw' => [], + public const ACTION_TYPE_ADD_TO_CALENDAR = 186; + + protected $table = 'calendar_items'; + protected $fillable = [ + 'calendar_id', + 'author_id', + 'is_all_day', + 'is_private', + 'is_read_only', + 'title', + 'body', + 'state', + 'location', + 'start', + 'end', ]; - $creator = User::where( 'id', $this->author_id )->first(); - if ( $creator !== null ) { - $retArr['raw']['creator'] = [ - 'id' => $this->author_id, - 'name' => $creator->getFullName(), - 'email' => $creator->email, - 'avatar' => $creator->getPhotoUrl(), - 'phone' => $creator->phone, - ]; + public function calendar(): BelongsTo { + return $this->belongsTo( Calendar::class ); } - return $retArr; - } + public function jsonSerialize(): array { + $retArr = [ + 'id' => $this->id, + 'title' => $this->title, + 'location' => $this->location, + 'body' => $this->body, + 'state' => $this->state, + 'start' => $this->start, + 'end' => $this->end, + 'isAllDay' => (int) $this->is_all_day, + 'category' => $this->is_all_day ? 'allday' : 'time', + 'isPrivate' => (int) $this->is_private, + 'isReadOnly' => (int) $this->is_read_only, + 'calendarId' => (int) $this->calendar_id, + 'raw' => [], + ]; + + $creator = User::where( 'id', $this->author_id )->first(); + if ( $creator !== null ) { + $retArr['raw']['creator'] = [ + 'id' => $this->author_id, + 'name' => $creator->getFullName(), + 'email' => $creator->email, + 'avatar' => $creator->getPhotoUrl(), + 'phone' => $creator->phone, + ]; + } + + return $retArr; + } }