Back to RouterView class

Method getPath

public array
getPath
(mixed $query)
Get the path of views from target view to root view including content items of a nestable view
Parameters
  • array $query Array of query elements
Returns
  • array List of views including IDs of content items
Since
  • 3.5
Class: RouterView
Project: Joomla

Method getPath - Source code

/**
 * Get the path of views from target view to root view
 * including content items of a nestable view
 *
 * @param   array  $query  Array of query elements
 *
 * @return  array List of views including IDs of content items
 *
 * @since   3.5
 */
public function getPath($query)
{
    $views = $this->getViews();
    $result = array();
    // Get the right view object
    if (isset($query['view']) && isset($views[$query['view']])) {
        $viewobj = $views[$query['view']];
    }
    // Get the path from the current item to the root view with all IDs
    if (isset($viewobj)) {
        $path = array_reverse($viewobj->path);
        $start = true;
        $childkey = false;
        foreach ($path as $element) {
            $view = $views[$element];
            if ($start) {
                $key = $view->key;
                $start = false;
            } else {
                $key = $childkey;
            }
            $childkey = $view->parent_key;
            if (($key || $view->key) && \is_callable(array($this, 'get' . ucfirst($view->name) . 'Segment'))) {
                if (isset($query[$key])) {
                    $result[$view->name] = \call_user_func_array(array($this, 'get' . ucfirst($view->name) . 'Segment'), array($query[$key], $query));
                } elseif (isset($query[$view->key])) {
                    $result[$view->name] = \call_user_func_array(array($this, 'get' . ucfirst($view->name) . 'Segment'), array($query[$view->key], $query));
                } else {
                    $result[$view->name] = array();
                }
            } else {
                $result[$view->name] = true;
            }
        }
    }
    return $result;
}