Passed
Push — master ( 03804a...32a61a )
by Curtis
04:47
created

Person::appellative()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\SoftDeletes;
7
8
class Person extends \LaravelEnso\People\App\Models\Person
9
{
10
    use SoftDeletes;
11
12
    /**
13
     * The attributes that should be mutated to dates.
14
     *
15
     * @var array
16
     */
17
    protected $dates = ['deleted_at', 'birthday'];
18
19
    protected $fillable = [
20
        'givn',
21
        'surn',
22
        'sex',
23
        'child_in_family_id',
24
        'description',
25
        'title',
26
	'uid',
27
	'email',
28
	'phone',
29
	'birthday',
30
        'obs',
31
32
    ];
33
34
    public function events()
35
    {
36
        return $this->hasMany(PersonEvent::class);
37
    }
38
39
    public function child_in_family()
40
    {
41
        return $this->belongsTo(Family::class, 'child_in_family_id');
42
    }
43
44
    public function husband_in_family()
45
    {
46
        return $this->hasMany(Family::class, 'husband_id');
47
    }
48
49
    public function wife_in_family()
50
    {
51
        return $this->hasMany(Family::class, 'wife_id');
52
    }
53
54
    public function fullname()
55
    {
56
        return $this->givn.' '.$this->surn;
0 ignored issues
show
Bug introduced by
The property surn does not seem to exist on App\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
Bug introduced by
The property givn does not seem to exist on App\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
57
    }
58
59
    public function getSex()
60
    {
61
        if ($this->sex == 'F') {
0 ignored issues
show
Bug introduced by
The property sex does not seem to exist on App\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
62
            return 'Female';
63
        }
64
65
        return 'Male';
66
    }
67
68
    public static function getList()
69
    {
70
        $persons = self::get();
71
        $result = [];
72
        foreach ($persons as $person) {
73
            $result[$person->id] = $person->fullname();
74
        }
75
76
        return collect($result);
77
    }
78
79
    public function addEvent($title, $date, $place, $description = '')
80
    {
81
        $place_id = Place::getIdByTitle($place);
82
        $event = PersonEvent::create([
83
            'person_id' => $this->id,
84
            'title' => $title,
85
            'description' => $description,
86
        ]);
87
88
        if ($date) {
89
            $event->date = $date;
0 ignored issues
show
Bug introduced by
The property date does not exist on App\PersonEvent. Did you mean dates?
Loading history...
90
            $event->save();
91
        }
92
93
        if ($place) {
94
            $event->places_id = $place_id;
0 ignored issues
show
Bug introduced by
The property places_id does not seem to exist on App\PersonEvent. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
95
            $event->save();
96
        }
97
    }
98
99
    public function birth()
100
    {
101
        return $this->events->where('title', '=', 'BIRT')->first();
102
    }
103
104
    public function death()
105
    {
106
        return $this->events->where('title', '=', 'DEAT')->first();
107
    }
108
109
    public function appellative()
110
    {
111
        return $this->givn;
0 ignored issues
show
Bug introduced by
The property givn does not seem to exist on App\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
112
    }
113
114
115
}
116