You are here

function acquia_lift_stop_test_for_audience in Acquia Lift Connector 7.2

Stops a test for the specified audience of the specified targeting agent.

Parameters

$agent: The targeting agent.

$audience: The audience to stop the test for.

$winner: (optional) The winning variation id to assign to the audience in place of the test.

Throws

\AcquiaLiftException

\PersonalizeException

3 calls to acquia_lift_stop_test_for_audience()
AcquiaLiftWebTestTarget::testStopAndPickWinner in tests/acquia_lift.test
acquia_lift_target_complete_audience_form_submit in ./acquia_lift.admin.inc
Submit handler for acquia_lift_target_complete_audience_form().
acquia_lift_update_7205 in ./acquia_lift.install
Retire first generation decision engine's tests. Store the time that the system has performed V2 report upgrade.

File

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

Code

function acquia_lift_stop_test_for_audience($agent, $audience, $winner = NULL) {
  $option_set = acquia_lift_get_option_set_for_targeting($agent->machine_name);
  if (empty($option_set) || !isset($option_set->targeting[$audience]) || !isset($option_set->targeting[$audience]['osid'])) {
    throw new AcquiaLiftException('There is no test for this audience.');
  }
  $nested_os = personalize_option_set_load($option_set->targeting[$audience]['osid']);

  // Assign the "winning" option to the audience. If no winner provided we use
  // the first one.
  if (empty($winner)) {
    $winner = $nested_os->options[0]['option_id'];
  }
  unset($option_set->targeting[$audience]['osid']);
  $option_set->targeting[$audience]['option_id'] = $winner;
  try {
    personalize_option_set_save($option_set);
  } catch (PersonalizeException $e) {
    drupal_set_message(t('There was a problem updating the targeting for this personalization.'));

    // Don't retire the test, something's amiss.
    return;
  }
  if (isset($agent->data['lift_targeting'][$audience])) {
    $agent->data['lift_targeting'][$audience] = array(
      $winner,
    );
    personalize_agent_save($agent);
  }
  $nested_agent = personalize_agent_load($nested_os->agent);
  $audience_label = isset($option_set->targeting[$audience]['label']) ? $option_set->targeting[$audience]['label'] : $audience;
  acquia_lift_retire_test($nested_agent, $agent->machine_name, $agent->label, $audience, $audience_label);
}