3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2017
35 * This class contains function for UFField.
37 class CRM_Core_BAO_UFField
extends CRM_Core_DAO_UFField
{
42 private static $_contriBatchEntryFields = NULL;
43 private static $_memberBatchEntryFields = NULL;
47 * Fetch object based on array of properties.
49 * @param array $params
50 * (reference ) an assoc array of name/value pairs.
51 * @param array $defaults
52 * (reference ) an assoc array to hold the flattened values.
54 * @return CRM_Core_BAO_UFField
56 public static function retrieve(&$params, &$defaults) {
57 return CRM_Core_DAO
::commonRetrieve('CRM_Core_DAO_UFField', $params, $defaults);
70 public static function getTitle($id) {
71 return CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFField', $groupId, 'title');
75 * Update the is_active flag in the db.
78 * Id of the database record.
79 * @param bool $is_active
80 * Value we want to set the is_active field.
83 * DAO object on success, null otherwise
85 public static function setIsActive($id, $is_active) {
86 //check if custom data profile field is disabled
88 if (CRM_Core_BAO_UFField
::checkUFStatus($id)) {
89 return CRM_Core_DAO
::setFieldValue('CRM_Core_DAO_UFField', $id, 'is_active', $is_active);
92 CRM_Core_Session
::setStatus(ts('Cannot enable this UF field since the used custom field is disabled.'), ts('Check Custom Field'), 'error');
96 return CRM_Core_DAO
::setFieldValue('CRM_Core_DAO_UFField', $id, 'is_active', $is_active);
101 * Delete the profile Field.
109 public static function del($id) {
111 $field = new CRM_Core_DAO_UFField();
118 * Check duplicate for duplicate field in a group.
120 * @param array $params
121 * An associative array with field and values.
125 * @ids array $ids array that containd ids
128 public static function duplicateField($params, $ids) {
129 $ufField = new CRM_Core_DAO_UFField();
130 $ufField->uf_group_id
= CRM_Utils_Array
::value('uf_group', $ids);
131 $ufField->field_type
= $params['field_name'][0];
132 $ufField->field_name
= $params['field_name'][1];
133 if ($params['field_name'][1] == 'url') {
134 $ufField->website_type_id
= CRM_Utils_Array
::value(2, $params['field_name'], NULL);
137 $ufField->location_type_id
= (CRM_Utils_Array
::value(2, $params['field_name'])) ?
$params['field_name'][2] : 'NULL';
139 $ufField->phone_type_id
= CRM_Utils_Array
::value(3, $params['field_name']);
141 if (!empty($ids['uf_field'])) {
142 $ufField->whereAdd("id <> " . CRM_Utils_Array
::value('uf_field', $ids));
145 return $ufField->find(TRUE);
149 * Does profile consists of a multi-record custom field.
155 public static function checkMultiRecordFieldExists($gId) {
156 $queryString = "SELECT f.field_name
157 FROM civicrm_uf_field f, civicrm_uf_group g
158 WHERE f.uf_group_id = g.id
159 AND g.id = %1 AND f.field_name LIKE 'custom%'";
160 $p = array(1 => array($gId, 'Integer'));
161 $dao = CRM_Core_DAO
::executeQuery($queryString, $p);
162 $customFieldIds = array();
163 $isMultiRecordFieldPresent = FALSE;
164 while ($dao->fetch()) {
165 if ($customId = CRM_Core_BAO_CustomField
::getKeyID($dao->field_name
)) {
166 if (is_numeric($customId)) {
167 $customFieldIds[] = $customId;
172 if (!empty($customFieldIds) && count($customFieldIds) == 1) {
173 $customFieldId = array_pop($customFieldIds);
174 $isMultiRecordFieldPresent = CRM_Core_BAO_CustomField
::isMultiRecordField($customFieldId);
176 elseif (count($customFieldIds) > 1) {
177 $customFieldIds = implode(", ", $customFieldIds);
180 FROM civicrm_custom_group cg
181 INNER JOIN civicrm_custom_field cf
182 ON cg.id = cf.custom_group_id
183 WHERE cf.id IN (" . $customFieldIds . ") AND is_multiple = 1 LIMIT 0,1";
185 $dao = CRM_Core_DAO
::executeQuery($queryString);
187 $isMultiRecordFieldPresent = ($dao->cgId
) ?
$dao->cgId
: FALSE;
191 return $isMultiRecordFieldPresent;
197 * @param array $params
198 * (reference) array containing the values submitted by the form.
200 * @return CRM_Core_BAO_UFField
202 public static function add(&$params) {
203 // set values for uf field properties and save
204 $ufField = new CRM_Core_DAO_UFField();
205 $ufField->copyValues($params);
206 $ufField->field_type
= $params['field_name'][0];
207 $ufField->field_name
= $params['field_name'][1];
209 //should not set location type id for Primary
210 $locationTypeId = NULL;
211 if ($params['field_name'][1] == 'url') {
212 $ufField->website_type_id
= CRM_Utils_Array
::value(2, $params['field_name']);
215 $locationTypeId = CRM_Utils_Array
::value(2, $params['field_name']);
216 $ufField->website_type_id
= NULL;
218 if ($locationTypeId) {
219 $ufField->location_type_id
= $locationTypeId;
222 $ufField->location_type_id
= 'null';
225 $ufField->phone_type_id
= CRM_Utils_Array
::value(3, $params['field_name'], 'NULL');
227 return $ufField->save();
231 * Automatically determine one weight and modify others.
233 * @param array $params
234 * UFField record, e.g. with 'weight', 'uf_group_id', and 'field_id'.
237 public static function autoWeight($params) {
241 if (!empty($params['field_id'])) {
242 $oldWeight = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFField', $params['field_id'], 'weight', 'id');
244 $fieldValues = array('uf_group_id' => $params['group_id']);
245 return CRM_Utils_Weight
::updateOtherWeights('CRM_Core_DAO_UFField', $oldWeight, CRM_Utils_Array
::value('weight', $params, 0), $fieldValues);
249 * Enable/disable profile field given a custom field id
251 * @param int $customFieldId
253 * @param bool $is_active
254 * Set the is_active field.
256 public static function setUFField($customFieldId, $is_active) {
257 //find the profile id given custom field
258 $ufField = new CRM_Core_DAO_UFField();
259 $ufField->field_name
= "custom_" . $customFieldId;
262 while ($ufField->fetch()) {
263 //enable/ disable profile
264 CRM_Core_BAO_UFField
::setIsActive($ufField->id
, $is_active);
269 * Copy existing profile fields to
270 * new profile from the already built profile
273 * From which we need to copy.
274 * @param bool $new_id
277 public static function copy($old_id, $new_id) {
278 $ufField = new CRM_Core_DAO_UFField();
279 $ufField->uf_group_id
= $old_id;
281 while ($ufField->fetch()) {
282 //copy the field records as it is on new ufgroup id
283 $ufField->uf_group_id
= $new_id;
290 * Delete profile field given a custom field.
292 * @param int $customFieldId
293 * ID of the custom field to be deleted.
295 public static function delUFField($customFieldId) {
296 //find the profile id given custom field id
297 $ufField = new CRM_Core_DAO_UFField();
298 $ufField->field_name
= "custom_" . $customFieldId;
301 while ($ufField->fetch()) {
302 //enable/ disable profile
303 CRM_Core_BAO_UFField
::del($ufField->id
);
308 * Enable/disable profile field given a custom group id
310 * @param int $customGroupId
312 * @param bool $is_active
313 * Value we want to set the is_active field.
315 public static function setUFFieldStatus($customGroupId, $is_active) {
316 //find the profile id given custom group id
317 $queryString = "SELECT civicrm_custom_field.id as custom_field_id
318 FROM civicrm_custom_field, civicrm_custom_group
319 WHERE civicrm_custom_field.custom_group_id = civicrm_custom_group.id
320 AND civicrm_custom_group.id = %1";
321 $p = array(1 => array($customGroupId, 'Integer'));
322 $dao = CRM_Core_DAO
::executeQuery($queryString, $p);
324 while ($dao->fetch()) {
325 //enable/ disable profile
326 CRM_Core_BAO_UFField
::setUFField($dao->custom_field_id
, $is_active);
331 * Check the status of custom field used in uf fields.
333 * @param int $UFFieldId
336 * false if custom field are disabled else true
338 public static function checkUFStatus($UFFieldId) {
339 $fieldName = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFField', $UFFieldId, 'field_name');
340 // return if field is not a custom field
341 if (!$customFieldId = CRM_Core_BAO_CustomField
::getKeyID($fieldName)) {
345 $customField = new CRM_Core_DAO_CustomField();
346 $customField->id
= $customFieldId;
347 // if uf field is custom field
348 if ($customField->find(TRUE)) {
349 if (!$customField->is_active
) {
359 * Find out whether given profile group using Activity
360 * Profile fields with contact fields
362 * @param int $ufGroupId
366 public static function checkContactActivityProfileType($ufGroupId) {
367 $ufGroup = new CRM_Core_DAO_UFGroup();
368 $ufGroup->id
= $ufGroupId;
369 $ufGroup->find(TRUE);
371 return self
::checkContactActivityProfileTypeByGroupType($ufGroup->group_type
);
376 * @param $ufGroupType
379 public static function checkContactActivityProfileTypeByGroupType($ufGroupType) {
380 $profileTypes = array();
382 $typeParts = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $ufGroupType);
383 $profileTypes = explode(',', $typeParts[0]);
386 if (empty($profileTypes)) {
389 $components = array('Contribution', 'Participant', 'Membership');
390 if (!in_array('Activity', $profileTypes)) {
393 elseif (count($profileTypes) == 1) {
397 if ($index = array_search('Contact', $profileTypes)) {
398 unset($profileTypes[$index]);
399 if (count($profileTypes) == 1) {
404 $contactTypes = array('Individual', 'Household', 'Organization');
405 $subTypes = CRM_Contact_BAO_ContactType
::subTypes();
407 $profileTypeComponent = array_intersect($components, $profileTypes);
408 if (!empty($profileTypeComponent) ||
409 count(array_intersect($contactTypes, $profileTypes)) > 1 ||
410 count(array_intersect($subTypes, $profileTypes)) > 1
419 * Find out whether given profile group uses $required
420 * and/or $optional profile types
422 * @param int $ufGroupId
424 * @param array $required
425 * Array of types those are required.
426 * @param array $optional
427 * Array of types those are optional.
431 public static function checkValidProfileType($ufGroupId, $required, $optional = NULL) {
432 if (!is_array($required) ||
empty($required)) {
436 $ufGroup = new CRM_Core_DAO_UFGroup();
437 $ufGroup->id
= $ufGroupId;
438 $ufGroup->find(TRUE);
440 $profileTypes = array();
441 if ($ufGroup->group_type
) {
442 $typeParts = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $ufGroup->group_type
);
443 $profileTypes = explode(',', $typeParts[0]);
446 if (empty($profileTypes)) {
451 foreach ($required as $key => $val) {
452 if (!in_array($val, $profileTypes)) {
458 if ($valid && is_array($optional)) {
459 foreach ($optional as $key => $val) {
460 if (in_array($val, $profileTypes)) {
471 * Check for mix profile fields (eg: individual + other contact types)
473 * @param int $ufGroupId
476 * true for mix profile else false
478 public static function checkProfileType($ufGroupId) {
479 $ufGroup = new CRM_Core_DAO_UFGroup();
480 $ufGroup->id
= $ufGroupId;
481 $ufGroup->find(TRUE);
483 $profileTypes = array();
484 if ($ufGroup->group_type
) {
485 $typeParts = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $ufGroup->group_type
);
486 $profileTypes = explode(',', $typeParts[0]);
489 //early return if new profile.
490 if (empty($profileTypes)) {
494 //we need to unset Contact
495 if (count($profileTypes) > 1) {
496 $index = array_search('Contact', $profileTypes);
497 if ($index !== FALSE) {
498 unset($profileTypes[$index]);
502 // suppress any subtypes if present
503 CRM_Contact_BAO_ContactType
::suppressSubTypes($profileTypes);
505 $contactTypes = array('Contact', 'Individual', 'Household', 'Organization');
506 $components = array('Contribution', 'Participant', 'Membership', 'Activity');
509 // check for mix profile condition
510 if (count($profileTypes) > 1) {
511 //check the there are any components include in profile
512 foreach ($components as $value) {
513 if (in_array($value, $profileTypes)) {
517 //check if there are more than one contact types included in profile
518 if (count($profileTypes) > 1) {
522 elseif (count($profileTypes) == 1) {
523 // note for subtype case count would be zero
524 $profileTypes = array_values($profileTypes);
525 if (!in_array($profileTypes[0], $contactTypes)) {
534 * Get the profile type (eg: individual/organization/household)
536 * @param int $ufGroupId
538 * @param bool $returnMixType
539 * This is true, then field type of mix profile field is returned.
540 * @param bool $onlyPure
541 * True if only pure profiles are required.
543 * @param bool $skipComponentType
549 public static function getProfileType($ufGroupId, $returnMixType = TRUE, $onlyPure = FALSE, $skipComponentType = FALSE) {
550 $ufGroup = new CRM_Core_DAO_UFGroup();
551 $ufGroup->id
= $ufGroupId;
552 $ufGroup->is_active
= 1;
554 $ufGroup->find(TRUE);
555 return self
::calculateProfileType($ufGroup->group_type
, $returnMixType, $onlyPure, $skipComponentType);
559 * Get the profile type (eg: individual/organization/household)
561 * @param string $ufGroupType
562 * @param bool $returnMixType
563 * This is true, then field type of mix profile field is returned.
564 * @param bool $onlyPure
565 * True if only pure profiles are required.
566 * @param bool $skipComponentType
568 * @return string profile group_type
571 public static function calculateProfileType($ufGroupType, $returnMixType = TRUE, $onlyPure = FALSE, $skipComponentType = FALSE) {
573 $contactTypes = array('Contact', 'Individual', 'Household', 'Organization');
574 $subTypes = CRM_Contact_BAO_ContactType
::subTypes();
575 $components = array('Contribution', 'Participant', 'Membership', 'Activity');
577 $profileTypes = array();
579 $typeParts = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $ufGroupType);
580 $profileTypes = explode(',', $typeParts[0]);
584 if (count($profileTypes) == 1) {
585 return $profileTypes[0];
592 //we need to unset Contact
593 if (count($profileTypes) > 1) {
594 $index = array_search('Contact', $profileTypes);
595 if ($index !== FALSE) {
596 unset($profileTypes[$index]);
600 $profileType = $mixProfileType = NULL;
602 // this case handles pure profile
603 if (count($profileTypes) == 1) {
604 $profileType = array_pop($profileTypes);
607 //check the there are any components include in profile
608 $componentCount = array();
609 foreach ($components as $value) {
610 if (in_array($value, $profileTypes)) {
611 $componentCount[] = $value;
615 //check contact type included in profile
616 $contactTypeCount = array();
617 foreach ($contactTypes as $value) {
618 if (in_array($value, $profileTypes)) {
619 $contactTypeCount[] = $value;
623 $subTypeCount = array();
624 foreach ($subTypes as $value) {
625 if (in_array($value, $profileTypes)) {
626 $subTypeCount[] = $value;
629 if (!$skipComponentType && count($componentCount) == 1) {
630 $profileType = $componentCount[0];
632 elseif (count($componentCount) > 1) {
633 $mixProfileType = $componentCount[1];
635 elseif (count($subTypeCount) == 1) {
636 $profileType = $subTypeCount[0];
638 elseif (count($contactTypeCount) == 1) {
639 $profileType = $contactTypeCount[0];
641 elseif (count($subTypeCount) > 1) {
642 // this is mix subtype profiles
643 $mixProfileType = $subTypeCount[1];
645 elseif (count($contactTypeCount) > 1) {
646 // this is mix contact profiles
647 $mixProfileType = $contactTypeCount[1];
651 if ($mixProfileType) {
652 if ($returnMixType) {
653 return $mixProfileType;
665 * Check for mix profiles groups (eg: individual + other contact types)
670 * true for mix profile group else false
672 public static function checkProfileGroupType($ctype) {
673 $ufGroup = new CRM_Core_DAO_UFGroup();
677 FROM civicrm_uf_group as ufg, civicrm_uf_join as ufj
678 WHERE ufg.id = ufj.uf_group_id
679 AND ufj.module = 'User Registration'
680 AND ufg.is_active = 1 ";
682 $ufGroup = CRM_Core_DAO
::executeQuery($query);
685 $validProfiles = array('Individual', 'Organization', 'Household', 'Contribution');
686 while ($ufGroup->fetch()) {
687 $profileType = self
::getProfileType($ufGroup->id
);
688 if (in_array($profileType, $validProfiles)) {
691 elseif ($profileType) {
700 * Check for searchable or in selector field for given profile.
702 * @param int $profileID
706 public static function checkSearchableORInSelector($profileID) {
714 From civicrm_uf_field
715 WHERE (in_selector = 1 OR is_searchable = 1)
716 AND uf_group_id = {$profileID}";
718 $ufFields = CRM_Core_DAO
::executeQuery($query);
719 while ($ufFields->fetch()) {
728 * Reset In selector and is searchable values for given $profileID.
730 * @param int $profileID
732 public function resetInSelectorANDSearchable($profileID) {
736 $query = "UPDATE civicrm_uf_field SET in_selector = 0, is_searchable = 0 WHERE uf_group_id = {$profileID}";
737 CRM_Core_DAO
::executeQuery($query);
741 * Add fields to $profileAddressFields as appropriate.
742 * profileAddressFields is assigned to the template to tell it
743 * what fields are in the profile address
744 * that potentially should be copied to the Billing fields
745 * we want to give precedence to
747 * 2) then Primary designated as 'Primary
748 * 3) location_type is primary
749 * 4) if none of these apply then it just uses the first one
751 * as this will be used to
752 * transfer profile address data to billing fields
753 * http://issues.civicrm.org/jira/browse/CRM-5869
756 * Field key - e.g. street_address-Primary, first_name.
757 * @param array $profileAddressFields
758 * Array of profile fields that relate to address fields.
759 * @param array $profileFilter
760 * Filter to apply to profile fields - expected usage is to only fill based on.
761 * the bottom profile per CRM-13726
764 * Can the address block be hidden safe in the knowledge all fields are elsewhere collected (see CRM-15118)
766 public static function assignAddressField($key, &$profileAddressFields, $profileFilter) {
767 $billing_id = CRM_Core_BAO_LocationType
::getBilling();
768 list($prefixName, $index) = CRM_Utils_System
::explode('-', $key, 2);
770 $profileFields = civicrm_api3('uf_field', 'get', array_merge($profileFilter,
773 'return' => 'field_name, is_required',
779 //check for valid fields ( fields that are present in billing block )
780 $validBillingFields = array(
785 'supplemental_address_1',
791 $requiredBillingFields = array_diff($validBillingFields, array('middle_name', 'supplemental_address_1'));
792 $validProfileFields = array();
793 $requiredProfileFields = array();
795 foreach ($profileFields['values'] as $field) {
796 if (in_array($field['field_name'], $validBillingFields)) {
797 $validProfileFields[] = $field['field_name'];
799 if (CRM_Utils_Array
::value('is_required', $field)) {
800 $requiredProfileFields[] = $field['field_name'];
804 if (!in_array($prefixName, $validProfileFields)) {
808 if (!empty($index) && (
809 // it's empty so we set it OR
810 !CRM_Utils_Array
::value($prefixName, $profileAddressFields)
811 //we are dealing with billing id (precedence)
812 ||
$index == $billing_id
813 // we are dealing with primary & billing not set
814 ||
($index == 'Primary' && $profileAddressFields[$prefixName] != $billing_id)
815 ||
($index == CRM_Core_BAO_LocationType
::getDefault()->id
816 && $profileAddressFields[$prefixName] != $billing_id
817 && $profileAddressFields[$prefixName] != 'Primary'
821 $profileAddressFields[$prefixName] = $index;
824 $potentiallyMissingRequiredFields = array_diff($requiredBillingFields, $requiredProfileFields);
825 CRM_Core_Resources
::singleton()
826 ->addSetting(array('billing' => array('billingProfileIsHideable' => empty($potentiallyMissingRequiredFields))));
830 * Get a list of fields which can be added to profiles.
832 * @param int $gid : UF group ID
833 * @param array $defaults : Form defaults
834 * @return array, multidimensional; e.g. $result['FieldGroup']['field_name']['label']
836 public static function getAvailableFields($gid = NULL, $defaults = array()) {
838 'Contact' => array(),
839 'Individual' => CRM_Contact_BAO_Contact
::importableFields('Individual', FALSE, FALSE, TRUE, TRUE, TRUE),
840 'Household' => CRM_Contact_BAO_Contact
::importableFields('Household', FALSE, FALSE, TRUE, TRUE, TRUE),
841 'Organization' => CRM_Contact_BAO_Contact
::importableFields('Organization', FALSE, FALSE, TRUE, TRUE, TRUE),
844 // include hook injected fields
845 $fields['Contact'] = array_merge($fields['Contact'], CRM_Contact_BAO_Query_Hook
::singleton()->getFields());
847 // add current employer for individuals
848 $fields['Individual']['current_employer'] = array(
849 'name' => 'organization_name',
850 'title' => ts('Current Employer'),
853 $addressOptions = CRM_Core_BAO_Setting
::valueOptions(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
854 'address_options', TRUE, NULL, TRUE
857 if (!$addressOptions['county']) {
858 unset($fields['Individual']['county'], $fields['Household']['county'], $fields['Organization']['county']);
861 // break out common contact fields array CRM-3037.
862 // from a UI perspective this makes very little sense
863 foreach ($fields['Individual'] as $key => $value) {
864 if (!empty($fields['Household'][$key]) && !empty($fields['Organization'][$key])) {
865 $fields['Contact'][$key] = $value;
866 unset($fields['Individual'][$key], $fields['Household'][$key], $fields['Organization'][$key]);
870 // Internal field not exposed to forms
871 unset($fields['Contact']['contact_type']);
872 unset($fields['Contact']['master_id']);
874 // convert phone extension in to psedo-field phone + phone extension
876 unset($fields['Contact']['phone_ext']);
878 $fields['Contact']['phone_and_ext'] = array(
879 'name' => 'phone_and_ext',
880 'title' => ts('Phone and Extension'),
881 'hasLocationType' => 1,
884 // include Subtypes For Profile
885 $subTypes = CRM_Contact_BAO_ContactType
::subTypeInfo();
886 foreach ($subTypes as $name => $val) {
887 //custom fields for sub type
888 $subTypeFields = CRM_Core_BAO_CustomField
::getFieldsForImport($name, FALSE, FALSE, FALSE, TRUE, TRUE);
889 if (array_key_exists($val['parent'], $fields)) {
890 $fields[$name] = $fields[$val['parent']] +
$subTypeFields;
893 $fields[$name] = $subTypeFields;
897 if (CRM_Core_Permission
::access('CiviContribute')) {
898 $contribFields = CRM_Contribute_BAO_Contribution
::getContributionFields(FALSE);
899 if (!empty($contribFields)) {
900 unset($contribFields['is_test']);
901 unset($contribFields['is_pay_later']);
902 unset($contribFields['contribution_id']);
903 $contribFields['contribution_note'] = array(
904 'name' => 'contribution_note',
905 'title' => ts('Contribution Note'),
907 $fields['Contribution'] = array_merge($contribFields, self
::getContribBatchEntryFields());
911 if (CRM_Core_Permission
::access('CiviEvent')) {
912 $participantFields = CRM_Event_BAO_Query
::getParticipantFields();
913 if ($participantFields) {
914 // Remove fields not supported by profiles
915 CRM_Utils_Array
::remove($participantFields,
916 'external_identifier',
918 'participant_contact_id',
919 'participant_role_id',
920 'participant_status_id',
921 'participant_is_test',
922 'participant_fee_level',
924 'participant_is_pay_later',
925 'participant_campaign'
927 if (isset($participantFields['participant_campaign_id'])) {
928 $participantFields['participant_campaign_id']['title'] = ts('Campaign');
930 $fields['Participant'] = $participantFields;
934 if (CRM_Core_Permission
::access('CiviMember')) {
935 $membershipFields = CRM_Member_BAO_Membership
::getMembershipFields();
936 // Remove fields not supported by profiles
937 CRM_Utils_Array
::remove($membershipFields,
939 'membership_type_id',
943 'member_is_pay_later'
945 if ($gid && CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $gid, 'name') == 'membership_batch_entry') {
946 $fields['Membership'] = array_merge($membershipFields, self
::getMemberBatchEntryFields());
949 $fields['Membership'] = $membershipFields;
953 if (CRM_Core_Permission
::access('CiviCase')) {
954 $caseFields = CRM_Case_BAO_Query
::getFields(TRUE);
955 $caseFields = array_merge($caseFields, CRM_Core_BAO_CustomField
::getFieldsForImport('Case'));
957 // Remove fields not supported by profiles
958 CRM_Utils_Array
::remove($caseFields,
968 $fields['Case'] = $caseFields;
971 $activityFields = CRM_Activity_BAO_Activity
::getProfileFields();
972 if ($activityFields) {
973 // campaign related fields.
974 if (isset($activityFields['activity_campaign_id'])) {
975 $activityFields['activity_campaign_id']['title'] = ts('Campaign');
977 $fields['Activity'] = $activityFields;
980 $fields['Formatting']['format_free_html_' . rand(1000, 9999)] = array(
981 'name' => 'free_html',
984 'title' => 'Free HTML',
988 foreach ($fields as &$values) {
989 $values = CRM_Utils_Array
::crmArraySortByField($values, 'title');
992 //group selected and unwanted fields list
993 $ufFields = $gid ? CRM_Core_BAO_UFGroup
::getFields($gid, FALSE, NULL, NULL, NULL, TRUE, NULL, TRUE) : array();
994 $groupFieldList = array_merge($ufFields, array(
996 'email_greeting_custom',
997 'postal_greeting_custom',
1001 //unset selected fields
1002 foreach ($groupFieldList as $key => $value) {
1004 unset($fields['Individual'][$value], $fields['Household'][$value], $fields['Organization'][$value]);
1007 if (!empty($defaults['field_name'])
1008 && $defaults['field_name']['0'] == $value['field_type']
1009 && $defaults['field_name']['1'] == $key
1013 unset($fields[$value['field_type']][$key]);
1020 * Get a list of fields which can be added to profiles.
1022 * @param bool $force
1024 * @return array, multidimensional; e.g. $result['field_name']['label']
1026 public static function getAvailableFieldsFlat($force = FALSE) {
1027 // FIXME reset when data model changes
1028 static $result = NULL;
1029 if ($result === NULL ||
$force) {
1030 $fieldTree = self
::getAvailableFields();
1032 foreach ($fieldTree as $field_type => $fields) {
1033 foreach ($fields as $field_name => $field) {
1034 if (!isset($result[$field_name])) {
1035 $field['field_type'] = $field_type;
1036 $result[$field_name] = $field;
1045 * Determine whether the given field_name is valid.
1047 * @param string $fieldName
1050 public static function isValidFieldName($fieldName) {
1051 $availableFields = CRM_Core_BAO_UFField
::getAvailableFieldsFlat();
1052 return isset($availableFields[$fieldName]);
1056 * @return array|null
1058 public static function getContribBatchEntryFields() {
1059 if (self
::$_contriBatchEntryFields === NULL) {
1060 self
::$_contriBatchEntryFields = array(
1061 'send_receipt' => array(
1062 'name' => 'send_receipt',
1063 'title' => ts('Send Receipt'),
1065 'soft_credit' => array(
1066 'name' => 'soft_credit',
1067 'title' => ts('Soft Credit'),
1069 'soft_credit_type' => array(
1070 'name' => 'soft_credit_type',
1071 'title' => ts('Soft Credit Type'),
1073 'product_name' => array(
1074 'name' => 'product_name',
1075 'title' => ts('Premiums'),
1077 'contribution_note' => array(
1078 'name' => 'contribution_note',
1079 'title' => ts('Contribution Note'),
1081 'contribution_soft_credit_pcp_id' => array(
1082 'name' => 'contribution_soft_credit_pcp_id',
1083 'title' => ts('Personal Campaign Page'),
1087 return self
::$_contriBatchEntryFields;
1091 * @return array|null
1093 public static function getMemberBatchEntryFields() {
1094 if (self
::$_memberBatchEntryFields === NULL) {
1095 self
::$_memberBatchEntryFields = array(
1096 'send_receipt' => array(
1097 'name' => 'send_receipt',
1098 'title' => ts('Send Receipt'),
1100 'soft_credit' => array(
1101 'name' => 'soft_credit',
1102 'title' => ts('Soft Credit'),
1104 'product_name' => array(
1105 'name' => 'product_name',
1106 'title' => ts('Premiums'),
1108 'financial_type' => array(
1109 'name' => 'financial_type',
1110 'title' => ts('Financial Type'),
1112 'total_amount' => array(
1113 'name' => 'total_amount',
1114 'title' => ts('Total Amount'),
1116 'receive_date' => array(
1117 'name' => 'receive_date',
1118 'title' => ts('Date Received'),
1120 'payment_instrument' => array(
1121 'name' => 'payment_instrument',
1122 'title' => ts('Payment Method'),
1124 'contribution_status_id' => array(
1125 'name' => 'contribution_status_id',
1126 'title' => ts('Contribution Status'),
1129 'name' => 'contribution_trxn_id',
1130 'title' => ts('Contribution Transaction ID'),
1134 return self
::$_memberBatchEntryFields;