X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCustom%2FForm%2FGroup.php;h=2e497f24450613192b274c84180ebfe4dd6182f5;hb=95d8ddc04c08360567c00283822622fb8bcb0b35;hp=79f23df779d90541531325fd49148ba8399b5afa;hpb=3f97ecc92eec8613d54c017f06ffcba962c7e2db;p=civicrm-core.git diff --git a/CRM/Custom/Form/Group.php b/CRM/Custom/Form/Group.php index 79f23df779..8f88a64ac7 100644 --- a/CRM/Custom/Form/Group.php +++ b/CRM/Custom/Form/Group.php @@ -1,7 +1,7 @@ array($name, 'String'), - 2 => array($title, 'String'), - 3 => array((int)$self->_id, 'Integer'), - )); + $title = $fields['title']; + $name = CRM_Utils_String::munge($title, '_', 64); + $query = 'select count(*) from civicrm_custom_group where ( name like %1 OR title like %2 ) and id != %3'; + $grpCnt = CRM_Core_DAO::singleValueQuery($query, array( + 1 => array($name, 'String'), + 2 => array($title, 'String'), + 3 => array((int) $self->_id, 'Integer'), + )); if ($grpCnt) { $errors['title'] = ts('Custom group \'%1\' already exists in Database.', array(1 => $title)); } @@ -154,7 +149,7 @@ class CRM_Custom_Form_Group extends CRM_Core_Form { } if (!empty($fields['is_multiple'])) { - $self->assign('showMultiple', TRUE); + $self->assign('showMultiple', TRUE); } if (empty($fields['is_multiple']) && $fields['style'] == 'Tab with table') { @@ -167,7 +162,7 @@ class CRM_Custom_Form_Group extends CRM_Core_Form { // gives the ascii value $asciiValue = ord($title{0}); if ($asciiValue >= 48 && $asciiValue <= 57) { - $errors['title'] = ts("Set's Name should not start with digit"); + $errors['title'] = ts("Name cannot not start with a digit"); } } @@ -175,26 +170,22 @@ class CRM_Custom_Form_Group extends CRM_Core_Form { } /** - * This function is used to add the rules (mainly global rules) for form. + * add the rules (mainly global rules) for form. * All local rules are added near the element * - * @param null * * @return void - * @access public * @see valid_date */ - function addRules() { + public function addRules() { $this->addFormRule(array('CRM_Custom_Form_Group', 'formRule'), $this); } /** - * Function to actually build the form + * Build the form object * - * @param null * * @return void - * @access public */ public function buildQuickForm() { $this->applyFilter('__ALL__', 'trim'); @@ -208,18 +199,18 @@ class CRM_Custom_Form_Group extends CRM_Core_Form { $contactTypes = array('Contact', 'Individual', 'Household', 'Organization'); $this->assign('contactTypes', json_encode($contactTypes)); - $sel1 = array("" => "- select -") + CRM_Core_SelectValues::customGroupExtends(); - $sel2 = array(); + $sel1 = array("" => ts("- select -")) + CRM_Core_SelectValues::customGroupExtends(); + $sel2 = array(); $activityType = CRM_Core_PseudoConstant::activityType(FALSE, TRUE, FALSE, 'label', TRUE); - $eventType = CRM_Core_OptionGroup::values('event_type'); - $grantType = CRM_Core_OptionGroup::values('grant_type'); - $campaignTypes = CRM_Campaign_PseudoConstant::campaignType(); - $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE); + $eventType = CRM_Core_OptionGroup::values('event_type'); + $grantType = CRM_Core_OptionGroup::values('grant_type'); + $campaignTypes = CRM_Campaign_PseudoConstant::campaignType(); + $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE); $participantRole = CRM_Core_OptionGroup::values('participant_role'); - $relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Individual'); - $relTypeOrg = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Organization'); - $relTypeHou = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Household'); + $relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Individual'); + $relTypeOrg = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Organization'); + $relTypeHou = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Household'); ksort($sel1); asort($activityType); @@ -263,11 +254,13 @@ class CRM_Custom_Form_Group extends CRM_Core_Form { if ($main == 'Relationship') { $relName = self::getFormattedList($sel2[$main]); $sel2[$main] = array( - '' => ts("- Any -")) + $relName; + '' => ts("- Any -"), + ) + $relName; } else { $sel2[$main] = array( - '' => ts("- Any -")) + $sel2[$main]; + '' => ts("- Any -"), + ) + $sel2[$main]; } } } @@ -280,7 +273,8 @@ class CRM_Custom_Form_Group extends CRM_Core_Form { $contactSubTypes[$key] = $key; } $sel2['Contact'] = array( - "" => "-- Any --") + $contactSubTypes; + "" => ("- Any -"), + ) + $contactSubTypes; } else { if (!isset($this->_id)) { @@ -298,7 +292,7 @@ class CRM_Custom_Form_Group extends CRM_Core_Form { ts('Used For'), array( 'name' => 'extends[0]', - 'style' => 'vertical-align: top;' + 'style' => 'vertical-align: top;', ), TRUE ); @@ -393,11 +387,11 @@ class CRM_Custom_Form_Group extends CRM_Core_Form { ), ); if (!$this->_isGroupEmpty && !empty($this->_subtypes)) { - $buttons[0]['js'] = array('onclick' => "return warnDataLoss()"); + $buttons[0]['class'] = 'crm-warnDataLoss'; } $this->addButtons($buttons); - // views are implemented as frozen form + // TODO: Is this condition ever true? Can this code be removed? if ($this->_action & CRM_Core_Action::VIEW) { $this->freeze(); $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/custom/group?reset=1&action=browse'")); @@ -405,15 +399,14 @@ class CRM_Custom_Form_Group extends CRM_Core_Form { } /** - * This function sets the default values for the form. Note that in edit/view mode + * Set default values for the form. Note that in edit/view mode * the default values are retrieved from the database * - * @param null * - * @return array array of default values - * @access public + * @return array + * array of default values */ - function setDefaultValues() { + public function setDefaultValues() { $defaults = &$this->_defaults; $this->assign('showMaxMultiple', TRUE); if ($this->_action == CRM_Core_Action::ADD) { @@ -444,9 +437,6 @@ class CRM_Custom_Form_Group extends CRM_Core_Form { $defaults['extends'][1] = array(0 => ''); } - - $subName = CRM_Utils_Array::value('extends_entity_column_id', $defaults); - if ($extends == 'Relationship' && !empty($this->_subtypes)) { $relationshipDefaults = array(); foreach ($defaults['extends'][1] as $donCare => $rel_type_id) { @@ -463,10 +453,8 @@ class CRM_Custom_Form_Group extends CRM_Core_Form { /** * Process the form * - * @param null * * @return void - * @access public */ public function postProcess() { // get the submitted form values. @@ -503,8 +491,8 @@ class CRM_Custom_Form_Group extends CRM_Core_Form { $action = CRM_Core_Resources::singleton()->ajaxPopupsEnabled ? '' : '/add'; $url = CRM_Utils_System::url("civicrm/admin/custom/group/field$action", 'reset=1&new=1&gid=' . $group->id . '&action=' . ($action ? 'add' : 'browse')); CRM_Core_Session::setStatus(ts("Your custom field set '%1' has been added. You can add custom fields now.", - array(1 => $group->title) - ), ts('Saved'), 'success'); + array(1 => $group->title) + ), ts('Saved'), 'success'); $session = CRM_Core_Session::singleton(); $session->replaceUserContext($url); } @@ -515,7 +503,7 @@ class CRM_Custom_Form_Group extends CRM_Core_Form { if (is_array($db_prefix) && $config->userSystem->is_drupal && module_exists('views')) { // get table_name for each custom group $tables = array(); - $sql = "SELECT table_name FROM civicrm_custom_group WHERE is_active = 1"; + $sql = "SELECT table_name FROM civicrm_custom_group WHERE is_active = 1"; $result = CRM_Core_DAO::executeQuery($sql); while ($result->fetch()) { $tables[$result->table_name] = $result->table_name; @@ -526,24 +514,22 @@ class CRM_Custom_Form_Group extends CRM_Core_Form { if (!empty($missingTableNames)) { CRM_Core_Session::setStatus(ts("To ensure that all of your custom data groups are available to Views, you may need to add the following key(s) to the db_prefix array in your settings.php file: '%1'.", - array(1 => implode(', ', $missingTableNames)) - ), ts('Note'), 'info'); + array(1 => implode(', ', $missingTableNames)) + ), ts('Note'), 'info'); } } } - /* - * Function to return a formatted list of relationship name. - * @param $list array array of relationship name. - * @static - * return array array of relationship name. - */ /** - * @param $list + * Return a formatted list of relationship name. + * + * @param array $list + * Array of relationship name. * * @return array + * Array of relationship name. */ - static function getFormattedList(&$list) { + public static function getFormattedList(&$list) { $relName = array(); foreach ($list as $listItemKey => $itemValue) { @@ -566,5 +552,5 @@ class CRM_Custom_Form_Group extends CRM_Core_Form { } return $relName; } -} +}