Skip to content

Commit

Permalink
New migration to add email & opt-in fields. New validation rules for …
Browse files Browse the repository at this point in the history
…these fields plus additional tour_json fields. Output new fields on proof of concept tour viewer page. Make unique gallery & artist counts available to the proof of concept tour viewer page
  • Loading branch information
lukew-cogapp committed Nov 9, 2023
1 parent c9d6b0f commit 801d823
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 17 deletions.
10 changes: 8 additions & 2 deletions app/Http/Controllers/API/CustomTourController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ public function store(CustomTourRequest $request)
{
$validated = $request->validated();

$tourJsonData = $validated['tour_json'];

// Perform basic data sanitization using strip_tags
$sanitizedData = $this->sanitizeData($validated);
$sanitizedTourJson = $this->sanitizeData($tourJsonData);

$record = CustomTour::create(['tour_json' => json_encode($sanitizedData)]);
$record = CustomTour::create([
'creator_email' => $validated['creator_email'],
'marketing_opt_in' => $validated['marketing_opt_in'] ?? false,
'tour_json' => json_encode($sanitizedTourJson)
]);

return response()->json(['message' => 'Custom tour created successfully!', 'custom_tour' => $record], 201);
}
Expand Down
16 changes: 15 additions & 1 deletion app/Http/Controllers/CustomTourController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,21 @@ public function show($id)
$this->seo->nofollow = true;
$this->seo->noindex = true;

return view('site.customTour', ['id' => $customTourItem->id, 'custom_tour' => $customTour]);
// Calculate unique galleries and artists
$galleryTitles = array_column($customTour['artworks'], 'galleryTitle');
$uniqueGalleryTitles = array_unique($galleryTitles);
$uniqueGalleriesCount = count($uniqueGalleryTitles);

$artistNames = array_column($customTour['artworks'], 'artistTitle');
$uniqueArtistNames = array_unique($artistNames);
$uniqueArtistsCount = count($uniqueArtistNames);

return view('site.customTour', [
'id' => $customTourItem->id,
'custom_tour' => $customTour,
'unique_galleries_count' => $uniqueGalleriesCount,
'unique_artists_count' => $uniqueArtistsCount,
]);
}

public function showCustomTourBuilder()
Expand Down
21 changes: 15 additions & 6 deletions app/Http/Requests/API/CustomTourRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,21 @@ class CustomTourRequest extends FormRequest
public function rules(): array
{
return [
'title' => 'required|string',
'description' => 'nullable|string',
'artworks' => 'required|array',
'artworks.*.id' => 'required|integer',
'artworks.*.title' => 'required|string',
'artworks.*.objectNote' => 'nullable|string',
'creator_email' => 'required|email',
'marketing_opt_in' => 'boolean',
'tour_json.title' => 'required|string',
'tour_json.description' => 'nullable|string',
'tour_json.creatorName' => 'nullable|string',
'tour_json.recipientName' => 'nullable|string',
'tour_json.artworks' => 'required|array',
'tour_json.artworks.*.id' => 'required|integer',
'tour_json.artworks.*.imageId' => 'nullable|string',
'tour_json.artworks.*.description' => 'nullable|string',
'tour_json.artworks.*.galleryTitle' => 'nullable|string',
'tour_json.artworks.*.artistTitle' => 'nullable|string',
'tour_json.artworks.*.dateDisplay' => 'nullable|string',
'tour_json.artworks.*.title' => 'required|string',
'tour_json.artworks.*.objectNote' => 'nullable|string',
];
}
}
2 changes: 1 addition & 1 deletion app/Models/CustomTour.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ public function __construct()
}
}

protected $fillable = ['id', 'tour_json', 'timestamp'];
protected $fillable = ['id', 'creator_email', 'marketing_opt_in', 'tour_json', 'timestamp'];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

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

return new class () extends Migration {
protected $connection;

public function __construct()
{
if (config('app.env') !== 'testing') {
$this->connection = 'tours';
}
}

public function up(): void
{
Schema::table('custom_tours', function (Blueprint $table) {
$table->string('creator_email', 255)->default('default@example.com');
$table->boolean('marketing_opt_in')->default(false);
});
}

public function down(): void
{
Schema::table('custom_tours', function (Blueprint $table) {
$table->dropColumn('creator_email');
$table->dropColumn('marketing_opt_in');
});
}
};
47 changes: 40 additions & 7 deletions resources/views/site/customTour.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,53 @@
<div class="o-blocks">
<p>ID: {{ $id }}</p>

@if(array_key_exists('description', $custom_tour) && $custom_tour['description'])
<p id="description">{{ $custom_tour['description'] }}</p>
@endif
@isset($custom_tour['creatorName'])
<p id="creatorName">Tour made by {{ $custom_tour['creatorName'] }},</p>
@endisset

@isset($custom_tour['recipientName'])
<p id="recipientName">for {{ $custom_tour['recipientName'] }}</p>
@endisset

<p>{{ count($custom_tour['artworks']) }} artworks, {{ $unique_artists_count }} artists across {{ $unique_galleries_count }} galleries</p>

@isset($custom_tour['description'])
<p id="description"><em>{{ $custom_tour['description'] }}</em>
@isset($custom_tour['creatorName'])
<br>— {{ $custom_tour['creatorName'] }}
@endisset
</p>
@endisset

<ul>
@foreach ($custom_tour['artworks'] as $artwork)
<li>
{{ $artwork['title'] }}
@isset($artwork['dateDisplay'])
, {{ $artwork['dateDisplay'] }}
@endisset
<ul>
@isset($artwork['artistTitle'])
<li>Artist title: {{ $artwork['artistTitle'] }}</li>
@endisset
@isset($artwork['imageId'])
<li>
<img src="https://www.artic.edu/iiif/2/{{ $artwork['imageId'] }}/full/256,/0/default.jpg" alt="Thumbnail for {{ $artwork['title'] }}">
</li>
@endisset
@isset($artwork['galleryTitle'])
<li>Gallery title: {{ $artwork['galleryTitle'] }}</li>
@endisset
@isset($artwork['objectNote'])
<li>Object note: {{ $artwork['objectNote'] }}</li>
@endisset
<li>Object page: <a href="https://www.artic.edu/artworks/{{ $artwork['id'] }}">Link</a></li>
@isset($artwork['description'])
<li>Object description: {{ $artwork['description'] }}</li>
@endisset
</ul>
</li>
@endforeach
</ul>
</div>
@endsection




0 comments on commit 801d823

Please sign in to comment.