From a82698e05db698ce311bf15e8667f34f7347caef Mon Sep 17 00:00:00 2001 From: Philipp Lang Date: Fri, 7 Oct 2022 14:47:35 +0200 Subject: [PATCH] Mod vcard output --- app/Member/Member.php | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/app/Member/Member.php b/app/Member/Member.php index 6865a0c4..fd8a53d4 100644 --- a/app/Member/Member.php +++ b/app/Member/Member.php @@ -41,10 +41,19 @@ class Member extends Model public $guarded = []; + /** + * @var array + */ public static array $namiFields = ['firstname', 'lastname', 'joined_at', 'birthday', 'send_newspaper', 'address', 'zip', 'location', 'nickname', 'other_country', 'further_address', 'main_phone', 'mobile_phone', 'work_phone', 'fax', 'email', 'email_parents', 'gender_id', 'confession_id', 'region_id', 'country_id', 'fee_id', 'nationality_id', 'slug']; + /** + * @var array + */ public $dates = ['try_created_at', 'joined_at', 'birthday']; + /** + * @var array + */ public $casts = [ 'pending_payment' => 'integer', 'send_newspaper' => 'boolean', @@ -62,6 +71,9 @@ class Member extends Model 'is_leader' => 'boolean', ]; + /** + * @return array}> + */ public function sluggable(): array { return [ @@ -116,6 +128,19 @@ class Member extends Model return null; } + public function getPreferredEmailAttribute(): ?string + { + if ($this->email) { + return $this->email; + } + + if ($this->email_parents) { + return $this->email_parents; + } + + return null; + } + public function getEtagAttribute(): string { return $this->updated_at->timestamp.'_'.$this->version; @@ -356,6 +381,7 @@ class Member extends Model public function toVcard(): VCard { $card = new VCard([ + 'VERSION' => '3.0', 'FN' => $this->fullname, 'TEL' => $this->mobile_phone, 'N' => [$this->lastname, $this->firstname, '', '', ''], @@ -363,8 +389,15 @@ class Member extends Model 'CATEGORIES' => 'Scoutrobot', ]); + $card->add('child.X-ABLABEL', 'Kind'); + $card->add('parent.X-ABLABEL', 'Eltern'); + if ($this->preferred_phone) { - $card->add('TEL', $this->preferred_phone, ['type' => 'pref,voice']); + $card->add('parent.TEL', $this->preferred_phone, ['type' => 'pref']); + } + + if ($this->preferred_email) { + $card->add('EMAIL', $this->preferred_email, ['type' => 'pref']); } if ($this->mobile_phone) { @@ -376,14 +409,15 @@ class Member extends Model } if ($this->children_phone) { - $card->add('TEL', $this->children_phone, ['type' => 'Kind']); + $card->add('child.TEL', $this->children_phone); } if ($this->email) { - $card->add('EMAIL', $this->email, ['type' => 'Kind']); + $card->add('child.EMAIL', $this->email); } + if ($this->email_parents) { - $card->add('EMAIL', $this->email_parents, ['type' => 'Eltern']); + $card->add('parent.EMAIL', $this->email_parents); } $card->add('ADR', [