$attributes['name'], TRUE
);
- $this->registerRule('paymentProcessorNameExists', 'callback', 'paymentProcessorNameExists', 'CRM_Admin_Form_PaymentProcessor');
- $this->addRule('name', ts('Name already exists in Database.'), 'paymentProcessorNameExists', array(
+ $this->addRule('name', ts('Name already exists in Database.'), 'objectExists', array(
'CRM_Financial_DAO_PaymentProcessor',
$this->_id,
+ 'name',
+ CRM_Core_Config::domainID(),
));
$this->add('text', 'description', ts('Description'),
civicrm_api3('PaymentProcessor', 'create', $params);
}
- /**
- * Check if there is a record with the same name in the db.
- *
- * @param string $value
- * The value of the field we are checking.
- * @param array $options
- * The daoName and fieldName (optional ).
- *
- * @return bool
- * true if object exists
- */
- public static function paymentProcessorNameExists($value, $options) {
- $fieldName = 'name';
- $daoName = CRM_Utils_Array::value(0, $options);
- $daoID = CRM_Utils_Array::value(1, $options);
- $domain_id = CRM_Core_Config::domainID();
- $object = new $daoName();
- $object->$fieldName = $value;
- $object->domain_id = $domain_id;
-
- $config = CRM_Core_Config::singleton();
-
- if ($object->find(TRUE)) {
- return ($daoID && $object->id == $daoID) ? TRUE : FALSE;
- }
- else {
- return TRUE;
- }
- }
-
}
* @param string $fieldName
* The name of the field in the DAO.
*
+ * @param string $domainID
+ * The id of the domain. Object exists only for the given domain.
+ *
* @return bool
* true if object exists
*/
- public static function objectExists($value, $daoName, $daoID, $fieldName = 'name') {
+ public static function objectExists($value, $daoName, $daoID, $fieldName = 'name', $domainID = NULL) {
$object = new $daoName();
$object->$fieldName = $value;
-
- $config = CRM_Core_Config::singleton();
+ if ($domainID) {
+ $object->domain_id = $domainID;
+ }
if ($object->find(TRUE)) {
return ($daoID && $object->id == $daoID) ? TRUE : FALSE;
* @param string $value
* The value of the field we are checking.
* @param array $options
- * The daoName and fieldName (optional ).
+ * The daoName, fieldName (optional) and DomainID (optional).
*
* @return bool
* true if object exists
$name = $options[2];
}
- return CRM_Core_DAO::objectExists($value, CRM_Utils_Array::value(0, $options), CRM_Utils_Array::value(1, $options), CRM_Utils_Array::value(2, $options, $name));
+ return CRM_Core_DAO::objectExists($value, CRM_Utils_Array::value(0, $options), CRM_Utils_Array::value(1, $options), CRM_Utils_Array::value(2, $options, $name), CRM_Utils_Array::value(3, $options));
}
/**