<?php

abstract class MY_Controller extends CI_Controller {

    public $title;
    public $cssFiles = array();
    public $javaScriptFiles = array();
    public $metaTags = array(
        'title' => '',
        'description' => '',
        'keywords' => '');

    
    public $noticias_high = array();
    
    public function __construct() {
        parent::__construct();
        if ($this->session->userdata('lang') != '') {
            $this->lang->load('messages', $this->session->userdata('lang'));
            setlocale(LC_ALL, $this->session->userdata('lang'));
        } else {
            $this->lang->load('messages', 'portuguese');
            setlocale(LC_ALL, 'portuguese');
        }
        
        
        
       /* $this->load->model('noticia_model');
        $noticias_data = $this->noticia_model->get_noticias(3);
        if ($noticias_data->num_rows > 0) {
            $this->noticias_high = $noticias_data->result_array();
        }*/
    }

    /**
     * This method shoud be called by extended classes after
     * setting all properties on $data array
     * 
     * @param view $viewToRender
     */
    protected function renderPage($viewToRender, $extraData = array()) {
        $this->data['javaScriptFiles'] = $this->javaScriptFiles;
        $this->data['cssFiles'] = $this->cssFiles;
        $this->data['title'] = $this->title;
        $this->data['metaTags'] = $this->metaTags;
        $this->data['extraData'] = $extraData;
        $this->data['body_content'] = $this->load->view($viewToRender, $this->data, TRUE);
        $this->load->view('layouts/base', $this->data);
    }

    public function addCssFile($param) {
        array_push($this->cssFiles, $param);
    }

    public function addScriptFile($param) {
        array_push($this->javaScriptFiles, $param);
    }

    public function setMetatags($title = '', $description = '', $keywords = '') {

        if ($title != '') {
            $this->metaTags['title'] = $title;
        }
        if ($description != '') {
            $this->metaTags['description'] = $description;
        }

        if ($keywords != '') {
            $this->metaTags['keywords'] = $keywords;
        }
    }

}
