/
Attribute.php
125 lines (95 loc) · 2.5 KB
/
Attribute.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
namespace Northstyle\Module\Shop\DataObject;
use Northstyle\Common\DataObject;
use Northstyle\Module\Core\DataObject\Id;
class Attribute extends DataObject {
public $id = null;
public $representation_id = null;
public $representation = array();
public $edit_url = '';
public $name = '';
public $label = null;
public $options = array();
public $values = array();
public $validators = array();
public $max_values_count = 1;
public $default_value = '';
public $required_create = false;
public $required_order = false;
public function _init($data = array()) {
if (!isset($data['id'])) {
$this->set_id(0);
}
if (!isset($data['representation_id'])) {
$this->set_representation_id(0);
}
}
public function set_id($value) {
if (is_object($value) && $value instanceof Id) {
$this->id = $value;
} else {
$this->id = Id::create($value);
}
}
public function set_representation_id($value) {
if (is_object($value) && $value instanceof Id) {
$this->representation_id = $value;
} else {
$this->representation_id = Id::create($value);
}
}
public function set_label($value) {
$this->label = $value;
}
public function set_attributes($value) {
if (is_array($value)) {
$this->options = array();
foreach ($value as $item) {
if (is_object($item) && $item instanceof Attribute) {
$this->options[] = $item;
}
}
}
}
public function set_values($data) {
if (is_array($data)) {
$this->values = array();
foreach ($data as $item) {
if (is_object($item) && $item instanceof ObjectValue) {
$this->values[$item->name] = $item;
} else if (is_array($item)) {
$this->values[$item['name']] = new ObjectValue($item);
}
}
}
}
public function set_validators($data) {
if (is_array($data)) {
$this->validators = array();
foreach ($data as $item) {
if (is_object($item) && $item instanceof Validator) {
$this->validators[] = $item;
}
}
}
}
public function set_representation($data) {
if (is_object($data) && $data instanceof AttributeRepresentation) {
$this->representation = $data;
} else if (is_array($data)) {
$this->representation = new AttributeRepresentation($data);
}
}
public function set_options($data) {
if (is_array($data)) {
$this->options = array();
foreach ($data as $item) {
if (is_object($item) && $item instanceof AttributeOption) {
$this->options[] = $item;
} else if (is_array($item)) {
$this->options[] = new AttributeOption($item);
}
}
}
}
}