/**
  * Test isGroupEmpty()
  */
 public function testIsGroupEmpty()
 {
     $customGrouptitle = 'Test Custom Group';
     $groupParams = array('title' => $customGrouptitle, 'name' => 'test_custom_group', 'style' => 'Tab', 'extends' => 'Individual', 'weight' => 10, 'is_active' => 1, 'version' => 3);
     $customGroup = Custom::createGroup($groupParams);
     $customGroupId = $customGroup->id;
     $isEmptyGroup = CRM_Core_BAO_CustomGroup::isGroupEmpty($customGroupId);
     $this->assertEquals($isEmptyGroup, TRUE, 'Check that custom Group is Empty.');
     Custom::deleteGroup($customGroup);
 }
Exemple #2
0
 /**
  * Build the form object.
  *
  *
  * @return void
  */
 public function buildQuickForm()
 {
     $this->applyFilter('__ALL__', 'trim');
     $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_CustomGroup');
     //title
     $this->add('text', 'title', ts('Set Name'), $attributes['title'], TRUE);
     //Fix for code alignment, CRM-3058
     $contactTypes = array('Contact', 'Individual', 'Household', 'Organization');
     $this->assign('contactTypes', json_encode($contactTypes));
     $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);
     $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');
     ksort($sel1);
     asort($activityType);
     asort($eventType);
     asort($grantType);
     asort($membershipType);
     asort($participantRole);
     $allRelationshipType = array();
     $allRelationshipType = array_merge($relTypeInd, $relTypeOrg);
     $allRelationshipType = array_merge($allRelationshipType, $relTypeHou);
     //adding subtype specific relationships CRM-5256
     $subTypes = CRM_Contact_BAO_ContactType::subTypeInfo();
     foreach ($subTypes as $subType => $val) {
         $subTypeRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, $val['parent'], FALSE, 'label', TRUE, $subType);
         $allRelationshipType = array_merge($allRelationshipType, $subTypeRelationshipTypes);
     }
     $sel2['Event'] = $eventType;
     $sel2['Grant'] = $grantType;
     $sel2['Activity'] = $activityType;
     $sel2['Campaign'] = $campaignTypes;
     $sel2['Membership'] = $membershipType;
     $sel2['ParticipantRole'] = $participantRole;
     $sel2['ParticipantEventName'] = CRM_Event_PseudoConstant::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )");
     $sel2['ParticipantEventType'] = $eventType;
     $sel2['Contribution'] = CRM_Contribute_PseudoConstant::financialType();
     $sel2['Relationship'] = $allRelationshipType;
     $sel2['Individual'] = CRM_Contact_BAO_ContactType::subTypePairs('Individual', FALSE, NULL);
     $sel2['Household'] = CRM_Contact_BAO_ContactType::subTypePairs('Household', FALSE, NULL);
     $sel2['Organization'] = CRM_Contact_BAO_ContactType::subTypePairs('Organization', FALSE, NULL);
     CRM_Core_BAO_CustomGroup::getExtendedObjectTypes($sel2);
     foreach ($sel2 as $main => $sub) {
         if (!empty($sel2[$main])) {
             if ($main == 'Relationship') {
                 $relName = self::getFormattedList($sel2[$main]);
                 $sel2[$main] = array('' => ts("- Any -")) + $relName;
             } else {
                 $sel2[$main] = array('' => ts("- Any -")) + $sel2[$main];
             }
         }
     }
     $cSubTypes = CRM_Core_Component::contactSubTypes();
     if (!empty($cSubTypes)) {
         $contactSubTypes = array();
         foreach ($cSubTypes as $key => $value) {
             $contactSubTypes[$key] = $key;
         }
         $sel2['Contact'] = array("" => "- Any -") + $contactSubTypes;
     } else {
         if (!isset($this->_id)) {
             $formName = 'document.forms.' . $this->_name;
             $js = "<script type='text/javascript'>\n";
             $js .= "{$formName}['extends_1'].style.display = 'none';\n";
             $js .= "</script>";
             $this->assign('initHideBlocks', $js);
         }
     }
     $sel =& $this->add('hierselect', 'extends', ts('Used For'), array('name' => 'extends[0]', 'style' => 'vertical-align: top;'), TRUE);
     $sel->setOptions(array($sel1, $sel2));
     if (is_a($sel->_elements[1], 'HTML_QuickForm_select')) {
         // make second selector a multi-select -
         $sel->_elements[1]->setMultiple(TRUE);
         $sel->_elements[1]->setSize(5);
     }
     if ($this->_action == CRM_Core_Action::UPDATE) {
         $subName = CRM_Utils_Array::value('extends_entity_column_id', $this->_defaults);
         if ($this->_defaults['extends'] == 'Participant') {
             if ($subName == 1) {
                 $this->_defaults['extends'] = 'ParticipantRole';
             } elseif ($subName == 2) {
                 $this->_defaults['extends'] = 'ParticipantEventName';
             } elseif ($subName == 3) {
                 $this->_defaults['extends'] = 'ParticipantEventType';
             }
         }
         //allow to edit settings if custom set is empty CRM-5258
         $this->_isGroupEmpty = CRM_Core_BAO_CustomGroup::isGroupEmpty($this->_id);
         if (!$this->_isGroupEmpty) {
             if (!empty($this->_subtypes)) {
                 // we want to allow adding / updating subtypes for this case,
                 // and therefore freeze the first selector only.
                 $sel->_elements[0]->freeze();
             } else {
                 // freeze both the selectors
                 $sel->freeze();
             }
         }
         $this->assign('isCustomGroupEmpty', $this->_isGroupEmpty);
         $this->assign('gid', $this->_id);
     }
     $this->assign('defaultSubtypes', json_encode($this->_subtypes));
     // help text
     $this->add('wysiwyg', 'help_pre', ts('Pre-form Help'), $attributes['help_pre']);
     $this->add('wysiwyg', 'help_post', ts('Post-form Help'), $attributes['help_post']);
     // weight
     $this->add('text', 'weight', ts('Order'), $attributes['weight'], TRUE);
     $this->addRule('weight', ts('is a numeric field'), 'numeric');
     // display style
     $this->add('select', 'style', ts('Display Style'), CRM_Core_SelectValues::customGroupStyle());
     // is this set collapsed or expanded ?
     $this->addElement('checkbox', 'collapse_display', ts('Collapse this set on initial display'));
     // is this set collapsed or expanded ? in advanced search
     $this->addElement('checkbox', 'collapse_adv_display', ts('Collapse this set in Advanced Search'));
     // is this set active ?
     $this->addElement('checkbox', 'is_active', ts('Is this Custom Data Set active?'));
     // does this set have multiple record?
     $multiple = $this->addElement('checkbox', 'is_multiple', ts('Does this Custom Field Set allow multiple records?'), NULL);
     // $min_multiple = $this->add('text', 'min_multiple', ts('Minimum number of multiple records'), $attributes['min_multiple'] );
     // $this->addRule('min_multiple', ts('is a numeric field') , 'numeric');
     $max_multiple = $this->add('text', 'max_multiple', ts('Maximum number of multiple records'), $attributes['max_multiple']);
     $this->addRule('max_multiple', ts('is a numeric field'), 'numeric');
     //allow to edit settings if custom set is empty CRM-5258
     $this->assign('isGroupEmpty', $this->_isGroupEmpty);
     if (!$this->_isGroupEmpty) {
         $multiple->freeze();
         //$min_multiple->freeze();
         $max_multiple->freeze();
     }
     $this->assign('showStyle', FALSE);
     $this->assign('showMultiple', FALSE);
     $buttons = array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')));
     if (!$this->_isGroupEmpty && !empty($this->_subtypes)) {
         $buttons[0]['class'] = 'crm-warnDataLoss';
     }
     $this->addButtons($buttons);
     // 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'"));
     }
 }
 /**
  * Test isGroupEmpty()
  */
 public function testIsGroupEmpty()
 {
     $customGroupTitle = 'Test Custom Group';
     $groupParams = array('title' => $customGroupTitle, 'name' => 'test_custom_group', 'style' => 'Tab', 'extends' => 'Individual', 'weight' => 10, 'is_active' => 1);
     $customGroup = $this->customGroupCreate($groupParams);
     $customGroupId = $customGroup['id'];
     $isEmptyGroup = CRM_Core_BAO_CustomGroup::isGroupEmpty($customGroupId);
     $this->assertEquals($isEmptyGroup, TRUE, 'Check that custom Group is Empty.');
     $this->customGroupDelete($customGroup['id']);
 }
