Skip to content

Instantly share code, notes, and snippets.

@gladunrv
Last active March 14, 2018 12:09
Show Gist options
  • Select an option

  • Save gladunrv/5e5c08558a064c5b35f7944316a9476d to your computer and use it in GitHub Desktop.

Select an option

Save gladunrv/5e5c08558a064c5b35f7944316a9476d to your computer and use it in GitHub Desktop.
<?
public function searchForDating($data, $limit = 200)
{
$queryTop = $this->searchForDatingQuery($data, true)->limit($limit);
$queryNonTop = $this->searchForDatingQuery($data)->limit($limit);
$queryFilterViewedUsers = $this->filterViewedUsers();
$query = (new Query)
->select('*')
->from([
$queryTop->union($queryNonTop),
])
->andWhere(['not in', 'uid', $queryFilterViewedUsers])
->limit($limit);
$items = $query->all();
return $items;
}
public function filterViewedUsers()
{
$query = (new Query())
->select('owner')
->from('dating_views')
->where(['dating_views.uid' => $this->uid])
->andWhere(['>', 'dating_views.time', time() - self::LAST_VIEW_TIME_LIMIT]);
return $query;
}
public function searchForDatingQuery($data, $top = false)
{
$minYearOfBirthy = (int) date('Y') - (int) $data['rangeAgeEnd'];
$maxYearOfBirthy = (int) date('Y') - (int) $data['rangeAgeStart'];
$subQuerySearchSetingsLimit = (new Query())
->select('uid')
->from(DatingSearchSettings::tableName())
->where(['and',
[
'dating_sex' => $this->dating_sex,
'country_id' => $this->country_id,
'city_id' => $this->city_id,
],
['<=', 'range_age_start', $this->datingAge],
['>=', 'range_age_end', $this->datingAge],
]);
$query = (new Query())
->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',
])
->from(self::tableName())
->andWhere(['!=', 'uid', $this->uid])
->andWhere(['>=', 'dating_year_of_birthy', $minYearOfBirthy])
->andWhere(['<=', 'dating_year_of_birthy', $maxYearOfBirthy])
->andWhere(['dating_sex' => $data['searchSex']]);
if ($data['online'] == 1) {
$query->andWhere(['online' => 1]);
$query->andWhere(['dating_show_online_status' => 1]);
}
if ((int) $data['countryId'] > 0) {
$query->andWhere(['country_id' => $data['countryId']]);
}
if ((int) $data['cityId'] > 0) {
$query->andWhere(['city_id' => $data['cityId']]);
}
if ($top) {
$query->andWhere(['dating_top' => 1]);
$query->andWhere(['uid' => $subQuerySearchSetingsLimit]);
$query->orderBy('dating_top_start DESC');
} else {
$query->andWhere(['dating_top' => 0]);
$query->orderBy('dating_rate DESC');
}
return $query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment