Automated Graphics – College Coach Staff Graphic

This feature automatically generates and emails a College Coach Staff Graphic when a college coach also serves as staff at an event. The graphic highlights their involvement and is shared on Prep Network social channels to boost engagement and recognition.

Key Components

  • Action Class
    Contains the core logic to assemble data and request graphic generation.
  • PnData Integration
    Wraps HTTP calls to the Prep Network Data API for image rendering.
  • Template Configuration
    Uses dynamic settings to select the correct graphic template per website.
  • Email Templates 📧
    Two Blade views handle successful graphic delivery and missing-data alerts.
  • Settings
    Configuration keys stored via the Laravel Settings package.

1. GenerateCollegeCoachStaffGraphic Action

Handles assembling event and staff data, calling the API, and returning the generated image URL.

<?php
namespace App\Actions\Staff;

use anlutro\LaravelSettings\Facades\Setting;
use App\Integrations\PnData;
use App\Models\Event;
use App\Models\Staff;
use Carbon\Carbon;

class GenerateCollegeCoachStaffGraphic
{
    /**
     * Execute the graphic generation.
     *
     * @param  Event  $event
     * @param  Staff  $staff
     * @return string  URL of the generated graphic
     * @throws \Exception if template ID is missing
     */
    public function execute(Event $event, Staff $staff): string
    {
        $templateID = (int) Setting::get(
            'graphic_automations_'.$event->website_id.'.college_coach_staff'
        );

        if (! $templateID) {
            throw new \Exception('College coach staff graphic template not found.');
        }

        $endpoint = 'templates/'.$templateID.'/generate';
        $data = [
            'location'     => $event->address_city.', '.$event->address_state,
            'date'         => Carbon::parse($event->start_date)->format('m.d'),
            'event_logo'   => $event->logo,
            'college_logo' => $staff->college()['logo'],
            'headshot'     => $staff->headshot,
        ];

        $response = (new PnData)->get($endpoint, $data);
        return $response['json']['data'];
    }
}

Responsibility: Fetch the correct template ID, prepare payload, invoke external API, return graphic URL.


2. Template Configuration

Templates are managed per website via the Laravel Settings package. The key pattern is:

Setting Key Description
graphic_automations_{website_id}.college_coach_staff ID of the graphic template for this site.

Ensure each website has this setting populated in the database.


3. PnData Integration

App\Integrations\PnData wraps Guzzle (or similar) to communicate with Prep Network’s image generation API. It exposes:

  • get(string $endpoint, array $payload): Performs a GET request to /v1/{endpoint} with $payload.

This abstraction keeps HTTP concerns out of business logic.


4. Email Templates

Once the graphic URL is obtained, it’s emailed to operations or marketing teams.

4.1 Successful Graphic Delivery

File: resources/views/emails/college-coach-staff-graphic.blade.php

@extends('emails.layouts.master-generic')

@section('email_content')
<p>Attached is the College Coach Staff Graphic for {{ $staff->name }} at {{ $event->title }}.</p>
<p>If there are any issues with the graphic, please reach out to Josiah (<a href="mailto:[email protected]">[email protected]</a>) or Sophia (<a href="mailto:[email protected]">[email protected]</a>).</p>
@stop

Variables:

  • $event: Event instance
  • $staff: Staff instance with headshot and college data

4.2 Missing Data Alert

File: resources/views/emails/college-staff-missing-info.blade.php

@extends('emails.layouts.master-generic')

@section('email_content')
<p>Hello,</p>
<p>The following staff member, {{ $staff->name }}, assigned to {{ $event->title }} is missing required information to generate their College Coach Staff Graphic.</p>
<ul>
    @if (empty($staff->college_id))
        <li>College is missing – please set the college for this staff member.</li>
    @endif
    @if (empty($staff->headshot) || $staff->headshot === config('constants.default_user_image'))
        <li>Headshot is missing – please upload a headshot for this staff member.</li>
    @endif
</ul>
<p><a href="{{ route('staff.edit', $staff) }}">View staff profile</a></p>
@stop

Alerts when essential data (college or headshot) is not present.


5. End-to-End Flow

sequenceDiagram
    participant Sched as Scheduler/EventTrigger
    participant Act as GenerateCollegeCoachStaffGraphic
    participant API as PnData API
    participant Mail as Mailer
    Note over Sched: Staff qualifies for graphic
    Sched->>Act: execute($event, $staff)
    Act->>API: GET /templates/{id}/generate (payload)
    API-->>Act: { json: { data: "<graphic_url>" } }
    Act-->>Sched: "<graphic_url>"
    alt Missing Data
        Sched->>Mail: sendMissingInfoEmail($event, $staff)
    else Data OK
        Sched->>Mail: sendGraphicEmail($event, $staff, "<graphic_url>")
    end
  • Trigger: Could be an Artisan command, queued job, or observer when staff assignments update.
  • Generation: Action class handles API call.
  • Emailing: Blade templates deliver the result or prompt for corrections.

6. Dependencies & Relationships

Component Depends On
GenerateCollegeCoachStaffGraphic Setting, PnData, Event, Staff
PnData HTTP client, base URL config
Email Blade Views $event, $staff instances
Settings (graphic_automations_*) Database via anlutro/laravel-settings
Config Constants constants.php for defaults

7. Developer Notes & Best Practices

  • Template Updates
    When updating graphic layouts, ensure the corresponding template_id is updated per website in Settings.

  • Error Handling
    Uncaught exceptions bubble up; consider wrapping calls in try/catch to notify ops teams.

  • Testing
    Mock PnData responses to test the action without external API calls.

  • Extensibility
    To add new graphic types, follow this pattern:

    1. Create a new action class under App\Actions\Staff.
    2. Add a Settings key (e.g., .college_coach_attendance).
    3. Create or reuse Blade email templates.

Happy coding! 🎨