Skip to content

How to add additional genders

β™š PH⑦ de Soriaβ„’β™› edited this page Jun 1, 2020 · 1 revision

How to add genders. In this example we add transsexual, female couple, male couple and transsexual couple. You can add what ever you like by changing the gender types used in this example.

1. Database

Note: Replace <REPLACE> with the correct credentials for your database.

Using the cmd line run

mysql -u <DB_USER> -p

<DB_PASSWORD>

use <DB_NAME>;

ALTER TABLE `<DB_PREFIX>_members` CHANGE `sex` `sex` ENUM('male','female','couple','transsexual','female_couple','male_couple','transsexual_couple') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'female';

ALTER TABLE `<DB_PREFIX>_members` CHANGE `matchSex` `matchSex` SET('male','female','couple','transsexual','female_couple','male_couple','transsexual_couple') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'male';

exit;

2. Changes in GenderTypeUserCore.php

_protected/app/system/core/classes/GenderTypeUserCore.php
    const CONSIDER_COUPLE_GENDER = true;
    const IGNORE_COUPLE_GENDER = false;

    const FEMALE = 'female';
    const MALE = 'male';
    const COUPLE = 'couple';
    const TRANSSEXUAL = 'transsexual';
    const FEMALECOUPLE = 'female_couple';
    const MALECOUPLE = 'male_couple';
    const TRANSSEXUALCOUPLE = 'transsexual_couple';

    const GENDERS = [
        self::FEMALE => self::FEMALE,
        self::MALE => self::MALE,
        self::COUPLE => self::COUPLE,
        self::TRANSSEXUAL => self::TRANSSEXUAL,
        self::FEMALECOUPLE => self::FEMALECOUPLE,
        self::MALECOUPLE => self::MALECOUPLE,
        self::TRANSSEXUALCOUPLE => self::TRANSSEXUALCOUPLE
    ];

3. Changes in JoinForm.php

_protected/app/system/modules/user/forms/JoinForm.php 
$oForm->addElement(
            new \PFBC\Element\Radio(
                t('I am a'),
                'sex',
                [
                    GenderTypeUserCore::FEMALE => 'πŸ‘© ' . t('Woman'),
                    GenderTypeUserCore::MALE => 'πŸ‘¨ ' . t('Man'),
                    GenderTypeUserCore::COUPLE => 'πŸ’‘ ' . t('Couple'),
                    GenderTypeUserCore::TRANSSEXUAL => 'πŸ‘¨ ' . t('Transsexual'),
                    GenderTypeUserCore::FEMALECOUPLE => 'πŸ’‘ ' . t('Female Couple'),
                    GenderTypeUserCore::MALECOUPLE => 'πŸ’‘ ' . t('Male Couple'),
                    GenderTypeUserCore::TRANSSEXUALCOUPLE => 'πŸ’‘ ' . t('Transsexual Couple')

                ],
                ['value' => GenderTypeUserCore::FEMALE, 'required' => 1]
            )
        );

        $oForm->addElement(
            new \PFBC\Element\Checkbox(
                t('Looking for a'),
                'match_sex',
                [
                    GenderTypeUserCore::MALE => 'πŸ‘¨ ' . t('Man'),
                    GenderTypeUserCore::FEMALE => 'πŸ‘© ' . t('Woman'),
                    GenderTypeUserCore::COUPLE => 'πŸ’‘ ' . t('Couple'),
                    GenderTypeUserCore::TRANSSEXUAL => 'πŸ‘¨ ' . t('Transsexual'),
                    GenderTypeUserCore::FEMALECOUPLE => 'πŸ’‘ ' . t('Female Couple'),
                    GenderTypeUserCore::MALECOUPLE => 'πŸ’‘ ' . t('Male Couple'),
                    GenderTypeUserCore::TRANSSEXUALCOUPLE => 'πŸ’‘ ' . t('Transsexual Couple')
                ],
                ['value' => GenderTypeUserCore::MALE, 'required' => 1]
            )
        );

4. Changes in UserCoreModel.php (LINE:1653)

