Skip to content

Commit

Permalink
fix: force some items of CalendarItem to be an int
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars- committed May 23, 2023
1 parent c2d8395 commit d8dabf0
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 95 deletions.
96 changes: 48 additions & 48 deletions LJPcCalendarModule/Entities/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ],
];
}
}
94 changes: 47 additions & 47 deletions LJPcCalendarModule/Entities/CalendarItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit d8dabf0

Please sign in to comment.