Passed
Pull Request — develop (#1)
by
unknown
03:00
created

EloquentExchangeRegistry::historyOfStudent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Judite\Registry;
4
5
use App\Judite\Models\Student;
6
use App\Judite\Models\Enrollment;
7
use App\Judite\Models\ExchangeRegistryEntry;
8
use App\Judite\Contracts\Registry\ExchangeRegistry;
9
10
class EloquentExchangeRegistry implements ExchangeRegistry
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    public function record(Enrollment $fromEnrollment, Enrollment $toEnrollment)
16
    {
17
        $logExchange = ExchangeRegistryEntry::make();
18
        $logExchange->fromShiftRelation()->associate($fromEnrollment->shift);
19
        $logExchange->toShiftRelation()->associate($toEnrollment->shift);
20
        $logExchange->fromStudentRelation()->associate($fromEnrollment->student);
21
        $logExchange->toStudentRelation()->associate($toEnrollment->student);
22
        $logExchange->save();
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function paginate()
29
    {
30
        return ExchangeRegistryEntry::latest('id')->paginate();
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function historyOfStudent(Student $student)
37
    {
38
        $history = ExchangeRegistryEntry::where('from_student_id', $student->id)
39
                    ->orWhere('to_student_id', $student->id)
40
                    ->orderBy('updated_at', 'dsc')
41
                    ->paginate();
42
43
        return $history;
44
    }
45
}
46