Location: PHPKode > projects > Chalange > com_chalange/models/register.php
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport('joomla.application.component.model');
jimport('joomla.utilities.date');
 class ChalangeModelRegister extends JModel{
	var $row=null;
	
	private function playerNotRegister($nroLicence, $idCarrera){
	if (!empty($nroLicence)){
	 		//obtenemos id Carrera y codUCI		
	 		$query= 'SELECT count(*) as nro '
 			.'FROM #__gcd_registered '
 			." WHERE idRace =$idCarrera and nroLicence='$nroLicence'";
 			$this->data= $this->_getList($query);
 			$row=$this->data[0];
 			if ($row->nro==0){ //si no existe este corredor en esta carrera	
 				return true;
 			}
		}
 		return false;
	}
	
 	function store($idPlayer,$player, $idCarrera){ 
	 	if ($this->playerNotRegister($player->nroLicence,$idCarrera)){
	 		JTable::addIncludePath(JPATH_COMPONENT.DS.'Tables');
	 		$row = JTable::getInstance('Registered','Table');
	  		$post['idPlayer']=$idPlayer;
	  		$post['idRace']=$idCarrera;  		
	   		$fecha=new JDate();
	 		$post['registerData']=$fecha->toMySQL();
	 		$post['registerIP']=$ip = $_SERVER['REMOTE_ADDR'];
	  		$post['name']=$player->name." ".$player->surname;
	  		$post['codUCI']=$player->codUCI;
	  		$post['nroLicence']=$player->nroLicence;
	  		$post['category']=$player->description;
	  		$post['club']=$player->club;
	  		$post['sponsor']=$player->sponsor;
	  		$post['dorsal']=$player->dorsal;
	  		if (!$row->bind($post)){
	  			return JError::raiseWarning(500,$row->getError());
	  		}
	  		if (!$row->store($post)){
	  			return JError::raiseWarning(500,$row->getError());
	  		}
	  		return true;
	 	}
		return false;
 	}
  	function modifyAndStore($idPlayer,$player, $idCarrera){
  		if ($this->playerNotRegister($player['nroLicence'],$idCarrera)){
	   		JTable::addIncludePath(JPATH_COMPONENT.DS.'Tables');
	 		$row = JTable::getInstance('Registered','Table');
	  		$post['idPlayer']=$idPlayer;
	  		$post['idRace']=$idCarrera;  		
	   		$fecha=new JDate();
	 		$post['registerData']=$fecha->toMySQL();
	 		$post['registerIP']=$ip = $_SERVER['REMOTE_ADDR'];
	  		$post['name']=$player['name']." ".$player['surname'];
	  		$post['codUCI']=$player['codUCI'];
	  		$post['nroLicence']=$player['nroLicence'];
	  		$post['category']=$player['category'];
	  		$post['club']=$player['club'];
	  		$post['sponsor']=$player['sponsor'];
	  		$post['dorsal']=$player['dorsal'];
	  		if (!$row->bind($post)){
	  			return JError::raiseWarning(500,$row->getError());
	  		}
	  		if (!$row->store($post)){
	  			return JError::raiseWarning(500,$row->getError());
	  		}
	  		return true;
  		}
  		return false;
  		
 	}
 }
?>
Return current item: Chalange