1 | <?php |
||
18 | trait Translatable |
||
19 | { |
||
20 | protected $_deleting_translation = false; |
||
21 | protected $_translating_relation = false; |
||
22 | |||
23 | /** |
||
24 | * {@inheritdoc} |
||
25 | */ |
||
26 | public static function bootTranslatable() |
||
27 | { |
||
28 | static::observe(TranslatableObserver::class); |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * Get the list of non translatable fields. |
||
33 | * |
||
34 | * @return array |
||
35 | */ |
||
36 | public function getNonTranslatable(): array |
||
37 | { |
||
38 | return isset($this->nonTranslatable) ? $this->nonTranslatable : []; |
||
|
|||
39 | } |
||
40 | |||
41 | /** |
||
42 | * Get the list of fields to duplicate on create. |
||
43 | * (Other fields MUST BE nullable in database). |
||
44 | * |
||
45 | * @return array |
||
46 | */ |
||
47 | public function getOnCreateTranslatable(): array |
||
48 | { |
||
49 | return isset($this->onCreateTranslatable) ? $this->onCreateTranslatable : $this->getNonTranslatable(); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Translation relationship. |
||
54 | * |
||
55 | * @return \Illuminate\Database\Eloquent\Relations\MorphOne |
||
56 | */ |
||
57 | public function translation(): MorphOne |
||
61 | |||
62 | /** |
||
63 | * Return current item translations. |
||
64 | * |
||
65 | * @return \BBSLab\NovaTranslation\Models\TranslationRelation |
||
66 | */ |
||
67 | public function translations(): TranslationRelation |
||
71 | |||
72 | /** |
||
73 | * Create and return a translation entry for given locale ID. |
||
74 | * |
||
75 | * @param int $localeId |
||
76 | * @param int $sourceId |
||
77 | * @param int $translationId |
||
78 | * @return \BBSLab\NovaTranslation\Models\Translation |
||
79 | */ |
||
80 | public function upsertTranslationEntry(int $localeId, int $sourceId, int $translationId = 0): Translation |
||
94 | |||
95 | /** |
||
96 | * Return next fresh translation ID. |
||
97 | * |
||
98 | * @return int |
||
99 | */ |
||
100 | public function freshTranslationId(): int |
||
108 | |||
109 | /** |
||
110 | * Scope a query to only retrieve items from given locale. |
||
111 | * |
||
112 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
113 | * @param string $iso |
||
114 | * @return \Illuminate\Database\Eloquent\Builder |
||
115 | */ |
||
116 | public function scopeLocale(EloquentBuilder $builder, string $iso = null) |
||
128 | |||
129 | /** |
||
130 | * Translate model to given locale and return translated model. |
||
131 | * |
||
132 | * @param \BBSLab\NovaTranslation\Models\Locale $locale |
||
133 | * @return \BBSLab\NovaTranslation\Models\Contracts\IsTranslatable |
||
134 | */ |
||
135 | public function translate(Locale $locale) |
||
160 | |||
161 | /** |
||
162 | * Set deleting translation state. |
||
163 | * |
||
164 | * @return void |
||
165 | */ |
||
166 | public function deletingTranslation(): void |
||
170 | |||
171 | /** |
||
172 | * Determine is the model currently in a delete translation process. |
||
173 | * |
||
174 | * @return bool |
||
175 | */ |
||
176 | public function isDeletingTranslation(): bool |
||
180 | |||
181 | /** |
||
182 | * Set translating relation state. |
||
183 | * |
||
184 | * @return void |
||
185 | */ |
||
186 | public function translatingRelation(): void |
||
190 | |||
191 | /** |
||
192 | * Determine is the model currently translating a relation. |
||
193 | * |
||
194 | * @return bool |
||
195 | */ |
||
196 | public function isTranslatingRelation(): bool |
||
200 | } |
||
201 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: