<?php

/**
 * Classe Participant
 **/
 
class Bloco extends TRecord
{
	private $subevents;
	private $bloco;
	
	function save()
	{
		try
		{
			Transaction::beginTransaction();
		
			$this->store();
			
			Transaction::closeTransaction();		
		}
		catch(Exception $ex)
		{
			Transaction::cancelTransaction();
			throw new Exception($ex->getMessage());
		}
	}
	
	function remove()
	{
		try
		{
			Transaction::beginTransaction();
		
			$this->delete();
			
			Transaction::closeTransaction();			
		}
		catch(Exception $ex)
		{
			Transaction::cancelTransaction();
			throw new Exception($ex->getMessage());
		}
	}
	
	static function getObject($id)
	{
		try
		{
			Transaction::beginTransaction();
		
			$object = new Bloco($id);
			
			Transaction::closeTransaction();			
			
			return $object;
		}
		catch(Exception $ex)
		{
			Transaction::cancelTransaction();
			throw new Exception($ex->getMessage());
		}
	}
	
	static function getObjectUId($Uid)
	{
		try
		{
			Transaction::beginTransaction();
	
			$criteria = new TCriteria();
			$criteria->add(new TFilter("guid", "=", $Uid));
				
			$repository = new TRepository("Bloco");
			
			$lstObject = $repository->load($criteria);
			
			if(is_array($lstObject))
				$object = $lstObject[0];
	
			Transaction::closeTransaction();
	
			return $object;
		}
		catch(Exception $ex)
		{
			Transaction::cancelTransaction();
			throw new Exception($ex->getMessage());
		}
	}
	
	static function listObjects($limit=null, $offset=null, $order=null,$group=null,$keyword=null,$idbloco=null,$num_bloco=null,$status=null)
	{
		try
		{
			Transaction::beginTransaction();
			
			$criteria = new TCriteria();
			
			if($limit != null)	$criteria->setProperty("limit", $limit);
			if($offset != null)	$criteria->setProperty("offset", $offset);
			if($order != null)	$criteria->setProperty("order", $order);
			if($group != null)	$criteria->setProperty("group", $group);
			
			$criteria1 = new TCriteria();
			$criteria2 = new TCriteria();
			
			if($num_bloco != "")
			{
				$criteria1->add(new TFilter("num_bloco", "LIKE", "%$num_bloco%"));
				$criteria2->add(new TFilter("num_bloco", "LIKE", "%$num_bloco%"));
			}		
			
			if($idbloco != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("idbloco", "=", $idbloco));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}
			if($sexo != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("sexo", "=", $sexo));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}			

			if($status != null){
				$criteria1->add(new TFilter("active", "=", $status));
				//$criteria2->add(new TFilter("active", "=", $active));
			}

			$criteria->add($criteria1,TExpression::OR_OPERATOR);
			//$criteria->add($criteria2,TExpression::OR_OPERATOR);
			
			$repository = new TRepository("Bloco");
			
			$lstObjects = $repository->load($criteria);
			
			Transaction::closeTransaction();
			
