1 | <?php
|
---|
2 |
|
---|
3 | /***************************************************************************
|
---|
4 | * Dolphin Smart Community Builder
|
---|
5 | * -----------------
|
---|
6 | * begin : Mon Mar 23 2006
|
---|
7 | * copyright : (C) 2006 BoonEx Group
|
---|
8 | * website : http://www.boonex.com/
|
---|
9 | * This file is part of Dolphin - Smart Community Builder
|
---|
10 | *
|
---|
11 | * Dolphin is free software. This work is licensed under a Creative Commons Attribution 3.0 License.
|
---|
12 | * http://creativecommons.org/licenses/by/3.0/
|
---|
13 | *
|
---|
14 | * Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
---|
15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
---|
16 | * See the Creative Commons Attribution 3.0 License for more details.
|
---|
17 | * You should have received a copy of the Creative Commons Attribution 3.0 License along with Dolphin,
|
---|
18 | * see license.txt file; if not, write to marketing@boonex.com
|
---|
19 | ***************************************************************************/
|
---|
20 |
|
---|
21 | require_once(BX_DIRECTORY_PATH_CLASSES . 'BxDolPageView.php');
|
---|
22 |
|
---|
23 | class BxDolBrowse extends BxDolPageView
|
---|
24 | {
|
---|
25 | // consist path to cache ;
|
---|
26 | var $sCacheFilePath;
|
---|
27 |
|
---|
28 | // consit all member's information ;
|
---|
29 | var $aMembersInfo;
|
---|
30 |
|
---|
31 | // consit all Date of birth range ;
|
---|
32 | var $aDateBirthRange;
|
---|
33 |
|
---|
34 | // consit all Sex ranges ;
|
---|
35 | var $aSexRange;
|
---|
36 |
|
---|
37 | // consit all Sex ranges ;
|
---|
38 | var $aCountryRange;
|
---|
39 |
|
---|
40 | // consist true value if isset permalink mode ;
|
---|
41 | var $bPermalinkMode;
|
---|
42 |
|
---|
43 | // need for array searching ;
|
---|
44 | var $sKeyName;
|
---|
45 |
|
---|
46 | var $iMemberOnlineTime;
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * @description : class constructor ;
|
---|
50 | */
|
---|
51 |
|
---|
52 | function BxDolBrowse()
|
---|
53 | {
|
---|
54 | global $aPreValues;
|
---|
55 |
|
---|
56 | $this -> sCacheFilePath = BX_DIRECTORY_PATH_DBCACHE . 'sys_browse_peoples.inc';
|
---|
57 |
|
---|
58 | // read data from cache file ;
|
---|
59 |
|
---|
60 | if ( file_exists($this -> sCacheFilePath ) ) {
|
---|
61 | $this -> aMembersInfo = unserialize( file_get_contents($this -> sCacheFilePath) );
|
---|
62 | }
|
---|
63 |
|
---|
64 | // fill aDateBirthRange array ;
|
---|
65 | $iStartDate = getParam('search_start_age');
|
---|
66 | $iLastDate = getParam('search_end_age');
|
---|
67 |
|
---|
68 | // fill date of birth array
|
---|
69 | while ( $iStartDate <= $iLastDate )
|
---|
70 | {
|
---|
71 | $this -> aDateBirthRange[$iStartDate . '-' . ($iStartDate + 2)] = 0;
|
---|
72 | $iStartDate +=3;
|
---|
73 | }
|
---|
74 |
|
---|
75 | // check permalink mode ;
|
---|
76 |
|
---|
77 | $this -> bPermalinkMode = ( getParam('permalinks_browse') )
|
---|
78 | ? true
|
---|
79 | : false;
|
---|
80 |
|
---|
81 | // check member on line time ;
|
---|
82 |
|
---|
83 | $this -> iMemberOnlineTime = getParam( "member_online_time" );
|
---|
84 |
|
---|
85 | // fill sex array ;
|
---|
86 | ksort($aPreValues['Sex'], SORT_STRING);
|
---|
87 | foreach( $aPreValues['Sex'] AS $sKey => $aItems )
|
---|
88 | {
|
---|
89 | $this -> aSexRange[$sKey] = 0;
|
---|
90 | }
|
---|
91 |
|
---|
92 | // fill country array ;
|
---|
93 | ksort($aPreValues['Country'], SORT_STRING);
|
---|
94 | foreach( $aPreValues['Country'] AS $sKey => $aItems )
|
---|
95 | {
|
---|
96 | $this -> aCountryRange[$sKey] = 0;
|
---|
97 | }
|
---|
98 |
|
---|
99 | }
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * @description : function will return count of male and female;
|
---|
103 | * @param : $PrimaryQuery (string) - additional sql query;
|
---|
104 | * @return : Array hash with `sex` list;
|
---|
105 | */
|
---|
106 |
|
---|
107 | function getSexCount( $PrimaryQuery )
|
---|
108 | {
|
---|
109 | foreach( $this -> aSexRange AS $sKey => $sValue )
|
---|
110 | {
|
---|
111 | $sWhereParam = " AND `Sex` = '{$sKey}' ";
|
---|
112 | $iCount = db_value( $PrimaryQuery . $sWhereParam );
|
---|
113 |
|
---|
114 | if ( $iCount )
|
---|
115 | $aSexArray[$sKey] = $iCount;
|
---|
116 | }
|
---|
117 |
|
---|
118 | return $aSexArray;
|
---|
119 | }
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * @description : function will return count of age ranges;
|
---|
123 | * @param : $PrimaryQuery (string) - additional sql query;
|
---|
124 | * @return : Array hash with `ages` list;
|
---|
125 | */
|
---|
126 |
|
---|
127 | function getAgesCount( $PrimaryQuery )
|
---|
128 | {
|
---|
129 | $aAgeArray = array();
|
---|
130 |
|
---|
131 | foreach( $this -> aDateBirthRange AS $sKey => $sValue )
|
---|
132 | {
|
---|
133 | $sWhereParam = null;
|
---|
134 |
|
---|
135 | $aDateRange = explode('-', $sKey);
|
---|
136 |
|
---|
137 | $iFrom = $aDateRange[0];
|
---|
138 | $iTo = $aDateRange[1];
|
---|
139 |
|
---|
140 | $sWhereParam .=
|
---|
141 | "
|
---|
142 | AND
|
---|
143 | ((YEAR(CURDATE())-YEAR(`DateOfBirth`)) - (RIGHT(CURDATE(),5)<RIGHT(`DateOfBirth`,5))) >= {$iFrom}
|
---|
144 | AND
|
---|
145 | ((YEAR(CURDATE())-YEAR(`DateOfBirth`)) - (RIGHT(CURDATE(),5)<RIGHT(`DateOfBirth`,5))) <= {$iTo}
|
---|
146 | ";
|
---|
147 |
|
---|
148 | $iCount = db_value( $PrimaryQuery . $sWhereParam);
|
---|
149 | if ( $iCount ) {
|
---|
150 | $aAgeArray[$sKey] = $iCount;
|
---|
151 | }
|
---|
152 | }
|
---|
153 |
|
---|
154 | return $aAgeArray;
|
---|
155 | }
|
---|
156 |
|
---|
157 | /**
|
---|
158 | * @description : function will return count of mens into counries;
|
---|
159 | * @param : $PrimaryQuery (string) - additional sql query;
|
---|
160 | * @return : Array with `countries` list;
|
---|
161 | */
|
---|
162 |
|
---|
163 | function getCountriesCount( $PrimaryQuery )
|
---|
164 | {
|
---|
165 | $aCountryArray = null;
|
---|
166 |
|
---|
167 | foreach( $this -> aCountryRange AS $sKey => $sValue )
|
---|
168 | {
|
---|
169 | $sWhereParam = " AND `Country` = '{$sKey}' ";
|
---|
170 | $iCount = db_value( $PrimaryQuery . $sWhereParam );
|
---|
171 |
|
---|
172 | if ( $iCount )
|
---|
173 | $aCountryArray[$sKey] = $iCount;
|
---|
174 | }
|
---|
175 |
|
---|
176 | return $aCountryArray;
|
---|
177 | }
|
---|
178 |
|
---|
179 | /**
|
---|
180 | * @description : function will generate array with all global statistics ;
|
---|
181 | * @param : $sSex (string) human's sex ;
|
---|
182 | * @param : $sAge (string) human's age range (possibility format - '15-60' ) ;
|
---|
183 | * @param : $sCountry (string) human's country ( use ISO2 format ) ;
|
---|
184 | * @param : $sPhoto (string) if isset user's primary photo;
|
---|
185 | * @param : $sOnline (string) if user online ;
|
---|
186 | * @param : $sType (string) set specific type of member information ;
|
---|
187 | * @return : array ;
|
---|
188 | */
|
---|
189 |
|
---|
190 | function getGlobalStatistics( $sSex = null, $sAge = null, $sCountry = null, $sPhoto = null, $sOnline = null, $sType = null )
|
---|
191 | {
|
---|
192 | $sCurrentKey = ( $this -> sKeyName )
|
---|
193 | ? $this -> sKeyName
|
---|
194 | : 'public';
|
---|
195 |
|
---|
196 | $aSexArray = $aAgeArray = $aCountryArray = array();
|
---|
197 |
|
---|
198 | // collect the SQL queries ;
|
---|
199 |
|
---|
200 | $sWhereParam = null;
|
---|
201 | $sWhereParam .= ( $sSex )
|
---|
202 | ? " AND `Sex` = '{$sSex}' "
|
---|
203 | : null;
|
---|
204 |
|
---|
205 | $sWhereParam .= ( $sCountry )
|
---|
206 | ? " AND `Country` = '{$sCountry}' "
|
---|
207 | : null;
|
---|
208 |
|
---|
209 | if ( $sAge )
|
---|
210 | {
|
---|
211 |
|
---|
212 | $aDateRange = explode('-', $sAge);
|
---|
213 |
|
---|
214 | $iFrom = $aDateRange[0] - 1;
|
---|
215 | $iTo = $aDateRange[1];
|
---|
216 |
|
---|
217 | unset($aDateRange);
|
---|
218 |
|
---|
219 | if ( !$iFrom or !$iTo )
|
---|
220 | return null;
|
---|
221 |
|
---|
222 | $sWhereParam .=
|
---|
223 | "
|
---|
224 | AND
|
---|
225 | ((YEAR(CURDATE())-YEAR(`DateOfBirth`)) - (RIGHT(CURDATE(),5)<RIGHT(`DateOfBirth`,5))) >= {$iFrom}
|
---|
226 | AND
|
---|
227 | ((YEAR(CURDATE())-YEAR(`DateOfBirth`)) - (RIGHT(CURDATE(),5)<RIGHT(`DateOfBirth`,5))) <= {$iTo}
|
---|
228 | ";
|
---|
229 |
|
---|
230 | }
|
---|
231 |
|
---|
232 | // primary photo ;
|
---|
233 |
|
---|
234 | $sWhereParam .= ( $sPhoto )
|
---|
235 | ? ' AND `Profiles`.`Avatar` <> 0'
|
---|
236 | : null;
|
---|
237 |
|
---|
238 | // online ;
|
---|
239 |
|
---|
240 | $sWhereParam .= ( $sOnline )
|
---|
241 | ? " AND (`Profiles`.`DateLastNav` > SUBDATE(NOW(), INTERVAL " . $this -> iMemberOnlineTime . " MINUTE)) "
|
---|
242 | : null;
|
---|
243 |
|
---|
244 | $sQuery = "SELECT COUNT(*) FROM `Profiles` WHERE `Status` = 'Active' {$sWhereParam}";
|
---|
245 |
|
---|
246 | // # end of collect SQL queries ;
|
---|
247 |
|
---|
248 | // if cache file not consist any of rows with received keyname ;
|
---|
249 |
|
---|
250 | if ( !isset($this -> aMembersInfo[$sCurrentKey]) )
|
---|
251 | {
|
---|
252 | // if KeyName empty the function will generate all information block ;
|
---|
253 |
|
---|
254 | if ( !$sSex )
|
---|
255 | {
|
---|
256 | $this -> aMembersInfo[$sCurrentKey]['sex']= $this -> getSexCount($sQuery);
|
---|
257 | }
|
---|
258 |
|
---|
259 | if ( !$sCountry )
|
---|
260 | {
|
---|
261 | $this -> aMembersInfo[$sCurrentKey]['country'] = $this -> getCountriesCount($sQuery);
|
---|
262 | }
|
---|
263 |
|
---|
264 | if ( !$sAge )
|
---|
265 | {
|
---|
266 | $this -> aMembersInfo[$sCurrentKey]['age'] = $this -> getAgesCount($sQuery);
|
---|
267 | }
|
---|
268 |
|
---|
269 | // online param must be non cacheble ( write into cache ) ;
|
---|
270 |
|
---|
271 | if ( !$sAge or !$sCountry or !$sSex )
|
---|
272 | {
|
---|
273 | // online param must be non cacheble ( write into cache ) ;
|
---|
274 |
|
---|
275 | if ( !$sOnline )
|
---|
276 | {
|
---|
277 | $this -> writeCache($this -> aMembersInfo);
|
---|
278 | }
|
---|
279 |
|
---|
280 | }
|
---|
281 |
|
---|
282 | }
|
---|
283 |
|
---|
284 | // gen selected block ;
|
---|
285 |
|
---|
286 | if ( $sType )
|
---|
287 | {
|
---|
288 | // this keyname need for already selected block ;
|
---|
289 |
|
---|
290 | $sBackKey = 'back_path_' . $sCurrentKey;
|
---|
291 |
|
---|
292 | switch ( $sType )
|
---|
293 | {
|
---|
294 | case 'sex' :
|
---|
295 | if ( !isset($this -> aMembersInfo[$sBackKey]['sex']) )
|
---|
296 | {
|
---|
297 | $aSexArray[$sBackKey]['sex'] = $this -> getSexCount($sQuery);
|
---|
298 |
|
---|
299 | if ( !$sOnline )
|
---|
300 | {
|
---|
301 | $this -> writeCache($aSexArray);
|
---|
302 | }
|
---|
303 |
|
---|
304 | return $aSexArray[$sBackKey]['sex'];
|
---|
305 | }
|
---|
306 | else
|
---|
307 | {
|
---|
308 | return $this -> aMembersInfo[$sBackKey]['sex'];
|
---|
309 | }
|
---|
310 | break;
|
---|
311 | case 'age' :
|
---|
312 | if ( !isset($this -> aMembersInfo[$sBackKey]['age']) )
|
---|
313 | {
|
---|
314 | $aAgeArray[$sBackKey]['age'] = $this -> getAgesCount($sQuery);
|
---|
315 |
|
---|
316 | if ( !$sOnline )
|
---|
317 | {
|
---|
318 | $this -> writeCache($aAgeArray);
|
---|
319 | }
|
---|
320 |
|
---|
321 | return $aAgeArray[$sBackKey]['age'];
|
---|
322 | }
|
---|
323 | else
|
---|
324 | {
|
---|
325 | return $this -> aMembersInfo[$sBackKey]['age'];
|
---|
326 | }
|
---|
327 | break;
|
---|
328 | case 'country' :
|
---|
329 | if ( !isset($this -> aMembersInfo[$sBackKey]['country']) )
|
---|
330 | {
|
---|
331 | $aCountryArray[$sBackKey]['country'] = $this -> getCountriesCount($sQuery);
|
---|
332 |
|
---|
333 | if ( !$sOnline )
|
---|
334 | {
|
---|
335 | $this -> writeCache($aCountryArray);
|
---|
336 | }
|
---|
337 |
|
---|
338 | return $aCountryArray[$sBackKey]['country'];
|
---|
339 | }
|
---|
340 | else
|
---|
341 | {
|
---|
342 | return $this -> aMembersInfo[$sBackKey]['country'];
|
---|
343 | }
|
---|
344 | break;
|
---|
345 | }
|
---|
346 |
|
---|
347 | }
|
---|
348 |
|
---|
349 | return $this -> aMembersInfo[$sCurrentKey];
|
---|
350 |
|
---|
351 | }
|
---|
352 |
|
---|
353 | /**
|
---|
354 | * @description : function will write data into cache file ;
|
---|
355 | * @param : $aMembersInfo (array) with all display parts ;
|
---|
356 | * @return :
|
---|
357 | */
|
---|
358 |
|
---|
359 | function writeCache( $aMembersInfo )
|
---|
360 | {
|
---|
361 | $aTmpData = array();
|
---|
362 | if ( file_exists($this -> sCacheFilePath) )
|
---|
363 | {
|
---|
364 | $aTmpData = unserialize( file_get_contents($this -> sCacheFilePath) );
|
---|
365 | }
|
---|
366 |
|
---|
367 | if ( is_array($aMembersInfo) and !empty($aMembersInfo) )
|
---|
368 | {
|
---|
369 | foreach( $aMembersInfo AS $sKey => $aFields )
|
---|
370 | foreach( $aFields AS $sFieldName => $aItems )
|
---|
371 | {
|
---|
372 | if ( is_array($aItems) and !empty($aItems) )
|
---|
373 | {
|
---|
374 | foreach( $aItems AS $sItemName => $sItemValue )
|
---|
375 | $aTmpData[$sKey][$sFieldName][$sItemName] = $sItemValue;
|
---|
376 | }
|
---|
377 |
|
---|
378 | }
|
---|
379 |
|
---|
380 | $handle = fopen($this -> sCacheFilePath, 'w');
|
---|
381 | fwrite($handle, serialize($aTmpData));
|
---|
382 | fclose($handle);
|
---|
383 | }
|
---|
384 | }
|
---|
385 |
|
---|
386 | }
|
---|
387 |
|
---|
388 | ?> |
---|