Check Criteria Beforesave

Hi profs,

I am new to yii and i have developped an online scheduler

The sceduler is almost ready to go live

and i have one/two last things to check out:

I have a class termin and here i have the fields:

id(int),datum (Date),employeename(Varchar),starttime(Time),endtime(Time),customername (varchar)

Bevore i create or update the termin i have to check if the employee has another termin

at the same date between the starttime and the endteime. How can I check this in a yii function

or get an activerecord wich i can stepthrough with a foreach loop or something.

My first concern was to write a function to the termin class and call it in the beforesave function just like this but here i cannot find any hints to how i can this get to work:


	protected function beforeSave()

	{

			//$this->Datum=date('Y-m-d');

			//   $this->Datum=strftime('%Y-%m-%d', strtotime(str_replace("/", "-", $this->Datum)));

	

		if(parent::beforeSave()){	

        $this->Datum = strtotime ($this->Datum);

        $this->Datum = date ('Y-m-d', $this->Datum);		

			return TRUE;

		}

		else return false;

	}

	

	public function checkTerminvalide($datumc,$mitarbeiterc,$startzeitc,$endzeitc){


	$criteria=new CDbCriteria;

	$criteria->select='Datum','Mitarbeiter','Startzeit','Endzeit';  

	$criteria->condition='Datum=:{$datumc}','Mitarbeiter=:{$mitarbeiterc}';

	$criteria->params=array(':startzeit'=>{$startzeitc}, ':endzeit <= {$endzeitc});

	$post=Post::model()->find($criteria); // 

	

return ?

	}

can anybody help ?