<commit_before><?php
/*
 * @author: <NAME>
 * <EMAIL>
 */
class immValidatorUnique extends sfValidatorBase
{
	/**
	 * @see sfValidatorRegex
	 */
	public function getPattern(){
		return '';
	}
	protected function configure($options = array(), $messages = array())
	{			
		$this->setOption('trim', true);
		$this->addOption('unique');
		$this->addOption('class');
		$this->addOption('column');
		
		$this->addMessage('unique','"%value%" already exists.');
		self::setRequiredMessage('This field is required!');
	}
	
	protected function doClean($value)
	{	
		$id = sfContext::getInstance()->getRequest()->getParameter("edit[0][id]",false);
		if(!$id) $id = sfContext::getInstance()->getRequest()->getParameter("edit[1][id]",false);
		
		$c = new Criteria();
		$c->add(constant($this->getOption('class')."Peer::".strtoupper($this->getOption('column'))),$value);
		$res = call_user_func(array($this->getOption('class')."Peer","doSelectOne"),$c);
		
		if($res and $res->getId() == $id)
		{
			return $value;
		}
		else if($res && $res->getId() != $id)
		{
			throw new sfValidatorError($this, 'unique', array('value' => $value,'unique' => $this->getOption('unique')));			
		}		
		
		return $value;
	}
}
?><commit_msg>#1789 validator now supports wizards<commit_after><?php
/*
 * @author: <NAME>
 * <EMAIL>
 */
class immValidatorUnique extends sfValidatorBase
{
	/**
	 * @see sfValidatorRegex
	 */
	public function getPattern(){
		return '';
	}
	protected function configure($options = array(), $messages = array())
	{			
		$this->setOption('trim', true);
		$this->addOption('unique');
		$this->addOption('class');
		$this->addOption('column');
		
		$this->addMessage('unique','"%value%" already exists.');
		self::setRequiredMessage('This field is required!');
	}
	
	protected function doClean($value)
	{	
		$id = sfContext::getInstance()->getRequest()->getParameter("edit[0][id]",false);
		if(!$id) $id = sfContext::getInstance()->getRequest()->getParameter("edit[1][id]",false);
		if(!$id) $id = sfContext::getInstance()->getRequest()->getParameter("edit[2][id]",false);
		
		$c = new Criteria();
		$c->add(constant($this->getOption('class')."Peer::".strtoupper($this->getOption('column'))),$value);
		$res = call_user_func(array($this->getOption('class')."Peer","doSelectOne"),$c);
		
		if($res and $res->getId() == $id)
		{
			return $value;
		}
		else if($res && $res->getId() != $id)
		{
			throw new sfValidatorError($this, 'unique', array('value' => $value,'unique' => $this->getOption('unique')));			
		}		
		
		return $value;
	}
}
?>
{'fraction_non_alphanumeric': 0.22031963470319635, 'fraction_numerical': 0.003424657534246575, 'mean_word_length': 4.175196850393701, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '812737', 'n_tokens_mistral': 956, 'n_tokens_neox': 855, 'n_words': 137}