You are here

public function AcquiaLiftAgent::getFixedTargetingSyncOperations in Acquia Lift Connector 7

Returns the operations needed to sync goals to Acquia Lift.

Parameters

$option_sets: An array representing the option sets whose targeting rules need to be sync'd.

Return value

array An array of items representing API calls to be made to Acquia Lift.

1 call to AcquiaLiftAgent::getFixedTargetingSyncOperations()
AcquiaLiftAgent::syncFixedTargeting in plugins/agent_types/AcquiaLiftAgent.inc
Implements AcquiaLiftAgentInterface::syncFixedTargeting().

File

plugins/agent_types/AcquiaLiftAgent.inc, line 1044
Provides an agent type for Acquia Lift

Class

AcquiaLiftAgent

Code

public function getFixedTargetingSyncOperations($option_sets) {
  $items = array();

  // If any of this agent's option sets has explicit targeting mappings configured,
  // we need to send these mappings to Acquia Lift.
  $mappings = array();
  foreach ($option_sets as $option_set) {
    if (empty($option_set->targeting)) {
      continue;
    }
    $point_name = $option_set->decision_point;
    $decision_name = $option_set->decision_name;
    $mappings[$point_name] = isset($mappings[$point_name]) ? $mappings[$point_name] : array();
    foreach ($option_set->targeting as $targ) {
      if (!isset($targ['option_id'])) {
        continue;
      }
      if (isset($targ['targeting_features'])) {

        // Check if we're supposed to AND or OR mulitple features together.
        if (isset($targ['targeting_strategy']) && $targ['targeting_strategy'] == 'AND') {

          // Create a single mapping, with a comma-separated list of features.
          $mappings[$point_name][] = array(
            'feature' => implode(',', $targ['targeting_features']),
            'decision' => $decision_name . ':' . $targ['option_id'],
          );
        }
        else {

          // Create a mapping for each feature and they will be OR'd together.
          foreach ($targ['targeting_features'] as $feature) {
            $mappings[$point_name][] = array(
              'feature' => $feature,
              'decision' => $decision_name . ':' . $targ['option_id'],
            );
          }
        }
      }
    }
  }

  // Send mappings per decision point.
  foreach ($mappings as $point_name => $map) {
    $items[] = array(
      'method' => 'saveFixedTargetingMapping',
      'args' => array(
        $this->machineName,
        $point_name,
        $map,
      ),
    );
  }
  return $items;
}