You are here

function panels_extra_layouts_adaptive_hash in Panels Extra Layouts 6

Same name and namespace in other branches
  1. 7.2 panels_extra_layouts.module \panels_extra_layouts_adaptive_hash()
  2. 7 panels_extra_layouts.module \panels_extra_layouts_adaptive_hash()

The hashing function is quite simple, hence imperfect. There are some exceptions that are handled below to make the way the grid is filled consistent.

h(i) = \sum_{i}_{j = 1,n} get_digit(c(i,j))

where i is the row number, j is the column number, c(i,j) is the content of entry (i,j) of the content matrix and get_digit is a function that returns m given a number nm, e.g., 41, returns 1.

Parameters

$indexes array: The indexes of a given row of the content array.

$columns integer: The number of columns in the current 'submatrix'.

$mapper_f string: The mapper function name.

Return value

integer The hash of a given row.

2 calls to panels_extra_layouts_adaptive_hash()
four-three-adaptive.tpl.php in plugins/layouts/four_three_adaptive/four-three-adaptive.tpl.php
three-four-adaptive.tpl.php in plugins/layouts/three_four_adaptive/three-four-adaptive.tpl.php

File

./panels_extra_layouts.module, line 62
panels_extra_layouts.module @author António P. P. Almeida <appa@perusio.net> @date Wed Aug 3 04:36:20 2011

Code

function panels_extra_layouts_adaptive_hash($indexes = array(), $columns = 3, $mapper_f) {

  // Bail out if there are no elements.
  if (empty($indexes)) {
    return 0;
  }

  // Count the number of elements in the given row.
  $n = count($indexes);

  // Compute the hash.
  $h = $n == 1 ? 1 : array_sum(array_map($mapper_f, $indexes));

  // For 4 columns there are a couple of special cases where the hash is
  // ambiguous.
  if ($h != 0 && $columns == 4) {

    // If we are in a special situation correct it. The hashing function is quite
    // naive. It's the sum of the column indexes in each row.
    // Some cases we get an incorrect value that needs to be corrected.
    if ($n == 2 && $h == 6) {
      return 4;
    }
    if ($n == 2 && ($h == 7 || $h == 5 && panels_extra_layouts_adaptive_get_digit($indexes[1]) == 3)) {
      return 3;
    }
  }
  return $h;
}