Cheetah
ChWsbBrowse.php
Go to the documentation of this file.
1 <?php
2 
8  require_once(CH_DIRECTORY_PATH_CLASSES . 'ChWsbPageView.php');
9 
10  class ChWsbBrowse extends ChWsbPageView
11  {
12  // consit all member's information ;
14 
15  // consit all Date of birth range ;
17 
18  // consit all Sex ranges ;
20 
21  // consit all Sex ranges ;
23 
24  // consist true value if isset permalink mode ;
26 
27  // need for array searching ;
28  var $sKeyName;
29 
31 
36  function __construct($sPageName = null)
37  {
38  global $aPreValues;
39 
40  // read data from cache file ;
41  $oCache = $GLOBALS['MySQL']->getDbCacheObject();
42  $this -> aMembersInfo = $oCache->getData($GLOBALS['MySQL']->genDbCacheKey('sys_browse_people'));
43  if (null === $this -> aMembersInfo)
44  $this -> aMembersInfo = array ();
45 
46  // fill aDateBirthRange array ;
47  $iStartDate = getParam('search_start_age');
48  $iLastDate = getParam('search_end_age');
49 
50  // fill date of birth array
51  while ( $iStartDate <= $iLastDate ) {
52  $this -> aDateBirthRange[$iStartDate . '-' . ($iStartDate + 2)] = 0;
53  $iStartDate +=3;
54  }
55 
56  // check permalink mode ;
57 
58  $this -> bPermalinkMode = ( getParam('permalinks_browse') )
59  ? true
60  : false;
61 
62  // check member on line time ;
63 
64  $this -> iMemberOnlineTime = (int)getParam( "member_online_time" );
65 
66  // fill sex array ;
67  ksort($aPreValues['Sex'], SORT_STRING);
68  foreach( $aPreValues['Sex'] AS $sKey => $aItems ) {
69  $this -> aSexRange[$sKey] = 0;
70  }
71 
72  // fill country array ;
73  ksort($aPreValues['Country'], SORT_STRING);
74  foreach( $aPreValues['Country'] AS $sKey => $aItems ) {
75  $this -> aCountryRange[$sKey] = 0;
76  }
77 
78  if($sPageName) {
79  parent::__construct($sPageName);
80  }
81 
82  }
83 
90  function getSexCount( $PrimaryQuery )
91  {
92  $aSexArray = array();
93 
94  foreach( $this -> aSexRange AS $sKey => $sValue ) {
96  $sWhereParam = " AND `Sex` = '{$sKey}' ";
97  $iCount = db_value( $PrimaryQuery . $sWhereParam );
98 
99  if ( $iCount )
100  $aSexArray[$sKey] = $iCount;
101  }
102 
103  return $aSexArray;
104  }
105 
112  function getAgesCount( $PrimaryQuery )
113  {
114  $aAgeArray = array();
115 
116  foreach( $this -> aDateBirthRange AS $sKey => $sValue ) {
117  $sWhereParam = null;
118  $aDateRange = explode('-', $sKey);
119 
120  $iFrom = (int) $aDateRange[0];
121  $iTo = (int) $aDateRange[1];
122 
123  $sWhereParam .=
124  "
125  AND
126  ((YEAR(CURDATE())-YEAR(`DateOfBirth`)) - (RIGHT(CURDATE(),5)<RIGHT(`DateOfBirth`,5))) >= {$iFrom}
127  AND
128  ((YEAR(CURDATE())-YEAR(`DateOfBirth`)) - (RIGHT(CURDATE(),5)<RIGHT(`DateOfBirth`,5))) <= {$iTo}
129  ";
130 
131  $iCount = db_value( $PrimaryQuery . $sWhereParam);
132  if ( $iCount ) {
133  $aAgeArray[$sKey] = $iCount;
134  }
135  }
136 
137  return $aAgeArray;
138  }
139 
146  function getCountriesCount( $PrimaryQuery )
147  {
148  $aCountryArray = null;
149 
150  foreach( $this -> aCountryRange AS $sKey => $sValue ) {
152  $sWhereParam = " AND `Country` = '{$sKey}' ";
153  $iCount = db_value( $PrimaryQuery . $sWhereParam );
154 
155  if ( $iCount )
156  $aCountryArray[$sKey] = $iCount;
157  }
158 
159  return $aCountryArray;
160  }
161 
173  function _getGlobalStatistics( $sSex = '', $sAge = '', $sCountry = ''
174  , $sPhoto = '', $sOnline = '', $sType = '' ) {
175 
176  $sCurrentKey = ( $this -> sKeyName )
177  ? $this -> sKeyName
178  : 'public';
179 
180  $aSexArray = $aAgeArray = $aCountryArray = array();
181 
182  // collect the SQL queries ;
183 
184  $sWhereParam = null;
185  $sWhereParam .= ( $sSex )
186  ? " AND `Sex` = '{$sSex}' "
187  : null;
188 
189  $sWhereParam .= ( $sCountry )
190  ? " AND `Country` = '{$sCountry}' "
191  : null;
192 
193  if ( $sAge ) {
194 
195  $aDateRange = explode('-', $sAge);
196 
197  $iFrom = (int)$aDateRange[0] - 1;
198  $iTo = (int)$aDateRange[1];
199 
200  unset($aDateRange);
201 
202  if ( !$iFrom or !$iTo )
203  return null;
204 
205  $sWhereParam .=
206  "
207  AND
208  ((YEAR(CURDATE())-YEAR(`DateOfBirth`)) - (RIGHT(CURDATE(),5)<RIGHT(`DateOfBirth`,5))) >= {$iFrom}
209  AND
210  ((YEAR(CURDATE())-YEAR(`DateOfBirth`)) - (RIGHT(CURDATE(),5)<RIGHT(`DateOfBirth`,5))) <= {$iTo}
211  ";
212 
213  }
214 
215  // primary photo ;
216 
217  $sWhereParam .= ( $sPhoto )
218  ? ' AND `Profiles`.`Avatar` <> 0'
219  : null;
220 
221  // online ;
222 
223  $sWhereParam .= ( $sOnline )
224  ? " AND (`Profiles`.`DateLastNav` > SUBDATE(NOW(), INTERVAL " . $this -> iMemberOnlineTime . " MINUTE)) "
225  : null;
226 
227  $sQuery = "SELECT COUNT(*) FROM `Profiles` WHERE `Status` = 'Active' {$sWhereParam}";
228 
229  // # end of collect SQL queries ;
230 
231  // if cache file not consist any of rows with received keyname ;
232 
233  if ( !isset($this -> aMembersInfo[$sCurrentKey]) ) {
234  // if KeyName empty the function will generate all information block ;
235 
236  if ( !$sSex ) {
237  $this -> aMembersInfo[$sCurrentKey]['sex']= $this -> getSexCount($sQuery);
238  }
239 
240  if ( !$sCountry ) {
241  $this -> aMembersInfo[$sCurrentKey]['country'] = $this -> getCountriesCount($sQuery);
242  }
243 
244  if ( !$sAge ) {
245  $this -> aMembersInfo[$sCurrentKey]['age'] = $this -> getAgesCount($sQuery);
246  }
247 
248  // online param must be non cacheble ( write into cache ) ;
249 
250  if ( !$sAge or !$sCountry or !$sSex ) {
251  // online param must be non cacheble ( write into cache ) ;
252 
253  if ( !$sOnline ) {
254  $this -> writeCache($this -> aMembersInfo);
255  }
256 
257  }
258 
259  }
260 
261  // gen selected block ;
262 
263  if ( $sType ) {
264  // this keyname need for already selected block ;
265 
266  $sBackKey = 'back_path_' . $sCurrentKey;
267 
268  switch ( $sType ) {
269  case 'sex' :
270  if ( !isset($this -> aMembersInfo[$sBackKey]['sex']) ) {
271  $aSexArray[$sBackKey]['sex'] = $this -> getSexCount($sQuery);
272 
273  if ( !$sOnline ) {
274  $this -> writeCache($aSexArray);
275  }
276 
277  return $aSexArray[$sBackKey]['sex'];
278  } else {
279  return $this -> aMembersInfo[$sBackKey]['sex'];
280  }
281  break;
282  case 'age' :
283  if ( !isset($this -> aMembersInfo[$sBackKey]['age']) ) {
284  $aAgeArray[$sBackKey]['age'] = $this -> getAgesCount($sQuery);
285 
286  if ( !$sOnline ) {
287  $this -> writeCache($aAgeArray);
288  }
289 
290  return $aAgeArray[$sBackKey]['age'];
291  } else {
292  return $this -> aMembersInfo[$sBackKey]['age'];
293  }
294  break;
295  case 'country' :
296  if ( !isset($this -> aMembersInfo[$sBackKey]['country']) ) {
297  $aCountryArray[$sBackKey]['country'] = $this -> getCountriesCount($sQuery);
298 
299  if ( !$sOnline ) {
300  $this -> writeCache($aCountryArray);
301  }
302 
303  return $aCountryArray[$sBackKey]['country'];
304  } else {
305  return $this -> aMembersInfo[$sBackKey]['country'];
306  }
307  break;
308  }
309 
310  }
311 
312  return $this -> aMembersInfo[$sCurrentKey];
313 
314  }
315 
323  {
324 
325  $oCache = $GLOBALS['MySQL']->getDbCacheObject();
326  $aTmpData = $oCache->getData($GLOBALS['MySQL']->genDbCacheKey('sys_browse_people'));
327  if (null === $aTmpData)
328  $aTmpData = array ();
329 
330  if ( is_array($aMembersInfo) and !empty($aMembersInfo) ) {
331  foreach( $aMembersInfo AS $sKey => $aFields )
332  foreach( $aFields AS $sFieldName => $aItems ) {
333  if ( is_array($aItems) and !empty($aItems) ) {
334  foreach( $aItems AS $sItemName => $sItemValue )
335  $aTmpData[$sKey][$sFieldName][$sItemName] = $sItemValue;
336  }
337 
338  }
339 
340  $oCache->setData ($GLOBALS['MySQL']->genDbCacheKey('sys_browse_people'), $aTmpData);
341  }
342  }
343 
344  }
process_db_input
process_db_input($sText, $iStripTags=0)
Definition: utils.inc.php:256
$sSex
$sSex
Definition: browse.php:24
ChWsbBrowse\getSexCount
getSexCount( $PrimaryQuery)
Definition: ChWsbBrowse.php:90
ChWsbBrowse\__construct
__construct($sPageName=null)
Definition: ChWsbBrowse.php:36
ChWsbBrowse\getAgesCount
getAgesCount( $PrimaryQuery)
Definition: ChWsbBrowse.php:112
ChWsbPageView
Definition: ChWsbPageView.php:99
php
ChWsbBrowse\$aDateBirthRange
$aDateBirthRange
Definition: ChWsbBrowse.php:16
ChWsbBrowse\getCountriesCount
getCountriesCount( $PrimaryQuery)
Definition: ChWsbBrowse.php:146
$oCache
$oCache
Definition: prof.inc.php:10
CH_SLASHES_NO_ACTION
const CH_SLASHES_NO_ACTION
Definition: utils.inc.php:30
ChWsbBrowse\$bPermalinkMode
$bPermalinkMode
Definition: ChWsbBrowse.php:25
$sType
$sType
Definition: actions.inc.php:11
and
and
Definition: license.txt:18
$aFields
$aFields
Definition: preValues.php:19
getParam
getParam($sParamName, $bUseCache=true)
Definition: db.inc.php:130
$sOnline
$sOnline
Definition: browse.php:46
ChWsbBrowse\$aCountryRange
$aCountryRange
Definition: ChWsbBrowse.php:22
CH_TAGS_NO_ACTION
const CH_TAGS_NO_ACTION
Definition: utils.inc.php:21
global
if(!defined("GLOBAL_MODULE")) define("GLOBAL_MODULE" global
Definition: header.inc.php:25
ChWsbBrowse\_getGlobalStatistics
_getGlobalStatistics( $sSex='', $sAge='', $sCountry='', $sPhoto='', $sOnline='', $sType='')
Definition: ChWsbBrowse.php:173
ChWsbBrowse\$sKeyName
$sKeyName
Definition: ChWsbBrowse.php:28
ChWsbBrowse\writeCache
writeCache( $aMembersInfo)
Definition: ChWsbBrowse.php:322
ChWsbPageView\$sPageName
$sPageName
Definition: ChWsbPageView.php:100
ChWsbBrowse\$iMemberOnlineTime
$iMemberOnlineTime
Definition: ChWsbBrowse.php:30
ChWsbBrowse
Definition: ChWsbBrowse.php:11
db_value
db_value($query, $bindings=[], $error_checking=true, $index=0)
Definition: db.inc.php:98
$sCountry
$sCountry
Definition: browse.php:26
ChWsbBrowse\$aSexRange
$aSexRange
Definition: ChWsbBrowse.php:19
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
ChWsbBrowse\$aMembersInfo
$aMembersInfo
Definition: ChWsbBrowse.php:13
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10
or
Voluntary License Schemes The Licensor waives the right to collect whether individually or
Definition: license.txt:37
$sAge
$sAge
Definition: browse.php:25