add attendees export

This commit is contained in:
HolgerHatGarKeineNode
2023-03-16 15:08:42 +01:00
parent fae97b39b6
commit 69c3ade296
20 changed files with 784 additions and 141 deletions

View File

@@ -0,0 +1,61 @@
<?php
namespace App\Exports;
use App\Models\MeetupEvent;
use App\Models\User;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
class MeetupEventAttendeesExport implements FromView, ShouldAutoSize
{
use Exportable;
public function __construct(public MeetupEvent $meetupEvent)
{
}
private function mapAttendees($collection, $status) {
return $collection->map(function ($value) use ($status) {
if (str($value)->contains('anon_')) {
$id = -1;
} else {
$id = str($value)
->before('|')
->after('id_')
->toString();
}
return [
'id' => $id,
'status' => $status,
'user' => $id > 0 ? User::withoutEvents(static fn() => User::query()
->select([
'id',
'name',
'profile_photo_path',
])
->find($id)
?->append('profile_photo_url')
->toArray())
: null,
'name' => str($value)
->after('|')
->toString(),
];
})
->toArray();
}
public function view(): View
{
$attendees = $this->mapAttendees(collect($this->meetupEvent->attendees), __('Participation confirmed'));
$mightAttendees = $this->mapAttendees(collect($this->meetupEvent->might_attendees), __('Perhaps'));
return view('exports.meetupEventsAttendees', [
'attendees' => array_merge($attendees, $mightAttendees),
]);
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Http\Controllers\Export;
use App\Exports\MeetupEventAttendeesExport;
use App\Http\Controllers\Controller;
use App\Models\MeetupEvent;
use Illuminate\Http\Request;
class MeetupEventAttendeesExportController extends Controller
{
/**
* Handle the incoming request.
*/
public function __invoke(Request $request, MeetupEvent $meetupEvent)
{
return (new MeetupEventAttendeesExport($meetupEvent))->download($meetupEvent->start->toDateString().'_'.$meetupEvent->meetup->slug.'.xlsx');
}
}

View File

@@ -5,6 +5,7 @@ namespace App\Http\Livewire\Meetup;
use App\Models\Country;
use App\Models\Meetup;
use App\Models\MeetupEvent;
use App\Models\User;
use App\Rules\UniqueAttendeeName;
use Livewire\Component;
use RalphJSmit\Laravel\SEO\Support\SEOData;
@@ -23,6 +24,9 @@ class LandingPageEvent extends Component
public string $name = '';
public array $attendees = [];
public array $mightAttendees = [];
public function rules()
{
return [
@@ -37,6 +41,7 @@ class LandingPageEvent extends Component
{
$this->meetupEvent->load('meetup.users');
$this->meetup = $this->meetupEvent->meetup;
$this->name = auth()->check() ? auth()->user()->name : '';
$this->checkShowUp();
}
@@ -45,38 +50,72 @@ class LandingPageEvent extends Component
$attendees = collect($this->meetupEvent->attendees);
$mightAttendees = collect($this->meetupEvent->might_attendees);
if (auth()->check() && $attendees->contains(fn ($value) => str($value)->contains('id_'.auth()->id()))) {
$this->name = str($attendees->filter(fn ($value) => str($value)->contains('id_'.auth()->id()))
if (auth()->check() && $attendees->contains(fn($value) => str($value)->contains('id_'.auth()->id()))) {
$this->name = str($attendees->filter(fn($value) => str($value)->contains('id_'.auth()->id()))
->first())
->after('|')
->toString();
$this->willShowUp = true;
}
if (! auth()->check() && $attendees->contains(fn ($value) => str($value)->contains('anon_'.session()->getId()))) {
$this->name = str($attendees->filter(fn ($value) => str($value)->contains('anon_'.session()->getId()))
if (!auth()->check() && $attendees->contains(fn($value) => str($value)->contains('anon_'.session()->getId()))) {
$this->name = str($attendees->filter(fn($value) => str($value)->contains('anon_'.session()->getId()))
->first())
->after('|')
->toString();
$this->willShowUp = true;
}
if (auth()->check() && $mightAttendees->contains(fn ($value) => str($value)->contains('id_'.auth()->id()))) {
$this->name = str($mightAttendees->filter(fn ($value) => str($value)->contains('id_'.auth()->id()))
if (auth()->check() && $mightAttendees->contains(fn($value) => str($value)->contains('id_'.auth()->id()))) {
$this->name = str($mightAttendees->filter(fn($value) => str($value)->contains('id_'.auth()->id()))
->first())
->after('|')
->toString();
$this->perhapsShowUp = true;
}
if (! auth()->check() && $mightAttendees->contains(fn ($value
if (!auth()->check() && $mightAttendees->contains(fn($value
) => str($value)->contains('anon_'.session()->getId()))) {
$this->name = str($mightAttendees->filter(fn ($value) => str($value)->contains('anon_'.session()->getId()))
$this->name = str($mightAttendees->filter(fn($value) => str($value)->contains('anon_'.session()->getId()))
->first())
->after('|')
->toString();
$this->perhapsShowUp = true;
}
$this->attendees = $this->mapAttendees($attendees);
$this->mightAttendees = $this->mapAttendees($mightAttendees);
}
private function mapAttendees($collection) {
return $collection->map(function ($value) {
if (str($value)->contains('anon_')) {
$id = -1;
} else {
$id = str($value)
->before('|')
->after('id_')
->toString();
}
return [
'id' => $id,
'user' => $id > 0 ? User::withoutEvents(static fn() => User::query()
->select([
'id',
'name',
'profile_photo_path',
])
->find($id)
?->append('profile_photo_url')
->toArray())
: null,
'name' => str($value)
->after('|')
->toString(),
];
})
->toArray();
}
public function cannotCome()
@@ -84,31 +123,33 @@ class LandingPageEvent extends Component
$attendees = collect($this->meetupEvent->attendees);
$mightAttendees = collect($this->meetupEvent->might_attendees);
if (auth()->check() && $attendees->contains(fn ($value) => str($value)->contains('id_'.auth()->id()))) {
$attendees = $attendees->filter(fn ($value) => ! str($value)->contains('id_'.auth()->id()));
if (auth()->check() && $attendees->contains(fn($value) => str($value)->contains('id_'.auth()->id()))) {
$attendees = $attendees->filter(fn($value) => !str($value)->contains('id_'.auth()->id()));
$this->willShowUp = false;
}
if (! auth()->check() && $attendees->contains(fn ($value) => str($value)->contains('anon_'.session()->getId()))) {
$attendees = $attendees->filter(fn ($value) => ! str($value)->contains('anon_'.session()->getId()));
if (!auth()->check() && $attendees->contains(fn($value) => str($value)->contains('anon_'.session()->getId()))) {
$attendees = $attendees->filter(fn($value) => !str($value)->contains('anon_'.session()->getId()));
$this->willShowUp = false;
}
if (auth()->check() && $mightAttendees->contains(fn ($value) => str($value)->contains('id_'.auth()->id()))) {
$mightAttendees = $mightAttendees->filter(fn ($value) => ! str($value)->contains('id_'.auth()->id()));
if (auth()->check() && $mightAttendees->contains(fn($value) => str($value)->contains('id_'.auth()->id()))) {
$mightAttendees = $mightAttendees->filter(fn($value) => !str($value)->contains('id_'.auth()->id()));
$this->perhapsShowUp = false;
}
if (! auth()->check() && $mightAttendees->contains(fn ($value
if (!auth()->check() && $mightAttendees->contains(fn($value
) => str($value)->contains('anon_'.session()->getId()))) {
$mightAttendees = $mightAttendees->filter(fn ($value) => ! str($value)->contains('anon_'.session()->getId()));
$mightAttendees = $mightAttendees->filter(fn($value) => !str($value)->contains('anon_'.session()->getId()));
$this->perhapsShowUp = false;
}
$this->meetupEvent->update([
'attendees' => $attendees->toArray(),
'attendees' => $attendees->toArray(),
'might_attendees' => $mightAttendees->toArray(),
]);
$this->checkShowUp();
}
public function attend()
@@ -116,12 +157,12 @@ class LandingPageEvent extends Component
$this->validate();
$attendees = collect($this->meetupEvent->attendees);
if (auth()->check() && ! $attendees->contains('id_'.auth()->id().'|'.$this->name)) {
if (auth()->check() && !$attendees->contains('id_'.auth()->id().'|'.$this->name)) {
$attendees->push('id_'.auth()->id().'|'.$this->name);
$this->willShowUp = true;
}
if (! auth()->check() && ! $attendees->contains('anon_'.session()->getId().'|'.$this->name)) {
if (!auth()->check() && !$attendees->contains('anon_'.session()->getId().'|'.$this->name)) {
$attendees->push('anon_'.session()->getId().'|'.$this->name);
$this->willShowUp = true;
}
@@ -129,6 +170,8 @@ class LandingPageEvent extends Component
$this->meetupEvent->update([
'attendees' => $attendees->toArray(),
]);
$this->checkShowUp();
}
public function mightAttend()
@@ -136,12 +179,12 @@ class LandingPageEvent extends Component
$this->validate();
$mightAttendees = collect($this->meetupEvent->might_attendees);
if (auth()->check() && ! $mightAttendees->contains('id_'.auth()->id().'|'.$this->name)) {
if (auth()->check() && !$mightAttendees->contains('id_'.auth()->id().'|'.$this->name)) {
$mightAttendees->push('id_'.auth()->id().'|'.$this->name);
$this->perhapsShowUp = true;
}
if (! auth()->check() && ! $mightAttendees->contains('anon_'.session()->getId().'|'.$this->name)) {
if (!auth()->check() && !$mightAttendees->contains('anon_'.session()->getId().'|'.$this->name)) {
$mightAttendees->push('anon_'.session()->getId().'|'.$this->name);
$this->perhapsShowUp = true;
}
@@ -149,6 +192,8 @@ class LandingPageEvent extends Component
$this->meetupEvent->update([
'might_attendees' => $mightAttendees->toArray(),
]);
$this->checkShowUp();
}
public function render()

View File

@@ -9,6 +9,12 @@ use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;
use Illuminate\Support\Stringable;
use Spatie\Translatable\Facades\Translatable;
use Maatwebsite\Excel\Events\AfterSheet;
use Maatwebsite\Excel\Events\BeforeExport;
use Maatwebsite\Excel\Events\BeforeSheet;
use Maatwebsite\Excel\Events\BeforeWriting;
use Maatwebsite\Excel\Sheet;
use Maatwebsite\Excel\Writer;
class AppServiceProvider extends ServiceProvider
{
@@ -20,6 +26,63 @@ class AppServiceProvider extends ServiceProvider
Date::use(
Carbon::class
);
// excel config
Sheet::macro(
'styleCells',
function (
Sheet $sheet,
string $cellRange,
array $style
) {
$sheet
->getDelegate()
->getStyle($cellRange)
->applyFromArray($style);
}
);
Sheet::macro(
'setAutofilter',
function (
Sheet $sheet,
$cellRange
) {
$sheet->getDelegate()
->setAutoFilter($cellRange);
}
);
Writer::listen(
BeforeExport::class,
function () {
}
);
Writer::listen(
BeforeWriting::class,
function () {
}
);
Sheet::listen(
BeforeSheet::class,
function () {
}
);
Sheet::listen(
AfterSheet::class,
function ($event) {
$event->sheet->freezePane('A2');
$event->sheet->setAutofilter(
$event->sheet->calculateWorksheetDimension()
);
$event->sheet->styleCells(
'A1:'.$event->sheet->getHighestColumn().'1',
[
'font' => [
'bold' => true,
],
]
);
}
);
}
/**