' . esc_html__('Where this form brings people from: the pages it was sent from, and the pages where its button and the call and chat buttons beside it were pressed.', 'ai-eshop-optimizer') . '

'; \Rooster\Admin\Markup::out(AIEO_Page_Actions::form_pages('aieo_form_' . (int) $post->ID)); } private static function notice($html, $tone) { return AIEO_DMM_UI::notice($html, $tone); } public static function render($post) { $form_id = (int) $post->ID; $fields = AIEO_Form_CPT::fields($form_id); $total = AIEO_Form_Entries::entry_count($form_id); if (empty($fields)) { echo '

' . esc_html__('Add some fields first.', 'ai-eshop-optimizer') . '

'; return; } if (!$total) { echo '

' . esc_html__('No answers yet.', 'ai-eshop-optimizer') . '

'; return; } printf( '

%s %s

', esc_html(number_format_i18n($total)), esc_html(_n('entry recorded.', 'entries recorded.', $total, 'ai-eshop-optimizer')) ); $latest = AIEO_Form_Entries::latest($form_id, 20); $rows = array(); $decide = class_exists('AIEO_Pro_Signup') && '' !== AIEO_Pro_Signup::kind_of_form($form_id); $statuses = $decide ? AIEO_Pro_Signup::statuses(array_map(static function ($e) { return (int) $e['id']; }, $latest)) : array(); if ($decide) { \Rooster\Admin\Markup::out(AIEO_Pro_Signup::result_notice()); } if (!class_exists('AIEO_Submission_Panel', false) && defined('AIEO_DIR') && is_readable(AIEO_DIR . 'includes/dmm/class-aieo-submission-panel.php')) { require_once AIEO_DIR . 'includes/dmm/class-aieo-submission-panel.php'; } $leads = class_exists('AIEO_Submission_Panel') ? AIEO_Submission_Panel::keys_for('aieo_form', array_map(static function ($e) { return (int) $e['id']; }, $latest)) : array(); foreach ($latest as $entry) { $lines = array(); foreach ($fields as $f) { if (!isset($entry['answers'][$f['key']])) { continue; } $label = '' !== trim((string) $f['label']) ? (string) $f['label'] : (string) $f['key']; $value = (string) $entry['answers'][$f['key']]; $value = 'consent' === $f['type'] ? __('Yes', 'ai-eshop-optimizer') : $value; $lines[] = '' . esc_html(class_exists('AIEO_Engine_Blocks') ? AIEO_Engine_Blocks::plain($label) : $label) . ': ' . esc_html(class_exists('AIEO_Engine_Blocks') && AIEO_Form_CPT::is_choice_type($f['type']) ? AIEO_Engine_Blocks::plain($value) : $value); } if ('' !== (string) ($entry['page_url'] ?? '')) { $path = (string) wp_parse_url((string) $entry['page_url'], PHP_URL_PATH); $lines[] = '' . esc_html__('Sent from', 'ai-eshop-optimizer') . ': ' . esc_html('' !== $path ? $path : (string) $entry['page_url']) . ''; } $campaign = ''; if (isset($leads[(int) $entry['id']]) && class_exists('AIEO_Form_Submit')) { $c = AIEO_Form_Submit::campaign((int) $entry['id']); $from = implode(' / ', array_filter(array($c['source'], $c['medium'], $c['campaign']))); $campaign = esc_html('' !== $from ? $from : __('Direct visit', 'ai-eshop-optimizer')) . ('' !== $c['referrer'] ? '
' . esc_html($c['referrer']) . '' : '') . '
' . esc_html__('Campaign and journey', 'ai-eshop-optimizer') . ''; } $seen = array_reverse((array) ($entry['seen_before'] ?? array())); $names = array(); foreach (array_slice($seen, 0, 5) as $pid) { $names[] = '' . esc_html(html_entity_decode(get_the_title((int) $pid), ENT_QUOTES, 'UTF-8')) . ''; } if (count($seen) > 5) { $names[] = '' . esc_html(sprintf(__('and %d more', 'ai-eshop-optimizer'), count($seen) - 5)) . ''; } $rows[] = array( 'received' => get_date_from_gmt($entry['created_at'], get_option('date_format') . ' ' . get_option('time_format')), 'answers' => array('html' => implode('
', $lines)), 'campaign' => '' !== $campaign ? array('html' => $campaign) : '', 'seen' => $names ? array('html' => implode('
', $names)) : '', ); if ($decide) { $rows[count($rows) - 1]['decision'] = array('html' => AIEO_Pro_Signup::decision_cell((int) $entry['id'], $statuses[(int) $entry['id']] ?? 'new')); } } if ($rows) { \Rooster\Admin\Markup::out(\Rooster\Admin\Ui::table( array( array('key' => 'received', 'label' => __('Received', 'ai-eshop-optimizer'), 'width' => 'sm'), array('key' => 'answers', 'label' => __('Entry', 'ai-eshop-optimizer')), array('key' => 'campaign', 'label' => __('Campaign', 'ai-eshop-optimizer'), 'width' => 'sm'), array('key' => 'seen', 'label' => __('Viewed before', 'ai-eshop-optimizer'), 'width' => 'sm'), ) + ($decide ? array(4 => array('key' => 'decision', 'label' => __('Decision', 'ai-eshop-optimizer'), 'width' => 'sm')) : array()), $rows, array('caption' => __('Latest entries', 'ai-eshop-optimizer'), 'cards' => true) )); } foreach ($fields as $f) { $asked = AIEO_Form_Entries::asked_count($form_id, $f['key']); echo '

