Primo commit
This commit is contained in:
44
app/Livewire/Campagne/CampagnaCreate.php
Normal file
44
app/Livewire/Campagne/CampagnaCreate.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Campagne;
|
||||
|
||||
use Livewire\Component;
|
||||
use App\Models\Campagna;
|
||||
|
||||
class CampagnaCreate extends Component
|
||||
{
|
||||
public string $descrizione = '';
|
||||
public string $start_date = '';
|
||||
public string $end_date = '';
|
||||
|
||||
protected function rules(): array
|
||||
{
|
||||
return [
|
||||
'descrizione' => 'required|string|max:255',
|
||||
'start_date' => 'required|date',
|
||||
'end_date' => 'required|date|after:start_date',
|
||||
];
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
$campagna = Campagna::create([
|
||||
'descrizione' => $this->descrizione,
|
||||
'start_date' => $this->start_date,
|
||||
'end_date' => $this->end_date,
|
||||
]);
|
||||
|
||||
session()->flash('success', "Campagna '{$campagna->descrizione}' creata.");
|
||||
return $this->redirect(route('campagne.index'), navigate: true);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.campagne.campagna-form', [
|
||||
'titolo' => 'Nuova Campagna',
|
||||
'btnLabel' => 'Crea Campagna',
|
||||
]);
|
||||
}
|
||||
}
|
||||
53
app/Livewire/Campagne/CampagnaEdit.php
Normal file
53
app/Livewire/Campagne/CampagnaEdit.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Campagne;
|
||||
|
||||
use Livewire\Component;
|
||||
use App\Models\Campagna;
|
||||
|
||||
class CampagnaEdit extends Component
|
||||
{
|
||||
public Campagna $campagna;
|
||||
public string $descrizione = '';
|
||||
public string $start_date = '';
|
||||
public string $end_date = '';
|
||||
|
||||
public function mount(Campagna $campagna)
|
||||
{
|
||||
$this->campagna = $campagna;
|
||||
$this->descrizione = $campagna->descrizione;
|
||||
$this->start_date = $campagna->start_date->format('Y-m-d');
|
||||
$this->end_date = $campagna->end_date->format('Y-m-d');
|
||||
}
|
||||
|
||||
protected function rules(): array
|
||||
{
|
||||
return [
|
||||
'descrizione' => 'required|string|max:255',
|
||||
'start_date' => 'required|date',
|
||||
'end_date' => 'required|date|after:start_date',
|
||||
];
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
$this->campagna->update([
|
||||
'descrizione' => $this->descrizione,
|
||||
'start_date' => $this->start_date,
|
||||
'end_date' => $this->end_date,
|
||||
]);
|
||||
|
||||
session()->flash('success', "Campagna aggiornata.");
|
||||
return $this->redirect(route('campagne.index'), navigate: true);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.campagne.campagna-form', [
|
||||
'titolo' => "Modifica: {$this->campagna->descrizione}",
|
||||
'btnLabel' => 'Salva Modifiche',
|
||||
]);
|
||||
}
|
||||
}
|
||||
26
app/Livewire/Campagne/CampagnaIndex.php
Normal file
26
app/Livewire/Campagne/CampagnaIndex.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Campagne;
|
||||
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
use App\Models\Campagna;
|
||||
|
||||
class CampagnaIndex extends Component
|
||||
{
|
||||
use WithPagination;
|
||||
|
||||
public function deleteCampagna(int $id)
|
||||
{
|
||||
$campagna = Campagna::findOrFail($id);
|
||||
$campagna->delete();
|
||||
session()->flash('success', "Campagna '{$campagna->descrizione}' eliminata.");
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.campagne.campagna-index', [
|
||||
'campagne' => Campagna::orderByDesc('start_date')->paginate(15),
|
||||
]);
|
||||
}
|
||||
}
|
||||
41
app/Livewire/Campagne/CampagnaShow.php
Normal file
41
app/Livewire/Campagne/CampagnaShow.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Campagne;
|
||||
|
||||
use Livewire\Component;
|
||||
use App\Models\Campagna;
|
||||
use App\Models\Assegnazione;
|
||||
use App\Models\Territorio;
|
||||
|
||||
class CampagnaShow extends Component
|
||||
{
|
||||
public Campagna $campagna;
|
||||
|
||||
public function mount(Campagna $campagna)
|
||||
{
|
||||
$this->campagna = $campagna;
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
// All assignments with returned_at in campaign range that were counted
|
||||
$conteggiate = Assegnazione::where('campagna_id', $this->campagna->id)
|
||||
->where('counted_in_campaign', true)
|
||||
->with(['territorio', 'proclamatore'])
|
||||
->orderBy('returned_at')
|
||||
->get();
|
||||
|
||||
// All assignments that were active during this campaign range
|
||||
$assegnateNelRange = Assegnazione::where('assigned_at', '<=', $this->campagna->end_date)
|
||||
->where(function ($q) {
|
||||
$q->whereNull('returned_at')
|
||||
->orWhere('returned_at', '>=', $this->campagna->start_date);
|
||||
})
|
||||
->count();
|
||||
|
||||
return view('livewire.campagne.campagna-show', [
|
||||
'conteggiate' => $conteggiate,
|
||||
'assegnateNelRange' => $assegnateNelRange,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user