'Field value must be unique', ); public function __construct(Qs_Db_Table $table, $column, $current = null, array $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); } } return $this; } public function setWhere($where) { if (is_array($where)) { $wherePart = array(); $db = $this->_table->getAdapter(); foreach ($where as $field => $value) { if (ctype_digit($field) || $field === 0) { $wherePart[] = $value; } else { $wherePart[] = $db->quoteInto($field . ' = ?', $value); } } $where = $wherePart; } $this->_where = (array) $where; return $this; } public function getWhere() { return $this->_where; } 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; } }