Exemple #4
0
 /**
  * Function to actually build the form
  * 
  * @param null
  * 
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     $this->applyFilter('__ALL__', 'trim');
     $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_CustomGroup');
     //title
     $this->add('text', 'title', ts('Group Name'), $attributes['title'], true);
     $this->addRule('title', ts('Name already exists in Database.'), 'objectExists', array('CRM_Core_DAO_CustomGroup', $this->_id, 'title'));
     //Fix for code alignment, CRM-3058
     require_once "CRM/Contribute/PseudoConstant.php";
     require_once "CRM/Member/BAO/MembershipType.php";
     require_once 'CRM/Event/PseudoConstant.php';
     require_once "CRM/Contact/BAO/Relationship.php";
     require_once 'CRM/Core/OptionGroup.php';
     require_once 'CRM/Contact/BAO/ContactType.php';
     $contactTypes = array('Contact', 'Individual', 'Household', 'Organization');
     $this->assign('contactTypes', json_encode($contactTypes));
     $sel1 = array("" => "- select -") + CRM_Core_SelectValues::customGroupExtends();
     $sel2 = array();
     $activityType = CRM_Core_PseudoConstant::activityType(false, true);
     $eventType = CRM_Core_OptionGroup::values('event_type');
     $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');
     ksort($sel1);
     asort($activityType);
     asort($eventType);
     asort($membershipType);
     asort($participantRole);
     $allRelationshipType = array();
     $allRelationshipType = array_merge($relTypeInd, $relTypeOrg);
     $allRelationshipType = array_merge($allRelationshipType, $relTypeHou);
     //adding subtype specific relationships CRM-5256
     $subTypes = CRM_Contact_BAO_ContactType::subTypeInfo();
     foreach ($subTypes as $subType => $val) {
         $subTypeRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, null, null, $val['parent'], false, 'label', true, $subType);
         $allRelationshipType = array_merge($allRelationshipType, $subTypeRelationshipTypes);
     }
     $sel2['Event'] = $eventType;
     $sel2['Activity'] = $activityType;
     $sel2['Membership'] = $membershipType;
     $sel2['ParticipantRole'] = $participantRole;
     $sel2['ParticipantEventName'] = CRM_Event_PseudoConstant::event(null, false, "( is_template IS NULL OR is_template != 1 )");
     $sel2['ParticipantEventType'] = $eventType;
     $sel2['Contribution'] = CRM_Contribute_PseudoConstant::contributionType();
     $sel2['Relationship'] = $allRelationshipType;
     $sel2['Individual'] = CRM_Contact_BAO_ContactType::subTypePairs('Individual', false, null);
     $sel2['Household'] = CRM_Contact_BAO_ContactType::subTypePairs('Household', false, null);
     $sel2['Organization'] = CRM_Contact_BAO_ContactType::subTypePairs('Organization', false, null);
     foreach ($sel2 as $main => $sub) {
         if (!empty($sel2[$main])) {
             $sel2[$main] = array('' => ts("- Any -")) + $sel2[$main];
         }
     }
     require_once "CRM/Core/Component.php";
     $cSubTypes = CRM_Core_Component::contactSubTypes();
     if (!empty($cSubTypes)) {
         $contactSubTypes = array();
         foreach ($cSubTypes as $key => $value) {
             $contactSubTypes[$key] = $key;
         }
         $sel2['Contact'] = array("" => "-- Any --") + $contactSubTypes;
     } else {
         if (!isset($this->_id)) {
             $formName = 'document.forms.' . $this->_name;
             $js = "<script type='text/javascript'>\n";
             $js .= "{$formName}['extends[1]'].style.display = 'none';\n";
             $js .= "</script>";
             $this->assign('initHideBlocks', $js);
         }
     }
     $sel =& $this->add('hierselect', 'extends', ts('Used For'), array('onClick' => 'showHideStyle();', 'name' => 'extends[0]', 'style' => 'vertical-align: top;'), true);
     $sel->setOptions(array($sel1, $sel2));
     if (is_a($sel->_elements[1], 'HTML_QuickForm_select')) {
         // make second selector a multi-select -
         $sel->_elements[1]->setMultiple(true);
         $sel->_elements[1]->setSize(5);
     }
     if ($this->_action == CRM_Core_Action::UPDATE) {
         //allow to edit settings if custom group is empty CRM-5258
         $this->_isGroupEmpty = CRM_Core_BAO_CustomGroup::isGroupEmpty($this->_id);
         if (!$this->_isGroupEmpty) {
             if (!empty($this->_subtypes) && count(array_intersect($this->_subtypes, $sel2[$this->_defaults['extends']])) < count($sel2[$this->_defaults['extends']])) {
                 // we want to allow adding subtypes for this case,
                 // and therefore freeze the first selector only.
                 $sel->_elements[0]->freeze();
             } else {
                 // freeze both the selectors
                 $sel->freeze();
             }
         }
         $this->assign('gid', $this->_id);
     }
     // help text
     $this->addWysiwyg('help_pre', ts('Pre-form Help'), $attributes['help_pre']);
     $this->addWysiwyg('help_post', ts('Post-form Help'), $attributes['help_post']);
     // weight
     $this->add('text', 'weight', ts('Order'), $attributes['weight'], true);
     $this->addRule('weight', ts('is a numeric field'), 'numeric');
     // display style
     $this->add('select', 'style', ts('Display Style'), CRM_Core_SelectValues::customGroupStyle());
     // is this group collapsed or expanded ?
     $this->addElement('checkbox', 'collapse_display', ts('Collapse this group on initial display'));
     // is this group collapsed or expanded ? in advanced search
     $this->addElement('checkbox', 'collapse_adv_display', ts('Collapse this group in Advanced Search'));
     // is this group active ?
     $this->addElement('checkbox', 'is_active', ts('Is this Custom Data Group active?'));
     // does this group have multiple record?
     $multiple = $this->addElement('checkbox', 'is_multiple', ts('Does this Custom Data Group allow multiple records?'), null, array('onclick' => "showRange();"));
     // $min_multiple = $this->add('text', 'min_multiple', ts('Minimum number of multiple records'), $attributes['min_multiple'] );
     // $this->addRule('min_multiple', ts('is a numeric field') , 'numeric');
     $max_multiple = $this->add('text', 'max_multiple', ts('Maximum number of multiple records'), $attributes['max_multiple']);
     $this->addRule('max_multiple', ts('is a numeric field'), 'numeric');
     //allow to edit settings if custom group is empty CRM-5258
     $this->assign('isGroupEmpty', $this->_isGroupEmpty);
     if (!$this->_isGroupEmpty) {
         $multiple->freeze();
         //$min_multiple->freeze();
         $max_multiple->freeze();
     }
     $this->assign('showStyle', false);
     $this->assign('showMultiple', false);
     $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
     // views are implemented as frozen form
     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'"));
     }
 }