You are here

function acquia_lift_set_audience_for_test in Acquia Lift Connector 7.2

Same name and namespace in other branches
  1. 7 acquia_lift.admin.inc \acquia_lift_set_audience_for_test()

Saves a test to a particular targeting audience.

Parameters

$option_set: The option set whose targeting is being changed.

$old_audience: The target audience that currently has this test running.

$new_audience: The target audience to move the test to.

File

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

Code

function acquia_lift_set_audience_for_test(&$option_set, $old_audience, $new_audience) {
  if ($old_audience == $new_audience) {
    return;
  }
  if (isset($option_set->targeting[$old_audience]) && isset($option_set->targeting[$old_audience]['osid'])) {
    $nested_osid = $option_set->targeting[$old_audience]['osid'];
    unset($option_set->targeting[$old_audience]['osid']);
  }
  else {
    return;
  }

  // Now add the test to the new audience.
  if (isset($option_set->targeting[$new_audience])) {

    // If this audience previously had a single option assigned to it, remove
    // that option.
    if (isset($option_set->targeting[$new_audience]['option_id'])) {
      unset($option_set->targeting[$new_audience]['option_id']);
    }
    $option_set->targeting[$new_audience]['osid'] = $nested_osid;
  }
}