			return $lstObjects;
		}
		catch(Exception $ex)
		{
			Transaction::cancelTransaction();
			throw new Exception($ex->getMessage());
		}
	}

	static function countObjects($limit=null, $offset=null, $order=null,$group=null,$keyword=null,$idbloco=null,$num_bloco=null,$status=null)
	{
		try
		{
			Transaction::beginTransaction();
				
			$criteria = new TCriteria();
			
			if($limit != null)	$criteria->setProperty("limit", $limit);
			if($offset != null)	$criteria->setProperty("offset", $offset);
			if($order != null)	$criteria->setProperty("order", $order);
			if($group != null)	$criteria->setProperty("group", $group);
			
			$criteria1 = new TCriteria();
			$criteria2 = new TCriteria();
			
			if($num_bloco != "")
			{
				$criteria1->add(new TFilter("num_bloco", "LIKE", "%$num_bloco%"));
				$criteria2->add(new TFilter("num_bloco", "LIKE", "%$num_bloco%"));
			}
			
			if($idbloco != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("idbloco", "=", $idbloco));
				
				//$repositoryPartEvent = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);
			}
			if($sexo != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("sexo", "=", $sexo));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}			

			if($status != null){
				$criteria1->add(new TFilter("active", "=", $status));
				//$criteria2->add(new TFilter("active", "=", $active));
			}
			
			$criteria->add($criteria1,TExpression::OR_OPERATOR);
			//$criteria->add($criteria2,TExpression::OR_OPERATOR);
				
			$repository = new TRepository("Bloco");
				
			$count = $repository->count($criteria);
				
			Transaction::closeTransaction();
				
			return $count;
		}
		catch(Exception $ex)
		{
			Transaction::cancelTransaction();
			throw new Exception($ex->getMessage());
		}
	}


	static function listBloco($limit=null, $offset=null, $order=null,$group=null,$keyword=null,$idbloco=null,$num_bloco=null,$status=null)
	{
		try
		{
			Transaction::beginTransaction();
			
			$criteria = new TCriteria();
			
			if($limit != null)	$criteria->setProperty("limit", $limit);
			if($offset != null)	$criteria->setProperty("offset", $offset);
			if($order != null)	$criteria->setProperty("order", $order);
			if($group != null)	$criteria->setProperty("group", $group);
			
			$criteria1 = new TCriteria();
			$criteria2 = new TCriteria();
			
			if($num_bloco != "")
			{
				$criteria1->add(new TFilter("num_bloco", "=", "$num_bloco"));
				$criteria2->add(new TFilter("num_bloco", "=", "$num_bloco"));
			}		
			
			if($idbloco != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("idbloco", "=", $idbloco));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}
			if($sexo != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("sexo", "=", $sexo));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}			

			if($status != null){
				$criteria1->add(new TFilter("active", "=", $status));
				//$criteria2->add(new TFilter("active", "=", $active));
			}

			$criteria->add($criteria1,TExpression::OR_OPERATOR);
			//$criteria->add($criteria2,TExpression::OR_OPERATOR);
			
			$repository = new TRepository("Bloco");
			
			$lstObjects = $repository->load($criteria);
			
			Transaction::closeTransaction();
			
			return $lstObjects;
		}
		catch(Exception $ex)
		{
			Transaction::cancelTransaction();
			throw new Exception($ex->getMessage());
		}
	}

	static function countBloco($limit=null, $offset=null, $order=null,$group=null,$keyword=null,$idbloco=null,$num_bloco=null,$status=null)
	{
		try
		{
			Transaction::beginTransaction();
				
			$criteria = new TCriteria();
			
			if($limit != null)	$criteria->setProperty("limit", $limit);
			if($offset != null)	$criteria->setProperty("offset", $offset);
			if($order != null)	$criteria->setProperty("order", $order);
			if($group != null)	$criteria->setProperty("group", $group);
			
			$criteria1 = new TCriteria();
			$criteria2 = new TCriteria();
			
			if($num_bloco != "")
			{
				$criteria1->add(new TFilter("num_bloco", "LIKE", "%$num_bloco%"));
				$criteria2->add(new TFilter("num_bloco", "LIKE", "%$num_bloco%"));
			}
			
			if($idbloco != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("idbloco", "=", $idbloco));
				
				//$repositoryPartEvent = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);
			}
			if($sexo != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("sexo", "=", $sexo));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}			

			if($status != null){
				$criteria1->add(new TFilter("active", "=", $status));
				//$criteria2->add(new TFilter("active", "=", $active));
			}
			
			$criteria->add($criteria1,TExpression::OR_OPERATOR);
			//$criteria->add($criteria2,TExpression::OR_OPERATOR);
				
			$repository = new TRepository("Bloco");
				
			$count = $repository->count($criteria);
				
			Transaction::closeTransaction();
				
			return $count;
		}
		catch(Exception $ex)
		{
			Transaction::cancelTransaction();
			throw new Exception($ex->getMessage());
		}
	}

	static function listBlocoCondominio($limit=null, $offset=null, $order=null,$group=null,$keyword=null,$idbloco=null,$idcondominio=null,$status=null)
	{
		try
		{
			Transaction::beginTransaction();
			
			$criteria = new TCriteria();
			
			if($limit != null)	$criteria->setProperty("limit", $limit);
			if($offset != null)	$criteria->setProperty("offset", $offset);
			if($order != null)	$criteria->setProperty("order", $order);
			if($group != null)	$criteria->setProperty("group", $group);
			
			$criteria1 = new TCriteria();
			$criteria2 = new TCriteria();
			
			if($num_bloco != "")
			{
				$criteria1->add(new TFilter("num_bloco", "LIKE", "%$num_bloco%"));
				$criteria2->add(new TFilter("num_bloco", "LIKE", "%$num_bloco%"));
			}		
			
			if($idbloco != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("idbloco", "=", $idbloco));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}

			if($idcondominio != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("idcondominio", "=", $idcondominio));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}

			if($sexo != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("sexo", "=", $sexo));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}			

			if($status != null){
				$criteria1->add(new TFilter("active", "=", $status));
				//$criteria2->add(new TFilter("active", "=", $active));
			}

			$criteria->add($criteria1,TExpression::OR_OPERATOR);
			//$criteria->add($criteria2,TExpression::OR_OPERATOR);
			
			$repository = new TRepository("Bloco");
			
			$lstObjects = $repository->load($criteria);
			
			Transaction::closeTransaction();
			
			return $lstObjects;
		}
		catch(Exception $ex)
		{
			Transaction::cancelTransaction();
			throw new Exception($ex->getMessage());
		}
	}

	static function listBlocoCondominioNum($limit=null, $offset=null, $order=null,$group=null,$keyword=null,$idbloco=null,$num_bloco=null,$idcondominio=null,$status=null)
	{
		try
		{
			Transaction::beginTransaction();
			
			$criteria = new TCriteria();
			
			if($limit != null)	$criteria->setProperty("limit", $limit);
			if($offset != null)	$criteria->setProperty("offset", $offset);
			if($order != null)	$criteria->setProperty("order", $order);
			if($group != null)	$criteria->setProperty("group", $group);
			
			$criteria1 = new TCriteria();
			$criteria2 = new TCriteria();
			
			if($num_bloco != "")
			{
				$criteria1->add(new TFilter("num_bloco", "LIKE", "%$num_bloco%"));
				$criteria2->add(new TFilter("num_bloco", "LIKE", "%$num_bloco%"));
			}		
			
			if($idbloco != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("idbloco", "=", $idbloco));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}

			if($idcondominio != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("idcondominio", "=", $idcondominio));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}

			if($sexo != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("sexo", "=", $sexo));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}			

			if($status != null){
				$criteria1->add(new TFilter("active", "=", $status));
				//$criteria2->add(new TFilter("active", "=", $active));
			}

			$criteria->add($criteria1,TExpression::OR_OPERATOR);
			//$criteria->add($criteria2,TExpression::OR_OPERATOR);
			
			$repository = new TRepository("Bloco");
			
			$lstObjects = $repository->load($criteria);
			
			Transaction::closeTransaction();
			
			return $lstObjects;
		}
		catch(Exception $ex)
		{
			Transaction::cancelTransaction();
			throw new Exception($ex->getMessage());
		}
	}

	static function countListBlocoCondominioNum($limit=null, $offset=null, $order=null,$group=null,$keyword=null,$idbloco=null,$num_bloco=null,$idcondominio=null,$status=null)
	{
		try
		{
			Transaction::beginTransaction();
			
			$criteria = new TCriteria();
			
			if($limit != null)	$criteria->setProperty("limit", $limit);
			if($offset != null)	$criteria->setProperty("offset", $offset);
			if($order != null)	$criteria->setProperty("order", $order);
			if($group != null)	$criteria->setProperty("group", $group);
			
			$criteria1 = new TCriteria();
			$criteria2 = new TCriteria();
			
			if($num_bloco != "")
			{
				$criteria1->add(new TFilter("num_bloco", "LIKE", "%$num_bloco%"));
				$criteria2->add(new TFilter("num_bloco", "LIKE", "%$num_bloco%"));
			}		
			
			if($idbloco != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("idbloco", "=", $idbloco));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}

			if($idcondominio != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("idcondominio", "=", $idcondominio));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}

			if($sexo != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("sexo", "=", $sexo));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}			

			if($status != null){
				$criteria1->add(new TFilter("active", "=", $status));
				//$criteria2->add(new TFilter("active", "=", $active));
			}

			$criteria->add($criteria1,TExpression::OR_OPERATOR);
			//$criteria->add($criteria2,TExpression::OR_OPERATOR);
			
			$repository = new TRepository("Bloco");
			
			$count = $repository->count($criteria);
				
			Transaction::closeTransaction();
				
			return $count;
		}
		catch(Exception $ex)
		{
			Transaction::cancelTransaction();
			throw new Exception($ex->getMessage());
		}
	}

	static function listBlocoSindico($limit=null, $offset=null, $order=null,$group=null,$keyword=null,$idbloco=null,$idcondominio=null,$idsindico=null,$status=null)
	{
		try
		{
			Transaction::beginTransaction();
			
			$criteria = new TCriteria();
			
			if($limit != null)	$criteria->setProperty("limit", $limit);
			if($offset != null)	$criteria->setProperty("offset", $offset);
			if($order != null)	$criteria->setProperty("order", $order);
			if($group != null)	$criteria->setProperty("group", $group);
			
			$criteria1 = new TCriteria();
			$criteria2 = new TCriteria();
			
			if($num_bloco != "")
			{
				$criteria1->add(new TFilter("num_bloco", "LIKE", "%$num_bloco%"));
				$criteria2->add(new TFilter("num_bloco", "LIKE", "%$num_bloco%"));
			}		
			
			if($idbloco != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("idbloco", "=", $idbloco));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}

			if($idcondominio != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("idcondominio", "=", $idcondominio));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}

			if($idsindico != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("idsindico", "=", $idsindico));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}			

			if($status != null){
				$criteria1->add(new TFilter("active", "=", $status));
				//$criteria2->add(new TFilter("active", "=", $active));
			}

			$criteria->add($criteria1,TExpression::OR_OPERATOR);
			//$criteria->add($criteria2,TExpression::OR_OPERATOR);
			
			$repository = new TRepository("Bloco");
			
			$lstObjects = $repository->load($criteria);
			
			Transaction::closeTransaction();
			
			return $lstObjects;
		}
		catch(Exception $ex)
		{
			Transaction::cancelTransaction();
			throw new Exception($ex->getMessage());
		}
	}

	static function listBlocoSindicoNum($limit=null, $offset=null, $order=null,$group=null,$keyword=null,$num_bloco=null,$idbloco=null,$idcondominio=null,$idsindico=null,$status=null)
	{
		try
		{
			Transaction::beginTransaction();
			
			$criteria = new TCriteria();
			
			if($limit != null)	$criteria->setProperty("limit", $limit);
			if($offset != null)	$criteria->setProperty("offset", $offset);
			if($order != null)	$criteria->setProperty("order", $order);
			if($group != null)	$criteria->setProperty("group", $group);
			
			$criteria1 = new TCriteria();
			$criteria2 = new TCriteria();
			
			if($num_bloco != "")
			{
				$criteria1->add(new TFilter("num_bloco", "LIKE", "%$num_bloco%"));
				$criteria2->add(new TFilter("num_bloco", "LIKE", "%$num_bloco%"));
			}		
			
			if($idbloco != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("idbloco", "=", $idbloco));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}

			if($idcondominio != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("idcondominio", "=", $idcondominio));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}

			if($idsindico != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("idsindico", "=", $idsindico));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}			

			if($status != null){
				$criteria1->add(new TFilter("active", "=", $status));
				//$criteria2->add(new TFilter("active", "=", $active));
			}

			$criteria->add($criteria1,TExpression::OR_OPERATOR);
			//$criteria->add($criteria2,TExpression::OR_OPERATOR);
			
			$repository = new TRepository("Bloco");
			
			$lstObjects = $repository->load($criteria);
			
			Transaction::closeTransaction();
			
			return $lstObjects;
		}
		catch(Exception $ex)
		{
			Transaction::cancelTransaction();
			throw new Exception($ex->getMessage());
		}
	}

	/**
	 * Admiinstradora::checkCnpj($cnpj)
	 *
	 * Verificar se existe empresas com o CNPJ informado
	 *
	 * @param $cnpj: CNPJ da empresa
	 *
	 * @return Verifica o CNPJ da empresa
	 */
	static function checkCnpj($cnpj)
	{
		try
		{
			Transaction::beginTransaction();
	
			$criteria = new TCriteria();
			$criteria->add(new TFilter("cnpj", "=", $cnpj));
	
			$repository = new TRepository("Condominio");
				
			$lstObjects = $repository->load($criteria);
				
			Transaction::closeTransaction();
	
			if(is_array($lstObjects))
			{
				return true;
			}
				
			return false;
		}
		catch(Exception $ex)
		{
			throw new Exception($ex->getMessage());
			Transaction::cancelTransaction();
		}
	}

	/**
    * Admiinstradora::checkLogin($login)
    * 
    * Verificar se existe usuários com o login informado  
    * 
    * @param $login: login do usuário
    * 
    * @return Verifica o login do usuário
    */
    static function checkLogin($login)
    {
    	try
    	{
    		Transaction::beginTransaction();
    		
    		$criteria = new TCriteria();
    		$criteria->add(new TFilter("email", "=", $login));
    		
    		$repository = new TRepository("Condominio");
			
			$lstObjects = $repository->load($criteria);
			
			Transaction::closeTransaction();

 			if(is_array($lstObjects))
 			{
 				return true;
 			}
 		
    		return false;
    	}
    	catch(Exception $ex)
    	{
    		throw new Exception($ex->getMessage());
    		Transaction::cancelTransaction();
    	}
    }

	static function listObjectsParicaoVaca($limit=null, $offset=null, $order=null,$group=null,$keyword=null,$idanimais=null,$sexo=null,$dateInicial=null,$dateFinal=null,$status=null)
	{
		try
		{
			Transaction::beginTransaction();
			
			$criteria = new TCriteria();
			
			if($limit != null)	$criteria->setProperty("limit", $limit);
			if($offset != null)	$criteria->setProperty("offset", $offset);
			if($order != null)	$criteria->setProperty("order", $order);
			if($group != null)	$criteria->setProperty("group", $group);
			
			$criteria1 = new TCriteria();
			$criteria2 = new TCriteria();
			
			if($keyword != "")
			{
				$criteria1->add(new TFilter("name", "LIKE", "%$keyword%"));
				$criteria2->add(new TFilter("name", "LIKE", "%$keyword%"));
			}		
			
			if($idanimais != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("idanimais", "=", $idanimais));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}
			if($sexo != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("sexo", "=", $sexo));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}			


			//$criteria1->add(new TFilter("TIMESTAMPDIFF (MONTH, birth_date, CURDATE())",">","24"));
			//$criteria2->add(new TFilter("status", "IN", $status));
			//$criteria2->add(new TFilter("active", "=", $active));


			if($status != null){
				$criteria1->add(new TFilter("status", "<>", $status));
				//$criteria2->add(new TFilter("status", "IN", $status));
				//$criteria2->add(new TFilter("active", "=", $active));
			}

			$criteria->add($criteria1,TExpression::OR_OPERATOR);
			//$criteria->add($criteria2,TExpression::OR_OPERATOR);
			
			$repository = new TRepository("Animais");
			
			$lstObjects = $repository->load($criteria);
			
			Transaction::closeTransaction();
			
			return $lstObjects;
		}
		catch(Exception $ex)
		{
			Transaction::cancelTransaction();
			throw new Exception($ex->getMessage());
		}
	}

	static function listObjectsNascimento($limit=null, $offset=null, $order=null,$group=null,$keyword=null,$idanimais=null,$sexo=null,$dateInicial=null,$dateFinal=null,$status=null)
	{
		try
		{
			Transaction::beginTransaction();
			
			$criteria = new TCriteria();
			
			if($limit != null)	$criteria->setProperty("limit", $limit);
			if($offset != null)	$criteria->setProperty("offset", $offset);
			if($order != null)	$criteria->setProperty("order", $order);
			if($group != null)	$criteria->setProperty("group", $group);
			
			$criteria1 = new TCriteria();
			$criteria2 = new TCriteria();
			
			if($keyword != "")
			{
				$criteria1->add(new TFilter("name", "LIKE", "%$keyword%"));
				$criteria2->add(new TFilter("name", "LIKE", "%$keyword%"));
			}		
			
			if($idanimais != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("idanimais", "=", $idanimais));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}
			if($sexo != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("sexo", "=", $sexo));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}

			if($dateInicial != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("birth_date", ">=", $dateInicial));
				$criteria1->add(new TFilter("birth_date", "<=", $dateFinal));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}				

			if($status != null){
				$criteria1->add(new TFilter("status", "<>", $status));
				//$criteria2->add(new TFilter("status", "IN", $status));
				//$criteria2->add(new TFilter("active", "=", $active));
			}

			$criteria1->add(new TFilter("idmae", 'IS NOT', NULL));
			$criteria->add($criteria1,TExpression::OR_OPERATOR);
			//$criteria->add($criteria2,TExpression::OR_OPERATOR);
			
			$repository = new TRepository("Animais");
			
			$lstObjects = $repository->load($criteria);
			
			Transaction::closeTransaction();
			
			return $lstObjects;
		}
		catch(Exception $ex)
		{
			Transaction::cancelTransaction();
			throw new Exception($ex->getMessage());
		}
	}

	static function countObjectsNascimento($limit=null, $offset=null, $order=null,$group=null,$keyword=null,$idanimais=null,$sexo=null,$dateInicial=null,$dateFinal=null,$status=null)
	{
		try
		{
			Transaction::beginTransaction();
				
			$criteria = new TCriteria();
			
			if($limit != null)	$criteria->setProperty("limit", $limit);
			if($offset != null)	$criteria->setProperty("offset", $offset);
			if($order != null)	$criteria->setProperty("order", $order);
			if($group != null)	$criteria->setProperty("group", $group);
			
			$criteria1 = new TCriteria();
			$criteria2 = new TCriteria();
			
			if($keyword != "")
			{
				$criteria1->add(new TFilter("name", "LIKE", "%$keyword%"));
				$criteria2->add(new TFilter("name", "LIKE", "%$keyword%"));
			}		
			
			if($idanimais != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("idanimais", "=", $idanimais));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}
			if($sexo != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("sexo", "=", $sexo));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}

			if($dateInicial != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("birth_date", ">=", $dateInicial));
				$criteria1->add(new TFilter("birth_date", "<=", $dateFinal));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}				

			if($status != null){
				$criteria1->add(new TFilter("status", "<>", $status));
				//$criteria2->add(new TFilter("status", "IN", $status));
				//$criteria2->add(new TFilter("active", "=", $active));
			}

			$criteria1->add(new TFilter("idmae", 'IS NOT', NULL));
			$criteria->add($criteria1,TExpression::OR_OPERATOR);
			//$criteria->add($criteria2,TExpression::OR_OPERATOR);
				
			$repository = new TRepository("Animais");
				
			$count = $repository->count($criteria);
				
			Transaction::closeTransaction();
				
			return $count;
		}
		catch(Exception $ex)
		{
			Transaction::cancelTransaction();
			throw new Exception($ex->getMessage());
		}
	}

	static function listObjectsParicao($limit=null, $offset=null, $order=null,$group=null,$keyword=null,$idanimais=null,$sexo=null,$dateInicial=null,$dateFinal=null,$mae=null,$status=null)
	{
		try
		{
			Transaction::beginTransaction();
			
			$criteria = new TCriteria();
			
			if($limit != null)	$criteria->setProperty("limit", $limit);
			if($offset != null)	$criteria->setProperty("offset", $offset);
			if($order != null)	$criteria->setProperty("order", $order);
			if($group != null)	$criteria->setProperty("group", $group);
			
			$criteria1 = new TCriteria();
			$criteria2 = new TCriteria();
			
			if($keyword != "")
			{
				$criteria1->add(new TFilter("name", "LIKE", "%$keyword%"));
				$criteria2->add(new TFilter("name", "LIKE", "%$keyword%"));
			}		
			
			if($idanimais != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("idanimais", "=", $idanimais));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}
			if($sexo != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("sexo", "=", $sexo));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}

			if($dateInicial != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("birth_date", ">=", $dateInicial));
				$criteria1->add(new TFilter("birth_date", "<=", $dateFinal));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}				

			if($status != null){
				$criteria1->add(new TFilter("status", "<>", $status));
				//$criteria2->add(new TFilter("status", "IN", $status));
				//$criteria2->add(new TFilter("active", "=", $active));
			}

			if($mae != null){
				$criteria1->add(new TFilter("idmae", "=", $mae));
				//$criteria2->add(new TFilter("active", "=", $active));
			}			

			//$criteria1->add(new TFilter("idmae", 'IS NOT', NULL));
			$criteria->add($criteria1,TExpression::OR_OPERATOR);
			//$criteria->add($criteria2,TExpression::OR_OPERATOR);
			
			$repository = new TRepository("Animais");
			
			$lstObjects = $repository->load($criteria);
			
			Transaction::closeTransaction();
			
			return $lstObjects;
		}
		catch(Exception $ex)
		{
			Transaction::cancelTransaction();
			throw new Exception($ex->getMessage());
		}
	}

	static function countObjectsParicao($limit=null, $offset=null, $order=null,$group=null,$keyword=null,$idanimais=null,$sexo=null,$dateInicial=null,$dateFinal=null,$mae=null,$status=null)
	{
		try
		{
			Transaction::beginTransaction();
			
			$criteria = new TCriteria();
			
			if($limit != null)	$criteria->setProperty("limit", $limit);
			if($offset != null)	$criteria->setProperty("offset", $offset);
			if($order != null)	$criteria->setProperty("order", $order);
			if($group != null)	$criteria->setProperty("group", $group);
			
			$criteria1 = new TCriteria();
			$criteria2 = new TCriteria();
			
			if($keyword != "")
			{
				$criteria1->add(new TFilter("name", "LIKE", "%$keyword%"));
				$criteria2->add(new TFilter("name", "LIKE", "%$keyword%"));
			}		
			
			if($idanimais != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("idanimais", "=", $idanimais));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}
			if($sexo != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("sexo", "=", $sexo));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}

			if($dateInicial != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("birth_date", ">=", $dateInicial));
				$criteria1->add(new TFilter("birth_date", "<=", $dateFinal));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}				

			if($status != null){
				$criteria1->add(new TFilter("status", "<>", $status));
				//$criteria2->add(new TFilter("status", "IN", $status));
				//$criteria2->add(new TFilter("active", "=", $active));
			}

			if($mae != null){
				$criteria1->add(new TFilter("idmae", "=", $mae));
				//$criteria2->add(new TFilter("active", "=", $active));
			}			

			//$criteria1->add(new TFilter("idmae", 'IS NOT', NULL));
			$criteria->add($criteria1,TExpression::OR_OPERATOR);
			//$criteria->add($criteria2,TExpression::OR_OPERATOR);
						
			$repository = new TRepository("Animais");

			//$lstObjects = $repository->load($criteria);			
			
			$count = $repository->count($criteria);

			Transaction::closeTransaction();

			return $count;

		}
		catch(Exception $ex)
		{
			Transaction::cancelTransaction();
			throw new Exception($ex->getMessage());
		}
	}

	static function listObjectsResumo($limit=null, $offset=null, $order=null,$group=null,$keyword=null,$idanimais=null,$sexo=null,$dateInicial=null,$dateFinal=null,$mae=null,$classificacao=null,$status=null)
	{
		try
		{
			Transaction::beginTransaction();
			
			$criteria = new TCriteria();
			
			if($limit != null)	$criteria->setProperty("limit", $limit);
			if($offset != null)	$criteria->setProperty("offset", $offset);
			if($order != null)	$criteria->setProperty("order", $order);
			if($group != null)	$criteria->setProperty("group", $group);
			
			$criteria1 = new TCriteria();
			$criteria2 = new TCriteria();
			
			if($keyword != "")
			{
				$criteria1->add(new TFilter("name", "LIKE", "%$keyword%"));
				$criteria2->add(new TFilter("name", "LIKE", "%$keyword%"));
			}		
			
			if($idanimais != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("idanimais", "=", $idanimais));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}
			if($classificacao != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("classificacao", "=", $classificacao));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}			
			if($sexo != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("sexo", "=", $sexo));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}

			if($dateInicial != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("birth_date", ">=", $dateInicial));
				$criteria1->add(new TFilter("birth_date", "<=", $dateFinal));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}				

			if($status != null){
				$criteria1->add(new TFilter("status", "<>", $status));
				//$criteria2->add(new TFilter("status", "IN", $status));
				//$criteria2->add(new TFilter("active", "=", $active));
			}

			if($mae != null){
				$criteria1->add(new TFilter("idmae", "=", $mae));
				//$criteria2->add(new TFilter("active", "=", $active));
			}			

			//$criteria1->add(new TFilter("idmae", 'IS NOT', NULL));
			$criteria->add($criteria1,TExpression::OR_OPERATOR);
			//$criteria->add($criteria2,TExpression::OR_OPERATOR);
						
			$repository = new TRepository("Animais");

			$lstObjects = $repository->load($criteria);
			
			Transaction::closeTransaction();
			
			return $lstObjects;

		}
		catch(Exception $ex)
		{
			Transaction::cancelTransaction();
			throw new Exception($ex->getMessage());
		}
	}

	static function countObjectsResumo($limit=null, $offset=null, $order=null,$group=null,$keyword=null,$idanimais=null,$sexo=null,$dateInicial=null,$dateFinal=null,$mae=null,$classificacao=null,$status=null)
	{
		try
		{
			Transaction::beginTransaction();
			
			$criteria = new TCriteria();
			
			if($limit != null)	$criteria->setProperty("limit", $limit);
			if($offset != null)	$criteria->setProperty("offset", $offset);
			if($order != null)	$criteria->setProperty("order", $order);
			if($group != null)	$criteria->setProperty("group", $group);
			
			$criteria1 = new TCriteria();
			$criteria2 = new TCriteria();
			
			if($keyword != "")
			{
				$criteria1->add(new TFilter("name", "LIKE", "%$keyword%"));
				$criteria2->add(new TFilter("name", "LIKE", "%$keyword%"));
			}		
			
			if($idanimais != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("idanimais", "=", $idanimais));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}
			if($classificacao != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("classificacao", "=", $classificacao));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}			
			if($sexo != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("sexo", "=", $sexo));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}

			if($dateInicial != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("birth_date", ">=", $dateInicial));
				$criteria1->add(new TFilter("birth_date", "<=", $dateFinal));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}				

			if($status != null){
				$criteria1->add(new TFilter("status", "<>", $status));
				//$criteria2->add(new TFilter("status", "IN", $status));
				//$criteria2->add(new TFilter("active", "=", $active));
			}

			if($mae != null){
				$criteria1->add(new TFilter("idmae", "=", $mae));
				//$criteria2->add(new TFilter("active", "=", $active));
			}			

			//$criteria1->add(new TFilter("idmae", 'IS NOT', NULL));
			$criteria->add($criteria1,TExpression::OR_OPERATOR);
			//$criteria->add($criteria2,TExpression::OR_OPERATOR);
						
			$repository = new TRepository("Animais");

			//$lstObjects = $repository->load($criteria);			
			
			$count = $repository->count($criteria);

			Transaction::closeTransaction();

			return $count;

		}
		catch(Exception $ex)
		{
			Transaction::cancelTransaction();
			throw new Exception($ex->getMessage());
		}
	}

	static function listObjectsStatus($limit=null, $offset=null, $order=null,$group=null,$keyword=null,$idanimais=null,$sexo=null,$dateInicial=null,$dateFinal=null,$mae=null,$classificacao=null,$status=null)
	{
		try
		{
			Transaction::beginTransaction();
			
			$criteria = new TCriteria();
			
			if($limit != null)	$criteria->setProperty("limit", $limit);
			if($offset != null)	$criteria->setProperty("offset", $offset);
			if($order != null)	$criteria->setProperty("order", $order);
			if($group != null)	$criteria->setProperty("group", $group);
			
			$criteria1 = new TCriteria();
			$criteria2 = new TCriteria();
			
			if($keyword != "")
			{
				$criteria1->add(new TFilter("name", "LIKE", "%$keyword%"));
				$criteria2->add(new TFilter("name", "LIKE", "%$keyword%"));
			}		
			
			if($idanimais != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("idanimais", "=", $idanimais));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}
			if($classificacao != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("classificacao", "=", $classificacao));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}			
			if($sexo != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("sexo", "=", $sexo));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}

			if($dateInicial != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("birth_date", ">=", $dateInicial));
				$criteria1->add(new TFilter("birth_date", "<=", $dateFinal));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}				

			if($status != null){
				$criteria1->add(new TFilter("status", "=", $status));
				//$criteria2->add(new TFilter("status", "IN", $status));
				//$criteria2->add(new TFilter("active", "=", $active));
			}

			if($mae != null){
				$criteria1->add(new TFilter("idmae", "=", $mae));
				//$criteria2->add(new TFilter("active", "=", $active));
			}			

			//$criteria1->add(new TFilter("idmae", 'IS NOT', NULL));
			$criteria->add($criteria1,TExpression::OR_OPERATOR);
			//$criteria->add($criteria2,TExpression::OR_OPERATOR);
						
			$repository = new TRepository("Animais");

			$lstObjects = $repository->load($criteria);
			
			Transaction::closeTransaction();
			
			return $lstObjects;

		}
		catch(Exception $ex)
		{
			Transaction::cancelTransaction();
			throw new Exception($ex->getMessage());
		}
	}

	static function countObjectsStatus($limit=null, $offset=null, $order=null,$group=null,$keyword=null,$idanimais=null,$sexo=null,$dateInicial=null,$dateFinal=null,$mae=null,$classificacao=null,$status=null)
	{
		try
		{
			Transaction::beginTransaction();
			
			$criteria = new TCriteria();
			
			if($limit != null)	$criteria->setProperty("limit", $limit);
			if($offset != null)	$criteria->setProperty("offset", $offset);
			if($order != null)	$criteria->setProperty("order", $order);
			if($group != null)	$criteria->setProperty("group", $group);
			
			$criteria1 = new TCriteria();
			$criteria2 = new TCriteria();
			
			if($keyword != "")
			{
				$criteria1->add(new TFilter("name", "LIKE", "%$keyword%"));
				$criteria2->add(new TFilter("name", "LIKE", "%$keyword%"));
			}		
			
			if($idanimais != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("idanimais", "=", $idanimais));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}
			if($classificacao != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("classificacao", "=", $classificacao));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}			
			if($sexo != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("sexo", "=", $sexo));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}

			if($dateInicial != null)
			{
				//$criteriaAnimais = new TCriteria();
				$criteria1->add(new TFilter("birth_date", ">=", $dateInicial));
				$criteria1->add(new TFilter("birth_date", "<=", $dateFinal));
				//$criteriaAnimais = new TRepository("Animais");
				
				//$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaAnimais);				
				
			}				

			if($status != null){
				$criteria1->add(new TFilter("status", "=", $status));
				//$criteria2->add(new TFilter("status", "IN", $status));
				//$criteria2->add(new TFilter("active", "=", $active));
			}

			if($mae != null){
				$criteria1->add(new TFilter("idmae", "=", $mae));
				//$criteria2->add(new TFilter("active", "=", $active));
			}			

			//$criteria1->add(new TFilter("idmae", 'IS NOT', NULL));
			$criteria->add($criteria1,TExpression::OR_OPERATOR);
			//$criteria->add($criteria2,TExpression::OR_OPERATOR);
						
			$repository = new TRepository("Animais");

			//$lstObjects = $repository->load($criteria);			
			
			$count = $repository->count($criteria);

			Transaction::closeTransaction();

			return $count;

		}
		catch(Exception $ex)
		{
			Transaction::cancelTransaction();
			throw new Exception($ex->getMessage());
		}
	}

