diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 900e9846..c0426417 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -3,6 +3,7 @@ namespace App\Http; use App\Http\Middleware\CustomEnsureEmailVerified; +use App\Http\Middleware\NeedMeetupMiddleware; use App\Http\Middleware\SetTimezoneForNovaMiddleware; use App\Http\Middleware\SetTimezoneMiddleware; use Illuminate\Foundation\Http\Kernel as HttpKernel; @@ -84,5 +85,6 @@ class Kernel extends HttpKernel 'signed' => \App\Http\Middleware\ValidateSignature::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 'verified' => CustomEnsureEmailVerified::class, + 'needMeetup' => NeedMeetupMiddleware::class, ]; } diff --git a/app/Http/Livewire/Profile/Meetups.php b/app/Http/Livewire/Profile/Meetups.php new file mode 100644 index 00000000..c70efdca --- /dev/null +++ b/app/Http/Livewire/Profile/Meetups.php @@ -0,0 +1,85 @@ + 'string', + ]; + } + + public function mount() + { + $this->meetups = Meetup::query() + ->where('name', 'ilike', '%'.$this->search.'%') + ->orderBy('name') + ->limit(10) + ->get(); + $this->myMeetups = auth() + ->user() + ->meetups() + ->pluck('meetup_id') + ->toArray(); + $this->myMeetupNames = auth() + ->user() + ->meetups() + ->pluck('meetups.name', 'meetups.id') + ->toArray(); + if (count($this->myMeetups) > 0) { + $this->hasMeetups = true; + } + } + + public function updatedSearch($value) + { + $this->meetups = Meetup::query() + ->where('name', 'ilike', '%'.$value.'%') + ->orderBy('name') + ->limit(10) + ->get(); + } + + public function render() + { + return view('livewire.profile.meetups'); + } + + public function signUpForMeetup($id) + { + $user = auth()->user(); + $user->meetups() + ->toggle($id); + $this->myMeetups = auth() + ->user() + ->meetups() + ->pluck('meetup_id') + ->toArray(); + if (count($this->myMeetups) > 0) { + $this->hasMeetups = true; + } else { + $this->hasMeetups = false; + } + $this->myMeetupNames = auth() + ->user() + ->meetups() + ->pluck('meetups.name', 'meetups.id') + ->toArray(); + $this->notification() + ->success(__('Saved.')); + } +} diff --git a/app/Http/Middleware/NeedMeetupMiddleware.php b/app/Http/Middleware/NeedMeetupMiddleware.php new file mode 100644 index 00000000..c3510283 --- /dev/null +++ b/app/Http/Middleware/NeedMeetupMiddleware.php @@ -0,0 +1,31 @@ +user()) { + $request->user()->load('meetups'); + if ($request->user()->meetups->count() < 1) { + return redirect()->route('profile.meetups')->with('redirectToThis', $request->route()?->getName()); + } + } + + return $next($request); + } +} diff --git a/app/Models/User.php b/app/Models/User.php index b5b56633..a5f23fc2 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -61,6 +61,11 @@ class User extends Authenticatable implements MustVerifyEmail, CanComment return $this->hasMany(OrangePill::class); } + public function meetups() + { + return $this->belongsToMany(Meetup::class); + } + public function reputations() { return $this->morphMany('QCod\Gamify\Reputation', 'subject'); diff --git a/app/Nova/Meetup.php b/app/Nova/Meetup.php index 494cb2b7..ffca0c19 100644 --- a/app/Nova/Meetup.php +++ b/app/Nova/Meetup.php @@ -37,6 +37,10 @@ class Meetup extends Resource public static function afterCreate(NovaRequest $request, Model $model) { + auth() + ->user() + ->meetups() + ->attach($model); \App\Models\User::find(1) ->notify(new ModelCreatedNotification($model, str($request->getRequestUri()) ->after('/nova-api/') diff --git a/app/Nova/MeetupEvent.php b/app/Nova/MeetupEvent.php index 38b3f1de..c2114c3e 100644 --- a/app/Nova/MeetupEvent.php +++ b/app/Nova/MeetupEvent.php @@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Http\Request; use Laravel\Nova\Fields\BelongsTo; use Laravel\Nova\Fields\DateTime; +use Laravel\Nova\Fields\Field; use Laravel\Nova\Fields\ID; use Laravel\Nova\Fields\Text; use Laravel\Nova\Http\Requests\NovaRequest; @@ -47,6 +48,18 @@ class MeetupEvent extends Resource ->toString())); } + public static function relatableMeetups(NovaRequest $request, $query, Field $field) + { + if ($field instanceof BelongsTo) { + $query->whereIn('meetups.id', $request->user() + ->meetups() + ->pluck('id') + ->toArray()); + } + + return $query; + } + public function subtitle() { return __('Created by: :name', ['name' => $this->createdBy->name]); @@ -79,14 +92,16 @@ class MeetupEvent extends Resource ->rules('required', 'string'), BelongsTo::make('Meetup') - ->searchable()->withSubtitles(), + ->searchable() + ->withSubtitles(), BelongsTo::make(__('Created By'), 'createdBy', User::class) ->canSee(function ($request) { return $request->user() ->hasRole('super-admin'); }) - ->searchable()->withSubtitles(), + ->searchable() + ->withSubtitles(), ]; } diff --git a/app/Policies/MeetupEventPolicy.php b/app/Policies/MeetupEventPolicy.php index f6c1b4f7..88f120b6 100644 --- a/app/Policies/MeetupEventPolicy.php +++ b/app/Policies/MeetupEventPolicy.php @@ -53,7 +53,7 @@ class MeetupEventPolicy extends BasePolicy */ public function update(User $user, MeetupEvent $meetupEvent) { - return $meetupEvent->created_by === $user->id || $user->can((new \ReflectionClass($this))->getShortName().'.'.__FUNCTION__); + return $user->meetups->contains($meetupEvent->meetup) || $user->can((new \ReflectionClass($this))->getShortName().'.'.__FUNCTION__); } /** @@ -65,7 +65,7 @@ class MeetupEventPolicy extends BasePolicy */ public function delete(User $user, MeetupEvent $meetupEvent) { - return false; + return false && $meetupEvent->created_by === $user->id; } /** diff --git a/app/Policies/MeetupPolicy.php b/app/Policies/MeetupPolicy.php index 58595def..85200e41 100644 --- a/app/Policies/MeetupPolicy.php +++ b/app/Policies/MeetupPolicy.php @@ -57,7 +57,7 @@ class MeetupPolicy extends BasePolicy */ public function update(User $user, Meetup $meetup) { - return true || $meetup->created_by === $user->id || $user->can((new \ReflectionClass($this))->getShortName().'.'.__FUNCTION__); + return $user->meetups->contains($meetup) || $user->can((new \ReflectionClass($this))->getShortName().'.'.__FUNCTION__); } /** @@ -70,7 +70,7 @@ class MeetupPolicy extends BasePolicy */ public function delete(User $user, Meetup $meetup) { - return false; + return $meetup->created_by === $user->id; } /** diff --git a/config/nova.php b/config/nova.php index cc425adb..4d4bf70c 100644 --- a/config/nova.php +++ b/config/nova.php @@ -109,7 +109,8 @@ return [ DispatchServingNovaEvent::class, BootTools::class, \Itsmejoshua\Novaspatiepermissions\ForgetCachedPermissions::class, - 'verified' + 'verified', + 'needMeetup', ], 'api_middleware' => [ diff --git a/database/migrations/2023_17_01_175957_create_meetup_user_table.php b/database/migrations/2023_17_01_175957_create_meetup_user_table.php new file mode 100644 index 00000000..30dd1eb3 --- /dev/null +++ b/database/migrations/2023_17_01_175957_create_meetup_user_table.php @@ -0,0 +1,41 @@ +foreignId('meetup_id') + ->constrained() + ->cascadeOnDelete() + ->cascadeOnUpdate(); + $table->foreignId('user_id') + ->constrained() + ->cascadeOnDelete() + ->cascadeOnUpdate(); + $table->boolean('is_leader') + ->default(false); + }); + + Schema::enableForeignKeyConstraints(); + } + + /** + * Reverse the migrations. + * @return void + */ + public function down() + { + Schema::dropIfExists('meetup_user'); + } +} diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 087a017a..aea25aa6 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -27,7 +27,6 @@ use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Str; use JoeDixon\Translation\Console\Commands\SynchroniseMissingTranslationKeys; -use JoeDixon\Translation\Console\Commands\SynchroniseTranslationsCommand; use Spatie\Permission\Models\Permission; use Spatie\Permission\Models\Role; @@ -186,7 +185,7 @@ class DatabaseSeeder extends Seeder 'lecturer_id' => 1, 'name' => 'Hands on Bitcoin', 'created_by' => 1, - 'description' => ' + 'description' => ' Klimakiller Bitcoin! Bitcoin hat keinen Nutzen! Bitcoin wird nur von Kriminellen genutzt! Diese oder ähnliche Aussprüche kennen Sie bestimmt? Dann lassen Sie uns Bitcoin doch einmal genauer anschauen! In meinem Kurs nehme ich Sie mit auf einen Weg der bei der Geschichte unseres Geldes beginnt. Lassen Sie uns schauen wie unser Geld entsteht und welche Aufgaben dabei Geschäftsbanken und Zentralbanken haben. Welche Rolle spielt eigentlich das Jahr 1971 und welche Auswirkungen hatte dies auf unser Geld wie wir es heute verwenden. Was hat die Banken- und Finanzkrise 2008/ 2009 mit Bitcoin und Neuseeland mit unserer Inflation zu tun? @@ -207,7 +206,7 @@ Deshalb werden Sie von mir in diesem Kurs leicht verständlich an das Thema hera 'lecturer_id' => 1, 'name' => 'Bitcoin <> Crypto', 'created_by' => 1, - 'description' => ' + 'description' => ' Klimakiller Bitcoin! Bitcoin hat keinen Nutzen! Bitcoin wird nur von Kriminellen genutzt! Diese oder ähnliche Aussprüche kennen Sie bestimmt? Dann lassen Sie uns Bitcoin doch einmal genauer anschauen! In meinem Kurs nehme ich Sie mit auf einen Weg der bei der Geschichte unseres Geldes beginnt. Lassen Sie uns schauen wie unser Geld entsteht und welche Aufgaben dabei Geschäftsbanken und Zentralbanken haben. Welche Rolle spielt eigentlich das Jahr 1971 und welche Auswirkungen hatte dies auf unser Geld wie wir es heute verwenden. Was hat die Banken- und Finanzkrise 2008/ 2009 mit Bitcoin und Neuseeland mit unserer Inflation zu tun? @@ -228,7 +227,7 @@ Deshalb werden Sie von mir in diesem Kurs leicht verständlich an das Thema hera 'lecturer_id' => 2, 'name' => 'Bitcoin Lightning Network', 'created_by' => 1, - 'description' => ' + 'description' => ' Klimakiller Bitcoin! Bitcoin hat keinen Nutzen! Bitcoin wird nur von Kriminellen genutzt! Diese oder ähnliche Aussprüche kennen Sie bestimmt? Dann lassen Sie uns Bitcoin doch einmal genauer anschauen! In meinem Kurs nehme ich Sie mit auf einen Weg der bei der Geschichte unseres Geldes beginnt. Lassen Sie uns schauen wie unser Geld entsteht und welche Aufgaben dabei Geschäftsbanken und Zentralbanken haben. Welche Rolle spielt eigentlich das Jahr 1971 und welche Auswirkungen hatte dies auf unser Geld wie wir es heute verwenden. Was hat die Banken- und Finanzkrise 2008/ 2009 mit Bitcoin und Neuseeland mit unserer Inflation zu tun? @@ -378,8 +377,8 @@ Deshalb werden Sie von mir in diesem Kurs leicht verständlich an das Thema hera Artisan::call(SyncOpenBooks::class); Meetup::create([ 'city_id' => 1, - 'name' => 'Einundzwanzig Kempten', - 'link' => 'https://t.me/EinundzwanzigKempten', + 'name' => 'Einundzwanzig ' . str()->random(5), + 'telegram_link' => 'https://t.me/EinundzwanzigKempten', 'created_by' => 1, ]); MeetupEvent::create([ @@ -404,6 +403,60 @@ Deshalb werden Sie von mir in diesem Kurs leicht verständlich an das Thema hera 'link' => 'https://t.me/EinundzwanzigKempten', 'created_by' => 1, ]); + Meetup::create([ + 'city_id' => 2, + 'name' => 'Einundzwanzig ' . str()->random(5), + 'telegram_link' => 'https://t.me/EinundzwanzigKempten', + 'created_by' => 1, + ]); + Meetup::create([ + 'city_id' => 3, + 'name' => 'Einundzwanzig ' . str()->random(5), + 'telegram_link' => 'https://t.me/EinundzwanzigKempten', + 'created_by' => 1, + ]); + Meetup::create([ + 'city_id' => 1, + 'name' => 'Einundzwanzig ' . str()->random(5), + 'telegram_link' => 'https://t.me/EinundzwanzigKempten', + 'created_by' => 1, + ]); + Meetup::create([ + 'city_id' => 1, + 'name' => 'Einundzwanzig ' . str()->random(5), + 'telegram_link' => 'https://t.me/EinundzwanzigKempten', + 'created_by' => 1, + ]); + Meetup::create([ + 'city_id' => 1, + 'name' => 'Einundzwanzig ' . str()->random(5), + 'telegram_link' => 'https://t.me/EinundzwanzigKempten', + 'created_by' => 1, + ]); + Meetup::create([ + 'city_id' => 1, + 'name' => 'Einundzwanzig ' . str()->random(5), + 'telegram_link' => 'https://t.me/EinundzwanzigKempten', + 'created_by' => 1, + ]); + Meetup::create([ + 'city_id' => 1, + 'name' => 'Einundzwanzig ' . str()->random(5), + 'telegram_link' => 'https://t.me/EinundzwanzigKempten', + 'created_by' => 1, + ]); + Meetup::create([ + 'city_id' => 1, + 'name' => 'Einundzwanzig ' . str()->random(5), + 'telegram_link' => 'https://t.me/EinundzwanzigKempten', + 'created_by' => 1, + ]); + Meetup::create([ + 'city_id' => 1, + 'name' => 'Einundzwanzig ' . str()->random(5), + 'telegram_link' => 'https://t.me/EinundzwanzigKempten', + 'created_by' => 1, + ]); BitcoinEvent::create([ 'venue_id' => 4, 'from' => Carbon::parse('2023-09-12') diff --git a/draft.yaml b/draft.yaml index 0d6e5034..e69de29b 100644 --- a/draft.yaml +++ b/draft.yaml @@ -1,4 +0,0 @@ -models: - Item: - name: string:unique - link: string diff --git a/resources/lang/de.json b/resources/lang/de.json index ef67a673..9cd11586 100644 --- a/resources/lang/de.json +++ b/resources/lang/de.json @@ -644,5 +644,18 @@ "points": "Punkte", "Submit new book case": "Bücherschrank einreichen", "Share url copied!": "Link kopiert!", - "Share link": "Link zum Teilen" + "Share link": "Link zum Teilen", + "Telegram-Link": "", + "Website": "", + "Twitter Username": "", + "Select one or more meetup groups so that you can get access to these groups in the backend.": "Suche dir eine oder mehrere Meetup-Gruppen aus, um Zugriff auf diese Gruppen im Backend zu erhalten.", + "choice": "Auswahl", + "By id": "nach ID", + "Twitter": "", + "New City": "Neue Stadt", + "My meetups": "Meine Meetups", + "please limit your search here": "bitte begrenze deine Suche hier", + "Deselect": "Abwählen", + "Your current Meetup groups": "Deine aktuellen Meetup-Gruppen", + "Thanks, continue here": "Danke, weiter geht es hier" } diff --git a/resources/lang/en.json b/resources/lang/en.json index 53fb562f..ce5eceb5 100644 --- a/resources/lang/en.json +++ b/resources/lang/en.json @@ -635,10 +635,20 @@ "logins": "", "points": "", "New meetup created: :title": "New meetup created: :title", - "Submit new book case": "", + "Submit new book case": "", "Telegram-Link": "", "Website": "", "Twitter Username": "", "Share url copied!": "", - "Share link": "" + "Share link": "", + "Select one or more meetup groups so that you can get access to these groups in the backend.": "", + "choice": "", + "By id": "", + "Twitter": "", + "New City": "", + "My meetups": "", + "please limit your search here": "", + "Deselect": "", + "Your current Meetup groups": "", + "Thanks, continue here": "" } diff --git a/resources/lang/es.json b/resources/lang/es.json index 930548de..4fc71387 100644 --- a/resources/lang/es.json +++ b/resources/lang/es.json @@ -634,5 +634,17 @@ "You get a point when you log in.": "", "points": "", "All courses of :name": "", - "Here you can see all events of :name.": "" + "Here you can see all events of :name.": "", + "By id": "", + "Telegram-Link": "", + "Website": "", + "Twitter Username": "", + "Share url copied!": "", + "Share link": "", + "Twitter": "", + "Submit new book case": "", + "choice": "", + "Select one or more meetup groups so that you can get access to these groups in the backend.": "", + "New City": "", + "My meetups": "" } \ No newline at end of file diff --git a/resources/lang/fr.json b/resources/lang/fr.json index c1d0b077..60f5926a 100644 --- a/resources/lang/fr.json +++ b/resources/lang/fr.json @@ -634,5 +634,17 @@ "You get a point when you log in.": "", "points": "", "All courses of :name": "", - "Here you can see all events of :name.": "" + "Here you can see all events of :name.": "", + "By id": "", + "Telegram-Link": "", + "Website": "", + "Twitter Username": "", + "Share url copied!": "", + "Share link": "", + "Twitter": "", + "Submit new book case": "", + "choice": "", + "Select one or more meetup groups so that you can get access to these groups in the backend.": "", + "New City": "", + "My meetups": "" } \ No newline at end of file diff --git a/resources/lang/hr.json b/resources/lang/hr.json index 5e0d7637..e28e958b 100644 --- a/resources/lang/hr.json +++ b/resources/lang/hr.json @@ -634,5 +634,17 @@ "You get a point when you log in.": "", "points": "", "All courses of :name": "", - "Here you can see all events of :name.": "" + "Here you can see all events of :name.": "", + "By id": "", + "Telegram-Link": "", + "Website": "", + "Twitter Username": "", + "Share url copied!": "", + "Share link": "", + "Twitter": "", + "Submit new book case": "", + "choice": "", + "Select one or more meetup groups so that you can get access to these groups in the backend.": "", + "New City": "", + "My meetups": "" } \ No newline at end of file diff --git a/resources/lang/it.json b/resources/lang/it.json index 43ef5d98..ac022190 100644 --- a/resources/lang/it.json +++ b/resources/lang/it.json @@ -634,5 +634,17 @@ "You get a point when you log in.": "", "points": "", "All courses of :name": "", - "Here you can see all events of :name.": "" + "Here you can see all events of :name.": "", + "By id": "", + "Telegram-Link": "", + "Website": "", + "Twitter Username": "", + "Share url copied!": "", + "Share link": "", + "Twitter": "", + "Submit new book case": "", + "choice": "", + "Select one or more meetup groups so that you can get access to these groups in the backend.": "", + "New City": "", + "My meetups": "" } \ No newline at end of file diff --git a/resources/lang/mk.json b/resources/lang/mk.json index d1cdb208..ddbc3a37 100644 --- a/resources/lang/mk.json +++ b/resources/lang/mk.json @@ -634,5 +634,17 @@ "You get a point when you log in.": "", "points": "", "All courses of :name": "", - "Here you can see all events of :name.": "" + "Here you can see all events of :name.": "", + "By id": "", + "Telegram-Link": "", + "Website": "", + "Twitter Username": "", + "Share url copied!": "", + "Share link": "", + "Twitter": "", + "Submit new book case": "", + "choice": "", + "Select one or more meetup groups so that you can get access to these groups in the backend.": "", + "New City": "", + "My meetups": "" } \ No newline at end of file diff --git a/resources/lang/pl.json b/resources/lang/pl.json index 76697d3a..967791f2 100644 --- a/resources/lang/pl.json +++ b/resources/lang/pl.json @@ -634,5 +634,17 @@ "You get a point when you log in.": "", "points": "", "All courses of :name": "", - "Here you can see all events of :name.": "" + "Here you can see all events of :name.": "", + "By id": "", + "Telegram-Link": "", + "Website": "", + "Twitter Username": "", + "Share url copied!": "", + "Share link": "", + "Twitter": "", + "Submit new book case": "", + "choice": "", + "Select one or more meetup groups so that you can get access to these groups in the backend.": "", + "New City": "", + "My meetups": "" } \ No newline at end of file diff --git a/resources/lang/pt.json b/resources/lang/pt.json index fc77c8cd..54193951 100644 --- a/resources/lang/pt.json +++ b/resources/lang/pt.json @@ -634,5 +634,17 @@ "You get a point when you log in.": "", "points": "", "All courses of :name": "", - "Here you can see all events of :name.": "" + "Here you can see all events of :name.": "", + "By id": "", + "Telegram-Link": "", + "Website": "", + "Twitter Username": "", + "Share url copied!": "", + "Share link": "", + "Twitter": "", + "Submit new book case": "", + "choice": "", + "Select one or more meetup groups so that you can get access to these groups in the backend.": "", + "New City": "", + "My meetups": "" } \ No newline at end of file diff --git a/resources/lang/tr.json b/resources/lang/tr.json index 63feb83f..019c0839 100644 --- a/resources/lang/tr.json +++ b/resources/lang/tr.json @@ -608,5 +608,17 @@ "You get a point when you log in.": "", "points": "", "All courses of :name": "", - "Here you can see all events of :name.": "" + "Here you can see all events of :name.": "", + "By id": "", + "Telegram-Link": "", + "Website": "", + "Twitter Username": "", + "Share url copied!": "", + "Share link": "", + "Twitter": "", + "Submit new book case": "", + "choice": "", + "Select one or more meetup groups so that you can get access to these groups in the backend.": "", + "New City": "", + "My meetups": "" } \ No newline at end of file diff --git a/resources/lang/vendor/livewire-tables/de.json b/resources/lang/vendor/livewire-tables/de.json index c22145c5..d859ba58 100644 --- a/resources/lang/vendor/livewire-tables/de.json +++ b/resources/lang/vendor/livewire-tables/de.json @@ -11,6 +11,7 @@ "Remove sort option": "Entferne Sortierauswahl", "Search": "Suche", "Select All": "Alle auswählen", + "Select": "Auswählen", "Showing": "Anzeigen", "Deselect All": "Alle abwählen", "You are currently selecting all": "Es sind schon alle ausgewählt", @@ -23,4 +24,4 @@ "rows, do you want to select all": "Zeilen, sollen alle ausgewählt werden", "to": "nach", "No items found. Try to broaden your search.": "Es gibt keine Ergebnisse\/Einträge. Versuche die Suche zu erweitern." -} \ No newline at end of file +} diff --git a/resources/views/livewire/profile/meetups.blade.php b/resources/views/livewire/profile/meetups.blade.php new file mode 100644 index 00000000..e17da3bc --- /dev/null +++ b/resources/views/livewire/profile/meetups.blade.php @@ -0,0 +1,109 @@ +
+ {{ __('Select one or more meetup groups so that you can get access to these groups in the backend.') }} +
+
+
{{ $meetup->name }}
+{{ $meetup->city->name }}
++ {{ __('Your current Meetup groups') }} +
+