Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
19 / 19 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| RolePlayConversationsRepository | |
100.00% |
19 / 19 |
|
100.00% |
5 / 5 |
5 | |
100.00% |
1 / 1 |
| countForUserThisMonth | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| sumDoneDurationForUserThisMonth | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| countStartedForUserThisMonth | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| sumDurationForUserThisMonth | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| recentDoneForUser | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Repositories; |
| 4 | |
| 5 | use App\Http\Models\Auth\User; |
| 6 | use App\Http\Models\RolePlayConversations; |
| 7 | use App\Http\Repositories\interfaces\IRolePlayConversationsRepository; |
| 8 | use Illuminate\Database\Eloquent\Collection; |
| 9 | use MongoDB\BSON\UTCDateTime; |
| 10 | |
| 11 | class RolePlayConversationsRepository implements IRolePlayConversationsRepository |
| 12 | { |
| 13 | /** |
| 14 | * {@inheritDoc} |
| 15 | */ |
| 16 | public function countForUserThisMonth(User $user): int |
| 17 | { |
| 18 | return RolePlayConversations::where('user_id', $user->id) |
| 19 | ->whereBetween('created_at', [now()->startOfMonth(), now()->endOfMonth()]) |
| 20 | ->count(); |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * {@inheritDoc} |
| 25 | */ |
| 26 | public function sumDoneDurationForUserThisMonth(User $user): int |
| 27 | { |
| 28 | return (int) RolePlayConversations::where('user_id', $user->id) |
| 29 | ->where('status', 'done') |
| 30 | ->where('created_at', '>=', new UTCDateTime(now()->startOfMonth()->getTimestampMs())) |
| 31 | ->sum('duration'); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * {@inheritDoc} |
| 36 | */ |
| 37 | public function countStartedForUserThisMonth(User $user): int |
| 38 | { |
| 39 | return RolePlayConversations::where('user_id', $user->id) |
| 40 | ->where('created_at', '>=', new UTCDateTime(now()->startOfMonth()->getTimestampMs())) |
| 41 | ->count(); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * {@inheritDoc} |
| 46 | */ |
| 47 | public function sumDurationForUserThisMonth(User $user): int |
| 48 | { |
| 49 | return (int) RolePlayConversations::where('user_id', $user->id) |
| 50 | ->where('created_at', '>=', new UTCDateTime(now()->startOfMonth()->getTimestampMs())) |
| 51 | ->sum('duration'); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * {@inheritDoc} |
| 56 | */ |
| 57 | public function recentDoneForUser(User $user, int $limit = 5): Collection |
| 58 | { |
| 59 | return RolePlayConversations::where('user_id', $user->id) |
| 60 | ->where('status', 'done') |
| 61 | ->with('project') |
| 62 | ->latest() |
| 63 | ->take($limit) |
| 64 | ->get(); |
| 65 | } |
| 66 | } |