diff --git a/app/Console/Commands/Test.php b/app/Console/Commands/Test.php index 1346d9ec..d046f7ba 100644 --- a/app/Console/Commands/Test.php +++ b/app/Console/Commands/Test.php @@ -7,6 +7,7 @@ use App\Filament\Resources\System\AgentAllowResource; use App\Http\Resources\TagResource; use App\Models\AgentAllow; use App\Models\Attendance; +use App\Models\Category; use App\Models\Exam; use App\Models\ExamProgress; use App\Models\ExamUser; @@ -91,15 +92,11 @@ class Test extends Command */ public function handle() { -// Notification::make() -// ->success() -// ->title('Test Test') -// ->send() -// ; - $key = 'sbsb'; - $r = session()->push($key, [1,2,3]); - $r = session()->get($key); - dd($r); + $categoryTaxonomies = [ + 'category' => ['table' => 'categories', 'model' => Category::class], + ]; + $categoryTaxonomies = array_merge($categoryTaxonomies, SearchBox::$taxonomies); + dd($categoryTaxonomies); } diff --git a/app/Filament/CreateRedirectIndexTrait.php b/app/Filament/CreateRedirectIndexTrait.php new file mode 100644 index 00000000..e12be98b --- /dev/null +++ b/app/Filament/CreateRedirectIndexTrait.php @@ -0,0 +1,11 @@ +record = $examRep->update($data, $this->record->id); - $this->notify('success', $this->getSavedNotificationMessage()); + $this->notify('success', $this->getSavedNotificationTitle()); $this->redirect($this->getResource()::getUrl('index')); } catch (\Exception $exception) { $this->notify('danger', $exception->getMessage()); diff --git a/app/Filament/Resources/System/SeedBoxRecordResource/Pages/EditSeedBoxRecord.php b/app/Filament/Resources/System/SeedBoxRecordResource/Pages/EditSeedBoxRecord.php index ed5a78ea..93e9b8e9 100644 --- a/app/Filament/Resources/System/SeedBoxRecordResource/Pages/EditSeedBoxRecord.php +++ b/app/Filament/Resources/System/SeedBoxRecordResource/Pages/EditSeedBoxRecord.php @@ -24,7 +24,7 @@ class EditSeedBoxRecord extends EditRecord $rep = new SeedBoxRepository(); try { $this->record = $rep->update($data, $this->record->id); - $this->notify('success', $this->getSavedNotificationMessage()); + $this->notify('success', $this->getSavedNotificationTitle()); $this->redirect($this->getResource()::getUrl('index')); } catch (\Exception $exception) { $this->notify('danger', $exception->getMessage()); diff --git a/app/Models/SearchBox.php b/app/Models/SearchBox.php index c336855c..9416a871 100644 --- a/app/Models/SearchBox.php +++ b/app/Models/SearchBox.php @@ -146,7 +146,7 @@ class SearchBox extends NexusModel $table = self::$taxonomies[$torrentField]['table']; return NexusDB::table($table)->where(function (Builder $query) use ($searchBox) { return $query->where('mode', $searchBox->id)->orWhere('mode', 0); - })->get(); + })->orderBy('sort_index')->orderBy('id')->get(); } public static function listModeOptions(): array @@ -174,17 +174,27 @@ class SearchBox extends NexusModel } } + public static function isSpecialEnabled(): bool + { + return Setting::get('main.spsct') == 'yes'; + } + + public static function getBrowseMode() + { + return Setting::get('main.browsecat'); + } + + public static function getSpecialMode() + { + return Setting::get('main.specialcat'); + } + public function categories(): \Illuminate\Database\Eloquent\Relations\HasMany { return $this->hasMany(Category::class, 'mode'); } - public function normal_fields(): \Illuminate\Database\Eloquent\Relations\HasMany - { - return $this->hasMany(SearchBoxField::class, 'searchbox_id'); - } - public function taxonomy_source(): \Illuminate\Database\Eloquent\Relations\HasMany { return $this->hasMany(Source::class, 'mode'); @@ -220,10 +230,5 @@ class SearchBox extends NexusModel return $this->hasMany(Processing::class, 'mode'); } - public function taxonomies(): \Illuminate\Database\Eloquent\Relations\HasMany - { - return $this->hasMany(Taxonomy::class, 'mode'); - } - } diff --git a/app/Models/SearchBoxField.php b/app/Models/SearchBoxField.php deleted file mode 100644 index db0de371..00000000 --- a/app/Models/SearchBoxField.php +++ /dev/null @@ -1,40 +0,0 @@ - ['text' => 'Source', 'model' => Source::class], - self::FIELD_TYPE_MEDIUM => ['text' => 'Medium', 'model' => Media::class], - self::FIELD_TYPE_CODEC => ['text' => 'Codec', 'model' => Codec::class], - self::FIELD_TYPE_AUDIO_CODEC => ['text' => 'Audio codec', 'model' => AudioCodec::class], - self::FIELD_TYPE_STANDARD => ['text' => 'Standard', 'model' => Standard::class], - self::FIELD_TYPE_PROCESSING => ['text' => 'Processing', 'model' => Processing::class], - self::FIELD_TYPE_TEAM => ['text' => 'Team', 'model' => Team::class], - self::FIELD_TYPE_CUSTOM => ['text' => 'Custom', ], - ]; - - - public function searchBox(): \Illuminate\Database\Eloquent\Relations\BelongsTo - { - return $this->belongsTo(SearchBox::class, 'searchbox_id'); - } - - - - -} diff --git a/app/Repositories/SearchBoxRepository.php b/app/Repositories/SearchBoxRepository.php index fdf6972e..6ae28b00 100644 --- a/app/Repositories/SearchBoxRepository.php +++ b/app/Repositories/SearchBoxRepository.php @@ -56,44 +56,6 @@ class SearchBoxRepository extends BaseRepository return $success; } - public function buildSearchBox($id) - { - $searchBox = SearchBox::query()->with(['categories', 'normal_fields'])->findOrFail($id); - $fieldData = []; - foreach ($searchBox->normal_fields as $normalField) { - $fieldType = $normalField->field_type; - $info = SearchBoxField::$fieldTypes[$fieldType] ?? null; - if ($info) { - /** @var NexusModel $model */ - $model = new $info[$fieldType]['model']; - $fieldData[$fieldType] = $model::query()->get(); - } - } - $searchBox->setRelation('normal_fields_data', $fieldData); - return $searchBox; - } - - public function initSearchBoxField($id) - { - $searchBox = SearchBox::query()->findOrFail($id); - $logPrefix = "searchBox: $id"; - $result = $searchBox->normal_fields()->delete(); - do_log("$logPrefix, remove all normal fields: $result"); - foreach (SearchBoxField::$fieldTypes as $fieldType => $info) { - if ($fieldType == SearchBoxField::FIELD_TYPE_CUSTOM) { - continue; - } - $name = str_replace('_', '', "show{$fieldType}"); - $log = "$logPrefix, name: $name, fieldType: $fieldType"; - if ($searchBox->{$name}) { - $searchBox->normal_fields()->create([ - 'field_type' => $fieldType, - ]); - do_log("$log, create."); - } - } - } - public function listIcon(array $idArr) { $searchBoxList = SearchBox::query()->with('categories')->find($idArr); diff --git a/include/constants.php b/include/constants.php index 4a5c1175..cfed51e5 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@ steps[$step - 1] ?? ''; } + public function migrateSearchBoxModeRelated() + { + $this->doLog("[migrateSearchBoxModeRelated]"); + $searchBoxRep = new SearchBoxRepository(); + $searchBoxRep->migrateToModeRelated(); + } + } diff --git a/nexus/Install/Update.php b/nexus/Install/Update.php index c1076290..11da806a 100644 --- a/nexus/Install/Update.php +++ b/nexus/Install/Update.php @@ -276,8 +276,7 @@ class Update extends Install $this->runMigrate('database/migrations/2022_09_05_230532_add_mode_to_section_related.php'); $this->runMigrate('database/migrations/2022_09_06_004318_add_section_name_to_searchbox_table.php'); $this->runMigrate('database/migrations/2022_09_06_030324_change_searchbox_field_extra_to_json.php'); - $searchBoxRep = new SearchBoxRepository(); - $searchBoxRep->migrateToModeRelated(); + $this->migrateSearchBoxModeRelated(); $this->doLog("[MIGRATE_TAXONOMY_TO_MODE_RELATED]"); } $this->removeMenu(['catmanage.php']); diff --git a/nexus/Install/install/install.php b/nexus/Install/install/install.php index 30ace48a..cfbd053d 100644 --- a/nexus/Install/install/install.php +++ b/nexus/Install/install/install.php @@ -111,6 +111,7 @@ if ($currentStep == 4) { $install->createSymbolicLinks($symbolicLinks); $install->runDatabaseSeeder(); $install->saveSettings($settings); + $install->migrateSearchBoxModeRelated(); $install->nextStep(); } catch (\Exception $e) { $error = $e->getMessage();