Home / Admin / ACF – KEYSMST_ Case – Tab 8: Contact Log Staging Fields
Duplicate Snippet

Embed Snippet on Your Site

ACF – KEYSMST_ Case – Tab 8: Contact Log Staging Fields

ismail daugherty PRO
<10
Code Preview
php
<?php
/**
 * WPCode Snippet: MST Case - Tab 8: Contact Log Staging Fields
 * Description: Temporary staging fields for weekly contact log aggregation
 * Priority: 13 (loads with Tab 8: Treatment Progress)
 * Location: mst_case post type
 * 
 * CRITICAL: These fields are TEMPORARY staging - overwritten each Friday 3PM
 * Purpose: Pre-populate Form 302 Section VIII with aggregated contact data
 * Source: Form 301 entries → Gravity Flow aggregation → These ACF fields
 * Destination: Form 302 fields 69-72 → weekly_case_summary post meta (permanent)
 */
if (!defined('ABSPATH')) {
    exit;
}
// Ensure this runs after Tab 8 main fields are loaded
add_action('acf/init', 'mst_add_contact_staging_fields_to_tab8', 13);
function mst_add_contact_staging_fields_to_tab8() {
    
    // Verify the parent group exists
    if (!function_exists('acf_get_field_group')) {
        return;
    }
    
    // ============================================
    // SECTION: WEEKLY CONTACT STAGING (READ-ONLY)
    // ============================================
    
    // Section Header
    acf_add_local_field(array(
        'key' => 'field_contact_staging_section',
        'label' => 'Weekly Contact Staging (Auto-Populated)',
        'name' => '',
        'type' => 'message',
        'parent' => 'group_mst_case_master',
        'message' => '<div style="background: #fff3cd; border-left: 4px solid #ffc107; padding: 12px; margin: 10px 0;">
            <strong>⚠️ TEMPORARY STAGING FIELDS</strong><br>
            These fields are automatically populated every Friday at 3 PM from Form 301 contact logs.<br>
            They are <strong>overwritten weekly</strong> and used to pre-populate Form 302 Section VIII.<br>
            <strong>Permanent records are stored in weekly_case_summary posts.</strong>
        </div>',
        'new_lines' => '',
        'esc_html' => 0,
        'wrapper' => array(
            'width' => '100',
        ),
    ));
    
    // ============================================
    // CONTACT LOGS SUMMARY (TEXTAREA)
    // ============================================
    
    acf_add_local_field(array(
        'key' => 'field_contact_logs_summary',
        'label' => 'Contact Logs Summary (This Week)',
        'name' => 'contact_logs_summary',
        'type' => 'textarea',
        'parent' => 'group_mst_case_master',
        'instructions' => 'Formatted summary of all Form 301 contact logs for the current week. Auto-populated by Gravity Flow aggregation workflow (Friday 3 PM). This field is REPLACED each week.',
        'required' => 0,
        'conditional_logic' => 0,
        'wrapper' => array(
            'width' => '100',
            'class' => 'contact-staging-field',
            'id' => '',
        ),
        'default_value' => '',
        'placeholder' => 'No contact logs aggregated yet for this week...',
        'maxlength' => '',
        'rows' => 15,
        'new_lines' => 'wpautop',
        'readonly' => 1, // Read-only - populated by workflow
    ));
    
    // ============================================
    // CONTACT METRICS (NUMBERS)
    // ============================================
    
    acf_add_local_field(array(
        'key' => 'field_contact_hours_this_week',
        'label' => 'Total Contact Hours (This Week)',
        'name' => 'contact_hours_this_week',
        'type' => 'number',
        'parent' => 'group_mst_case_master',
        'instructions' => 'Total contact hours from Form 301 entries this week. Auto-calculated by Gravity Flow.',
        'required' => 0,
        'conditional_logic' => 0,
        'wrapper' => array(
            'width' => '25',
            'class' => 'contact-staging-field',
            'id' => '',
        ),
        'default_value' => 0,
        'placeholder' => '0.0',
        'min' => 0,
        'max' => '',
        'step' => 0.1,
        'readonly' => 1, // Read-only
        'append' => 'hrs',
    ));
    
    acf_add_local_field(array(
        'key' => 'field_contact_count_this_week',
        'label' => 'Contact Count (This Week)',
        'name' => 'contact_count_this_week',
        'type' => 'number',
        'parent' => 'group_mst_case_master',
        'instructions' => 'Number of Form 301 contact logs submitted this week. Auto-counted by Gravity Flow.',
        'required' => 0,
        'conditional_logic' => 0,
        'wrapper' => array(
            'width' => '25',
            'class' => 'contact-staging-field',
            'id' => '',
        ),
        'default_value' => 0,
        'placeholder' => '0',
        'min' => 0,
        'max' => '',
        'step' => 1,
        'readonly' => 1, // Read-only
        'append' => 'contacts',
    ));
    
    acf_add_local_field(array(
        'key' => 'field_face_to_face_hours_this_week',
        'label' => 'Face-to-Face Hours (This Week)',
        'name' => 'face_to_face_hours_this_week',
        'type' => 'number',
        'parent' => 'group_mst_case_master',
        'instructions' => 'Face-to-face contact hours only. Filtered from Form 301 contact type field.',
        'required' => 0,
        'conditional_logic' => 0,
        'wrapper' => array(
            'width' => '25',
            'class' => 'contact-staging-field',
            'id' => '',
        ),
        'default_value' => 0,
        'placeholder' => '0.0',
        'min' => 0,
        'max' => '',
        'step' => 0.1,
        'readonly' => 1, // Read-only
        'append' => 'hrs',
    ));
    
    acf_add_local_field(array(
        'key' => 'field_phone_hours_this_week',
        'label' => 'Phone/Virtual Hours (This Week)',
        'name' => 'phone_hours_this_week',
        'type' => 'number',
        'parent' => 'group_mst_case_master',
        'instructions' => 'Phone and virtual contact hours. Filtered from Form 301 contact type field.',
        'required' => 0,
        'conditional_logic' => 0,
        'wrapper' => array(
            'width' => '25',
            'class' => 'contact-staging-field',
            'id' => '',
        ),
        'default_value' => 0,
        'placeholder' => '0.0',
        'min' => 0,
        'max' => '',
        'step' => 0.1,
        'readonly' => 1, // Read-only
        'append' => 'hrs',
    ));
    
    // ============================================
    // HELPER TEXT
    // ============================================
    
    acf_add_local_field(array(
        'key' => 'field_contact_staging_help',
        'label' => '',
        'name' => '',
        'type' => 'message',
        'parent' => 'group_mst_case_master',
        'message' => '<div style="background: #e7f3ff; border-left: 4px solid #2271b1; padding: 12px; margin: 10px 0;">
            <strong>📊 How This Works:</strong><br>
            <ol style="margin: 10px 0 0 20px;">
                <li><strong>Mon-Thu:</strong> Therapist submits Form 301 contact logs (stored as Gravity Forms entries)</li>
                <li><strong>Friday 3 PM:</strong> Gravity Flow aggregates all Form 301 entries for this week → Updates these fields</li>
                <li><strong>Friday PM:</strong> These fields pre-populate Form 302 Section VIII (Contact Summary)</li>
                <li><strong>After Form 302 submission:</strong> Data saved permanently to weekly_case_summary post</li>
                <li><strong>Next Monday:</strong> These fields are cleared and process repeats for new week</li>
            </ol>
            <p style="margin: 10px 0 0 0;"><em>💡 To view complete contact history, see the Contact Logs GravityView or individual Form 301 entries.</em></p>
        </div>',
        'new_lines' => '',
        'esc_html' => 0,
        'wrapper' => array(
            'width' => '100',
        ),
    ));
}
// ============================================
// ADD CUSTOM CSS FOR STAGING FIELDS
// ============================================
add_action('acf/input/admin_head', 'mst_contact_staging_fields_css');
function mst_contact_staging_fields_css() {
    global $post_type;
    
    if ($post_type !== 'mst_case') {
        return;
    }
    ?>
    <style>
        /* Style for contact staging fields - make them visually distinct */
        .contact-staging-field .acf-input-wrap {
            background-color: #f8f9fa;
            border: 1px solid #dee2e6;
        }
        
        .contact-staging-field .acf-input input[readonly],
        .contact-staging-field .acf-input textarea[readonly] {
            background-color: #f8f9fa;
            cursor: not-allowed;
            font-family: 'Monaco', 'Courier New', monospace;
        }
        
        .contact-staging-field .acf-label label {
            font-weight: 600;
            color: #495057;
        }
        
        /* Highlight the summary field */
        .acf-field[data-name="contact_logs_summary"] {
            background: #f8f9fa;
            padding: 15px;
            border-radius: 4px;
            margin: 15px 0;
        }
        
        /* Make read-only text more readable */
        .contact-staging-field textarea[readonly] {
            font-size: 13px;
            line-height: 1.6;
            color: #212529;
        }
    </style>
    <?php
}

Comments

Add a Comment