|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; |
|
6
|
|
|
|
|
7
|
|
|
use Yiisoft\ActiveRecord\ActiveQuery; |
|
8
|
|
|
use Yiisoft\ActiveRecord\ActiveQueryInterface; |
|
9
|
|
|
use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class Dossier |
|
13
|
|
|
*/ |
|
14
|
|
|
final class Dossier extends ActiveRecord |
|
15
|
|
|
{ |
|
16
|
|
|
protected int $id; |
|
17
|
|
|
protected int $department_id; |
|
18
|
|
|
protected int $employee_id; |
|
19
|
|
|
protected string $summary; |
|
20
|
|
|
|
|
21
|
|
|
public function getTableName(): string |
|
22
|
|
|
{ |
|
23
|
|
|
return 'dossier'; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function getId(): int |
|
27
|
|
|
{ |
|
28
|
|
|
return $this->id; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function getDepartmentId(): int |
|
32
|
|
|
{ |
|
33
|
|
|
return $this->department_id; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function getEmployeeId(): int |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->employee_id; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function getSummary(): string |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->summary; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function setId(int $id): void |
|
47
|
|
|
{ |
|
48
|
|
|
$this->id = $id; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function setDepartmentId(int $departmentId): void |
|
52
|
|
|
{ |
|
53
|
|
|
$this->setAttribute('department_id', $departmentId); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function setEmployeeId(int $employeeId): void |
|
57
|
|
|
{ |
|
58
|
|
|
$this->setAttribute('employee_id', $employeeId); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function setSummary(string $summary): void |
|
62
|
|
|
{ |
|
63
|
|
|
$this->summary = $summary; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function relationQuery(string $name): ActiveQueryInterface |
|
67
|
|
|
{ |
|
68
|
|
|
return match ($name) { |
|
69
|
|
|
'employee' => $this->getEmployeeQuery(), |
|
70
|
|
|
default => parent::relationQuery($name), |
|
71
|
|
|
}; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function getEmployee(): Employee|null |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->relation('employee'); |
|
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function getEmployeeQuery(): ActiveQuery |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->hasOne( |
|
82
|
|
|
Employee::class, |
|
83
|
|
|
[ |
|
84
|
|
|
'department_id' => 'department_id', |
|
85
|
|
|
'id' => 'employee_id', |
|
86
|
|
|
] |
|
87
|
|
|
)->inverseOf('dossier'); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|