/** * Fills $registration with $formData (as submitted via the registration form). * * This function sets all necessary registration data except for three * things: * - event * - user * - whether the registration is on the queue * * Note: This functions does not check whether registration is possible at all. * * @param tx_seminars_Model_Registration $registration the registration to fill, must already have an event assigned * @param array $formData the raw data submitted via the form, may be empty * * @return void */ protected function setRegistrationData(tx_seminars_Model_Registration $registration, array $formData) { $event = $registration->getEvent(); $seats = isset($formData['seats']) ? (int) $formData['seats'] : 1; if ($seats < 1) { $seats = 1; } $registration->setSeats($seats); $registeredThemselves = isset($formData['registered_themselves']) ? (bool) $formData['registered_themselves'] : FALSE; $registration->setRegisteredThemselves($registeredThemselves); $availablePrices = $event->getAvailablePrices(); if (isset($formData['price']) && isset($availablePrices[$formData['price']])) { $priceCode = $formData['price']; } else { reset($availablePrices); $priceCode = key($availablePrices); } $registration->setPrice($priceCode); $totalPrice = $availablePrices[$priceCode] * $seats; $registration->setTotalPrice($totalPrice); $attendeesNames = isset($formData['attendees_names']) ? strip_tags($formData['attendees_names']) : ''; $registration->setAttendeesNames($attendeesNames); $kids = isset($formData['kids']) ? max(0, (int) $formData['kids']) : 0; $registration->setKids($kids); $paymentMethod = NULL; if ($totalPrice > 0) { $availablePaymentMethods = $event->getPaymentMethods(); if (!$availablePaymentMethods->isEmpty()) { if ($availablePaymentMethods->count() == 1) { $paymentMethod = $availablePaymentMethods->first(); } else { $paymentMethodUid = isset($formData['method_of_payment']) ? max(0, (int) $formData['method_of_payment']) : 0; if ($paymentMethodUid > 0 && $availablePaymentMethods->hasUid($paymentMethodUid)) { /** @var tx_seminars_Mapper_PaymentMethod $mapper */ $mapper = tx_oelib_MapperRegistry::get('tx_seminars_Mapper_PaymentMethod'); /** @var tx_seminars_Model_PaymentMethod $paymentMethod */ $paymentMethod = $mapper->find($paymentMethodUid); } } } } $registration->setPaymentMethod($paymentMethod); $accountNumber = isset($formData['account_number']) ? strip_tags($this->unifyWhitespace($formData['account_number'])) : ''; $registration->setAccountNumber($accountNumber); $bankCode = isset($formData['bank_code']) ? strip_tags($this->unifyWhitespace($formData['bank_code'])) : ''; $registration->setBankCode($bankCode); $bankName = isset($formData['bank_name']) ? strip_tags($this->unifyWhitespace($formData['bank_name'])) : ''; $registration->setBankName($bankName); $accountOwner = isset($formData['account_owner']) ? strip_tags($this->unifyWhitespace($formData['account_owner'])) : ''; $registration->setAccountOwner($accountOwner); $company = isset($formData['company']) ? strip_tags($formData['company']) : ''; $registration->setCompany($company); $validGenderMale = (string) tx_oelib_Model_FrontEndUser::GENDER_MALE; $validGenderFemale = (string) tx_oelib_Model_FrontEndUser::GENDER_FEMALE; if (isset($formData['gender']) && ($formData['gender'] === $validGenderMale || $formData['gender'] === $validGenderFemale)) { $gender = (int) $formData['gender']; } else { $gender = tx_oelib_Model_FrontEndUser::GENDER_UNKNOWN; } $registration->setGender($gender); $name = isset($formData['name']) ? strip_tags($this->unifyWhitespace($formData['name'])) : ''; $registration->setName($name); $address = isset($formData['address']) ? strip_tags($formData['address']) : ''; $registration->setAddress($address); $zip = isset($formData['zip']) ? strip_tags($this->unifyWhitespace($formData['zip'])) : ''; $registration->setZip($zip); $city = isset($formData['city']) ? strip_tags($this->unifyWhitespace($formData['city'])) : ''; $registration->setCity($city); $country = isset($formData['country']) ? strip_tags($this->unifyWhitespace($formData['country'])) : ''; $registration->setCountry($country); }
/** * @test */ public function setAddressSetsAddress() { $this->fixture->setAddress('Main Street 123'); self::assertEquals('Main Street 123', $this->fixture->getAddress()); }