<?php

class Zend_View_Helper_GetLanguage extends Zend_View_Helper_Abstract {
  
  /**
   * @var array
   */
  private $_languages;
  
  private function _fetchLanguages(){
    if(empty($this->_languages)){
      // initialize the array
      $this->_languages = array();
      
      // fetch all languages
      $modelLanguages = new Model_Languages();
      $languages = $modelLanguages->fetchAll();
      
      // index with id
      foreach($languages as $l){
        $this->_languages[$l->id] = Pampa_Util_Array::toObject($l->toArray());
      }
    }
  }
  
  /**
   *
   * @param integer $language_id
   * @return Array
   */
  public function getLanguage($language_id = NULL){
    // index all languages
    $this->_fetchLanguages();
    
    if(isset($this->_languages[$language_id])){
      return $this->_languages[$language_id];
    }
    return NULL;
  }

}