kompass/modules/Gruppen/Actions/CreateGroupMemberDataAction.php
2024-03-23 20:46:44 +01:00

37 lines
1.1 KiB
PHP

<?php
use Bdp\Modules\Gruppen\Controllers\MainController;
class CreateGroupMemberDataAction
{
public static function execute(array $userData) : array
{
$dataKeys = [
'vorname' => 'kompass_group_member_firstname',
'nachname' => 'kompass_group_member_lastname',
'geburtsdatum' => 'kompass_group_member_birthday',
'ansprechpartner' => 'kompass_group_member_parents',
'email_1' => 'kompass_group_member_email_1',
'email_2' => 'kompass_group_member_email_2',
'telefon_1' => 'kompass_group_member_phone_1',
'telefon_2' => 'kompass_group_member_phone_2',
];
$return = ['data' => [], 'rawData' => [], 'errors' => []];
foreach ($dataKeys as $dbKey => $formKey) {
$value = trim($userData[$formKey]);
$return['rawData'][$formKey] = $value;
if ($dbKey === 'email_2' || $dbKey === 'telefon_2') {
$return['data'][$dbKey] = $value;
} else {
if ( $value === '' ) {
$return['errors'][] = sprintf(__( 'The field "%s" is required.', BDP_LV_PLUGIN_SLUG ), $dbKey);
} else {
$return['data'][ $dbKey ] = $value;
}
}
}
return $return;
}
}