1 | <?php |
||
15 | class Line extends Model |
||
16 | { |
||
17 | use BaseTranslatable, Translatable; |
||
18 | |||
19 | public $table = 'squanto_lines'; |
||
20 | public $translatedAttributes = ['value']; |
||
21 | |||
22 | /** |
||
23 | * @param $key |
||
24 | * @return Line |
||
25 | */ |
||
26 | 48 | public static function make($key) |
|
39 | |||
40 | /** |
||
41 | * @param $key |
||
42 | * @return Line |
||
43 | */ |
||
44 | 9 | public static function findOrCreateByKey($key) |
|
45 | { |
||
46 | 9 | if ($line = self::findByKey($key)) { |
|
47 | return $line; |
||
48 | } |
||
49 | |||
50 | 9 | return self::make($key); |
|
51 | } |
||
52 | |||
53 | /** |
||
54 | * Save a translated value |
||
55 | * |
||
56 | * @param $locale |
||
57 | * @param $value |
||
58 | * @return $this |
||
59 | */ |
||
60 | 42 | public function saveValue($locale, $value) |
|
66 | |||
67 | /** |
||
68 | * Save a translated value |
||
69 | * |
||
70 | * @param $locale |
||
71 | * @return $this |
||
72 | */ |
||
73 | public function removeValue($locale) |
||
74 | { |
||
75 | $this->removeTranslation($locale); |
||
76 | |||
77 | return $this; |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * @param null $locale |
||
82 | * @param bool $fallback |
||
83 | * @return string |
||
84 | */ |
||
85 | 21 | public function getValue($locale = null, $fallback = true) |
|
86 | { |
||
87 | 21 | return $this->getTranslationFor('value', $locale, $fallback); |
|
88 | } |
||
89 | |||
90 | public static function findValue($key, $locale) |
||
91 | { |
||
92 | if (!$line = self::findByKey($key)) { |
||
93 | return null; |
||
94 | } |
||
95 | |||
96 | return $line->getValue($locale, false); |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * @param $key |
||
101 | * @return mixed |
||
102 | */ |
||
103 | 39 | public static function findByKey($key) |
|
104 | { |
||
105 | 39 | return self::where('key', $key)->first(); |
|
106 | } |
||
107 | |||
108 | 9 | public function saveSuggestedType() |
|
109 | { |
||
110 | // Based on first value found we will suggest a type |
||
111 | 9 | if (!$value = $this->getValue()) { |
|
112 | return; |
||
113 | } |
||
114 | |||
115 | 9 | $this->type = (new LineType($value))->suggest(); |
|
116 | 9 | $this->save(); |
|
117 | 9 | } |
|
118 | |||
119 | public function editInEditor() |
||
120 | { |
||
121 | return $this->type == LineType::EDITOR; |
||
122 | } |
||
123 | |||
124 | public function editInTextarea() |
||
128 | |||
129 | public function editInTextinput() |
||
133 | |||
134 | public function areParagraphsAllowed() |
||
138 | |||
139 | /** |
||
140 | * Get key - value pairs for all lines per locale |
||
141 | * |
||
142 | * @param $locale |
||
143 | * @return mixed |
||
144 | */ |
||
145 | 12 | public static function getValuesByLocale($locale) |
|
149 | |||
150 | 15 | public static function getValuesByLocaleAndPage($locale, $pagekey = null) |
|
175 | } |
||
176 |
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.