Skip to content

Commit

Permalink
adds an option for supporting unlisted events
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronpk committed Jan 27, 2021
1 parent 0da5cb6 commit 85c8558
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Event extends Model
'location_name', 'location_address', 'location_locality', 'location_region', 'location_country',
'latitude', 'longitude', 'timezone', 'status',
'website', 'tickets_url', 'code_of_conduct_url', 'meeting_url',
'description', 'cover_image',
'description', 'cover_image', 'unlisted',
];

public static function slug_from_name($name) {
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ private function events_query($year=false, $month=false, $day=false, $only_futur
$events = new Event();
}

$events = $events->where('unlisted', 0);

if($only_future)
$events = $events->orderBy('sort_date');
else
Expand Down
11 changes: 8 additions & 3 deletions app/Http/Controllers/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public function create_event(Request $request) {

$event->cover_image = request('cover_image');

$event->unlisted = request('unlisted') ?: 0;

$event->created_by = Auth::user()->id;
$event->last_modified_by = Auth::user()->id;

Expand All @@ -117,7 +119,7 @@ public function create_event(Request $request) {
// Store a snapshot in the revision table
$revision = EventRevision::createFromEvent($event);
$revision->save();

event(new EventCreated($event));

return redirect($event->permalink());
Expand Down Expand Up @@ -164,6 +166,9 @@ public function save_event(Request $request, Event $event) {
$event->{$p} = (request($p) ?: null);
}

if(!$event->unlisted)
$event->unlisted = 0; // override null from above

$event->sort_date = $event->sort_date();

// Generate a new slug
Expand Down Expand Up @@ -230,7 +235,7 @@ public function view_revision(Event $event, EventRevision $revision) {
'mode' => 'archive',
'event_id' => $event->id,
]);
}
}

public function view_revision_diff(Event $event, EventRevision $revision) {
Gate::authorize('manage-event', $revision);
Expand All @@ -246,7 +251,7 @@ public function view_revision_diff(Event $event, EventRevision $revision) {
'previous' => $previous,
'event_id' => $event->id,
]);
}
}

public function upload_event_cover_image(Event $event) {
Gate::authorize('manage-event', $event);
Expand Down
5 changes: 4 additions & 1 deletion app/Http/Controllers/ICSController.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ private function _addEventToCal(&$vCalendar, &$event) {
public function index($year=false, $month=false) {

$events = Event::orderBy('start_date', 'desc')
->where('unlisted', 0)
->get();

$vCalendar = new \Eluceo\iCal\Component\Calendar(parse_url(env('APP_URL'), PHP_URL_HOST));
Expand All @@ -157,7 +158,9 @@ public function tag($tag) {

$events = Event::whereHas('tags', function($query) use ($tag){
$query->where('tag', $tag);
})->orderBy('events.start_date', 'desc')->get();
})
->where('unlisted', 0)
->orderBy('events.start_date', 'desc')->get();

$vCalendar = new \Eluceo\iCal\Component\Calendar(parse_url(env('APP_URL'), PHP_URL_HOST).' '.$tag);

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function post() {
}

$checkboxes = ['enable_webmention_responses', 'enable_ticket_url', 'show_rsvps_in_ics',
'auth_hide_login', 'auth_hide_logout'
'auth_hide_login', 'auth_hide_logout', 'support_unlisted_events'
];
foreach($checkboxes as $id) {
Setting::set($id, request($id) ? 1 : 0);
Expand Down
38 changes: 38 additions & 0 deletions database/migrations/2021_01_27_221005_unlisted_events.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class UnlistedEvents extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('events', function (Blueprint $table) {
$table->boolean('unlisted')->default(0);
});
Schema::table('event_revisions', function (Blueprint $table) {
$table->boolean('unlisted')->default(0);
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('events', function (Blueprint $table) {
$table->dropColumn('unlisted');
});
Schema::table('event_revisions', function (Blueprint $table) {
$table->dropColumn('unlisted');
});
}
}
11 changes: 11 additions & 0 deletions resources/views/edit-event.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,17 @@
</div>
</div>

@if(Setting::value('support_unlisted_events'))
<div class="field">
<div class="control is-expanded">
<label class="checkbox">
<input type="checkbox" name="unlisted" value="1" {{ $event->unlisted ? 'checked' : '' }}>
Unlisted event (prevents this event from showing on the home page and other feeds)
</label>
</div>
</div>
@endif

<div class="field">
<label class="label">Edit Summary</label>
<input class="input" type="text" name="edit_summary" value="{{ old('edit_summary') }}" autocomplete="off">
Expand Down
8 changes: 8 additions & 0 deletions resources/views/settings.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
<p class="help">When checked, event names in the ics feeds will include the names of people who have RSVP'd to the event.</p>
</div>

<div class="field">
<label class="label">
<input type="checkbox" name="support_unlisted_events" value="1" {{ Setting::value('support_unlisted_events') ? 'checked="checked"' : ''}}>
Support Unlisted Events
</label>
<p class="help">When checked, events can be marked as "unlisted", preventing them from showing up on the home page and all feeds.</p>
</div>

<div class="field">
<label class="label">
<input type="checkbox" name="enable_webmention_responses" value="1" {{ Setting::value('enable_webmention_responses') ? 'checked="checked"' : ''}}>
Expand Down

0 comments on commit 85c8558

Please sign in to comment.