Last active
April 6, 2018 15:53
-
-
Save levelsio/46f6c342ec03cd9013bb72e1f45caf9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
code to match for dating | |
these are BOOLEAN values | |
match_gender = the gender of the user itself | |
match_target_gender = the gender of the target user | |
if match_gender_male = true it means the user is a male | |
if match_target_gender_male = true it means the user is looking for a male | |
I need to match for example: | |
User is a female that likes male, target user is a male that likes female | |
User is a male that likes male, target user is a male that likes male | |
etc. | |
I think my current code has some bugs, it seems to match for example target female that likes male with male that likes male, can u help me? | |
*/ | |
if( | |
( | |
($user['match_target_gender_male'] && $targetUser['match_target_gender_male'] && $user['match_gender_male']) || | |
($user['match_target_gender_female'] && $targetUser['match_target_gender_female'] && $user['match_gender_female']) || | |
($user['match_target_gender_trans'] && $targetUser['match_target_gender_trans'] && $user['match_gender_trans']) || | |
($user['match_target_gender_other'] && $targetUser['match_target_gender_other'] && $user['match_gender_other']) || | |
($user['match_target_gender_male'] && $user['match_target_gender_male'] && $targetUser['match_gender_male']) || | |
($user['match_target_gender_female'] && $user['match_target_gender_female'] && $targetUser['match_gender_female']) || | |
($user['match_target_gender_trans'] && $user['match_target_gender_trans'] && $targetUser['match_gender_trans']) || | |
($user['match_target_gender_other'] && $user['match_target_gender_other'] && $targetUser['match_gender_other'])) | |
) | |
&& | |
( | |
($user['match_want_relationship'] && $targetUser['match_want_relationship']) || | |
($user['match_want_casual'] && $targetUser['match_want_casual']) || | |
($user['match_want_open'] && $targetUser['match_want_open'])) | |
) | |
) { | |
$isRomanticMatch=true; | |
} |
If you consider refactoring how you're structuring the data like this:
$user['match_target_relationship'] = "open"
$user['match_gender'] = "male"
$user['match_target_genders'] = ["male", "female"]
(assuming people can have multiple target genders)
Then you can simplify it:
/*
if we both want same relationship AND they want my gender AND I want their gender => ❤️
*/
if (
$user['match_target_relationship'] == $targetUser['match_target_relationship'] &&
in_array($user['match_gender'], $targetUser['match_target_genders']) &&
in_array($targetUser['match_gender'], $user['match_target_genders'])
) {
$isRomanticMatch = true;
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is some kind of decorator for User's with Match capabilities. One could take the logic out of wantTheSame & compatibleTarget if you don't want the classes. But I think this improves readability a lot.
Put some simple test at the end of the class.
I don't know why your conditions are something like:
user['match_target_gender_male'] && $targetUser['match_target_gender_male'] && $user['match_gender_male']
When I see what I want and what is my target sex, my own sex doesn't matters (see compatibleTarget method). So, you only need to check if target is compatible with my preferences and if I'm compatible with target preferences.