You are here

function acquia_lift_target_complete_audience_form in Acquia Lift Connector 7.2

Form handler to complete an audience within a campaign.

This form is called within a ctools modal window.

Parameters

stdClass $agent_data: The data for the campaign.

string $audience_id: The id of the audience to complete.

1 string reference to 'acquia_lift_target_complete_audience_form'
acquia_lift_target_complete_audience_modal_callback in ./acquia_lift.admin.inc
Page callback to show the form to stop a test for a particular audience in a CTools modal window.

File

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

Code

function acquia_lift_target_complete_audience_form($form, &$form_state, $agent_data, $audience_id) {
  ctools_include('modal');
  ctools_include('ajax');
  ctools_add_js('ajax-responder');

  // As this is just a small modal form without validation, don't show any
  // dsm messages as they would be repetitive of what is on the main page.
  drupal_get_messages();
  $option_set = acquia_lift_get_option_set_for_targeting($agent_data->machine_name);
  $audience_label = isset($option_set->targeting[$audience_id]['label']) ? $option_set->targeting[$audience_id]['label'] : $audience_id;
  if (!isset($option_set->targeting[$audience_id])) {
    $form['error'] = array(
      '#markup' => t('The specified audience does not exist in the %name personalization.  Close this window and refresh in order to see current options.', array(
        '%name' => $agent_data->label,
      )),
    );
    return $form;
  }
  else {
    if (!isset($option_set->targeting[$audience_id]['osid'])) {
      $form['error'] = array(
        '#markup' => t('The %audience audience does not include a test.  Close this window and refresh in order to see current tests.', array(
          '%audience' => $audience_label,
        )),
      );
    }
  }

  // Get all the display variations for the option set.
  $option_sets = personalize_option_set_load_by_agent($agent_data->machine_name);
  module_load_include('inc', 'acquia_lift', 'acquia_lift.admin.wizard');
  $all_variations = _acquia_lift_personalize_campaign_wizard_variation_displays($option_sets, isset($agent_data->data['variation_set_handling']) ? $agent_data->data['variation_set_handling'] : NULL, FALSE);
  $has_multiple = count($option_sets) > 1;
  foreach ($all_variations as $displays) {
    $variation_displays = array();
    $targeting_option_id = '';
    foreach ($displays as $option) {
      if ($has_multiple && is_array($option) && isset($option['option_set_label'])) {
        $variation_displays[] = theme('acquia_lift_single_variation', array(
          'option' => $option['option_label'],
          'option_set' => $option['option_set_label'],
        ));
      }
      else {
        $variation_displays[] = is_string($option) ? $option : $option['option_label'];
      }
      if (!$has_multiple || !empty($option['targeting'])) {
        $targeting_option_id = $option['option_id'];
      }
    }

    // The targeting option id could remain empty if there are invalid
    // combinations of options resulting in a smaller number of variations in
    // the option set used for targeting.
    if (!empty($targeting_option_id)) {
      $variation_options[$targeting_option_id] = implode(', ', $variation_displays);
    }
  }
  $existing_targeting = acquia_lift_get_structure_from_targeting($option_set);
  $options = array();
  foreach ($existing_targeting[$audience_id] as $option_id) {
    $options[$option_id] = $variation_options[$option_id];
  }
  $instructions = t('Choose a winner for this test for the %audience audience.', array(
    '%audience' => $audience_label,
  ));
  $instructions .= '<br />';
  $instructions .= t('After you select a winner, the test will end.');
  $instructions .= '<br /><span class="acquia-lift-alert"><em>';
  $instructions .= t('This action cannot be undone!');
  $instructions .= '</em></span>';
  $form = array();
  $form['audience_id'] = array(
    '#type' => 'value',
    '#value' => $audience_id,
  );
  $form['audience_label'] = array(
    '#type' => 'value',
    '#value' => $audience_label,
  );
  $form['agent_data'] = array(
    '#type' => 'value',
    '#value' => $agent_data,
  );
  $form['instructions'] = array(
    '#markup' => $instructions,
  );
  $form['winner'] = array(
    '#type' => 'radios',
    '#options' => $options,
    '#required' => TRUE,
    '#title' => t('Winning variation'),
    '#title_display' => 'invisible',
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Complete test'),
    '#attributes' => array(
      'class' => array(
        'action-item-primary-active acquia-lift-submit-button',
      ),
    ),
  );
  return $form;
}