@@ -10,23 +10,28 @@ class ThingEditor
1010 private ?int $ id ;
1111 public array $ fields = [];
1212 private array $ relations = [];
13- private DataWriter $ updater ;
13+ private DataWriter $ writer ;
1414 private ?array $ langs = null ;
1515
1616 /**
1717 * @param string[]|string|null $langs
1818 */
19- function __construct (DataWriter $ updater , int $ id = null , $ langs = null )
19+ function __construct (DataWriter $ writer , int $ id = null , $ langs = null )
2020 {
2121 $ this ->id = $ id ;
22- $ this ->updater = $ updater ;
22+ $ this ->writer = $ writer ;
2323 if (is_string ($ langs )) $ langs = [$ langs ];
2424 $ this ->langs = $ langs ;
2525 }
2626
27+ function setLangs (array $ langs = null )
28+ {
29+ $ this ->langs = $ langs ;
30+ }
31+
2732 private function resource (): Resource
2833 {
29- return $ this ->updater ->resource ();
34+ return $ this ->writer ->resource ();
3035 }
3136
3237 function hasData (): bool
@@ -52,7 +57,7 @@ function setValues(string $field_name, $values, $lang = null, bool $append = fal
5257 if (!$ field ) throw FieldNotFound::from ($ field_name );
5358
5459 if ($ field ->is_translatable && !$ lang ) {
55- $ lang = $ this ->langs [0 ] ?? $ this ->updater ->schema ()->lang ;
60+ $ lang = $ this ->langs [0 ] ?? $ this ->writer ->schema ()->lang ;
5661 }
5762 if (!$ field ->is_translatable ) $ lang = null ;
5863 if ($ append ) {
@@ -92,14 +97,14 @@ function toArray(): array
9297 }
9398 function save ()
9499 {
95- return $ this ->updater ->save ();
100+ return $ this ->writer ->save ();
96101 }
97102 function copyFromThing (Thing $ th , array $ limit_langs = null ): Self
98103 {
99- foreach ($ this ->updater ->resource ()->fields ()->whereNotIn ('type ' , ['relation ' ]) as $ f ) {
104+ foreach ($ this ->writer ->resource ()->fields ()->whereNotIn ('type ' , ['relation ' ]) as $ f ) {
100105 $ remote_field = $ th ->resource ()->field ($ f ->name );
101106 if (!$ remote_field ) continue ;
102- $ langs = $ f ->is_translatable ? $ limit_langs ?? $ this ->langs ?? $ this ->updater ->schema ()->langs : [null ];
107+ $ langs = $ f ->is_translatable ? $ limit_langs ?? $ this ->langs ?? $ this ->writer ->schema ()->langs : [null ];
103108
104109 foreach ($ langs as $ l ) {
105110 $ this ->setValues ($ f ->name , $ th ->values ($ f ->name , $ l ), $ l );
@@ -110,13 +115,13 @@ function copyFromThing(Thing $th, array $limit_langs = null): Self
110115
111116 function ignoreInvalidUrls (bool $ ignore = true ): Self
112117 {
113- $ this ->updater ->ignoreInvalidUrls ($ ignore );
118+ $ this ->writer ->ignoreInvalidUrls ($ ignore );
114119 return $ this ;
115120 }
116121
117122 function queuePdfGenerators (bool $ queue = true ): Self
118123 {
119- $ this ->updater ->queuePdfGenerators ($ queue );
124+ $ this ->writer ->queuePdfGenerators ($ queue );
120125 return $ this ;
121126 }
122127}
0 commit comments