From e4bfe9c7230ae5fcf78095dab008389ef4b6b1f6 Mon Sep 17 00:00:00 2001 From: Björn Geiger Date: Wed, 28 Sep 2011 17:46:27 +0200 Subject: verschiedene Korrekturen --- library/Poolctrl/Validator/TitleUnique.php | 44 ++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 6 deletions(-) (limited to 'library') diff --git a/library/Poolctrl/Validator/TitleUnique.php b/library/Poolctrl/Validator/TitleUnique.php index e935736..f051438 100755 --- a/library/Poolctrl/Validator/TitleUnique.php +++ b/library/Poolctrl/Validator/TitleUnique.php @@ -9,17 +9,49 @@ class Poolctrl_Validate_TitleUnique extends Zend_Validate_Abstract self::NOT_UNIQUE => "Title is already assigned", ); + public function __construct($option) + { + if ($option instanceof Zend_Config) { + $option = $option->toArray(); + } + + if (is_array($option)) { + if (array_key_exists('title', $option)) { + $this->oldTitle = $option['title']; + } + } + } + + protected $oldTitle; + public function isValid($value) { $this->_setValue($value); - $eventMapper = new Application_Model_EventMapper(); - $sameEvent = $eventMapper->findBy(array("title" => $value)); + if(empty($this->oldTitle)) { + $eventMapper = new Application_Model_EventMapper(); + $sameEvent = $eventMapper->findBy(array("title" => $value)); - if (count($sameEvent) > 0) { - $this->_error(self::NOT_UNIQUE); - return false; + if (count($sameEvent) > 0) { + $this->_error(self::NOT_UNIQUE); + return false; + } else { + return true; + } } else { - return true; + if($this->oldTitle == $value) { + return true; + } else { + $eventMapper = new Application_Model_EventMapper(); + $sameEvent = $eventMapper->findBy(array("title" => $value)); + + if (count($sameEvent) > 0) { + $this->_error(self::NOT_UNIQUE); + return false; + } else { + return true; + } + + } } } } \ No newline at end of file -- cgit v1.2.3-55-g7522