<?php
/*
 * @version			$Id: index.php 10381 2008-06-01 03:35:53Z $
 * @package			Carteasy
 * @copyright		Copyright (C) 2005 - 2011 Wlanium
 * @license			proprietary
 * @author			Thomas Bartelt
 * Carteasy is a web shop system
 */

include_once './core/structure.class.php';
include_once './core/item.class.php';
include_once './core/cache.class.php';

class Sitemap {
	private $db;
	private $config;
	private $base_object;

	public function __construct($base_object) {
		$this->config_object = $base_object->config;
		$this->db = $base_object->db;
		$this->base_object = $base_object;
	} // end __construct


	public function get_sitemap() {
		// get cache data
		$cache_object = new Cache($base_object);

		if (!$data = $cache_object->get_data('sitemap_object_get_sitemap')) {
			// get menu structure
			$structure_object = new Structure($this->base_object);
			$item_object = new Item($this->base_object);

			$all_structure = $structure_object->get_all_tree_full_path(1);
			foreach ($all_structure as $structure) {

				// get structure items
				$all_items = array();
				$item_list = $item_object->get_all_structure_items($structure->id);
				foreach ($item_list as $item) {
					$item->structure_short_uri = $structure->short_uri;
					$item->structure_uri_path = $structure->uri_path;
					$all_items[] = $item;
				}
				$structure->items = $all_items;
				/*if (count($all_items) > 0) {
					$structure->name = $structure->name.' ('.count($all_items).')';
				}*/
				$data['structure'][] = $structure;
			}
		}

		return $data;
	}

}

?>