Last active
August 6, 2016 07:18
-
-
Save Yiin/3f5cd1502a4336f182e9c9ed49f80b51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function getSitePositionAds($site_id, $position_id, $container_width) | |
{ | |
$ads = Ad::leftJoin('sites', 'sites.id', '=', \DB::raw($site_id)) | |
->leftJoin('positions', 'positions.id', '=', \DB::raw($position_id)) | |
->leftJoin('ad_position', function ($join) use ($position_id) { | |
$join->on('ad_position.ad_id', '=', 'ads.id') | |
->on('ad_position.position_id', '=', 'positions.id'); | |
}) | |
->leftJoin('ad_site', function ($join) use ($site_id) { | |
$join->on('ad_site.ad_id', '=', 'ads.id') | |
->on('ad_site.site_id', '=', 'sites.id'); | |
}) | |
->where('ad_site.is_excluded', false) | |
->where('ads.max_position_width', '<=', $container_width) | |
->where(function ($query) { | |
$query->where('ads.limit_displays', '>', 0) | |
->orWhereNull('ads.limit_displays'); | |
}) | |
->where(function ($query) { | |
$query->where('ad_position.limit_displays', '>', 0) | |
->orWhereNull('ad_position.limit_displays'); | |
}) | |
->where(function ($query) { | |
$query->where('ad_site.limit_displays', '>', 0) | |
->orWhereNull('ad_site.limit_displays'); | |
}) | |
->get(); | |
return $ads->toJson(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment