|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* To change this license header, choose License Headers in Project Properties. |
|
5
|
|
|
* To change this template file, choose Tools | Templates |
|
6
|
|
|
* and open the template in the editor. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Maslosoft\Mangan\Annotations; |
|
10
|
|
|
|
|
11
|
|
|
use Maslosoft\Addendum\Helpers\ParamsExpander; |
|
12
|
|
|
use Maslosoft\Mangan\Interfaces\SortInterface; |
|
13
|
|
|
use Maslosoft\Mangan\Meta\ManganPropertyAnnotation; |
|
14
|
|
|
use Maslosoft\Mangan\Meta\RelatedMeta; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* RelatedOrderingAnnotation |
|
18
|
|
|
* |
|
19
|
|
|
* Use this annotation to store order of related documents. |
|
20
|
|
|
* This should be used on same field as Related or RelatedArray annotations are applied. |
|
21
|
|
|
* This will apply incrementing values on selected field. |
|
22
|
|
|
* |
|
23
|
|
|
* Will also apply sort if not set. |
|
24
|
|
|
* |
|
25
|
|
|
* Compact notation: |
|
26
|
|
|
* |
|
27
|
|
|
* RelatedOrdering('order') |
|
28
|
|
|
* |
|
29
|
|
|
* Extended notation: |
|
30
|
|
|
* |
|
31
|
|
|
* RelatedOrdering(orderField = 'order') |
|
32
|
|
|
* |
|
33
|
|
|
* @template RelatedOrdering('${orderField}') |
|
34
|
|
|
* @author Piotr Maselkowski <pmaselkowski at gmail.com> |
|
35
|
|
|
*/ |
|
36
|
|
|
class RelatedOrderingAnnotation extends ManganPropertyAnnotation |
|
37
|
|
|
{ |
|
38
|
|
|
|
|
39
|
|
|
public $value; |
|
40
|
|
|
public $orderField; |
|
41
|
|
|
|
|
42
|
1 |
|
public function init() |
|
43
|
|
|
{ |
|
44
|
1 |
|
$data = ParamsExpander::expand($this, ['orderField']); |
|
45
|
1 |
|
if (empty($this->_entity->related)) |
|
46
|
1 |
|
{ |
|
47
|
|
|
$relMeta = new RelatedMeta(); |
|
48
|
|
|
} |
|
49
|
|
|
else |
|
50
|
|
|
{ |
|
51
|
1 |
|
$relMeta = $this->_entity->related; |
|
52
|
|
|
} |
|
53
|
1 |
|
foreach ($data as $key => $val) |
|
54
|
|
|
{ |
|
55
|
1 |
|
$relMeta->$key = $val; |
|
56
|
1 |
|
} |
|
57
|
1 |
|
if (empty($relMeta->sort)) |
|
58
|
1 |
|
{ |
|
59
|
|
|
$relMeta->sort = [ |
|
|
|
|
|
|
60
|
|
|
$relMeta->orderField => SortInterface::SortAsc |
|
61
|
|
|
]; |
|
62
|
|
|
} |
|
63
|
1 |
|
$this->_entity->related = $relMeta; |
|
64
|
1 |
|
} |
|
65
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..