You are here

function acquia_lift_get_campaign_details in Acquia Lift Connector 7

Same name and namespace in other branches
  1. 7.2 acquia_lift.module \acquia_lift_get_campaign_details()

Generate an array of campaign settings that are currently configured. This administrative information is used for navigation and campaign management.

Return value

array An array of campaigns keyed by machine_name.

11 calls to acquia_lift_get_campaign_details()
acquia_lift_build_page in ./acquia_lift.ui.inc
Attaches the front-end controls to the page.
acquia_lift_campaign_start_complete_callback in ./acquia_lift.admin.unibar.inc
Form complete callback for the acquia_lift_campaign_start_form form.
acquia_lift_campaign_type_create_complete_callback in ./acquia_lift.admin.unibar.inc
Ctools form processing complete handler for the creation of a new campaign by type.
acquia_lift_command_goal_updates in ./acquia_lift.module
Returns an AJAX command to force the update of goals data within a campaign.
acquia_lift_element_variation_delete_complete_callback in ./acquia_lift.admin.unibar.inc
Ctools form processing complete handler for deletion of an element variation.

... See full list

File

./acquia_lift.module, line 3024
acquia_lift.module Provides Acquia Lift-specific personalization functionality.

Code

function acquia_lift_get_campaign_details($include_status = TRUE) {
  $campaigns =& drupal_static(__FUNCTION__, NULL);
  if (is_array($campaigns)) {
    return $campaigns;
  }
  $campaigns = array();

  // We need to provide information about all configured campaigns
  // and goals for the control UI.
  $actions = visitor_actions_get_actions();

  // List the campaigns in Drupal.settings, excluding completed campaigns.
  foreach (personalize_agent_load_multiple(array(), array(), FALSE, FALSE, 'label') as $agent) {
    $plugin = personalize_agent_load_agent($agent->machine_name);
    if (!$plugin) {
      continue;
    }
    $supports_goals = $plugin instanceof PersonalizeAgentGoalInterface;
    if ($supports_goals) {
      foreach (personalize_goal_load_by_conditions(array(
        'agent' => $agent->machine_name,
      )) as $goal) {
        if (isset($actions[$goal->action])) {
          $goals[$goal->action] = filter_xss($actions[$goal->action]['label']);
        }
      }
    }
    $option_sets = personalize_option_set_load_by_agent($agent->machine_name);
    $option_set_types = array();
    foreach ($option_sets as $option_set) {
      $option_set_types[] = $option_set->plugin;
    }
    $current_status = personalize_agent_get_status($agent->machine_name);
    $report_is_active = $plugin instanceof PersonalizeAgentReportInterface && $current_status != PERSONALIZE_STATUS_NOT_STARTED;
    $campaigns[$agent->machine_name] = array(
      'name' => $agent->machine_name,
      'label' => filter_xss($agent->label),
      'type' => $agent->plugin,
      'links' => array(
        'view' => url('admin/structure/personalize/manage/' . $agent->machine_name),
        'edit' => url('admin/structure/personalize/manage/' . $agent->machine_name . '/edit'),
        'report' => $report_is_active ? url('admin/structure/personalize/manage/' . $agent->machine_name . '/report') : '',
      ),
      'supportsGoals' => $supports_goals,
      'optionSetTypes' => array_unique($option_set_types),
      'goals' => isset($goals) ? $goals : NULL,
    );
    if ($include_status) {

      // Add information that will allow starting / pausing the campaign from the
      // unibar.
      list($next_status, $status_text) = _personalize_status_toggle_next($current_status);
      $campaigns[$agent->machine_name]['status'] = $current_status;
      $campaigns[$agent->machine_name]['nextStatus'] = array(
        'status' => $next_status,
        'text' => $status_text,
      );
      $campaigns[$agent->machine_name]['verified'] = acquia_lift_agent_verification_cache_get($agent->machine_name);
    }

    // In the client, goals will render to an array when it is empty and an
    // object when it has data, so the no-data state must be NULL to keep
    // the type consistent as an object.
    unset($goals);
  }
  return $campaigns;
}