' . esc_html($f['label']); echo ' ' . esc_html($f['key']) . ''; printf( ' · %s', esc_html(sprintf( __('%d asked', 'ai-eshop-optimizer'), $asked )) ); echo '

'; if ($asked !== $total) { $partial = sprintf( __('%1$d of %2$d entries were shown this question; the rest are excluded from the percentages below.', 'ai-eshop-optimizer'), $asked, $total ); echo self::notice(esc_html($partial), 'warning'); } if (AIEO_Form_CPT::is_choice_type($f['type'])) { $dist = AIEO_Form_Entries::distribution($form_id, $f['key']); if (empty($dist)) { echo '

' . esc_html__('Nobody has answered this one.', 'ai-eshop-optimizer') . '

'; continue; } $fe_rows = array(); foreach ($f['choices'] as $ck => $cl) { $n = isset($dist[$ck]) ? (int) $dist[$ck] : 0; $pct = $asked ? (int) round($n / $asked * 100) : 0; $fe_rows[] = array( 'choice' => (string) $cl, 'count' => $n . ' / ' . (int) $asked, 'share' => array('value' => $pct, 'label' => $pct . '%'), ); } foreach ($dist as $ck => $n) { if (isset($f['choices'][$ck])) { continue; } $pct = $asked ? (int) round($n / $asked * 100) : 0; $fe_rows[] = array( 'choice' => array('html' => '' . esc_html($ck) . ' ' . esc_html__('no longer offered', 'ai-eshop-optimizer') . ''), 'count' => (int) $n . ' / ' . (int) $asked, 'share' => array('value' => $pct, 'label' => $pct . '%'), ); } \Rooster\Admin\Markup::out(\Rooster\Admin\Ui::table( array( array('key' => 'choice', 'label' => __('Answer', 'ai-eshop-optimizer'), 'type' => 'text'), array('key' => 'count', 'label' => __('Answers', 'ai-eshop-optimizer'), 'type' => 'num', 'priority' => 'low'), array('key' => 'share', 'label' => __('Share', 'ai-eshop-optimizer'), 'type' => 'progress'), ), $fe_rows, array('caption' => esc_html($f['label'])) )); } else { $texts = AIEO_Form_Entries::free_text($form_id, $f['key'], 50); if (empty($texts)) { echo '

' . esc_html__('Nobody has answered this one.', 'ai-eshop-optimizer') . '

'; continue; } $list = ''; $title = sprintf(_n('%d written answer', '%d written answers', count($texts), 'ai-eshop-optimizer'), count($texts)); if (function_exists('rooster_admin_table_assets')) { rooster_admin_table_assets(); } \Rooster\Admin\Markup::out('
' . \Rooster\Admin\Ui::fold($title, $list, array('open' => true)) . '
'); } } } } }