Guest User

Untitled

a guest
Mar 22nd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. <?
  2.  
  3. public function searchForDating($data, $limit = 200)
  4. {
  5. $queryTop = $this->searchForDatingQuery($data, true)->limit($limit);
  6. $queryNonTop = $this->searchForDatingQuery($data)->limit($limit);
  7. $queryFilterViewedUsers = $this->filterViewedUsers();
  8. $query = (new Query)
  9. ->select('*')
  10. ->from([
  11. $queryTop->union($queryNonTop),
  12. ])
  13. ->andWhere(['not in', 'uid', $queryFilterViewedUsers])
  14. ->limit($limit);
  15.  
  16. $items = $query->all();
  17. return $items;
  18. }
  19.  
  20. public function filterViewedUsers()
  21. {
  22. $query = (new Query())
  23. ->select('owner')
  24. ->from('dating_views')
  25. ->where(['dating_views.uid' => $this->uid])
  26. ->andWhere(['>', 'dating_views.time', time() - self::LAST_VIEW_TIME_LIMIT]);
  27. return $query;
  28. }
  29.  
  30. public function searchForDatingQuery($data, $top = false)
  31. {
  32. $minYearOfBirthy = (int) date('Y') - (int) $data['rangeAgeEnd'];
  33. $maxYearOfBirthy = (int) date('Y') - (int) $data['rangeAgeStart'];
  34. $subQuerySearchSetingsLimit = (new Query())
  35. ->select('uid')
  36. ->from(DatingSearchSettings::tableName())
  37. ->where(['and',
  38. [
  39. 'dating_sex' => $this->dating_sex,
  40. 'country_id' => $this->country_id,
  41. 'city_id' => $this->city_id,
  42.  
  43. ],
  44. ['<=', 'range_age_start', $this->datingAge],
  45. ['>=', 'range_age_end', $this->datingAge],
  46. ]);
  47.  
  48. $query = (new Query())
  49. ->select(['users.uid', 'dating_name', 'vip', 'city_id', 'country_id', 'dating_year_of_birthy', 'dating_month_of_birthy', 'dating_birthday', 'dating_not_show_to_friends', 'users.photo_id', 'photo_url',
  50. ])
  51. ->from(self::tableName())
  52. ->andWhere(['!=', 'uid', $this->uid])
  53. ->andWhere(['>=', 'dating_year_of_birthy', $minYearOfBirthy])
  54. ->andWhere(['<=', 'dating_year_of_birthy', $maxYearOfBirthy])
  55. ->andWhere(['dating_sex' => $data['searchSex']]);
  56. if ($data['online'] == 1) {
  57. $query->andWhere(['online' => 1]);
  58. $query->andWhere(['dating_show_online_status' => 1]);
  59. }
  60. if ((int) $data['countryId'] > 0) {
  61. $query->andWhere(['country_id' => $data['countryId']]);
  62. }
  63. if ((int) $data['cityId'] > 0) {
  64. $query->andWhere(['city_id' => $data['cityId']]);
  65. }
  66.  
  67. if ($top) {
  68. $query->andWhere(['dating_top' => 1]);
  69. $query->andWhere(['uid' => $subQuerySearchSetingsLimit]);
  70. $query->orderBy('dating_top_start DESC');
  71. } else {
  72. $query->andWhere(['dating_top' => 0]);
  73. $query->orderBy('dating_rate DESC');
  74. }
  75.  
  76. return $query;
  77. }
Add Comment
Please, Sign In to add comment