mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-25 04:27:22 +08:00
SearchBoxRepository
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Models\ExamProgress;
|
||||
use App\Models\ExamUser;
|
||||
use App\Models\User;
|
||||
use App\Repositories\ExamRepository;
|
||||
use App\Repositories\SearchBoxRepository;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -61,7 +62,10 @@ class Test extends Command
|
||||
// $r = $disk->put('/', base_path('composer.json'));
|
||||
// $r = DB::table('users')->where('id', 1)->update(['modcomment' => DB::raw("concat_ws(',', 'ddddd', modcomment)")]);
|
||||
|
||||
$r = format_description('[em4] [em27]');
|
||||
// $r = format_description('[em4] [em27]');
|
||||
|
||||
$rep = new SearchBoxRepository();
|
||||
$r = $rep->initSearchBoxField(4);
|
||||
dd($r);
|
||||
}
|
||||
|
||||
|
||||
@@ -76,15 +76,18 @@ class Handler extends ExceptionHandler
|
||||
protected function prepareJsonResponse($request, Throwable $e)
|
||||
{
|
||||
$data = $request->all();
|
||||
if (config('app.debug')) {
|
||||
$httpStatusCode = $this->getHttpStatusCode($e);
|
||||
if ($httpStatusCode == 200) {
|
||||
$msg = $e->getMessage() ?: get_class($e);
|
||||
$data['trace'] = $e->getTraceAsString();
|
||||
} else {
|
||||
$msg = 'Server Error';
|
||||
}
|
||||
if (config('app.debug')) {
|
||||
$data['trace'] = $e->getTraceAsString();
|
||||
}
|
||||
return new JsonResponse(
|
||||
fail($msg, $data),
|
||||
$this->getHttpStatusCode($e),
|
||||
$httpStatusCode,
|
||||
$this->isHttpException($e) ? $e->getHeaders() : [],
|
||||
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
|
||||
);
|
||||
|
||||
@@ -5,5 +5,7 @@ namespace App\Models;
|
||||
|
||||
class Category extends NexusModel
|
||||
{
|
||||
protected $table = 'categories';
|
||||
|
||||
protected $fillable = ['mode', 'name', 'class_name', 'image', 'sort_index', 'icon_id'];
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class Searchbox extends NexusModel
|
||||
class SearchBox extends NexusModel
|
||||
{
|
||||
protected $table = 'searchbox';
|
||||
|
||||
@@ -12,4 +12,17 @@ class Searchbox extends NexusModel
|
||||
'custom_fields', 'custom_fields_display_name', 'custom_fields_display'
|
||||
];
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class SearchBoxField extends NexusModel
|
||||
{
|
||||
protected $table = 'searchbox_fields';
|
||||
|
||||
protected $fillable = ['searchbox_id', 'field_type', 'field_id', ];
|
||||
|
||||
const FIELD_TYPE_SOURCE = 'source';
|
||||
const FIELD_TYPE_MEDIUM = 'medium';
|
||||
const FIELD_TYPE_CODEC = 'codec';
|
||||
const FIELD_TYPE_AUDIO_CODEC = 'audio_codec';
|
||||
const FIELD_TYPE_STANDARD = 'standard';
|
||||
const FIELD_TYPE_PROCESSING = 'processing';
|
||||
const FIELD_TYPE_TEAM = 'team';
|
||||
const FIELD_TYPE_CUSTOM = 'custom';
|
||||
|
||||
public static $fieldTypes = [
|
||||
self::FIELD_TYPE_SOURCE => ['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');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class SearchboxField extends NexusModel
|
||||
{
|
||||
protected $table = 'searchbox_fields';
|
||||
|
||||
protected $fillable = ['searchbox_id', 'field_type', 'field_id', ];
|
||||
|
||||
public function searchbox()
|
||||
{
|
||||
return $this->belongsTo(Searchbox::class, 'searchbox_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\NexusModel;
|
||||
use App\Models\SearchBox;
|
||||
use App\Models\SearchBoxField;
|
||||
|
||||
class SearchBoxRepository extends BaseRepository
|
||||
{
|
||||
public function getList(array $params): \Illuminate\Contracts\Pagination\LengthAwarePaginator
|
||||
{
|
||||
$query = SearchBox::query();
|
||||
list($sortField, $sortType) = $this->getSortFieldAndType($params);
|
||||
$query->orderBy($sortField, $sortType);
|
||||
return $query->paginate();
|
||||
}
|
||||
|
||||
public function store(array $params)
|
||||
{
|
||||
$result = SearchBox::query()->create($params);
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function update(array $params, $id)
|
||||
{
|
||||
$result = SearchBox::query()->findOrFail($id);
|
||||
$result->update($params);
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getDetail($id)
|
||||
{
|
||||
$result = SearchBox::query()->findOrFail($id);
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$result = SearchBox::query()->findOrFail($id);
|
||||
$success = $result->delete();
|
||||
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);
|
||||
foreach (SearchBoxField::$fieldTypes as $fieldType => $info) {
|
||||
if ($fieldType == SearchBoxField::FIELD_TYPE_CUSTOM) {
|
||||
continue;
|
||||
}
|
||||
$name = str_replace('_', '', "show{$fieldType}");
|
||||
$log = "name: $name, fieldType: $fieldType";
|
||||
$searchBox->normal_fields()->where('field_type', $fieldType)->delete();
|
||||
if ($searchBox->{$name}) {
|
||||
$searchBox->normal_fields()->create([
|
||||
'field_type' => $fieldType,
|
||||
]);
|
||||
do_log("$log, create.");
|
||||
} else {
|
||||
do_log("$log, delete.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user