Code:
public function get_profile_data()
{
if (!$this->app->getIdentity()->authorise('eventbooking.registrantsmanagement', 'com_eventbooking'))
{
throw new RuntimeException('You do not have permission', 403);
}
$userId = $this->input->getInt('user_id', 0);
$eventId = $this->input->getInt('event_id');
$data = [];
if ($userId && $eventId)
{
$rowFields = EventbookingHelperRegistration::getFormFields($eventId, 0);
$data = EventbookingHelperRegistration::getFormData($rowFields, $eventId, $userId);
}
if ($userId && !isset($data['first_name']))
{
//Load the name from Joomla default name
/* @var User $user */
$user = Factory::getContainer()->get(UserFactoryInterface::class)->loadUserById((int) $userId);
$name = $user->name;
if ($name)
{
[$firstName, $lastName] = EventbookingHelper::callOverridableHelperMethod(
'Registration',
'detectFirstAndLastNameFromFullName',
[$name]
);
$data['first_name'] = $firstName;
$data['last_name'] = $lastName;
}
}
if ($userId && !isset($data['email']))
{
if (empty($user))
{
/* @var User $user */
$user = Factory::getContainer()->get(UserFactoryInterface::class)->loadUserById((int) $userId);
}
$data['email'] = $user->email;
}
echo json_encode($data);
$this->app->close();
}