Paltzhalter
This commit is contained in:
1 parent
44da4addcd
commit
d1ce891d9c
10 files changed
+205
-47
No files matched your search
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Create;
|
||||
|
||||
use App\Models\ProjektInhaltsverzeichnis;
|
||||
use App\Models\ProjektPlatzhalter;
|
||||
|
||||
class CreatePlatzhalter
|
||||
{
|
||||
public function create($record)
|
||||
{
|
||||
$result = ProjektInhaltsverzeichnis::select('textblock')->where('projekte_id', $record->id)->get();
|
||||
|
||||
$_platzhalter = [];
|
||||
foreach ($result as $value) {
|
||||
preg_match_all('/###(.*)###/U', $value['textblock'], $pat_array);
|
||||
$_platzhalter = array_merge($_platzhalter, $pat_array[0]);
|
||||
}
|
||||
|
||||
$_platzhalter = array_unique($_platzhalter);
|
||||
|
||||
ProjektPlatzhalter::where('projekte_id', $record->id)->update(['controll' => true]);
|
||||
|
||||
foreach ($_platzhalter as $platzhalter) {
|
||||
$result = ProjektPlatzhalter::where('projekte_id', $record->id)->where('platzhalter', $platzhalter)->get();
|
||||
if ($result->count() == 0) {
|
||||
$tmp = new ProjektPlatzhalter;
|
||||
$tmp->projekte_id = $record->id;
|
||||
$tmp->platzhalter = $platzhalter;
|
||||
$tmp->controll = false;
|
||||
$tmp->save();
|
||||
}
|
||||
}
|
||||
ProjektPlatzhalter::where('projekte_id', $record->id)->where('controll', true)->delete();
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ use App\Filament\Resources\Projektes\RelationManagers\AllgemeinflaechensRelation
|
||||
use App\Filament\Resources\Projektes\RelationManagers\OrientierungZuAbschlaegesRelationManager;
|
||||
use App\Filament\Resources\Projektes\RelationManagers\ProjektInhaltsverzeichnisRelationManager;
|
||||
use App\Filament\Resources\Projektes\RelationManagers\ProjektMethodesRelationManager;
|
||||
use App\Filament\Resources\Projektes\RelationManagers\ProjektPlatzhalterRelationManager;
|
||||
use App\Filament\Resources\Projektes\RelationManagers\RaeumeallesRelationManager;
|
||||
use App\Filament\Resources\Projektes\Schemas\ProjekteForm;
|
||||
use App\Filament\Resources\Projektes\Tables\ProjektesTable;
|
||||
@@ -51,6 +52,7 @@ class ProjekteResource extends Resource
|
||||
ProjektMethodesRelationManager::class,
|
||||
OrientierungZuAbschlaegesRelationManager::class,
|
||||
ProjektInhaltsverzeichnisRelationManager::class,
|
||||
ProjektPlatzhalterRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Projektes\RelationManagers;
|
||||
|
||||
use App\Actions\Create\CreatePlatzhalter;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\TextInputColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class ProjektPlatzhalterRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'projekt_platzhalters';
|
||||
|
||||
protected static ?string $title = 'Platzhalter';
|
||||
|
||||
protected static ?string $navigationLabel = 'Platzhalter';
|
||||
|
||||
protected static ?string $modelLabel = 'Platzhalter';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Platzhalter';
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
TextInput::make('platzhalter')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
TextInput::make('platzhaltertext')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('name')
|
||||
->columns([
|
||||
TextColumn::make('platzhalter')
|
||||
->searchable(),
|
||||
TextInputColumn::make('platzhaltertext')
|
||||
->label('Platzhalter Text')
|
||||
->searchable(),
|
||||
])
|
||||
->headerActions([
|
||||
Action::make('generate')
|
||||
->action(fn (CreatePlatzhalter $createPlatzhalter) => $createPlatzhalter->create($this->ownerRecord))
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Platzhalter neu generieren')
|
||||
->modalDescription('Bestehende Platzhalter bleiben erhalten, neue werden hinzugefügt und nicht mehr verwendete werden gelöscht.')
|
||||
->modalSubmitActionLabel('Ja, neu generieren')
|
||||
->label('Generieren')
|
||||
->tooltip('Platzhalter werden neu eingelesen.')
|
||||
->icon('heroicon-o-cog-8-tooth'),
|
||||
])
|
||||
->recordActions([
|
||||
// EditAction::make()->iconButton()->color('gray'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ProjektPlatzhalter extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'projekte_id',
|
||||
'platzhalter',
|
||||
'platzhaltertext',
|
||||
'controll',
|
||||
];
|
||||
}
|
||||
@@ -53,6 +53,11 @@ class Projekte extends Model
|
||||
return $this->belongsTo(Auftraggeber::class);
|
||||
}
|
||||
|
||||
public function projekt_platzhalters()
|
||||
{
|
||||
return $this->hasMany(ProjektPlatzhalter::class);
|
||||
}
|
||||
|
||||
public function gutachter()
|
||||
{
|
||||
return $this->belongsTo(Gutachter::class);
|
||||
|
||||
Reference in new issue
Block a user