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

/**
 * Class of resmng_sitemap_api
 *
 * @author r.ratsun <r.ratsun@gmail.com>
 */
class resmng_sitemap_api extends abstract_sitemap
{

    /**
     * Get module sitemap data
     */
    protected function get_data()
    {
        $CI     = & get_instance();
        // get data
        $dbData = $CI->db->
                select('p.alias, rtpd.updated, rtpd.id_lan')->
                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')->
                join('resource_type_page_data rtpd', 'rtpd.id_resource_type_page = p.id_resource_type_page', '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) {
                if ($v['id_lan'] == $lang->id_lan) {
                    $CI->uri->current_language = $lang->short_name;
                    $this->map[]               = new sitemap_item($CI->core_model->create_page_url($v['alias']),
                        date("Y-m-d", strtotime($v['updated'])), $this->changefreq, $this->priority);
                }
            }
        }
    }
}
