From 92b7dd3335a6572debeacfb5faa82c63a5e67888 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Fri, 8 Jun 2018 20:03:25 +0200 Subject: Some minor fixes --- .../account/src/Database/Models/Activity.php | 166 ++++++++++----------- 1 file changed, 83 insertions(+), 83 deletions(-) (limited to 'main/app/sprinkles/account/src/Database/Models/Activity.php') diff --git a/main/app/sprinkles/account/src/Database/Models/Activity.php b/main/app/sprinkles/account/src/Database/Models/Activity.php index 4e5b609..8f6cd18 100644 --- a/main/app/sprinkles/account/src/Database/Models/Activity.php +++ b/main/app/sprinkles/account/src/Database/Models/Activity.php @@ -1,83 +1,83 @@ -select('activities.*'); - - $query = $query->leftJoin('users', 'activities.user_id', '=', 'users.id'); - - return $query; - } - - /** - * Add clauses to select the most recent event of each type for each user, to the query. - * - * @return \Illuminate\Database\Query\Builder - */ - public function scopeMostRecentEvents($query) { - return $query->select('user_id', 'event_type', Capsule::raw('MAX(occurred_at) as occurred_at')) - ->groupBy('user_id') - ->groupBy('type'); - } - - /** - * Add clauses to select the most recent event of a given type for each user, to the query. - * - * @param string $type The type of event, matching the `event_type` field in the user_event table. - * @return \Illuminate\Database\Query\Builder - */ - public function scopeMostRecentEventsByType($query, $type) { - return $query->select('user_id', Capsule::raw('MAX(occurred_at) as occurred_at')) - ->where('type', $type) - ->groupBy('user_id'); - } - - /** - * Get the user associated with this activity. - */ - public function user() { - /** @var UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */ - $classMapper = static::$ci->classMapper; - - return $this->belongsTo($classMapper->getClassMapping('user'), 'user_id'); - } -} +select('activities.*'); + + $query = $query->leftJoin('users', 'activities.user_id', '=', 'users.id'); + + return $query; + } + + /** + * Add clauses to select the most recent event of each type for each user, to the query. + * + * @return \Illuminate\Database\Query\Builder + */ + public function scopeMostRecentEvents($query) { + return $query->select('user_id', 'event_type', Capsule::raw('MAX(occurred_at) as occurred_at')) + ->groupBy('user_id') + ->groupBy('type'); + } + + /** + * Add clauses to select the most recent event of a given type for each user, to the query. + * + * @param string $type The type of event, matching the `event_type` field in the user_event table. + * @return \Illuminate\Database\Query\Builder + */ + public function scopeMostRecentEventsByType($query, $type) { + return $query->select('user_id', Capsule::raw('MAX(occurred_at) as occurred_at')) + ->where('type', $type) + ->groupBy('user_id'); + } + + /** + * Get the user associated with this activity. + */ + public function user() { + /** @var UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */ + $classMapper = static::$ci->classMapper; + + return $this->belongsTo($classMapper->getClassMapping('user'), 'user_id'); + } +} -- cgit v1.2.3