<?php

class Atendimento_Model_TipoRecusaSinistro extends Agro_Db_Table_Abstract {
    protected $_schema = 'atendimento';
    protected $_name = 'tipo_recusa_sinistro';
    protected $_primary = 'id';
    public $_order = 'ds_tipo_recusa';

    public function save($data) {
        $Row = $this->getRow($data['id']);
        $Row->ds_tipo_recusa = $data['ds_tipo_recusa'];
        $Row->ds_chave = $data['ds_chave'];
        return $Row->save();
    }

    public function getCombo() {
        $Select = $this->select();
        $Select->where('fl_ativo=true');
        $Select->order('ds_tipo_recusa ASC');

        $Rs = $this->fetchAll($Select);

        $options = array();
        $options[''] = '';
        if ($Rs->count()) {
            foreach ($Rs as $row) {
                $options[$row['id']] = (strlen($row['ds_tipo_recusa']) > 70) ? mb_substr($row['ds_tipo_recusa'], 0, 70, 'UTF-8')."..." : $row['ds_tipo_recusa'];
            }
        }

        return $options;
    }

    public function getRecusaSinistro() {
        $Select = $this->select();
        $Select->where('fl_ativo=true');
        $Select->order('ds_tipo_recusa ASC');

        $Rs = $this->fetchAll($Select);

        return $Rs->toArray();
    }
    
    public function getRecusaSinistroById($id_tipo_recusa) {
        $Select = $this->select();
        $Select->where('id = '.$id_tipo_recusa);
        
        return $this->getDefaultAdapter()->fetchRow($Select);
    }
}
