You are here

function _simpleads_load_ads in SimpleAds 7

Helper function. Returns data array for an adertisement block.

Parameters

int $tid:

int $limit:

Return value

array

2 calls to _simpleads_load_ads()
simpleads_preprocess_simpleads_block in includes/simpleads.theme.inc
Preprocess for simpleads_block.tpl.php
_simpleads_show_ads in ./simpleads.module
Menu callback. Callback for AJAX call.

File

includes/simpleads.helper.inc, line 16
SimpleAds Helper functions.

Code

function _simpleads_load_ads($tid, $limit) {
  $result = array();
  $term_ids = array();
  if (is_array($tid)) {
    $term_ids = $tid;
  }
  else {
    $term_ids[] = $tid;
  }
  if (is_numeric($limit)) {
    $ad_settings = _simpleads_adgroup_settings($tid);
    $order_delta = isset($ad_settings['ads_order']) ? $ad_settings['ads_order'] : 'random';
    $queries = module_invoke_all('simpleads_order', $order_delta, $term_ids, $limit);
    if (count($queries) > 0) {
      foreach ($queries as $i => $query) {
        foreach ($queries[$i] as $row) {
          $node = node_load($row->nid);
          $active = TRUE;
          if (isset($node->field_ad_status[$node->language])) {
            if ($node->field_ad_status[$node->language][0]['value'] != 1) {
              $active = FALSE;
            }
          }
          if ($active) {
            $result[] = _simpleads_ads_data($node);
          }
        }
      }
    }
  }
  return $result;
}