'Field value must be unique', ); public function __construct($table, $column, $current = null, $options = array()) { $this->_table = $table; $this->_column = $column; $this->_current = $current; if (is_array($options) && !empty($options)) { $this->setOptions($options); } } public function setOptions($options) { if (isset($options['options'])) { unset($options['options']); } foreach ($options as $key => $value) { $method = 'set' . ucfirst($key); if (method_exists($this, $method)) { // Setter exists; use it $this->$method($value); } } } public function setWhere($where) { $this->_where = (array)$where; } public function getWhere() { return $this->_where; } public function setMethod($method) { if (!method_exists($this->dataObj, $method)) { throw new Zend_Validate_Exception('Unknown method "' .$method . '"'); } } public function getMethod() { if (null === $this->_method) { $this->setMethod('isUnique'); } return $this->_method; } public function isValid($value, $context = null) { $value = (string) $value; $this->_setValue($value); $db = $this->_table->getAdapter(); $where = $this->getWhere(); $where[] = $db->quoteInto($this->_column . ' = ?', $value); if (isset($this->_current)) { $current = (array) $this->_current; $info = $this->_table->info(); foreach ($info['primary'] as $key => $column) { $where[] = $db->quoteInto($column . ' <> ?', $current[$key - 1]); } } $rowset = $this->_table->fetchAll($where); if ($rowset->count()) { $this->_error(self::NOT_UNIQUE); return false; } return true; } }