<?php

Goweb::loadClass('Goweb_Db_Model');

/**
 * Goweb Sitemanager 5 Framework
 * @version    5.0.0
 * @category   Frontoffice
 * @package    Painel
 * @subpackage Model
 * @author     I&D <dev@goweb.pt>, Pedro Pinto <ppinto@goweb.pt>
 * @copyright  2009 (c) Goweb (http://www.goweb.pt)
*/
class Painel_Model_Config extends Goweb_Db_Model {
    
    /**
     * Nome da Tabela
     *
     * @var string
    */
    protected $_table = 'painel_config';
    
    /**
     * Chave Primaria
     * 
     * @var string
    */
    protected $_primary = 'id';
    
    /**
     * Campo que sera retornado se um
     * echo do objecto for chamado
     *
     * @var string
    */
    protected $_toString = 'id';

    /**
     * Configuração do site
     *
     * @var Zend_Config_Ini
     */
    protected $_config = null;
    
    /**
     * Línguas do site
     *
     * @var array
     */
    protected $_langsNames = array('pt' => 'Portugu&ecirc;s',
                                   'en' => 'Ingl&ecirc;s',
                                   'fr' => 'Franc&ecirc;s',
                                   'de' => 'Alem&atilde;o',
    							   'it' => 'Italiano',
                                   'ru' => 'Russo',
    							   'es' => 'Espanhol');
    
    
    /**
     * Metodo obrigatorio. Informa a definicao da tabela
     * referente ao Model em questao.
    */
    protected function _setup() {
        $this->_config = Goweb::registry('config');
        $this->initLang();
        $this->setSyncCols(array('linguas_activas', 'google_analytics', 'meta_copyright', 'meta_extra', 'google_sitemap'));
        $this->title = $this->Char(array('maxlength' => 200, 'size' => 40, 'label' => 'Titulo'));
        $this->meta_copyright = $this->Char(array('maxlength' => 200, 'size' => 40, 'label' => 'Copyright'));
        $this->meta_keywords = $this->Text(array('label' => 'Keywords', 'cols' => 50, 'rows' => 5, 'help' => 'Palavras separadas por virgulas.'));
        $this->meta_description = $this->Text(array('maxlength' => 500, 'cols' => 50, 'rows' => 5, 'label' => 'Description'));
        $this->meta_extra = $this->Text(array('cols' => 50, 'rows' => 5, 'label' => 'Extra'));
        $this->google_map_key = $this->Text(array('maxlength' => 500, 'cols' => 50, 'rows' => 5, 'label' => translate('Google Map Key')));
        $this->google_sitemap = $this->Text(array('maxlength' => 500, 'cols' => 50, 'rows' => 5, 'label' => 'Google Sitemap'));
        $this->google_analytics = $this->Text(array('maxlength' => 500, 'cols' => 50, 'rows' => 5, 'label' => 'Google Analytics'));        
        $this->linguas_activas = $this->Char(array('maxlength' => 255, 'form' => 'MultiCheckbox', 'options' => $this->_getLangsAvailable()));
        $this->actualizado = $this->Datetime(array('on_update' => '_currentDatetime', 'label' => 'Actualizado em'));
        $this->criado = $this->Datetime(array('on_insert' => '_currentDatetime', 'label' => 'Criado em'));
        $this->ip = $this->IpAddress(array('on_update' => '_remoteAddress'));
    }

    /**
     * Metodo auxiliar. Pega todas as linguas disponiveis no sistema.
     *
     * @return array
    */
    protected function _getLangsAvailable() {
        $langs = array();
        $available = explode(',', $this->_config->languages->available);
        foreach ($available as $lang) {
            $langs[$lang] = html_entity_decode($this->_langsNames[$lang], ENT_NOQUOTES, CHARSET);
        }
        return $langs;
    }
}