/**
  * Tests the getViews() method
  *
  * @return  void
  *
  * @since   3.4
  * @covers  JComponentRouterView::getViews
  */
 public function testGetViews()
 {
     $views = $this->getComContentViews();
     foreach ($views as $view) {
         $this->object->registerView($view);
     }
     $this->assertEquals($views, $this->object->getViews());
 }
Exemple #2
0
 /**
  * Build a menu-less URL
  *
  * @param   array  &$query     The vars that should be converted
  * @param   array  &$segments  The URL segments to create
  *
  * @return  void
  *
  * @since   3.4
  */
 public function build(&$query, &$segments)
 {
     $menu_found = false;
     if (isset($query['Itemid'])) {
         $item = $this->router->menu->getItem($query['Itemid']);
         if (!isset($query['option']) || $item && $item->query['option'] == $query['option']) {
             $menu_found = true;
         }
     }
     if (!$menu_found && isset($query['view'])) {
         $views = $this->router->getViews();
         if (isset($views[$query['view']])) {
             $view = $views[$query['view']];
             $segments[] = $query['view'];
             if ($view->key && isset($query[$view->key])) {
                 if (is_callable(array($this->router, 'get' . ucfirst($view->name) . 'Segment'))) {
                     $result = call_user_func_array(array($this->router, 'get' . ucfirst($view->name) . 'Segment'), array($query[$view->key], $query));
                     $segments[] = str_replace(':', '-', array_shift($result));
                 } else {
                     $segments[] = str_replace(':', '-', $query[$view->key]);
                 }
                 unset($query[$views[$query['view']]->key]);
             }
             unset($query['view']);
         }
     }
 }
Exemple #3
0
 /**
  * Build a standard URL
  *
  * @param   array  &$query     The vars that should be converted
  * @param   array  &$segments  The URL segments to create
  *
  * @return  void
  *
  * @since   3.4
  */
 public function build(&$query, &$segments)
 {
     // Get the menu item belonging to the Itemid that has been found
     $item = $this->router->menu->getItem($query['Itemid']);
     if (!isset($query['view'])) {
         return;
     }
     // Get all views for this component
     $views = $this->router->getViews();
     // Return directly when the URL of the Itemid is identical with the URL to build
     if (isset($item->query['view']) && $item->query['view'] == $query['view']) {
         $view = $views[$query['view']];
         if (isset($item->query[$view->key]) && $item->query[$view->key] == (int) $query[$view->key]) {
             unset($query[$view->key]);
             while ($view) {
                 unset($query[$view->parent_key]);
                 $view = $view->parent;
             }
             unset($query['view']);
             if (isset($item->query['layout']) && isset($query['layout']) && $item->query['layout'] == $query['layout']) {
                 unset($query['layout']);
             }
             return;
         }
         if (!$view->key) {
             if (isset($item->query['layout']) && isset($query['layout']) && $item->query['layout'] == $query['layout']) {
                 unset($query['view']);
                 unset($query['layout']);
                 return;
             }
         }
     }
     // Get the path from the view of the current URL and parse it to the menu item
     $path = array_reverse($this->router->getPath($query), true);
     $found = false;
     $found2 = false;
     for ($i = 0, $j = count($path); $i < $j; $i++) {
         reset($path);
         $view = key($path);
         if ($found) {
             $ids = array_shift($path);
             if ($views[$view]->nestable) {
                 foreach (array_reverse($ids, true) as $id => $segment) {
                     if ($found2) {
                         $segments[] = str_replace(':', '-', $segment);
                     } else {
                         if ((int) $item->query[$views[$view]->key] == (int) $id) {
                             $found2 = true;
                         }
                     }
                 }
             } else {
                 if (is_bool($ids)) {
                     $segments[] = $views[$view]->name;
                 } else {
                     $segments[] = str_replace(':', '-', array_shift($ids));
                 }
             }
         } else {
             if ($item->query['view'] != $view) {
                 array_shift($path);
             } else {
                 if (!$views[$view]->nestable) {
                     array_shift($path);
                 } else {
                     $i--;
                     $found2 = false;
                 }
                 $found = true;
             }
         }
         unset($query[$views[$view]->parent_key]);
     }
     if ($found) {
         unset($query['layout']);
         unset($query[$views[$query['view']]->key]);
         unset($query['view']);
     }
 }