mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig-portal.git
synced 2025-12-11 06:46:47 +00:00
bookCases added
This commit is contained in:
58
app/Console/Commands/OpenBooks/SyncOpenBooks.php
Normal file
58
app/Console/Commands/OpenBooks/SyncOpenBooks.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\OpenBooks;
|
||||
|
||||
use App\Models\BookCase;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class SyncOpenBooks extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'books:sync';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$response = Http::post('https://openbookcase.de/api/listarea/83.08995477111446/-200.56640625000003/-38.13455657705413/221.30859375000003');
|
||||
|
||||
foreach ($response->json()['cases'] as $case) {
|
||||
BookCase::updateOrCreate(
|
||||
[
|
||||
'id' => $case['id'],
|
||||
],
|
||||
[
|
||||
'title' => $case['title'],
|
||||
'lat' => (float)$case['lat'],
|
||||
'lon' => (float)$case['lon'],
|
||||
'address' => $case['address'],
|
||||
'type' => $case['type'],
|
||||
'open' => $case['open'],
|
||||
'comment' => $case['comment'],
|
||||
'contact' => $case['contact'],
|
||||
'bcz' => $case['bcz'],
|
||||
'digital' => $case['digital'] ?? false,
|
||||
'icontype' => $case['icontype'],
|
||||
'deactivated' => $case['deactivated'],
|
||||
'deactreason' => $case['deactreason'],
|
||||
'entrytype' => $case['entrytype'],
|
||||
'homepage' => $case['homepage'],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
22
app/Http/Livewire/Frontend/SearchBookCase.php
Normal file
22
app/Http/Livewire/Frontend/SearchBookCase.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Frontend;
|
||||
|
||||
use App\Models\BookCase;
|
||||
use App\Models\Country;
|
||||
use Livewire\Component;
|
||||
|
||||
class SearchBookCase extends Component
|
||||
{
|
||||
public string $c = 'de';
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.frontend.search-book-case', [
|
||||
'bookCases' => BookCase::get(),
|
||||
'countries' => Country::query()
|
||||
->select(['code', 'name'])
|
||||
->get(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
55
app/Http/Livewire/Tables/BookCaseTable.php
Normal file
55
app/Http/Livewire/Tables/BookCaseTable.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Tables;
|
||||
|
||||
use App\Models\BookCase;
|
||||
use Rappasoft\LaravelLivewireTables\DataTableComponent;
|
||||
use Rappasoft\LaravelLivewireTables\Views\Column;
|
||||
use Rappasoft\LaravelLivewireTables\Views\Columns\BooleanColumn;
|
||||
|
||||
class BookCaseTable extends DataTableComponent
|
||||
{
|
||||
protected $model = BookCase::class;
|
||||
|
||||
public function configure(): void
|
||||
{
|
||||
$this->setPrimaryKey('id')
|
||||
->setAdditionalSelects(['id'])
|
||||
->setThAttributes(function (Column $column) {
|
||||
return [
|
||||
'class' => 'px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider dark:bg-gray-800 dark:text-gray-400',
|
||||
'default' => false,
|
||||
];
|
||||
})
|
||||
->setTdAttributes(function (Column $column, $row, $columnIndex, $rowIndex) {
|
||||
return [
|
||||
'class' => 'px-6 py-4 text-sm font-medium dark:text-white',
|
||||
'default' => false,
|
||||
];
|
||||
})
|
||||
->setColumnSelectStatus(false)
|
||||
->setPerPage(50);
|
||||
}
|
||||
|
||||
public function columns(): array
|
||||
{
|
||||
return [
|
||||
Column::make("Name", "title")
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Column::make("Adresse", "address")
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Column::make("Link")
|
||||
->label(
|
||||
fn(
|
||||
$row,
|
||||
Column $column
|
||||
) => '<a class="underline text-amber-500" href="'.$row->homepage.'">Link</a>'
|
||||
)
|
||||
->html(),
|
||||
BooleanColumn::make('Oranged-Pilled', 'deactivated')
|
||||
->sortable(),
|
||||
];
|
||||
}
|
||||
}
|
||||
31
app/Models/BookCase.php
Normal file
31
app/Models/BookCase.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class BookCase extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that aren't mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'lat' => 'double',
|
||||
'lon' => 'array',
|
||||
'digital' => 'boolean',
|
||||
'deactivated' => 'boolean',
|
||||
];
|
||||
}
|
||||
141
app/Nova/BookCase.php
Normal file
141
app/Nova/BookCase.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
namespace App\Nova;
|
||||
|
||||
use Laravel\Nova\Fields\ID;
|
||||
use Illuminate\Http\Request;
|
||||
use Laravel\Nova\Fields\Code;
|
||||
use Laravel\Nova\Fields\Text;
|
||||
use Laravel\Nova\Fields\Number;
|
||||
use Laravel\Nova\Fields\Boolean;
|
||||
|
||||
class BookCase extends Resource
|
||||
{
|
||||
/**
|
||||
* The model the resource corresponds to.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $model = \App\Models\BookCase::class;
|
||||
|
||||
/**
|
||||
* The single value that should be used to represent the resource when being displayed.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $title = 'id';
|
||||
|
||||
/**
|
||||
* The columns that should be searched.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $search = [
|
||||
'id',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the fields displayed by the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function fields(Request $request)
|
||||
{
|
||||
return [
|
||||
ID::make()->sortable(),
|
||||
|
||||
Text::make('Title')
|
||||
->rules('required', 'string'),
|
||||
|
||||
Number::make('Lat')
|
||||
->rules('required', 'numeric'),
|
||||
|
||||
Code::make('Lon')
|
||||
->rules('required', 'json')
|
||||
->json(),
|
||||
|
||||
Text::make('Address')
|
||||
->rules('required', 'string'),
|
||||
|
||||
Text::make('Type')
|
||||
->rules('required', 'string'),
|
||||
|
||||
Text::make('Open')
|
||||
->rules('required', 'string'),
|
||||
|
||||
Text::make('Comment')
|
||||
->rules('required', 'string'),
|
||||
|
||||
Text::make('Contact')
|
||||
->rules('required', 'string'),
|
||||
|
||||
Text::make('Bcz')
|
||||
->rules('required', 'string'),
|
||||
|
||||
Boolean::make('Digital')
|
||||
->rules('required'),
|
||||
|
||||
Text::make('Icontype')
|
||||
->rules('required', 'string'),
|
||||
|
||||
Boolean::make('Deactivated')
|
||||
->rules('required'),
|
||||
|
||||
Text::make('Deactreason')
|
||||
->rules('required', 'string'),
|
||||
|
||||
Text::make('Entrytype')
|
||||
->rules('required', 'string'),
|
||||
|
||||
Text::make('Homepage')
|
||||
->rules('required', 'string'),
|
||||
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cards available for the request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function cards(Request $request)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the filters available for the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function filters(Request $request)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the lenses available for the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function lenses(Request $request)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the actions available for the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function actions(Request $request)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user