function acquia_lift_add_new_test_for_audience in Acquia Lift Connector 7.2
Same name and namespace in other branches
- 7 acquia_lift.admin.inc \acquia_lift_add_new_test_for_audience()
Creates a new nested test of the specified variations for the specified agent.
Parameters
$option_set: The option set whose targeting is being changed.
$audience: The target audience for the test.
$parent_agent: The parent agent.
$variations: The variations to create a test for.
Throws
\PersonalizeException
1 call to acquia_lift_add_new_test_for_audience()
- acquia_lift_implement_targeting in ./
acquia_lift.admin.inc - Takes whatever is in the 'lift_targeting' data property and converts it into the required campaign structure (including nested tests where needed).
File
- ./
acquia_lift.admin.inc, line 1810 - acquia_lift.admin.inc Provides functions needed for the admin UI.
Code
function acquia_lift_add_new_test_for_audience(&$option_set, $audience, $parent_agent, $variations) {
if (!isset($option_set->targeting[$audience])) {
return;
}
// First we need to create a new agent.
$agent = new stdClass();
$agent->label = 'Sub-test for ' . $parent_agent->label;
$agent->plugin = ACQUIA_LIFT_TESTING_AGENT;
$agent->data = array();
$agent->machine_name = personalize_generate_machine_name($parent_agent->machine_name . '-test', 'personalize_agent_machine_name_exists');
$agent = personalize_agent_save($agent);
$nested_os = new stdClass();
$nested_os->agent = $agent->machine_name;
$nested_os->label = $agent->label;
$nested_os->is_new = TRUE;
$nested_os->data = array();
$nested_os->options = array();
// This is basically a non-renderable option set - just set the plugin to
// 'options'.
$nested_os->plugin = 'options';
foreach ($variations as $option_id) {
$nested_os->options[] = array(
'option_id' => $option_id,
);
}
$nested_os = personalize_option_set_save($nested_os);
$option_set->targeting[$audience]['osid'] = $nested_os->osid;
if (isset($option_set->targeting[$audience]['option_id'])) {
unset($option_set->targeting[$audience]['option_id']);
}
}