<?php

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

class resmng_sitemap_api extends sitemap
{

    protected $module_name = 'resmng';

    public function __construct()
    {

        $this->get_static();
        $this->get_data();
    }

    protected function get_data()
    {

        if (!empty($this->basepage['id'])) {
            $CI = & get_instance();
            // get data
            $dbData = $CI->db->
                            select('p.alias')->
                            where('p.active', TRUE)->
                            where('r.deleted', FALSE)->
                            where_not_in('p.alias', array('404'))->
                            join('resource r', 'r.id_item = p.id_resource_type_page AND r.id_resource_type = 3', 'left')->
                            order_by('p.id_resource_type_page', 'DESC')->
                            get('resource_type_page p')->result_array();

            // load core model
            $CI->load->model('ciext/core_model');
            $CI->load->library('db_lang_lib');

            foreach ($CI->db_lang_lib->get_lang_by_id() as $lang) {
                foreach ($dbData as $k => $v) {
                    $CI->uri->current_language = $lang->short_name;
                    $this->map[] = new sitemap_item($CI->core_model->create_page_url($v['alias']), date("Y-m-d"), $this->changefreq, $this->priority);
                }
            }
        }
    }

}
