|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @file classes/components/forms/invitation/AcceptUserDetailsForm.php |
| 4 | + * |
| 5 | + * Copyright (c) 2014-2024 Simon Fraser University |
| 6 | + * Copyright (c) 2000-2024 John Willinsky |
| 7 | + * Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. |
| 8 | + * |
| 9 | + * @class AcceptUserDetailsForm |
| 10 | + * |
| 11 | + * |
| 12 | + * @brief Handles accept invitation user details form |
| 13 | + */ |
| 14 | + |
| 15 | +namespace PKP\components\forms\invitation; |
| 16 | + |
| 17 | +use PKP\components\forms\FieldSelect; |
| 18 | +use PKP\components\forms\FieldText; |
| 19 | +use PKP\components\forms\FormComponent; |
| 20 | +use PKP\facades\Locale; |
| 21 | + |
| 22 | +class AcceptUserDetailsForm extends FormComponent |
| 23 | +{ |
| 24 | + public const ACCEPT_FORM_USER_DETAILS = 'acceptUserDetails'; |
| 25 | + /** @copydoc FormComponent::$id */ |
| 26 | + public $id = self::ACCEPT_FORM_USER_DETAILS; |
| 27 | + |
| 28 | + /** @copydoc FormComponent::$method */ |
| 29 | + public $method = 'POST'; |
| 30 | + |
| 31 | + /** |
| 32 | + * Constructor |
| 33 | + * |
| 34 | + * @param string $action URL to submit the form to |
| 35 | + * @param array $locales Supported locales |
| 36 | + */ |
| 37 | + public function __construct($action, $locales) |
| 38 | + { |
| 39 | + $this->action = $action; |
| 40 | + $this->locales = $locales; |
| 41 | + |
| 42 | + $countries = []; |
| 43 | + foreach (Locale::getCountries() as $country) { |
| 44 | + $countries[] = [ |
| 45 | + 'value' => $country->getAlpha2(), |
| 46 | + 'label' => $country->getLocalName() |
| 47 | + ]; |
| 48 | + } |
| 49 | + |
| 50 | + usort($countries, function ($a, $b) { |
| 51 | + return strcmp($a['label'], $b['label']); |
| 52 | + }); |
| 53 | + |
| 54 | + $this->addField(new FieldText('givenName', [ |
| 55 | + 'label' => __('user.givenName'), |
| 56 | + 'description' => __('acceptInvitation.userDetailsForm.givenName.description'), |
| 57 | + 'isRequired' => true, |
| 58 | + 'isMultilingual' => true, |
| 59 | + 'size' => 'large', |
| 60 | + 'value' => '' |
| 61 | + ])) |
| 62 | + ->addField(new FieldText('familyName', [ |
| 63 | + 'label' => __('user.familyName'), |
| 64 | + 'description' => __('acceptInvitation.userDetailsForm.familyName.description'), |
| 65 | + 'isRequired' => false, |
| 66 | + 'isMultilingual' => true, |
| 67 | + 'size' => 'large', |
| 68 | + 'value' => '' |
| 69 | + ])) |
| 70 | + ->addField(new FieldText('affiliation', [ |
| 71 | + 'label' => __('user.affiliation'), |
| 72 | + 'description' => __('acceptInvitation.userDetailsForm.affiliation.description'), |
| 73 | + 'isMultilingual' => true, |
| 74 | + 'isRequired' => false, |
| 75 | + 'size' => 'large', |
| 76 | + |
| 77 | + ])) |
| 78 | + ->addField(new FieldSelect('userCountry', [ |
| 79 | + 'label' => __('acceptInvitation.userDetailsForm.countryOfAffiliation.label'), |
| 80 | + 'description' => __('acceptInvitation.userDetailsForm.countryOfAffiliation.description'), |
| 81 | + 'options' => $countries, |
| 82 | + 'isRequired' => true, |
| 83 | + 'size' => 'large', |
| 84 | + ])); |
| 85 | + |
| 86 | + } |
| 87 | +} |
0 commit comments