Exemplo n.º 1
0
 /**
  * function for validation
  *
  * @param array $params (reference) an assoc array of name/value pairs
  *
  * @return mixed true or array of errors
  * @access public
  * @static
  */
 function newGroupRule(&$params)
 {
     if (CRM_Utils_Array::value('_qf_Import_refresh', $_POST)) {
         return true;
     }
     /* If we're not creating a new group, accept */
     if (!$params['newGroupName']) {
         return true;
     }
     $errors = array();
     //         if ($params['newGroupName'] === '') {
     //             $errors['newGroupName'] = ts( 'Please enter a name for the new group.');
     //         } else {
     if ($params['newGroupName']) {
         if (!CRM_Utils_Rule::objectExists(trim($params['newGroupName']), array('CRM_Contact_DAO_Group'))) {
             $errors['newGroupName'] = ts('Group "%1" already exists.', array(1 => $params['newGroupName']));
         }
         //         }
     }
     return empty($errors) ? true : $errors;
 }
Exemplo n.º 2
0
 /**
  * global validation rules for the form
  *
  * @param array $fields posted values of the form
  *
  * @param $files
  * @param $self
  *
  * @return array list of errors to be posted back to the form
  * @static
  * @access public
  */
 static function formRule($fields, $files, $self)
 {
     $errors = array();
     $invalidTagName = $invalidGroupName = FALSE;
     if (!empty($fields['newTagName'])) {
         if (!CRM_Utils_Rule::objectExists(trim($fields['newTagName']), array('CRM_Core_DAO_Tag'))) {
             $errors['newTagName'] = ts('Tag \'%1\' already exists.', array(1 => $fields['newTagName']));
             $invalidTagName = TRUE;
         }
     }
     if (!empty($fields['newGroupName'])) {
         $title = trim($fields['newGroupName']);
         $name = CRM_Utils_String::titleToVar($title);
         $query = 'select count(*) from civicrm_group where name like %1 OR title like %2';
         $grpCnt = CRM_Core_DAO::singleValueQuery($query, array(1 => array($name, 'String'), 2 => array($title, 'String')));
         if ($grpCnt) {
             $invalidGroupName = TRUE;
             $errors['newGroupName'] = ts('Group \'%1\' already exists.', array(1 => $fields['newGroupName']));
         }
     }
     $self->assign('invalidTagName', $invalidTagName);
     $self->assign('invalidGroupName', $invalidGroupName);
     return empty($errors) ? TRUE : $errors;
 }
Exemplo n.º 3
0
 /**
  * function for validation
  *
  * @param array $params (reference) an assoc array of name/value pairs
  *
  * @return mixed true or array of errors
  * @access public
  * @static
  */
 static function newTagRule(&$params)
 {
     if (CRM_Utils_Array::value('_qf_Import_refresh', $_POST)) {
         return true;
     }
     /* If we're not creating a new Tag, accept */
     if (!$params['newTagName']) {
         return true;
     }
     $errors = array();
     if ($params['newTagName']) {
         if (!CRM_Utils_Rule::objectExists(trim($params['newTagName']), array('CRM_Core_DAO_Tag'))) {
             $errors['newTagName'] = ts('Tag \'%1\' already exists.', array(1 => $params['newTagName']));
         }
     }
     return empty($errors) ? true : $errors;
 }