You are here

function _simpleads_render_ajax_template in SimpleAds 7

Helper function. Return rendered SimpleAds block template.

Parameters

array $nodes:

int $tid:

int $limit:

array $settings1:

array $settings2:

Return value

string

2 calls to _simpleads_render_ajax_template()
template_preprocess_views_simpleads in includes/simpleads.theme.inc
Preprocess for SimpleAds Views template. views-simpleads.tpl.php
_simpleads_show_ads in ./simpleads.module
Menu callback. Callback for AJAX call.

File

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

Code

function _simpleads_render_ajax_template($nodes, $tid, $limit, $settings1 = array(), $settings2 = array()) {
  $settings = array();
  $result = "";
  $count = 0;
  foreach ($nodes as $ad) {
    $ad_block = db_select('simpleads_blocks', 'sb')
      ->fields('sb', array(
      'settings',
    ))
      ->condition('sb.tid', $tid)
      ->execute()
      ->fetchField();
    $this_ad_setting = unserialize($ad_block);
    if (count($settings1) > 0) {
      $ad_setting = array_merge($this_ad_setting, $settings1);
    }
    else {
      $ad_setting = $this_ad_setting;
    }
    $css_class = array();
    if ($count == 0) {
      $css_class = array(
        'first',
      );
    }
    else {
      if ($count == count($nodes) - 1) {
        $css_class = array(
          'last',
        );
      }
    }
    if ($ad['type'] == 'graphic') {
      $result .= theme('simpleads_img_element', array(
        'ad' => $ad,
        'settings' => $ad_setting,
        'css_class' => $css_class,
      ));
    }
    elseif ($ad['type'] == 'text') {
      $result .= theme('simpleads_text_element', array(
        'ad' => $ad,
        'settings' => $ad_setting,
        'css_class' => $css_class,
      ));
    }
    else {
      $result .= theme('simpleads_flash_element', array(
        'ad' => $ad,
        'settings' => $ad_setting,
        'css_class' => $css_class,
      ));
    }
    $count++;
  }
  $this_block_settings = _simpleads_adgroup_settings($tid);
  if (count($settings2) > 0) {
    $settings = array_merge($this_block_settings, $settings2);
  }
  else {
    $settings = $this_block_settings;
  }
  return theme('simpleads_ajax_call', array(
    'content' => $result,
    'total_ads' => $count,
    'tid' => $tid,
    'settings' => $settings,
  ));
}