_protected/app/system/core/models/UserCoreModel.php

 private function getSexInClauseSql(array $aSex)
    {
        $sGender = '';

        foreach ($aSex as $sSex) {
            if ($sSex === GenderTypeUserCore::MALE) {
                $sGender .= "'" . GenderTypeUserCore::MALE . "',";
            }

            if ($sSex === GenderTypeUserCore::FEMALE) {
                $sGender .= "'" . GenderTypeUserCore::FEMALE . "',";
            }

            if ($sSex === GenderTypeUserCore::COUPLE) {
                $sGender .= "'" . GenderTypeUserCore::COUPLE . "',";
            }
            
            if ($sSex === GenderTypeUserCore::TRANSSEXUAL) {
                $sGender .= "'" . GenderTypeUserCore::TRANSSEXUAL . "',";
            }
            
            if ($sSex === GenderTypeUserCore::FEMALECOUPLE) {
                $sGender .= "'" . GenderTypeUserCore::FEMALECOUPLE . "',";
            }
            
            if ($sSex === GenderTypeUserCore::MALECOUPLE) {
                $sGender .= "'" . GenderTypeUserCore::MALECOUPLE . "',";
            }
            
            if ($sSex === GenderTypeUserCore::TRANSSEXUALCOUPLE) {
                $sGender .= "'" . GenderTypeUserCore::TRANSSEXUALCOUPLE . "',";
            }
            
        }

        $sInClauseValue = rtrim($sGender, ','); // Removes the last extra comma

        if (!empty($sInClauseValue)) {
            return ' AND sex IN (' . $sInClauseValue . ') ';
        }

        return '';
    }

5. Changes in SearchUserCoreForm.php

