You are here

function ad_channel_ad_build_cache in Advertisement 6.2

Same name and namespace in other branches
  1. 5.2 channel/ad_channel.module \ad_channel_ad_build_cache()
  2. 6.3 channel/ad_channel.module \ad_channel_ad_build_cache()
  3. 7 channel/ad_channel.module \ad_channel_ad_build_cache()

Implementation of hook_ad_build_cache().

File

channel/ad_channel.module, line 556
Ad Channel module.

Code

function ad_channel_ad_build_cache() {
  $cache = array();
  $ads = array();
  $active = db_query("SELECT aid FROM {ads} WHERE adstatus = 'active'");
  while ($ad = db_fetch_object($active)) {

    // cache channel<->node relation
    $result = db_query('SELECT chid FROM {ad_channel_node} WHERE nid = %d', $ad->aid);
    while ($channel = db_fetch_object($result)) {
      $ads[$ad->aid][$channel->chid] = $channel->chid;

      //$ads[$channel->chid][$ad->aid] = $ad->aid;
    }
  }
  $channels = array();
  $result = db_query('SELECT chid, display, urls, no_channel_percent, inventory FROM {ad_channel}');
  while ($channel = db_fetch_object($result)) {
    $channels[$channel->chid] = $channel;
  }
  $result = db_query("SELECT p.aid, p.priority FROM {ads} a LEFT JOIN {ad_priority} p ON a.aid = p.aid WHERE a.adstatus = 'active' AND p.priority = 1");
  $premiere = array();
  while ($priority = db_fetch_object($result)) {
    $premiere[$priority->aid] = $priority->aid;
  }
  $result = db_query("SELECT r.aid, r.remnant FROM {ads} a LEFT JOIN {ad_channel_remnant} r ON a.aid = r.aid WHERE a.adstatus = 'active' AND r.remnant = 1");
  $remnants = array();
  while ($remnant = db_fetch_object($result)) {
    $remnants[$remnant->aid] = $remnant->aid;
  }
  $cache['channel']['ads'] = $ads;
  $cache['channel']['channels'] = $channels;
  $cache['channel']['display'] = variable_get('ad_channel_display', 0);
  $cache['premiere'] = $premiere;
  $cache['remnant'] = $remnants;
  $cache['channel']['hook_filter'] = array(
    'weight' => 0,
    'file' => drupal_get_path('module', 'ad_channel') . '/ad_channel.inc',
    'function' => 'ad_channel_cache_filter',
  );
  return $cache;
}