1 | <?php |
||
13 | class Line extends Model |
||
14 | { |
||
15 | use BaseTranslatable, Translatable; |
||
16 | |||
17 | public $table = 'squanto_lines'; |
||
18 | public $translatedAttributes = ['value']; |
||
19 | 36 | ||
20 | /** |
||
21 | 36 | * @param $key |
|
22 | * @return Line |
||
23 | 36 | */ |
|
24 | 36 | public static function make($key) |
|
25 | 36 | { |
|
26 | 36 | $linekey = new LineKey($key); |
|
27 | |||
28 | 36 | $line = new self; |
|
29 | $line->key = $linekey->get(); |
||
|
|||
30 | 36 | $line->label = $linekey->getAsLabel(); |
|
31 | $line->page_id = Page::findOrCreateByKey($linekey->getPageKey())->id; |
||
32 | |||
33 | $line->save(); |
||
34 | |||
35 | return $line; |
||
36 | } |
||
37 | 12 | ||
38 | /** |
||
39 | 12 | * @param $key |
|
40 | 3 | * @return Line |
|
41 | */ |
||
42 | public static function findOrCreateByKey($key) |
||
43 | 12 | { |
|
44 | if ($line = self::findByKey($key)) { |
||
45 | return $line; |
||
46 | } |
||
47 | |||
48 | return self::make($key); |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * Save a translated value |
||
53 | 30 | * |
|
54 | * @param $locale |
||
55 | 30 | * @param $value |
|
56 | * @return $this |
||
57 | 30 | */ |
|
58 | public function saveValue($locale, $value) |
||
59 | { |
||
60 | $this->saveTranslation($locale, 'value', $value); |
||
61 | |||
62 | return $this; |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Save a translated value |
||
67 | * |
||
68 | * @param $locale |
||
69 | * @return $this |
||
70 | */ |
||
71 | public function removeValue($locale) |
||
72 | { |
||
73 | $this->removeTranslation($locale); |
||
74 | |||
75 | return $this; |
||
76 | } |
||
77 | |||
78 | 24 | /** |
|
79 | * @param null $locale |
||
80 | 24 | * @param bool $fallback |
|
81 | * @return string |
||
82 | */ |
||
83 | public function getValue($locale = null, $fallback = true) |
||
84 | { |
||
85 | return $this->getTranslationFor('value', $locale, $fallback); |
||
86 | } |
||
87 | |||
88 | public static function findValue($key, $locale) |
||
89 | { |
||
90 | if (!$line = self::findByKey($key)) { |
||
91 | return null; |
||
92 | } |
||
93 | |||
94 | return $line->getValue($locale, false); |
||
95 | } |
||
96 | 39 | ||
97 | /** |
||
98 | 39 | * @param $key |
|
99 | * @return mixed |
||
100 | */ |
||
101 | 12 | public static function findByKey($key) |
|
102 | { |
||
103 | return self::where('key', $key)->first(); |
||
104 | 12 | } |
|
105 | |||
106 | public function saveSuggestedType() |
||
107 | { |
||
108 | 12 | // Based on first value found we will suggest a type |
|
109 | 12 | if (!$value = $this->getValue()) { |
|
110 | 12 | return; |
|
111 | } |
||
112 | |||
113 | $this->type = (new LineType($value))->suggest(); |
||
114 | $this->save(); |
||
115 | } |
||
116 | |||
117 | public function editInEditor() |
||
121 | |||
122 | public function editInTextarea() |
||
126 | |||
127 | public function editInTextinput() |
||
128 | { |
||
129 | return (!$this->type || $this->type == LineType::TEXT); |
||
130 | } |
||
131 | } |
||
132 |
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.