Skip to content

Commit c96aa6f

Browse files
Add Models from Genealogy Project
1 parent fa56ada commit c96aa6f

34 files changed

+1370
-0
lines changed

src/Models/Addr.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace GenealogiaWebsite\LaravelGedcom\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
8+
/**
9+
* @property int $id
10+
* @property string $adr1
11+
* @property string $adr2
12+
* @property string $city
13+
* @property string $stae
14+
* @property string $post
15+
* @property string $ctry
16+
* @property string $created_at
17+
* @property string $updated_at
18+
*/
19+
class Addr extends Model
20+
{
21+
22+
23+
/**
24+
* The "type" of the auto-incrementing ID.
25+
*
26+
* @var string
27+
*/
28+
protected $keyType = 'integer';
29+
30+
/**
31+
* @var array
32+
*/
33+
protected $fillable = ['adr1', 'adr2', 'city', 'stae', 'post', 'ctry', 'created_at', 'updated_at'];
34+
}

src/Models/Author.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace GenealogiaWebsite\LaravelGedcom\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
8+
class Author extends Model
9+
{
10+
11+
12+
protected $fillable = ['description', 'is_active', 'name'];
13+
14+
protected $attributes = ['is_active' => false];
15+
16+
protected $casts = ['is_active' => 'boolean'];
17+
}

src/Models/Chan.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace GenealogiaWebsite\LaravelGedcom\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
8+
/**
9+
* @property int $id
10+
* @property string $group
11+
* @property int $gid
12+
* @property string $date
13+
* @property string $time
14+
* @property string $created_at
15+
* @property string $updated_at
16+
*/
17+
class Chan extends Model
18+
{
19+
20+
21+
/**
22+
* The "type" of the auto-incrementing ID.
23+
*
24+
* @var string
25+
*/
26+
protected $keyType = 'integer';
27+
28+
/**
29+
* @var array
30+
*/
31+
protected $fillable = ['group', 'gid', 'date', 'time', 'created_at', 'updated_at'];
32+
}

src/Models/Citation.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace GenealogiaWebsite\LaravelGedcom\Models;
4+
5+
use App\Source;
6+
use Illuminate\Database\Eloquent\Model;
7+
8+
9+
class Citation extends Model
10+
{
11+
12+
13+
protected $fillable = ['name', 'description', 'repository_id', 'volume', 'page', 'is_active', 'confidence', 'source_id'];
14+
15+
protected $attributes = ['is_active' => false];
16+
17+
protected $casts = ['is_active' => 'boolean'];
18+
19+
public function sources()
20+
{
21+
return $this->belongsToMany(Source::class);
22+
}
23+
}

src/Models/Event.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace GenealogiaWebsite\LaravelGedcom\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class Event extends Model
8+
{
9+
10+
protected $gedcom_event_names = [];
11+
12+
public function place()
13+
{
14+
return $this->hasOne(Place::class, 'id', 'places_id');
15+
}
16+
17+
public function getPlacename()
18+
{
19+
if ($this->place) {
20+
return $this->place->title;
21+
} else {
22+
return 'unknown place';
23+
}
24+
}
25+
26+
public function getTitle()
27+
{
28+
return $this->gedcom_event_names[$this->title] ?? $this->title;
29+
}
30+
31+
public function scopeOrderByDate($query)
32+
{
33+
return $query->orderBy('year')->orderBy('month')->orderBy('day');
34+
}
35+
}