static function listObjectsParticipantEventActive($limit=null, $offset=null, $order=null,$group=null,$keyword=null,$idevent=null,$idsubevent=null,$active=null)
	{
		try
		{
			Transaction::beginTransaction();
			
			$criteria = new TCriteria();
			
			if($limit != null)	$criteria->setProperty("limit", $limit);
			if($offset != null)	$criteria->setProperty("offset", $offset);
			if($order != null)	$criteria->setProperty("order", $order);
			if($group != null)	$criteria->setProperty("group", $group);
			
			$criteria1 = new TCriteria();
			$criteria2 = new TCriteria();
			
			if($keyword != "")
			{
				$criteria1->add(new TFilter("first_name", "LIKE", "%$keyword%"));
				$criteria2->add(new TFilter("first_name", "LIKE", "%$keyword%"));
			}

			
			/*if($idevent != null)
			{
				$criteriaPartEvent = new TCriteria();
				$criteriaPartEvent->add(new TFilter("idevent", "=", $idevent));
				//$criteria->add(new TFilter("active", "=", "$active"));
				
				$repositoryPartEvent = new TRepository("Participant_event");
				
				$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaPartEvent);
				$arrayPart[] = 0;
				if(is_array($lstObjectsPartEvent))
				{
					foreach($lstObjectsPartEvent as $objPartEvent)
					{
						$arrayPart[] = $objPartEvent->idparticipant;
					}
				}
				$criteria1->add(new TFilter("idparticipant", "IN", $arrayPart));
				$criteria2->add(new TFilter("idparticipant", "IN", $arrayPart));
			}*/
			if($idsubevent != null)
			{
				$criteriaPartSubEvent = new TCriteria();
				$criteriaPartSubEvent->add(new TFilter("idsubevent", "=", $idsubevent));
			
				$repositoryPartSubEvent = new TRepository("Participant_subevent");
			
				$lstObjectsPartSubEvent = $repositoryPartSubEvent->load($criteriaPartSubEvent);
				$arrayPart[] = 0;
				if(is_array($lstObjectsPartSubEvent))
				{
					foreach($lstObjectsPartSubEvent as $objPartSubEvent)
					{
						$arrayPart[] = $objPartSubEvent->idparticipant;
					}
				}
				$criteria1->add(new TFilter("idparticipant", "IN", $arrayPart));
				$criteria2->add(new TFilter("idparticipant", "IN", $arrayPart));
			}			
			if($active != null){

				$criteriaPartEvent = new TCriteria();
				$criteriaPartEvent->add(new TFilter("idevent", "=", $idevent));
				$criteriaPartEvent->add(new TFilter("active", "=", $active));
				
				$repositoryPartEvent = new TRepository("Participant_event");
				
				$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaPartEvent);
				$arrayPartEvent[] = 0;
				if(is_array($lstObjectsPartEvent))
				{
					foreach($lstObjectsPartEvent as $objPartEvent)
					{
						$arrayPartEvent[] = $objPartEvent->idparticipant;
					}
				}

				$criteria1->add(new TFilter("idparticipant", "IN", $arrayPartEvent));
				$criteria2->add(new TFilter("idparticipant", "IN", $arrayPartEvent));

				//$criteria1->add(new TFilter("active", "=", $active));
				//$criteria2->add(new TFilter("active", "=", $active));
			}
			
			$criteria->add($criteria1,TExpression::OR_OPERATOR);
			$criteria->add($criteria2,TExpression::OR_OPERATOR);
			
			$repository = new TRepository("Participant");
			
			$lstObjects = $repository->load($criteria);
			
			Transaction::closeTransaction();
			
			return $lstObjects;
		}
		catch(Exception $ex)
		{
			Transaction::cancelTransaction();
			throw new Exception($ex->getMessage());
		}
	}


	static function listObjectEmail($email)
	{
		try
		{
			Transaction::beginTransaction();
	
			$criteria = new TCriteria();
			$criteria->add(new TFilter("email", "LIKE", "%$email%"));
				
			$repository = new TRepository("Participant");
			
			$lstObject = $repository->load($criteria);
			
			if(is_array($lstObject))
				$object = $lstObject[0];
	
			Transaction::closeTransaction();
	
			return $object;
		}
		catch(Exception $ex)
		{
			Transaction::cancelTransaction();
			throw new Exception($ex->getMessage());
		}
	}

	static function listObjectParticipantId($idparticipant)
	{
		try
		{
			Transaction::beginTransaction();
	
			$criteria = new TCriteria();
			$criteria->add(new TFilter("idparticipant", "=", $idparticipant));
				
			$repository = new TRepository("Participant");
			
			$lstObject = $repository->load($criteria);
			
			if(is_array($lstObject))
				$object = $lstObject[0];
	
			Transaction::closeTransaction();
	
			return $object;
		}
		catch(Exception $ex)
		{
			Transaction::cancelTransaction();
			throw new Exception($ex->getMessage());
		}
	}


