You are here

protected function uc_addresses_views_access::uc_addresses_find_arg_positions in Ubercart Addresses 7

Same name and namespace in other branches
  1. 6.2 views/uc_addresses_views_access.inc \uc_addresses_views_access::uc_addresses_find_arg_positions()

Looksup the position in the path for each argument.

Parameters

string $path: The path to examine.

Return value

array positions An array with the following items:

  • uid_arg_position: integer if found, NULL otherwise.
  • aid_arg_position: integer if found, NULL otherwise.
2 calls to uc_addresses_views_access::uc_addresses_find_arg_positions()
uc_addresses_views_access::access in views/uc_addresses_views_access.inc
Implements views_plugin_access#access().
uc_addresses_views_access::get_access_callback in views/uc_addresses_views_access.inc
Implements views_plugin_access#get_access_callback().

File

views/uc_addresses_views_access.inc, line 176
Contains uc_addresses_views_access class.

Class

uc_addresses_views_access
Access plugin that provides access control based on custom PHP code.

Code

protected function uc_addresses_find_arg_positions($path) {
  $positions = array(
    'uid' => NULL,
    'aid' => NULL,
  );

  // Get list of Views arguments.
  $handlers = $this->display->handler
    ->get_handlers('argument');

  // Find the positions for any arguments embedded in the path via '%'.
  $i = 0;
  $args = array();
  foreach (explode('/', $path) as $element) {
    if ($element == '%') {
      $args[] = $i;
    }
    $i++;
  }

  // Find out which argument handler belongs to which position.
  $j = 0;
  foreach ($handlers as $key => $handler) {
    switch ($key) {
      case $this->options['uid_argument']:
      case $this->options['aid_argument']:

        // Check if this argument is explicitly noted in the path.
        if (isset($args[$j])) {

          // The argument is one of the '%' signs in the path.
          $position = $args[$j];
        }
        else {

          // The argument is not defined in the path. Assume the
          // argument is at the end of the path.
          $position = $i;
          $i++;
        }
        if ($key == $this->options['uid_argument']) {
          $positions['uid'] = $position;
        }
        if ($key == $this->options['aid_argument']) {
          $positions['aid'] = $position;
        }
        break;
    }
    $j++;
  }
  return $positions;
}