_protected/app/system/core/forms/SearchUserCoreForm.php
public static function quick($iWidth = null, $bSetDefVals = true)
    {
        if ($bSetDefVals) {
            self::setAttrVals();
        }

        // Generate the Quick Search form
        $oForm = new \PFBC\Form('form_search', $iWidth);
        $oForm->configure(['action' => Uri::get('user', 'browse', 'index') . PH7_SH, 'method' => 'get']);
        $oForm->addElement(new \PFBC\Element\Hidden('submit_search', 'form_search'));
        $oForm->addElement(
            new \PFBC\Element\Select(
                t('I am a:'),
                SearchQueryCore::MATCH_SEX,
                [
                    GenderTypeUserCore::MALE => t('πŸ‘¨ Man'),
                    GenderTypeUserCore::FEMALE => t('πŸ‘© Woman'),
                    GenderTypeUserCore::COUPLE => t('πŸ’‘ Couple'),
                    GenderTypeUserCore::TRANSSEXUAL => 'πŸ‘¨ ' . t('Transsexual'),
                    GenderTypeUserCore::FEMALECOUPLE => 'πŸ’‘ ' . t('Female Couple'),
                    GenderTypeUserCore::MALECOUPLE => 'πŸ’‘ ' . t('Male Couple'),
                    GenderTypeUserCore::TRANSSEXUALCOUPLE => 'πŸ’‘ ' . t('Transsexual Couple')
                ],
                self::$aSexOption
            )
        );
        $oForm->addElement(
            new \PFBC\Element\Checkbox(
                t('Looking for a:'),
                SearchQueryCore::SEX,
                [
                    GenderTypeUserCore::MALE => t('πŸ‘¨ Man'),
                    GenderTypeUserCore::FEMALE => t('πŸ‘© Woman'),
                    GenderTypeUserCore::COUPLE => t('πŸ’‘ Couple'),
                    GenderTypeUserCore::TRANSSEXUAL => 'πŸ‘¨ ' . t('Transsexual'),
                    GenderTypeUserCore::FEMALECOUPLE => 'πŸ’‘ ' . t('Female Couple'),
                    GenderTypeUserCore::MALECOUPLE => 'πŸ’‘ ' . t('Male Couple'),
                    GenderTypeUserCore::TRANSSEXUALCOUPLE => 'πŸ’‘ ' . t('Transsexual Couple')
                ],
                self::$aMatchSexOption
            )
        );
        $oForm->addElement(new \PFBC\Element\Age(self::$aAgeOption));
        $oForm->addElement(new \PFBC\Element\Select(t('Country:'), SearchQueryCore::COUNTRY, Form::getCountryValues(), self::$aCountryOption));
        $oForm->addElement(new \PFBC\Element\Textbox(t('City:'), SearchQueryCore::CITY, self::$aCityOption));
        $oForm->addElement(new \PFBC\Element\Checkbox('', SearchQueryCore::ORDER, [SearchCoreModel::LATEST => '<span class="bold">' . t('Latest members') . '</span>'], self::$aLatestOrder));
        $oForm->addElement(new \PFBC\Element\Checkbox('', SearchQueryCore::AVATAR, ['1' => '<span class="bold">' . t('Only with Avatar') . '</span>'], self::$aAvatarOnly));
        $oForm->addElement(new \PFBC\Element\Checkbox('', SearchQueryCore::ONLINE, ['1' => '<span class="bold green2">' . t('Only Online') . '</span>'], self::$aOnlineOnly));
        $oForm->addElement(new \PFBC\Element\Button(t('Search'), 'submit', ['icon' => 'search']));
        $oForm->addElement(new \PFBC\Element\HTMLExternal('<p class="center"><a href="' . Uri::get('user', 'search', 'advanced') . '">' . t('Advanced Search') . '</a></p>'));
        $oForm->addElement(new \PFBC\Element\HTMLExternal('<script src="' . PH7_URL_STATIC . PH7_JS . 'geo/autocompleteCity.js"></script>'));
        $oForm->render();
    }

    /**
     * @param int $iWidth Width of the form in pixel. If null, will be 100%
     * @param bool $bSetDefVals Set default values in the form fields, or not...
     *
     * @return void HTML output.
     */
    public static function advanced($iWidth = null, $bSetDefVals = true)
    {
        if ($bSetDefVals) {
            self::setAttrVals();
        }

        // Generate the Advanced Search form
        $oForm = new \PFBC\Form('form_search', $iWidth);
        $oForm->configure(['action' => Uri::get('user', 'browse', 'index') . PH7_SH, 'method' => 'get']);
        $oForm->addElement(new \PFBC\Element\Hidden('submit_search', 'form_search'));
        $oForm->addElement(
            new \PFBC\Element\Select(
                t('I am a:'),
                SearchQueryCore::MATCH_SEX,
                [
                    GenderTypeUserCore::MALE => t('πŸ‘¨ Man'),
                    GenderTypeUserCore::FEMALE => t('πŸ‘© Woman'),
                    GenderTypeUserCore::COUPLE => t('πŸ’‘ Couple'),
                    GenderTypeUserCore::TRANSSEXUAL => 'πŸ‘¨ ' . t('Transsexual'),
                    GenderTypeUserCore::FEMALECOUPLE => 'πŸ’‘ ' . t('Female Couple'),
                    GenderTypeUserCore::MALECOUPLE => 'πŸ’‘ ' . t('Male Couple'),
                    GenderTypeUserCore::TRANSSEXUALCOUPLE => 'πŸ’‘ ' . t('Transsexual Couple')
                ],
                self::$aSexOption
            )
        );
        $oForm->addElement(
            new \PFBC\Element\Checkbox(
                t('Looking for:'),
                SearchQueryCore::SEX,
                [
                    GenderTypeUserCore::MALE => t('πŸ‘¨ Man'),
                    GenderTypeUserCore::FEMALE => t('πŸ‘© Woman'),
                    GenderTypeUserCore::COUPLE => t('πŸ’‘ Couple'),
                    GenderTypeUserCore::TRANSSEXUAL => 'πŸ‘¨ ' . t('Transsexual'),
                    GenderTypeUserCore::FEMALECOUPLE => 'πŸ’‘ ' . t('Female Couple'),
                    GenderTypeUserCore::MALECOUPLE => 'πŸ’‘ ' . t('Male Couple'),
                    GenderTypeUserCore::TRANSSEXUALCOUPLE => 'πŸ’‘ ' . t('Transsexual Couple')
                ],
                self::$aMatchSexOption
            )
        );
        $oForm->addElement(new \PFBC\Element\Age(self::$aAgeOption));
        $oForm->addElement(new \PFBC\Element\Select(t('Country:'), SearchQueryCore::COUNTRY, Form::getCountryValues(), self::$aCountryOption));
        $oForm->addElement(new \PFBC\Element\Textbox(t('City:'), SearchQueryCore::CITY, self::$aCityOption));
        $oForm->addElement(new \PFBC\Element\Textbox(t('State/Province:'), SearchQueryCore::STATE, self::$aStateOption));
        $oForm->addElement(new \PFBC\Element\Textbox(t('Postal Code:'), SearchQueryCore::ZIP_CODE, ['id' => 'str_zip_code']));
        $oForm->addElement(new \PFBC\Element\Email(t('Email Address:'), SearchQueryCore::EMAIL));
        $oForm->addElement(new \PFBC\Element\Checkbox('', SearchQueryCore::AVATAR, ['1' => '<span class="bold">' . t('Only with Avatar') . '</span>']));
        $oForm->addElement(new \PFBC\Element\Checkbox('', SearchQueryCore::ONLINE, ['1' => '<span class="bold green2">' . t('Only Online') . '</span>']));
        $oForm->addElement(
            new \PFBC\Element\Select(
                t('Browse By:'),
                SearchQueryCore::ORDER,
                [
                    SearchCoreModel::LATEST => t('Latest Members'),
                    SearchCoreModel::LAST_ACTIVITY => t('Last Activity'),
                    SearchCoreModel::VIEWS => t('Most Popular'),
                    SearchCoreModel::RATING => t('Top Rated'),
                    SearchCoreModel::USERNAME => t('Username'),
                    SearchCoreModel::FIRST_NAME => t('First Name'),
                    SearchCoreModel::LAST_NAME => t('Last Name'),
                    SearchCoreModel::EMAIL => t('Email')
                ]
            )
        );
        $oForm->addElement(
            new \PFBC\Element\Select(
                t('Direction:'),
                SearchQueryCore::SORT,
                [
                    SearchCoreModel::DESC => t('Descending'),
                    SearchCoreModel::ASC => t('Ascending')
                ]
            )
        );
        $oForm->addElement(new \PFBC\Element\Button(t('Search'), 'submit', ['icon' => 'search'])));
        $oForm->addElement(new \PFBC\Element\HTMLExternal('<script src="' . PH7_URL_STATIC . PH7_JS . 'geo/autocompleteCity.js"></script>'));
        $oForm->render();
    }

    /**
     * If a user is logged, get the relative 'user_sex' and 'match_sex' for better and more intuitive search.
     *
     * @param UserCoreModel $oUserModel
     * @param Session $oSession
     *
     * @return array The 'user_sex' and 'match_sex'
     */
    protected static function getGenderVals(UserCoreModel $oUserModel, Session $oSession)
    {
        $sUserSex = GenderTypeUserCore::MALE;
        $aMatchSex = [
            GenderTypeUserCore::MALE,
            GenderTypeUserCore::FEMALE,
            GenderTypeUserCore::COUPLE,
            GenderTypeUserCore::TRANSSEXUAL,
            GenderTypeUserCore::FEMALECOUPLE,
            GenderTypeUserCore::MALECOUPLE,
            GenderTypeUserCore::TRANSSEXUALCOUPLE
        ];

        if (UserCore::auth()) {
            $sUserSex = $oUserModel->getSex($oSession->get('member_id'));
            $aMatchSex = Form::getVal($oUserModel->getMatchSex($oSession->get('member_id')));
        }

        return ['user_sex' => $sUserSex, 'match_sex' => $aMatchSex];
    }

