Hi,

would it be possible to add :

1) a way to reorder the appearance of the banners.

2) a random feature for the banners.

Thx.

Comments

donniewiko’s picture

Status: Active » Needs review

I have looked into this myself. I cant say how to do 1: reorder. But i have managed to display banners on a random notice.

I dont know how to do a patch so ill write it here:

in file: logics/banners.inc
row 91:

function marinelli_show_banners() {
  $banners = marinelli_get_banners(FALSE);
  $display_banners = array();

// START A COUNTER:
$i = 0;

  // Current path alias
  $path = drupal_strtolower(drupal_get_path_alias($_GET['q']));

  // Check visibility for each banner
  foreach ($banners as $banner) {
    // Pages
    $pages = drupal_strtolower($banner['image_visibility']);

    // Check path for alias, and (if required) for path
    $page_match = drupal_match_path($path, $pages);
    if ($path != $_GET['q']) {
      $page_match = $page_match || drupal_match_path($_GET['q'], $pages);
    }

    // Add banner to visible banner
    if ($page_match) {
      $display_banners[] = $banner;

// INCREASE COUNTER BY 1
$i++;

    }
  }

// CREATE A RANDOM NUMBER FROM $i AND KEEP THE OFFSET IN MIND
$_random = rand(1, $i) -1;

// SHIFT THE RANDOM ENTRY TO THE BEGINNING OF THE ARRAY
array_unshift($display_banners, $display_banners[$_random]);

  return $display_banners;
}

This is how it worked for me.

Ill look into the reordering.

cfan’s picture

Your randomization does not work. Try calling shuffle():

function marinelli_show_banners() {
  $banners = marinelli_get_banners(FALSE);
  $display_banners = array();

  // Current path alias
  $path = drupal_strtolower(drupal_get_path_alias($_GET['q']));

  // Randomize banners   <--- new code
  shuffle( $banners );

  // Check visibility for each banner
  foreach ($banners as $banner) {
    // Pages
    $pages = drupal_strtolower($banner['image_visibility']);
. . .

The order changes every time the pages is refreshed.

donniewiko’s picture

Well strangly, it does work in my setup.

However, shuffle() is so much cleaner and easier.

Thanks for your input.

cehfisher’s picture

I had the same issue and neither of the solutions worked for me on their own. However, if you add the solutions together, they worked! Now I get a random first image and random subsequent images follow. If I refresh the page, I get a new batch of images.

cehfisher’s picture

Quick note, if you only have the banner on the front page, you will need to remove:
array_unshift($display_banners, $display_banners[$_random]);