src/Models/Family.php

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
namespace GenealogiaWebsite\LaravelGedcom\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
use LaravelEnso\People\Models\Person;
7+
// use App\Person;
8+
9+
10+
class Family extends Model
11+
{
12+
13+
14+
protected $fillable = ['description', 'is_active', 'husband_id', 'wife_id', 'type_id', 'chan', 'nchi', 'rin'];
15+
16+
protected $attributes = ['is_active' => false];
17+
18+
protected $casts = ['is_active' => 'boolean'];
19+
20+
public function events()
21+
{
22+
return $this->hasMany(FamilyEvent::class);
23+
}
24+
25+
public function children()
26+
{
27+
return $this->hasMany(Person::class, 'child_in_family_id');
28+
}
29+
30+
public function husband()
31+
{
32+
return $this->hasOne(Person::class, 'id', 'husband_id');
33+
}
34+
35+
public function wife()
36+
{
37+
return $this->hasOne(Person::class, 'id', 'wife_id');
38+
}
39+
40+
public function title()
41+
{
42+
return (($this->husband) ? $this->husband->fullname() : '?').
43+
' + '.
44+
(($this->wife) ? $this->wife->fullname() : '?');
45+
}
46+
47+
public static function getList()
48+
{
49+
$families = self::get();
50+
$result = [];
51+
foreach ($families as $family) {
52+
$result[$family->id] = $family->title();
53+
}
54+
55+
return collect($result);
56+
}
57+
58+
public function addEvent($title, $date, $place, $description = '')
59+
{
60+
$place_id = Place::getIdByTitle($place);
61+
$event = FamilyEvent::updateOrCreate(
62+
[
63+
'family_id' => $this->id,
64+
'title' => $title,
65+
],
66+
[
67+
'family_id' => $this->id,
68+
'title' => $title,
69+
'description' => $description,
70+
]);
71+
if ($date) {
72+
$event->date = $date;
73+
$event->save();
74+
}
75+
if ($place) {
76+
$event->places_id = $place_id;
77+
$event->save();
78+
}
79+
}
80+
81+
public function getWifeName()
82+
{
83+
if ($this->wife) {
84+
return $this->wife->fullname();
85+
} else {
86+
return 'unknown woman';
87+
}
88+
}
89+
90+
public function getHusbandName()
91+
{
92+
if ($this->husband) {
93+
return $this->husband->fullname();
94+
} else {
95+
return 'unknown man';
96+
}
97+
}
98+
}

src/Models/FamilyEvent.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace GenealogiaWebsite\LaravelGedcom\Models;
4+
5+
use Illuminate\Database\Eloquent\SoftDeletes;
6+
7+
use GenealogiaWebsite\LaravelGedcom\Observers\EventActionsObserver;
8+
9+
class FamilyEvent extends Event
10+
{
11+
use SoftDeletes;
12+
13+
14+
/**
15+
* The attributes that should be mutated to dates.
16+
*
17+
* @var array
18+
*/
19+
protected $dates = ['deleted_at'];
20+
21+
protected $table = 'family_events';
22+
23+
protected $fillable = [
24+
'family_id',
25+
'places_id',
26+
'date',
27+
'title',
28+
'description',
29+
'year',
30+
'month',
31+
'day',
32+
'type',
33+
'plac',
34+
'phon',
35+
'caus',
36+
'age',
37+
'husb',
38+
'wife',
39+
];
40+
41+
public static function boot()
42+
{
43+
parent::boot();
44+
45+
self::observe(new EventActionsObserver());
46+
}
47+
48+
public function family()
49+
{
50+
return $this->hasOne(Family::class, 'id', 'family_id');
51+
}
52+
}

src/Models/FamilySlgs.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace GenealogiaWebsite\LaravelGedcom\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
8+
/**
9+
* @property int $id
10+
* @property int $family_id
11+
* @property string $stat
12+
* @property string $date
13+
* @property string $plac
14+
* @property string $temp
15+
* @property string $created_at
16+
* @property string $updated_at
17+
*/
18+
class FamilySlgs extends Model
19+
{
20+
21+
22+
/**
23+
* The "type" of the auto-incrementing ID.
24+
*
25+
* @var string
26+
*/
27+
protected $keyType = 'integer';
28+
29+
/**
30+
* @var array
31+
*/
32+
protected $fillable = ['family_id', 'stat', 'date', 'plac', 'temp', 'created_at', 'updated_at'];
33+
}

src/Models/ImportJob.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace GenealogiaWebsite\LaravelGedcom\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
/**
8+
* @property int $id
9+
* @property int $user_id
10+
* @property string $slug
11+
* @property string $status
12+
* @property string $created_at
13+
* @property string $updated_at
14+
*/
15+
class ImportJob extends Model
16+
{
17+
/**
18+
* The table associated with the model.
19+
*
20+
* @var string
21+
*/
22+
protected $table = 'importjobs';
23+
24+
/**
25+
* The "type" of the auto-incrementing ID.
26+
*
27+
* @var string
28+
*/
29+
protected $keyType = 'integer';
30+
31+
/**
32+
* @var array
33+
*/
34+
protected $fillable = ['user_id', 'slug', 'status', 'created_at', 'updated_at'];
35+
}

0 commit comments

Comments
 (0)