Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MINOR: fixed example and "code formating/indentations"

  • Loading branch information...
commit 639f1b351cd25dca8fab3045823d1109ab095532 1 parent 7439b99
Zauberfisch Zauberfisch authored
Showing with 34 additions and 34 deletions.
  1. +34 −34 code/rules/NetefxValidatorRuleUNIQUE.php
68 code/rules/NetefxValidatorRuleUNIQUE.php
View
@@ -6,39 +6,39 @@
* @author zauberfisch
*/
class NetefxValidatorRuleUNIQUE extends NetefxValidatorRule {
- /**
- * Check if any other DataObject has the same value already
- * @example $rule = new NetefxValidatorRuleUNIQUE('Nickname', 'This Nickname is already in use.', null, array('Nickname', 'Member', 'MemberID', 'MemberID'));
- * @param string $field name of the field
- * @param string $errorMsg the message to be displayed
- * @param string $errorMsgType the css class added to the field on validation error
- * @param array $args first argument is the classname, the second the DB field name on the class, the third is optional the ID to excluse from the uniqe rule or the name of another field in the form (default is field ID in the form), the 4th is optional the DB field name to check for the exclude id
- */
- public function __construct($field, $errorMsg = null, $errorMsgType = 'error', $args = null) {
- parent::__construct($field, $errorMsg, $errorMsgType, $args);
+ /**
+ * Check if any other DataObject has the same value already
+ * @example $rule = new NetefxValidatorRuleUNIQUE('Nickname', 'This Nickname is already in use.', null, array('Member', 'Nickname', 'MemberID', 'MemberID'));
+ * @param string $field name of the field
+ * @param string $errorMsg the message to be displayed
+ * @param string $errorMsgType the css class added to the field on validation error
+ * @param array $args first argument is the classname, the second the DB field name on the class, the third is optional the ID to excluse from the uniqe rule or the name of another field in the form (default is field ID in the form), the 4th is optional the DB field name to check for the exclude id
+ */
+ public function __construct($field, $errorMsg = null, $errorMsgType = 'error', $args = null) {
+ parent::__construct($field, $errorMsg, $errorMsgType, $args);
+ }
+
+ /**
+ * @param array $data
+ * @return boolean
+ */
+ public function validate($data) {
+ $newValue = Convert::raw2sql($data[$this->field]);
+ $classCame = $this->args[0];
+ $fieldName = $this->args[1];
+ if (isset($this->args[2]) && is_numeric($this->args[2])) {
+ $id = $this->args[2];
+ } else {
+ $idFieldInForm = (isset($this->args[2]))?$this->args[2]:'ID';
+ $id = (isset($data[$idFieldInForm]))?Convert::raw2sql($data[$idFieldInForm]):false;
}
-
- /**
- * @param array $data
- * @return boolean
- */
- public function validate($data) {
- $newValue = Convert::raw2sql($data[$this->field]);
- $classCame = $this->args[0];
- $fieldName = $this->args[1];
- if (isset($this->args[2]) && is_numeric($this->args[2])) {
- $id = $this->args[2];
- } else {
- $idFieldInForm = (isset($this->args[2]))?$this->args[2]:'ID';
- $id = (isset($data[$idFieldInForm]))?Convert::raw2sql($data[$idFieldInForm]):false;
- }
- $idFieldInDB = (isset($this->args[3]))?$this->args[3]:'ID';
- if (is_string($id)) $id = "'$id'";
- if ((is_numeric($id) && $id > 0) || is_string($id))
- $filter = "\"$fieldName\" = '$newValue' AND \"$idFieldInDB\" <> $id";
- else
- $filter = "\"$fieldName\" = '$newValue'";
- $otherEntry = DataObject::get_one($classCame, $filter);
- return ($otherEntry && $otherEntry->exists()) ? false : true;
- }
+ $idFieldInDB = (isset($this->args[3]))?$this->args[3]:'ID';
+ if (is_string($id))
+ $id = "'$id'";
+ $filter = "\"$fieldName\" = '$newValue'";
+ if ((is_numeric($id) && $id > 0) || is_string($id))
+ $filter .= " AND \"$idFieldInDB\" <> $id";
+ $otherEntry = DataObject::get_one($classCame, $filter);
+ return ($otherEntry && $otherEntry->exists()) ? false : true;
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.