1 | <?php namespace Rocket\Entities; |
||
18 | abstract class Entity |
||
19 | { |
||
20 | public static $types; |
||
21 | |||
22 | /** |
||
23 | * The content represented by this entity |
||
24 | * |
||
25 | * @var Content |
||
26 | */ |
||
27 | protected $content; //id, created_at |
||
28 | |||
29 | /** |
||
30 | * The revision represented by this entity |
||
31 | * |
||
32 | * @var Revision |
||
33 | */ |
||
34 | protected $revision; //language_id, updated_at |
||
35 | |||
36 | /** |
||
37 | * The fields in this entity |
||
38 | * |
||
39 | * @var array<FieldCollection> |
||
40 | */ |
||
41 | protected $data; |
||
42 | |||
43 | /** |
||
44 | * Entity constructor. |
||
45 | * |
||
46 | * @param int $language_id The language this specific entity is in |
||
47 | */ |
||
48 | 42 | public function __construct($language_id) |
|
60 | |||
61 | 39 | protected function initialize(array $fields) |
|
70 | |||
71 | /** |
||
72 | * @param string $field |
||
73 | * @param array $settings |
||
74 | * @return static |
||
75 | * @throws InvalidFieldTypeException |
||
76 | * @throws ReservedFieldNameException |
||
77 | */ |
||
78 | 39 | protected function initializeField($field, $settings) |
|
96 | |||
97 | abstract public function getFields(); |
||
98 | |||
99 | /** |
||
100 | * Get the database friendly content type |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | 6 | public static function getContentType() |
|
108 | |||
109 | /** |
||
110 | * Create a new revision based on the same content ID but without the content. |
||
111 | * Very useful if you want to add a new language |
||
112 | * |
||
113 | * @param int $language_id |
||
114 | * @return static |
||
115 | */ |
||
116 | 3 | public function newRevision($language_id = null) |
|
123 | |||
124 | /** |
||
125 | * Check if the field is related to the content |
||
126 | * |
||
127 | * @param string $field |
||
128 | * @return bool |
||
129 | */ |
||
130 | 39 | protected function isContentField($field) |
|
134 | |||
135 | /** |
||
136 | * Check if the field exists on the entity |
||
137 | * |
||
138 | * @param string $field |
||
139 | * @return bool |
||
140 | */ |
||
141 | 30 | public function hasField($field) |
|
145 | |||
146 | /** |
||
147 | * @param string $field |
||
148 | * @return FieldCollection |
||
149 | */ |
||
150 | 24 | public function getField($field) |
|
154 | |||
155 | /** |
||
156 | * Check if the field is related to the revision |
||
157 | * |
||
158 | * @param string $field |
||
159 | * @return bool |
||
160 | */ |
||
161 | 36 | protected function isRevisionField($field) |
|
165 | |||
166 | /** |
||
167 | * Dynamically retrieve attributes on the model. |
||
168 | * |
||
169 | * @param string $key |
||
170 | * @throws NonExistentFieldException |
||
171 | * @return $this|bool|\Carbon\Carbon|\DateTime|mixed|static |
||
172 | */ |
||
173 | 30 | public function __get($key) |
|
189 | |||
190 | /** |
||
191 | * Dynamically set attributes on the model. |
||
192 | * |
||
193 | * @param string $key |
||
194 | * @param mixed $value |
||
195 | * @throws NonExistentFieldException |
||
196 | */ |
||
197 | 15 | public function __set($key, $value) |
|
225 | |||
226 | /** |
||
227 | * Find the latest valid revision for this entity |
||
228 | * |
||
229 | * @param int $id |
||
230 | * @param int $language_id |
||
231 | * @return static |
||
232 | */ |
||
233 | 3 | public static function find($id, $language_id) |
|
263 | |||
264 | /** |
||
265 | * Save a revision |
||
266 | */ |
||
267 | 6 | public function save($newRevision = false) |
|
310 | |||
311 | /** |
||
312 | * Convert the Entity to an array. |
||
313 | * |
||
314 | * @return array |
||
315 | */ |
||
316 | 6 | public function toArray() |
|
329 | } |
||
330 |