|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace roaresearch\yii2\formgenerator\roa\models; |
|
4
|
|
|
|
|
5
|
|
|
use roaresearch\yii2\formgenerator\models as base; |
|
6
|
|
|
use roaresearch\yii2\roa\hal\{Contract, ContractTrait}; |
|
7
|
|
|
use yii\{helpers\Url, web\Link, web\NotFoundHttpException}; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* ROA contract handling Solicitude records. |
|
11
|
|
|
*/ |
|
12
|
|
|
class Solicitude extends base\Solicitude implements Contract |
|
13
|
|
|
{ |
|
14
|
|
|
use ContractTrait { |
|
15
|
|
|
getLinks as getContractLinks; |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @inheritdoc |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $formClass = Form::class; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @inheritdoc |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $solicitudeValueClass = SolicitudeValue::class; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @inheritdoc |
|
30
|
|
|
*/ |
|
31
|
4 |
|
public function getLinks() |
|
32
|
|
|
{ |
|
33
|
4 |
|
$selfLink = $this->getSelfLink(); |
|
34
|
|
|
|
|
35
|
4 |
|
return array_merge($this->getContractLinks(), [ |
|
36
|
4 |
|
'values' => $selfLink . '/value', |
|
37
|
|
|
'curies' => [ |
|
38
|
4 |
|
new Link([ |
|
39
|
4 |
|
'name' => 'embeddable', |
|
40
|
4 |
|
'href' => Url::to($selfLink, ['expand' => '{rel}']), |
|
|
|
|
|
|
41
|
4 |
|
'title' => 'Embeddable and not Nestable related resources.', |
|
42
|
|
|
]), |
|
43
|
4 |
|
new Link([ |
|
44
|
4 |
|
'name' => 'nestable', |
|
45
|
4 |
|
'href' => Url::to($selfLink, ['expand' => '{rel}']), |
|
46
|
4 |
|
'title' => 'Embeddable and Nestable related resources.', |
|
47
|
|
|
]), |
|
48
|
|
|
], |
|
49
|
4 |
|
'embeddable:values' => 'values', |
|
50
|
4 |
|
'nestable:form' => 'form', |
|
51
|
|
|
]); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @inheritdoc |
|
56
|
|
|
*/ |
|
57
|
11 |
|
protected function slugBehaviorConfig(): array |
|
58
|
|
|
{ |
|
59
|
|
|
return [ |
|
60
|
11 |
|
'resourceName' => 'solicitude', |
|
61
|
11 |
|
'parentSlugRelation' => 'form', |
|
62
|
11 |
|
'checkAccess' => function ($params) { |
|
63
|
|
|
if ( |
|
64
|
8 |
|
isset($params['solicitude_id']) |
|
65
|
8 |
|
&& $params['solicitude_id'] != $this->id |
|
66
|
|
|
) { |
|
67
|
|
|
throw new NotFoundHttpException( |
|
68
|
|
|
'Solicitude doesnt contain the requested route.' |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
11 |
|
}, |
|
72
|
|
|
]; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @inheritdoc |
|
77
|
|
|
*/ |
|
78
|
4 |
|
public function extraFields() |
|
79
|
|
|
{ |
|
80
|
4 |
|
return ['form', 'values']; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|