Mod vcard output
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Philipp Lang 2022-10-07 14:47:35 +02:00
parent 1ba84ebae7
commit a82698e05d
1 changed files with 38 additions and 4 deletions

View File

@ -41,10 +41,19 @@ class Member extends Model
public $guarded = []; public $guarded = [];
/**
* @var array<int, string>
*/
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']; 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<int, string>
*/
public $dates = ['try_created_at', 'joined_at', 'birthday']; public $dates = ['try_created_at', 'joined_at', 'birthday'];
/**
* @var array<string, string>
*/
public $casts = [ public $casts = [
'pending_payment' => 'integer', 'pending_payment' => 'integer',
'send_newspaper' => 'boolean', 'send_newspaper' => 'boolean',
@ -62,6 +71,9 @@ class Member extends Model
'is_leader' => 'boolean', 'is_leader' => 'boolean',
]; ];
/**
* @return array<string, array{source: array<int, string>}>
*/
public function sluggable(): array public function sluggable(): array
{ {
return [ return [
@ -116,6 +128,19 @@ class Member extends Model
return null; 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 public function getEtagAttribute(): string
{ {
return $this->updated_at->timestamp.'_'.$this->version; return $this->updated_at->timestamp.'_'.$this->version;
@ -356,6 +381,7 @@ class Member extends Model
public function toVcard(): VCard public function toVcard(): VCard
{ {
$card = new VCard([ $card = new VCard([
'VERSION' => '3.0',
'FN' => $this->fullname, 'FN' => $this->fullname,
'TEL' => $this->mobile_phone, 'TEL' => $this->mobile_phone,
'N' => [$this->lastname, $this->firstname, '', '', ''], 'N' => [$this->lastname, $this->firstname, '', '', ''],
@ -363,8 +389,15 @@ class Member extends Model
'CATEGORIES' => 'Scoutrobot', 'CATEGORIES' => 'Scoutrobot',
]); ]);
$card->add('child.X-ABLABEL', 'Kind');
$card->add('parent.X-ABLABEL', 'Eltern');
if ($this->preferred_phone) { 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) { if ($this->mobile_phone) {
@ -376,14 +409,15 @@ class Member extends Model
} }
if ($this->children_phone) { if ($this->children_phone) {
$card->add('TEL', $this->children_phone, ['type' => 'Kind']); $card->add('child.TEL', $this->children_phone);
} }
if ($this->email) { if ($this->email) {
$card->add('EMAIL', $this->email, ['type' => 'Kind']); $card->add('child.EMAIL', $this->email);
} }
if ($this->email_parents) { if ($this->email_parents) {
$card->add('EMAIL', $this->email_parents, ['type' => 'Eltern']); $card->add('parent.EMAIL', $this->email_parents);
} }
$card->add('ADR', [ $card->add('ADR', [