'Name must be unique', ); public function isValid($value, $context = null) { $value = (string) $value; $this->_setValue($value); $db = Qs_Db::getInstance(); $valueTableName = Qs_Db::getTableName('FormElementPropertyValue'); $elementTableName = Qs_Db::getTableName('FormElement'); $nameExists = $db->select() ->from(array('fepv' => $valueTableName), array('count' => 'COUNT(*)')) ->join(array('fe' => $elementTableName), 'fe.id = fepv.elementId', array()) ->join(array('fe2' => $elementTableName), 'fe2.formId = fe.formId AND fe2.formType = fe.formType AND fe2.id != fe.id', array()) ->where('fe2.id = ?', $context['elementId'], Zend_Db::INT_TYPE) ->where('fe.draftFor IS NOT NULL') ->where('fepv.propertyId = ?', self::NAME_PROPERTY_ID, Zend_Db::INT_TYPE) ->where('fepv.value = ?', $value) ->query()->fetchColumn(); if ($nameExists) { $this->_error(self::NOT_UNIQUE); return false; } return true; } }