Skip to content

Commit

Permalink
reorder includes in UserTransformer
Browse files Browse the repository at this point in the history
  • Loading branch information
notbakaneko committed May 18, 2018
1 parent e0b421d commit 5a5e473
Showing 1 changed file with 94 additions and 93 deletions.
187 changes: 94 additions & 93 deletions app/Transformers/UserTransformer.php
Expand Up @@ -97,6 +97,22 @@ public function transform(User $user)
];
}

public function includeAccountHistory(User $user)
{
$histories = $user->accountHistories()->recent();

if (!priv_check('UserSilenceShowExtendedInfo')->can()) {
$histories->default();
} else {
$histories->with('actor');
}

return $this->collection(
$histories->get(),
new UserAccountHistoryTransformer()
);
}

public function includeActiveTournamentBanner(User $user)
{
return $this->item($user->profileBanners()->active(), new ProfileBannerTransformer);
Expand All @@ -117,6 +133,39 @@ public function includeDefaultStatistics(User $user)
return $this->item($stats, new UserStatisticsTransformer);
}

public function includeDisqusAuth(User $user)
{
return $this->item($user, function ($user) {
$data = [
'id' => $user->user_id,
'username' => $user->username,
'email' => $user->user_email,
'avatar' => $user->user_avatar,
'url' => route('users.show', $user->user_id),
];

$encodedData = base64_encode(json_encode($data));
$timestamp = time();
$hmac = hash_hmac('sha1', "$encodedData $timestamp", config('services.disqus.secret_key'));

return [
'short_name' => config('services.disqus.short_name'),
'public_key' => config('services.disqus.public_key'),
'auth_data' => "$encodedData $hmac $timestamp",
];
});
}

public function includeFavouriteBeatmapsetCount(User $user)
{
return $this->item($user, function ($user) {
return [
$user->profileBeatmapsetsFavourite()->count(),
];
});
}


public function includeFollowerCount(User $user)
{
return $this->item($user, function ($user) {
Expand All @@ -132,6 +181,24 @@ public function includeFriends(User $user)
);
}

public function includeGraveyardBeatmapsetCount(User $user)
{
return $this->item($user, function ($user) {
return [
$user->profileBeatmapsetsGraveyard()->count(),
];
});
}

public function includeLovedBeatmapsetCount(User $user)
{
return $this->item($user, function ($user) {
return [
$user->profileBeatmapsetsLoved() ->count(),
];
});
}

public function includeMonthlyPlaycounts(User $user)
{
return $this->collection(
Expand All @@ -154,36 +221,21 @@ public function includePage(User $user)
});
}

public function includeReplaysWatchedCounts(User $user)
{
return $this->collection(
$user->replaysWatchedCounts,
new UserReplaysWatchedCountTransformer
);
}

public function includeUserAchievements(User $user)
{
return $this->collection(
$user->userAchievements()->orderBy('date', 'desc')->get(),
new UserAchievementTransformer()
);
}

public function includeAccountHistory(User $user)
public function includePreviousUsernames(User $user)
{
$histories = $user->accountHistories()->recent();

if (!priv_check('UserSilenceShowExtendedInfo')->can()) {
$histories->default();
} else {
$histories->with('actor');
}

return $this->collection(
$histories->get(),
new UserAccountHistoryTransformer()
);
return $this->item($user, function ($user) {
return $user
->usernameChangeHistory()
->visible()
->select(['username_last', 'timestamp'])
->withPresent('username_last')
->where('username_last', '<>', $user->username)
->orderBy('timestamp', 'ASC')
->get()
->pluck('username_last')
->unique()
->toArray();
});
}

public function includeRankedAndApprovedBeatmapsetCount(User $user)
Expand All @@ -195,6 +247,14 @@ public function includeRankedAndApprovedBeatmapsetCount(User $user)
});
}

public function includeReplaysWatchedCounts(User $user)
{
return $this->collection(
$user->replaysWatchedCounts,
new UserReplaysWatchedCountTransformer
);
}

public function includeScoresFirstCount(User $user, Fractal\ParamBag $params)
{
$mode = $params->get('mode')[0];
Expand All @@ -220,70 +280,11 @@ public function includeUnrankedBeatmapsetCount(User $user)
});
}

public function includeGraveyardBeatmapsetCount(User $user)
{
return $this->item($user, function ($user) {
return [
$user->profileBeatmapsetsGraveyard()->count(),
];
});
}

public function includeFavouriteBeatmapsetCount(User $user)
{
return $this->item($user, function ($user) {
return [
$user->profileBeatmapsetsFavourite()->count(),
];
});
}

public function includeLovedBeatmapsetCount(User $user)
{
return $this->item($user, function ($user) {
return [
$user->profileBeatmapsetsLoved() ->count(),
];
});
}

public function includeDisqusAuth(User $user)
{
return $this->item($user, function ($user) {
$data = [
'id' => $user->user_id,
'username' => $user->username,
'email' => $user->user_email,
'avatar' => $user->user_avatar,
'url' => route('users.show', $user->user_id),
];

$encodedData = base64_encode(json_encode($data));
$timestamp = time();
$hmac = hash_hmac('sha1', "$encodedData $timestamp", config('services.disqus.secret_key'));

return [
'short_name' => config('services.disqus.short_name'),
'public_key' => config('services.disqus.public_key'),
'auth_data' => "$encodedData $hmac $timestamp",
];
});
}

public function includePreviousUsernames(User $user)
public function includeUserAchievements(User $user)
{
return $this->item($user, function ($user) {
return $user
->usernameChangeHistory()
->visible()
->select(['username_last', 'timestamp'])
->withPresent('username_last')
->where('username_last', '<>', $user->username)
->orderBy('timestamp', 'ASC')
->get()
->pluck('username_last')
->unique()
->toArray();
});
return $this->collection(
$user->userAchievements()->orderBy('date', 'desc')->get(),
new UserAchievementTransformer()
);
}
}

0 comments on commit 5a5e473

Please sign in to comment.