<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

abstract class sitemap {

    protected $map = array();
    protected $module_name = 'example';
    protected $changefreq = 'weekly';
    protected $priority = '0.5';
    protected $html = '';
    protected $basepage = array(
        'id' => 0,
        'alias' => '',
        'name' => ''
    );
    
    public function __construct() {
        $this->get_static();
        $this->get_data();
    }

    public function get_mudule_map() {

        return (array) $this->map;
    }

    protected function get_static() {

        $CI = & get_instance();
        $static_val = $CI->db->
                        select('rtp.name, sc.changefreq,sc.priority,rtp.alias,sc.basepage')->
                        where('sc.module_name', $this->module_name)->
                        join('resource_type_page rtp', 'rtp.id_resource_type_page = sc.basepage AND rtp.active = 1', 'left')->
                        get('sitemap_config sc')->row_array();

        if (!empty($static_val['changefreq'])) {
            $this->changefreq = $static_val['changefreq'];
        }

        if (!empty($static_val['priority'])) {
            $this->priority = $static_val['priority'];
        }

        if (!empty($static_val['basepage'])) {
            $this->basepage['id'] = $static_val['basepage'];
        }

        if (!empty($static_val['alias'])) {
            $this->basepage['alias'] = $static_val['alias'];
        }
        if (!empty($static_val['name'])) {
            $this->basepage['name'] = $static_val['name'];
        }
    }

}

class sitemap_item {

    protected $data = array();

    // set data

    public function add_loc($loc) {
        $this->data['loc'] = $loc;
    }

    public function add_lastmod($lastmod) {
        $this->data['lastmod'] = $lastmod;
    }

    public function add_changefreq($changefreq) {
        $this->data['changefreq'] = $changefreq;
    }

    public function add_priority($priority) {
        $this->data['priority'] = $priority;
    }

    public function add_html($html) {
        $this->data['html'] = $html;
    }

    //get data

    public function get_loc() {
        return $this->data['loc'];
    }

    public function get_lastmod() {
        return $this->data['lastmod'];
    }

    public function get_changefreq() {
        return $this->data['changefreq'];
    }

    public function get_priority() {
        return $this->data['priority'];
    }

    public function get_html() {
        return $this->data['html'];
    }

    public function __construct($loc = '', $lastmod = '', $changefreq = '', $priority = '') {
        $this->add_loc($loc);
        $this->add_lastmod($lastmod);
        $this->add_changefreq($changefreq);
        $this->add_priority($priority);
    }

}
