public function getTemplate($templateId, $language=null)
    {
        if (!$language) {
            $language = $this->getLanguage();
        }
        $select = $this->db->select();
        $select->from('gems__comm_template_translations')
               ->where('gctt_id_template = ?', $templateId)
               ->where('gctt_lang = ?', $language);

        $template = $this->db->fetchRow($select);
        if ($template && !empty($template['gctt_subject'])) {
            return $template;
        }

        if ($language !== $this->project->getLocaleDefault()) {
            $language = $this->project->getLocaleDefault();
            $select = $this->db->select();
            $select->from('gems__comm_template_translations')
                   ->where('gctt_id_template = ?', $templateId)
                   ->where('gctt_lang = ?', $language);

            $template = $this->db->fetchRow($select);
            if ($template && !empty($template['gctt_subject'])) {
                return $template;
            }
        }

        $select = $this->db->select();
        $select->from('gems__comm_template_translations')
               ->where('gctt_id_template = ?', $templateId)
               ->where('gctt_subject <> ""')
               ->where('gctt_body <> ""');
        $template = $this->db->fetchRow($select);
        if ($template && !empty($template['gctt_subject'])) {
            return $template;
        } else {
            return false;
        }
    }
public function getTemplate($templateId, $language=null)
    {
        if (!$language) {
            $language = $this->getLanguage();
        }
        $select = $this->db->select();
        $select->from('gems__comm_template_translations')
               ->where('gctt_id_template = ?', $templateId)
               ->where('gctt_lang = ?', $language);

        $template = $this->db->fetchRow($select);
        if ($template && !empty($template['gctt_subject'])) {
            return $template;
        }

        if ($language !== $this->project->getLocaleDefault()) {
            $language = $this->project->getLocaleDefault();
            $select = $this->db->select();
            $select->from('gems__comm_template_translations')
                   ->where('gctt_id_template = ?', $templateId)
                   ->where('gctt_lang = ?', $language);

            $template = $this->db->fetchRow($select);
            if ($template && !empty($template['gctt_subject'])) {
                return $template;
            }
        }

        $select = $this->db->select();
        $select->from('gems__comm_template_translations')
               ->where('gctt_id_template = ?', $templateId)
               ->where('gctt_subject <> ""')
               ->where('gctt_body <> ""');
        $template = $this->db->fetchRow($select);
        if ($template && !empty($template['gctt_subject'])) {
            return $template;
        } else {
            return false;
        }
    }
public function getTemplate ( $ templateId , $ language = null ) { if ( ! $ language ) { $ language = $ this -> getLanguage ( ) ; } $ select = $ this -> db -> select ( ) ; $ select -> from ( 'gems__comm_template_translations' ) -> where ( 'gctt_id_template = ?' , $ templateId ) -> where ( 'gctt_lang = ?' , $ language ) ; $ template = $ this -> db -> fetchRow ( $ select ) ; if ( $ template && ! empty ( $ template [ 'gctt_subject' ] ) ) { return $ template ; } if ( $ language !== $ this -> project -> getLocaleDefault ( ) ) { $ language = $ this -> project -> getLocaleDefault ( ) ; $ select = $ this -> db -> select ( ) ; $ select -> from ( 'gems__comm_template_translations' ) -> where ( 'gctt_id_template = ?' , $ templateId ) -> where ( 'gctt_lang = ?' , $ language ) ; $ template = $ this -> db -> fetchRow ( $ select ) ; if ( $ template && ! empty ( $ template [ 'gctt_subject' ] ) ) { return $ template ; } } $ select = $ this -> db -> select ( ) ; $ select -> from ( 'gems__comm_template_translations' ) -> where ( 'gctt_id_template = ?' , $ templateId ) -> where ( 'gctt_subject <> ""' ) -> where ( 'gctt_body <> ""' ) ; $ template = $ this -> db -> fetchRow ( $ select ) ; if ( $ template && ! empty ( $ template [ 'gctt_subject' ] ) ) { return $ template ; } else { return false ; } }
get a specific template.
If the selected translation exists, get that translation
Else if the selected translation isn't the default, select the default translation
Else select the first not empty translation
Else return false
@param integer  $templateId Template ID
get a specific template . If the selected translation exists get that translation Else if the selected translation isn t the default select the default translation Else select the first not empty translation Else return false