<?php

class Solicitacao_Model_TarefaTipo extends Agro_Db_Table_Abstract {
	protected $_schema = 'solicitacao';
	protected $_name = 'tarefa_tipo';
	public $_order = 'vl_ordem';
	protected $_primary = 'id';
	
	public function save($values) {
		$Row = $this->getRow($values['id']);
		
		$Row->id_departamento = $values['id_departamento'];
		$Row->ds_nome_tipo = $values['ds_nome_tipo'];
		$Row->vl_ordem = $values['vl_ordem'];
		
		return $Row->save();
	}
	
	public function getData($where) {
		$Select = $this->select()->setIntegrityCheck(false);
		$Select->from(array('t' => 'solicitacao.tarefa_tipo'));
		$Select->join(array('d' => 'sistema.departamentos'), 'd.id = t.id_departamento', 'ds_nome_departamento');
		$this->getWhere($Select, $where);
		
		if ($this->_order) {
			$Select->order($this->_order);
		}
		
		return $Select;
	}
	
	public function getCombo($idDepartamento) {
		$Select = $this->select()->setIntegrityCheck(false);
		$Select->from('solicitacao.tarefa_tipo', array('id', 'ds_nome_tipo'));
		$Select->where('id_departamento = ?', $idDepartamento);
		$Select->order('vl_ordem');
		
		return $this->getDefaultAdapter()->fetchPairs($Select);
	}
	
}