Example #1
0
 public function _index($showroom, $sub_tool = FALSE)
 {
     $url_array = uri::url_array();
     list($page_name, $first_node, $item) = $url_array;
     $page_name = $this->get_page_name($page_name, 'showroom', $showroom->id);
     # parse the params.
     $params = explode('|', $showroom->params);
     $primary = new View("public_showroom/display/wrapper");
     # what is the url asking for?
     if ('get' == $url_array['0'] or empty($first_node)) {
         # if empty, display default category
         $primary->items = empty($showroom->home_cat) ? '(Home Category not set)' : self::items_category($page_name, $showroom, (int) $showroom->home_cat);
     } elseif (is_numeric($first_node)) {
         if ('0' == substr($first_node, 0, 1)) {
             $primary->item = self::item($page_name, $first_node, $item);
         } else {
             $primary->items = self::items_category($page_name, $showroom, $first_node);
         }
     } else {
         Event::run('system.404');
     }
     # determine the category to highlight.
     $first_node = empty($first_node) ? $showroom->home_cat : $first_node;
     # how do we show the category list on every showroom page?
     $category_list = '';
     if (!empty($params[0])) {
         if ('flat' == $params[0]) {
             # showing only root categories.
             $root_cats = ORM::factory('showroom_cat')->where(array('fk_site' => $this->site_id, 'showroom_id' => $showroom->id, 'local_parent' => $showroom->root_id))->orderby(array('lft' => 'asc'))->find_all();
             $category_list = Tree::display_flat_tree('showroom', $root_cats, $page_name, $first_node);
         } else {
             $category_list = Tree::display_tree('showroom', $showroom->showroom_cats, $page_name, $first_node);
         }
     }
     $primary->categories = $category_list;
     # add custom javascript;
     $primary->global_readyJS(self::javascripts($showroom));
     # admin js hack.
     if ($this->client->can_edit($this->site_id)) {
         $primary->global_readyJS('
     $("#click_hook").click(function(){
       $().add_toolkit_items("showroom");
     });
   ');
     }
     return $this->wrap_tool($primary, 'showroom', $showroom);
 }