#86: Updated stats API to work with Postgres

This commit is contained in:
Josef Citrine 2016-07-11 21:12:02 +01:00
parent a57c1640e8
commit 4c6aeb1a6e

View file

@ -33,17 +33,17 @@ use Carbon\Carbon;
class StatsController extends ApiControllerBase
{
private function getStatsData($id, $hourly = false) {
$playRange = "1 MONTH";
$playRange = "'1 MONTH'";
if ($hourly) {
$playRange = "2 DAY";
$playRange = "'2 DAY'";
}
$statQuery = DB::table('resource_log_items')
->selectRaw('created_at, COUNT(1) AS `plays`')
->selectRaw('created_at, COUNT(1) AS "plays"')
->where('track_id', '=', $id)
->where('log_type', '=', ResourceLogItem::PLAY)
->whereRaw('`created_at` > now() - INTERVAL '.$playRange)
->whereRaw('"created_at" > now() - INTERVAL '.$playRange)
->groupBy('created_at')
->orderBy('created_at')
->get();