You are here

function acquia_lift_report_ab in Acquia Lift Connector 7

Form build function for an A/B Acquia Lift agent report.

Parameters

AcquiaLiftAgentInterface $agent: The plugin agent for the selected campaign.

stdClass $agent_data: The campaign agent data for this report.

1 call to acquia_lift_report_ab()
acquia_lift_report in ./acquia_lift.admin.inc
Form build function for the Acquia Lift report, which has filters.

File

./acquia_lift.admin.inc, line 770
acquia_lift.admin.inc Provides functions needed for the admin UI.

Code

function acquia_lift_report_ab($form, &$form_state, $agent, $agent_data) {
  $agent_name = $agent
    ->getMachineName();

  // Check for Rickshaw and D3 libraries and alert users if not exist.
  if (_acquia_lift_missing_library_warning(array(
    'rickshaw',
    'd3',
  ), t('The following libraries are required in order to view the Acquia Lift reports:'))) {
    return array();
  }
  $selected_goal = empty($form_state['values']['goal']) ? NULL : $form_state['values']['goal'];
  $selected_metric = empty($form_state['values']['metric']) ? 'rate' : $form_state['values']['metric'];
  $build = array();
  $build['options'] = array(
    '#type' => 'container',
    '#attributes' => array(
      'class' => array(
        'acquia-lift-report-section-options',
      ),
    ),
    '#tree' => FALSE,
    'goal' => acquia_lift_report_goal_dropdown($agent_name, $selected_goal),
    'metric' => acquia_lift_report_conversion_metric_dropdown($selected_metric),
    'submit' => array(
      '#type' => 'submit',
      '#value' => t('Filter'),
    ),
  );
  list($date_start_report, $date_end_report) = acquia_lift_get_report_dates_for_agent($agent_data);

  // Acquia Lift A/B reports have a decision name that is the same as the
  // campaign machine name.
  $options = array(
    'decision' => $agent_data->machine_name,
    'start' => $date_start_report,
    'end' => $date_end_report,
  );
  $build['reports'] = $agent
    ->buildCampaignReports($options);
  if (!$build['reports']['#has_data']) {

    // This campaign hasn't been shown yet, so there is no data for reporting.
    return array(
      'no_report' => array(
        '#markup' => t('This campaign does not yet contain information about your visitors\' website interactions. This situation generally occurs for campaigns that have either just been started or do not generate much website traffic.'),
      ),
    );
  }
  $build['reports']['#attached']['library'][] = array(
    'acquia_lift',
    'acquia_lift.reports',
  );
  return $build;
}