static function countObjectsParticipantEventActive($limit=null, $offset=null, $order=null,$group=null,$keyword=null,$idevent=null,$idsubevent=null,$active=null)
	{
		try
		{
			Transaction::beginTransaction();
				
			$criteria = new TCriteria();
			
			if($limit != null)	$criteria->setProperty("limit", $limit);
			if($offset != null)	$criteria->setProperty("offset", $offset);
			if($order != null)	$criteria->setProperty("order", $order);
			if($group != null)	$criteria->setProperty("group", $group);
			
			$criteria1 = new TCriteria();
			$criteria2 = new TCriteria();
			
			if($keyword != "")
			{
				$criteria1->add(new TFilter("first_name", "LIKE", "%$keyword%"));
				$criteria2->add(new TFilter("first_name", "LIKE", "%$keyword%"));
			}
			
			/*if($idevent != null)
			{
				$criteriaPartEvent = new TCriteria();
				$criteriaPartEvent->add(new TFilter("idevent", "=", $idevent));
				
				$repositoryPartEvent = new TRepository("Participant_event");
				
				$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaPartEvent);
				$arrayPart = null;
				if(is_array($lstObjectsPartEvent))
				{
					foreach($lstObjectsPartEvent as $objPartEvent)
					{
						$arrayPart[] = $objPartEvent->idparticipant;
					}
					$criteria1->add(new TFilter("idparticipant", "IN", $arrayPart));
					$criteria2->add(new TFilter("idparticipant", "IN", $arrayPart));
				}
			}*/
			if($idsubevent != null)
			{
				$criteriaPartSubEvent = new TCriteria();
				$criteriaPartSubEvent->add(new TFilter("idsubevent", "=", $idsubevent));
			
				$repositoryPartSubEvent = new TRepository("Participant_subevent");
			
				$lstObjectsPartSubEvent = $repositoryPartSubEvent->load($criteriaPartSubEvent);
				$arrayPart = null;
				if(is_array($lstObjectsPartSubEvent))
				{
					foreach($lstObjectsPartSubEvent as $objPartSubEvent)
					{
						$arrayPart[] = $objPartSubEvent->idparticipant;
					}
					$criteria1->add(new TFilter("idparticipant", "IN", $arrayPart));
					$criteria2->add(new TFilter("idparticipant", "IN", $arrayPart));
				}
			}			
			if($active != null){
				$criteriaPartEvent = new TCriteria();
				$criteriaPartEvent->add(new TFilter("idevent", "=", $idevent));
				$criteriaPartEvent->add(new TFilter("active", "=", $active));
				
				$repositoryPartEvent = new TRepository("Participant_event");
				
				$lstObjectsPartEvent = $repositoryPartEvent->load($criteriaPartEvent);
				$arrayPartEvent[] = 0;
				if(is_array($lstObjectsPartEvent))
				{
					foreach($lstObjectsPartEvent as $objPartEvent)
					{
						$arrayPartEvent[] = $objPartEvent->idparticipant;
					}
				}

				$criteria1->add(new TFilter("idparticipant", "IN", $arrayPartEvent));
				$criteria2->add(new TFilter("idparticipant", "IN", $arrayPartEvent));

				//$criteria1->add(new TFilter("active", "=", $active));
				//$criteria2->add(new TFilter("active", "=", $active));
			}
			
			$criteria->add($criteria1,TExpression::OR_OPERATOR);
			$criteria->add($criteria2,TExpression::OR_OPERATOR);
				
			$repository = new TRepository("Participant");
				
			$count = $repository->count($criteria);
				
			Transaction::closeTransaction();
				
			return $count;
		}
		catch(Exception $ex)
		{
			Transaction::cancelTransaction();
			throw new Exception($ex->getMessage());
		}
	}

	
	/**
	 * Participant::get_subevents()
	 *
	 * Retornar todos os eventos do participante
	 *
	 * @return void
	 */
	function get_events($transactionActive=false, $force=false)
	{
		try {
			if(!isset($this->events) || $force)
			{
				Transaction::beginTransaction();
				$criteria = new TCriteria();
				$criteria->add(new TFilter("idparticipant", "=", $this->idparticipant));
	
				$repository = new TRepository("Participant_event");
	
				$lstObjects = $repository->load($criteria);
	
				if(!$transactionActive)
					Transaction::closeTransaction();
	
				$this->events = $lstObjects;
			}
			return $this->events;
	
		} catch (Exception $e) {
			Transaction::cancelTransaction();
			throw new Exception($e->getMessage());
		}
	}
	
	function add_participant_event($objPartEvent)
	{
		$this->events[] = $objPartEvent;
	}
	
	/**
	 * Participant::get_subevents()
	 *
	 * Retornar todos os subeventos do participante
	 *
	 * @return void
	 */
	function get_subevents($transactionActive=false, $force=false)
	{
		try {
			if(!isset($this->subevents) || $force)
			{
				Transaction::beginTransaction();
				$criteria = new TCriteria();
				$criteria->add(new TFilter("idparticipant", "=", $this->idparticipant));
	
				$repository = new TRepository("Participant_subevent");
	
				$lstObjects = $repository->load($criteria);
	
				if(!$transactionActive)
					Transaction::closeTransaction();
	
				$this->subevents = $lstObjects;
			}
			return $this->subevents;
				
		} catch (Exception $e) {
			Transaction::cancelTransaction();
			throw new Exception($e->getMessage());
		}
	}
	
	function add_participant_subevent($objPartSubEvent)
	{
		$this->subevents[] = $objPartSubEvent;
	}

     /**
     * Participante::inactivate()
     * 
     * Inativa um objeto no banco de dados
     * 
     * @return void
     */
    function inactivate()
    {
        try
        {
            Transaction::beginTransaction();
            
            $this->active = false;
            $this->store();
            
            Transaction::closeTransaction();
        }
        catch(Exception $ex)
        {
            Transaction::cancelTransaction();
            throw new Exception($ex->getMessage());
        }        
    }

}

?>