Issues (533)

src/Models/Person.php (4 issues)

1
<?php
2
3
namespace FamilyTree365\LaravelGedcom\Models;
4
5
use Illuminate\Database\Eloquent\Model;
0 ignored issues
show
The type Illuminate\Database\Eloquent\Model was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
7
class Person extends Model
8
{
9
    /**
10
     * The attributes that should be mutated to dates.
11
     *
12
     * @var array
13
     */
14
    protected $dates = ['deleted_at', 'birthday', 'deathday'];
15
16
    protected $guarded = ['id'];
17
18
    protected $fillable = [
19
        'gid',
20
        'givn',
21
        'surn',
22
        'sex',
23
        'child_in_family_id',
24
        'description',
25
        'title', 'name', 'appellative', 'uid', 'email', 'phone', 'birthday', 'birth_year',
26
        'deathday', 'death_year', 'burial_day', 'burial_year', 'bank', 'bank_account',
27
        'uid', 'chan', 'rin', 'resn', 'rfn', 'afn', 'type',
28
    ];
29
30
    public function events()
31
    {
32
        return $this->hasMany(PersonEvent::class);
33
    }
34
35
    public function child_in_family()
36
    {
37
        return $this->belongsTo(Family::class, 'child_in_family_id');
38
    }
39
40
    public function husband_in_family()
41
    {
42
        return $this->hasMany(Family::class, 'husband_id');
43
    }
44
45
    public function wife_in_family()
46
    {
47
        return $this->hasMany(Family::class, 'wife_id');
48
    }
49
50
    public function fullname()
51
    {
52
        return $this->givn.' '.$this->surn;
53
    }
54
55
    public function getSex()
56
    {
57
        if ($this->sex == 'F') {
58
            return 'Female';
59
        }
60
61
        return 'Male';
62
    }
63
64
    public static function getList()
65
    {
66
        $persons = self::query()->get();
67
        $result = [];
68
        foreach ($persons as $person) {
69
            $result[$person->id] = $person->fullname();
70
        }
71
72
        return collect($result);
0 ignored issues
show
The function collect was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

72
        return /** @scrutinizer ignore-call */ collect($result);
Loading history...
73
    }
74
75
    public function addEvent($title, $date, $place, $description = '')
76
    {
77
        $place_id = Place::getIdByTitle($place);
78
        $event = PersonEvent::query()->updateOrCreate(
79
            [
80
                'person_id' => $this->id,
81
                'title'     => $title,
82
            ],
83
            [
84
                'person_id'   => $this->id,
85
                'title'       => $title,
86
                'description' => $description,
87
            ]
88
        );
89
90
        if ($date) {
91
            $event->date = $date;
92
            $event->save();
93
        }
94
95
        if ($place) {
96
            $event->places_id = $place_id;
97
            $event->save();
98
        }
99
100
        // add birthyear to person table ( for form builder )
101
        if ($title == 'BIRT' && !empty($date)) {
102
            $this->birthday = date('Y-m-d', strtotime($date));
0 ignored issues
show
Bug Best Practice introduced by
The property birthday does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
103
        }
104
        // add deathyear to person table ( for form builder )
105
        if ($title == 'DEAT' && !empty($date)) {
106
            $this->deathday = date('Y-m-d', strtotime($date));
0 ignored issues
show
Bug Best Practice introduced by
The property deathday does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
107
        }
108
        $this->save();
109
110
        return $event;
111
    }
112
113
    public function birth()
114
    {
115
        return $this->events->where('title', '=', 'BIRT')->first();
116
    }
117
118
    public function death()
119
    {
120
        return $this->events->where('title', '=', 'DEAT')->first();
121
    }
122
123
    public function appellative()
124
    {
125
        return $this->givn;
126
    }
127
}
128