6. Upload Icons

/templates/themes/clubhouse/img/icon/

You will also need to upload icons for the default images should the user not upload one. The easiest way to do this is to copy the existing icons and rename them. You MUST name them the same as the genders you have added and don't use spaces.

transsexual_no_picture.svg
transsexual_no_picture-32.svg
transsexual_no_picture-64.svg
transsexual_no_picture-100.svg
transsexual_no_picture-200.svg
transsexual_no_picture-400.svg

female_couple_no_picture.svg
female_couple_no_picture-32.svg
female_couple_no_picture-64.svg
female_couple_no_picture-100.svg
female_couple_no_picture-200.svg
female_couple_no_picture-400.svg

male_couple_no_picture.svg
male_couple_no_picture-32.svg
male_couple_no_picture-64.svg
male_couple_no_picture-100.svg
male_couple_no_picture-200.svg
male_couple_no_picture-400.svg

transsexual_couple_no_picture.svg
transsexual_couple_no_picture-32.svg
transsexual_couple_no_picture-64.svg
transsexual_couple_no_picture-100.svg
transsexual_couple_no_picture-200.svg
transsexual_couple_no_picture-400.svg

Do this for each gender added.

7. Changes in EditForm.php

_protected/app/system/modules/user/forms/EditForm.php
 $oForm->addElement(
                new \PFBC\Element\Radio(
                    t('Gender:'),
                    'sex',
                    [
                        GenderTypeUserCore::FEMALE => t('Woman'),
                        GenderTypeUserCore::MALE => t('Man'),
                        GenderTypeUserCore::COUPLE => t('Couple'),
                        GenderTypeUserCore::TRANSSEXUAL => t('Transsexual'),
                        GenderTypeUserCore::FEMALECOUPLE => t('Female Couple'),
                        GenderTypeUserCore::MALECOUPLE => t('Male Couple'),
                        GenderTypeUserCore::TRANSSEXUALCOUPLE => t('Transsexual Couple')
                    ],
                    [
                        'value' => $oUser->sex,
                        'required' => 1
                    ]
                )
            );
        }

        $oForm->addElement(
            new \PFBC\Element\Checkbox(
                t('Looking for a:'),
                'match_sex',
                [
                    GenderTypeUserCore::FEMALE => t('Woman'),
                    GenderTypeUserCore::MALE => t('Man'),
                    GenderTypeUserCore::COUPLE => t('Couple'),
                    GenderTypeUserCore::TRANSSEXUAL => t('Transsexual'),
                    GenderTypeUserCore::FEMALECOUPLE => t('Female Couple'),
                    GenderTypeUserCore::MALECOUPLE => t('Male Couple'),
                    GenderTypeUserCore::TRANSSEXUALCOUPLE => t('Transsexual Couple')
                ],
                ['value' => Form::getVal($oUser->matchSex), 'required' => 1]
            )
        );

NOTE: PAY CLOSE ATTENTION TO COMMAS , WHEN YOU ADD THE EXTRA LINES OF CODE