summaryrefslogtreecommitdiffstats
path: root/apps/admin/lib/myChangeNicknameValidator.php
blob: e8dfdb1bb1a88cae35c3c1bbf273e07ed5b3726f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php

class myChangeNicknameValidator extends sfValidator
{
	public function initialize($context, $parameters = null)
	{
		// initialize parent
		parent::initialize($context);

		// set defaults
		$this->setParameter('change_error', 'Invalid input');

		$this->getParameterHolder()->add($parameters);

		return true;
	}

	public function execute(&$value, &$error)
	{
		$current_nickname = $this->getContext()->getUser()->getNickname();

		$new_nickname = $value;

		// changed the nickname?
		if($new_nickname == $current_nickname)
			return true;

		$c = new Criteria();
		$c->add(UserPeer::NICKNAME, $new_nickname);
		$user = UserPeer::doSelectOne($c);

		// nickname exists?
		if($user)
		{
			$error = $this->getParameter('change_error');
			return false;
		}

		return true;
	}
}

?>