1 | <?php
|
---|
2 |
|
---|
3 | require_once( BX_DIRECTORY_PATH_CLASSES . 'BxDolProfileFields.php' );
|
---|
4 | require_once( BX_DIRECTORY_PATH_CLASSES . 'BxDolEmailTemplates.php' );
|
---|
5 |
|
---|
6 | function getMatchFields()
|
---|
7 | {
|
---|
8 | $oDb = new BxDolDb();
|
---|
9 | return $oDb->fromCache('sys_profile_fields', 'getAllWithKey',
|
---|
10 | 'SELECT `ID`, `Name`, `MatchField`, `MatchPercent` FROM `sys_profile_fields` WHERE `MatchPercent` > 0', 'ID');
|
---|
11 | }
|
---|
12 |
|
---|
13 | function getMatchProfiles($iProfileId, $bForce = false, $sSort = 'none')
|
---|
14 | {
|
---|
15 | $aResult = array();
|
---|
16 |
|
---|
17 | if (!getParam('enable_match'))
|
---|
18 | return $aResult;
|
---|
19 |
|
---|
20 | $oDb = new BxDolDb();
|
---|
21 |
|
---|
22 | if (!(int)$iProfileId)
|
---|
23 | return $iResult;
|
---|
24 |
|
---|
25 | if (!$bForce)
|
---|
26 | {
|
---|
27 | $aMatch = $oDb->getRow("SELECT `profiles_match` FROM `sys_profiles_match` WHERE `profile_id` = $iProfileId AND `sort` = '$sSort'");
|
---|
28 | if (!empty($aMatch))
|
---|
29 | return unserialize($aMatch['profiles_match']);
|
---|
30 | }
|
---|
31 | else
|
---|
32 | $oDb->query("DELETE FROM `sys_profiles_match` WHERE `profile_id` = $iProfileId");
|
---|
33 |
|
---|
34 | $aProf = getProfileInfo($iProfileId);
|
---|
35 |
|
---|
36 | if (empty($aProf))
|
---|
37 | return $iResult;
|
---|
38 |
|
---|
39 | $aMathFields = getMatchFields();
|
---|
40 | $iAge = (int)$oDb->getOne("SELECT DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(), '{$aProf['DateOfBirth']}')), '%Y') + 0 AS age");
|
---|
41 |
|
---|
42 | foreach ($aMathFields as $sKey => $aFields)
|
---|
43 | {
|
---|
44 | $aMathFields[$sKey]['profiles'] = array();
|
---|
45 |
|
---|
46 | if ($aProf[$aFields['Name']])
|
---|
47 | {
|
---|
48 | if ($aMathFields[$aFields['MatchField']]['Name'] == 'DateOfBirth')
|
---|
49 | {
|
---|
50 | if ($iAge)
|
---|
51 | $sCond = "(DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(), `DateOfBirth`)), '%Y') + 0) = $iAge";
|
---|
52 | }
|
---|
53 | else
|
---|
54 | $sCond = "`{$aMathFields[$aFields['MatchField']]['Name']}` = '" .
|
---|
55 | process_db_input($aProf[$aFields['Name']], BX_TAGS_NO_ACTION, BX_SLASHES_NO_ACTION) . "'";
|
---|
56 |
|
---|
57 | $aMathFields[$sKey]['profiles'] = $oDb->getAllWithKey("SELECT `ID` FROM `Profiles` WHERE `Status` = 'Active' AND `ID` != $iProfileId AND $sCond", 'ID');
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 | $sCondSort = '';
|
---|
62 | if ($sSort == 'activity')
|
---|
63 | $sCondSort = 'ORDER BY `DateLastNav` DESC';
|
---|
64 | else if ($sSort == 'date_reg')
|
---|
65 | $sCondSort = 'ORDER BY `DateReg` DESC';
|
---|
66 |
|
---|
67 | $aProfiles = $oDb->getColumn("SELECT `ID` FROM `Profiles` WHERE `Status` = 'Active' AND `ID` != $iProfileId $sCondSort");
|
---|
68 | foreach ($aProfiles as $iProfId)
|
---|
69 | {
|
---|
70 | $iPercent = 0;
|
---|
71 |
|
---|
72 | foreach ($aMathFields as $sKey => $aFields)
|
---|
73 | {
|
---|
74 | if (isset($aFields['profiles'][$iProfId]))
|
---|
75 | $iPercent += (int)$aFields['MatchPercent'];
|
---|
76 | }
|
---|
77 |
|
---|
78 | if ($iPercent >= getParam('match_percent'))
|
---|
79 | $aResult[] = $iProfId;
|
---|
80 | }
|
---|
81 |
|
---|
82 | $oDb->query("INSERT INTO `sys_profiles_match`(`profile_id`, `sort`, `profiles_match`) VALUES($iProfileId, '$sSort', '" .
|
---|
83 | serialize($aResult) . "')");
|
---|
84 |
|
---|
85 | return $aResult;
|
---|
86 | }
|
---|
87 |
|
---|
88 | function getProfilesMatch( $iPID1 = 0, $iPID2 = 0 )
|
---|
89 | {
|
---|
90 | $iPID1 = (int)$iPID1;
|
---|
91 | $iPID2 = (int)$iPID2;
|
---|
92 |
|
---|
93 | if( !$iPID1 or !$iPID2 )
|
---|
94 | return 0;
|
---|
95 |
|
---|
96 | if( $iPID1 == $iPID2 )
|
---|
97 | return 0;
|
---|
98 |
|
---|
99 | $aProf1 = getProfileInfo($iPID1);
|
---|
100 | $aProf2 = getProfileInfo($iPID2);
|
---|
101 |
|
---|
102 | if(empty($aProf1) || empty($aProf2))
|
---|
103 | return 0;
|
---|
104 |
|
---|
105 | $iMatch = 0;
|
---|
106 | $aMathFields = getMatchFields();
|
---|
107 |
|
---|
108 | foreach ($aMathFields as $sKey => $aFields)
|
---|
109 | {
|
---|
110 | $bRes = false;
|
---|
111 |
|
---|
112 | if ($aProf1[$aFields['Name']])
|
---|
113 | {
|
---|
114 | if ($aMathFields[$aFields['MatchField']]['Name'] == 'DateOfBirth')
|
---|
115 | $bRes = age($aProf1['DateOfBirth']) == age($aProf2['DateOfBirth']);
|
---|
116 | else
|
---|
117 | $bRes = $aProf1[$aFields['Name']] == $aProf2[$aMathFields[$aFields['MatchField']]['Name']];
|
---|
118 | }
|
---|
119 |
|
---|
120 | if ($bRes)
|
---|
121 | $iMatch += (int)$aFields['MatchPercent'];
|
---|
122 | }
|
---|
123 |
|
---|
124 | return $iMatch;
|
---|
125 | }
|
---|
126 |
|
---|
127 | ?> |
---|