22
33namespace App \Models ;
44
5+ use App \Http \Middleware \Locale ;
56use Illuminate \Database \Eloquent \Casts \Attribute ;
67use Illuminate \Database \Query \Builder ;
78use Illuminate \Support \Str ;
@@ -182,6 +183,25 @@ public function setCustomFieldsAttribute($value)
182183 }
183184 }
184185
186+ public function getDisplaySectionNameAttribute ()
187+ {
188+ $ locale = Locale::getDefault ();
189+ if (!empty ($ this ->section_name [$ locale ])) {
190+ return $ this ->section_name [$ locale ];
191+ }
192+ $ defaultLang = get_setting ("main.defaultlang " );
193+ if (!empty ($ this ->section_name [$ defaultLang ])) {
194+ return $ this ->section_name [$ defaultLang ];
195+ }
196+ if ($ this ->isSectionBrowse ()) {
197+ return nexus_trans ("searchbox.sections.browse " );
198+ }
199+ if ($ this ->isSectionSpecial ()) {
200+ return nexus_trans ("searchbox.sections.special " );
201+ }
202+ return $ this ->name ;
203+ }
204+
185205 public static function listSearchModes (): array
186206 {
187207 $ result = [];
@@ -206,6 +226,16 @@ public static function getSpecialMode()
206226 return Setting::get ('main.specialcat ' );
207227 }
208228
229+ public function isSectionBrowse (): bool
230+ {
231+ return $ this ->id == self ::getBrowseMode ();
232+ }
233+
234+ public function isSectionSpecial (): bool
235+ {
236+ return $ this ->id == self ::getSpecialMode ();
237+ }
238+
209239
210240 public function categories (): \Illuminate \Database \Eloquent \Relations \HasMany
211241 {
@@ -247,6 +277,17 @@ public function taxonomy_processing(): \Illuminate\Database\Eloquent\Relations\H
247277 return $ this ->hasMany (Processing::class, 'mode ' );
248278 }
249279
280+ public function loadSubCategories (): void
281+ {
282+ foreach (self ::$ taxonomies as $ name => $ info ) {
283+ $ relationName = "taxonomy_ " . $ name ;
284+ $ show = "show " . $ name ;
285+ if ($ this ->{$ show }) {
286+ $ this ->setRelation ($ relationName , $ this ->{$ relationName }()->orWhere ('mode ' , 0 )->get ());
287+ }
288+ }
289+ }
290+
250291 public static function getDefaultSearchMode ()
251292 {
252293 $ meiliConf = get_setting ("meilisearch " );
0 commit comments