You are here

public static function AcquiaLiftContext::getOptions in Acquia Lift Connector 7

Implements PersonalizeContextInterface::getOptions().

File

plugins/visitor_context/AcquiaLiftContext.inc, line 29
Provides an agent type for Acquia Lift

Class

AcquiaLiftContext
@file Provides an agent type for Acquia Lift

Code

public static function getOptions() {
  $options = array();
  try {
    $transform_options = AcquiaLiftAPI::getInstance(variable_get('acquia_lift_account_info', array()))
      ->getTransformOptions();
    if (empty($transform_options)) {
      return $transform_options;
    }

    // @todo Once more visitor_context plugins have been developed it may
    //   make sense to define some of these categories at a higher
    //   level and have multiple plugins add to them. We could define
    //   the categories as constants in the Personalize module.
    $category_tags = array(
      'Census' => t('Location demographics'),
      'Time' => t('Time related'),
      'Geo' => t('Location'),
      'User-Agent' => t('Browser/device related'),
    );
    foreach ($transform_options['providers'] as $option) {

      // Only options with providesFeatures set to TRUE can be used for
      // automatic targeting.
      if (isset($option['providesFeatures']) && $option['providesFeatures']) {
        if (isset($option['tags'])) {
          if (in_array('Referer', $option['tags'])) {

            // We don't want to include any of the Referer-related tags as we
            // provide this functionality via the Personalize URL Context module.
            continue;
          }

          // Find the first category that exists in this option's tags
          // and use that as the group.
          foreach (array_keys($category_tags) as $tag) {
            if (in_array($tag, $option['tags'])) {
              $group = $category_tags[$tag];
              break;
            }
          }
        }
        $options[$option['code']] = array(
          'name' => $option['name'],
        );
        if (isset($group)) {
          $options[$option['code']]['group'] = $group;
        }
      }
    }
  } catch (AcquiaLiftException $e) {
    drupal_set_message($e
      ->getMessage(), 'error');
  }
  return $options;
}