<?php

class Sistema_Model_Row_Empresa extends Agro_Db_Table_Row_Abstract {
	
	public function departamentos($ds_chave_departamento=false) {
		if ($ds_chave_departamento){
			$Model = new Sistema_Model_Departamentos();
			$Depto = $Model->fetchRow("id_empresa=$this->id and ds_chave = '$ds_chave_departamento'");
			
			if ($Depto){
				return $Depto;
			} else {
				return false;
			}
		} else {
			return $this->findDependentRowset('Sistema_Model_Departamentos', null, $this->select()->order('ds_nome_departamento'));
		}		
	}
	
	
	
	public function id_grupamento_cultura(){
		$Model = new Sistema_Model_EmpresaGrupamentoCulturas();
		$Rows = $Model->fetchAll("id_empresa=$this->id");
		
		$result = array();
		
		foreach ($Rows as $grupamento){
			$result[] = $grupamento->id_grupamento_cultura;		
		}
		
		return (count($result) ? $result : false);
	}
}