addElement('text', 'firstName', ['label' => 'First Name', 'required' => true]); $this->addElement('text', 'lastName', ['label' => 'Last Name', 'required' => true]); $this->addSubForm(new AddressForm(), AddressEntity::TYPE_CONCACT); $this->addElement('phone', 'phone', ['label' => 'Phone', 'required' => true]); $this->addElement('email', 'email', ['label' => 'Email', 'required' => true]); $this->addUniqueValidator('email', 'Email must be unique'); $minAge = (int) $this->getConfig('minAge'); $this->addElement('date', 'birthdate', [ 'label' => 'Date of Birth', 'required' => true, 'autocomplete' => 'off', 'defaultDate' => "-{$minAge}y", 'yearRange' => 'c-57:-' . $minAge, 'validators' => [ ['LessThan', true, [ 'max' => date('Y-m-d', strtotime('-' . $minAge . ' years +1 day')), 'messages' => 'Minimum allowed age is 13', ]], ], ]); return $this; } protected function addUniqueValidator($field, $message) { $uniqueValidator = new Qs_Validate_Unique(new Qs_Db_Table('User'), $field, $this->_getData('id')); $uniqueValidator->setMessage($message, Qs_Validate_Unique::NOT_UNIQUE); $uniqueValidator->setWhere('`bought` = "y"'); $this->getElement($field)->addValidator($uniqueValidator); return $this; } protected function _initMemberFields() { $this->addElement('text', 'login', ['label' => 'User Name (login)', 'required' => true]); $this->addUniqueValidator('login', 'Login must be unique'); $this->addElement('password', 'password', ['label' => 'Password', 'autocomplete' => 'off', 'required' => true]); $this->getElement('password')->addValidator('Callback', true, [[$this, 'validatePassword']]); $this->addElement('password', 'confirmPassword', [ 'label' => 'Confirm Password', 'autocomplete' => 'off', 'required' => true, ]); $this->getElement('confirmPassword')->addValidator('ConfirmPassword', true, ['password']); if (($questions = (new Qs_Db_Table('UserSecurityQuestion'))->get4Select())) { $this->addElement('select', 'securityQuestionId', [ 'label' => 'Security Question', 'multiOptions' => ['' => 'Select One'] + $questions, 'required' => true, ]); $this->addElement('text', 'securityAnswer', [ 'label' => 'Security Answer', 'required' => true, 'filters' => ['StringTrim'], ]); } return $this; } protected function _initMembershipFields() { if (!($memberships = (new Qs_Db_Table('MembershipType'))->get4Select())) { throw new Exception('Membership Types are not defined in the module config'); } $this->addElement('radio', 'membershipTypeId', [ 'label' => 'Membership', 'multiOptions' => $memberships, 'required' => true, 'value' => Entity::MEMBERSHIP_ASSOCIATE, 'disable' => [Entity::MEMBERSHIP_VIP], ]); return $this; } protected function _initBillingShippingFields() { $this->addSubForm(new AddressForm([ 'legend' => 'Billing Address', 'hasPersonName' => true, ]), AddressEntity::TYPE_BILLING); $this->addSubForm(new AddressForm([ 'legend' => 'Shipping Address', 'clearUnused' => false, 'sameAs' => ['label' => 'Same as Billing Address', 'value' => AddressEntity::TYPE_BILLING], ]), AddressEntity::TYPE_SHIPPING); return $this; } public function validatePassword($value, $context = null) { if (!empty($value) && empty($context['confirmPassword'])) { $this->getElement('confirmPassword')->setRequired()->isValid(''); $this->getElement('confirmPassword')->setErrors(['Password confirmation does not match']); } return true; } protected function _initPrizeFields() { $this->addElement('selectOther', 'shirtSize', [ 'label' => 'Shirt Size', 'required' => true, 'multiOptions' => ['' => 'Select One'] + (array) $this->getConfigArray('shirtSizes'), ]); $this->addElement('selectOther', 'shoeSize', [ 'label' => 'Shoe Size', 'required' => true, 'multiOptions' => ['' => 'Select One'] + $this->getShoeSizes(), ]); $this->addElement('selectOther', 'dressSize', [ 'label' => 'Dress Size', 'required' => true, 'multiOptions' => ['' => 'Select One'] + $this->getDressSizes(), ]); $this->addElement('select', 'nailColor', [ 'label' => 'Favorite Pageant Life Nail Polish Color', 'required' => true, 'multiOptions' => ['' => 'Select One'] + $this->getConfigArray('nailColors'), ]); return $this; } private function getShoeSizes() { $sizes = []; for ($size = 5; $size <= 11; $size += 0.5) { $sizes['' . $size] = $size; } return $sizes; } private function getDressSizes() { $sizes = []; for ($size = 2; $size <= 20; $size += 2) { $sizes['' . $size] = $size; } return $sizes; } protected function _initShowcaseInfoFields() { $this->addSeoGroup('User', 'metaTitle'); $this->addElement('text', 'subtitle', ['label' => 'Subtitle', 'required' => true]); $this->addElement( 'htmlEditor', 'introduction', [ 'label' => 'Introduction', 'toolbar' => 'Basic', 'required' => true, 'userId' => Qs_Array::get($this->getPrimaryKey(), 'id'), ] ); $this->addElement( 'extendedImage', 'photoH', [ 'label' => 'Photo Horizontal', 'resize' => $this->getConfigArray('photoH'), ] ); $this->addElement( 'extendedImage', 'photoV', [ 'label' => 'Photo Vertical', 'resize' => $this->getConfigArray('photoV'), ] ); $this->addElement( 'extendedImage', 'videoThumbnail', [ 'label' => 'Video Thumbnail', 'resize' => $this->getConfigArray('videoThumbnail'), ] ); $this->addElement( 'media', 'video', [ 'label' => 'Video', 'description' => 'If this field is left blank then the Youtube Video below (if any) will be used instead.', 'userId' => Qs_Array::get($this->getPrimaryKey(), 'id'), ] ); $this->addElement( 'text', 'youtubeVideo', [ 'label' => 'Youtube Video Url', 'filters' => ['StringTrim'], 'description' => 'Example: https://www.youtube.com/watch?v=***********', ] ); $this->getElement('youtubeVideo')->addValidator('YoutubeUrl'); return $this; } protected function _initSocialLinksFields() { $socialLinks = Obj::getSocialLinks(); foreach ($socialLinks as $socialLink) { $this->addElement( 'text', 'socialLink' . $socialLink['id'], [ 'label' => $socialLink['serviceName'] . ' Profile Link', 'validators' => ['Url'], 'description' => 'Example: ' . $socialLink['exampleLink'], ] ); } return $this; } public static function parseYoutubeVideoId($url) { if (empty($url)) { return false; } $pattern = '/^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/'; $matches = []; if (preg_match($pattern, $url, $matches)) { return $matches[1]; } return false; } }