3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
37 * This class contains function for UFField
40 class CRM_Core_BAO_UFField
extends CRM_Core_DAO_UFField
{
45 private static $_contriBatchEntryFields = NULL;
46 private static $_memberBatchEntryFields = NULL;
50 * Takes a bunch of params that are needed to match certain criteria and
51 * retrieves the relevant objects. Typically the valid params are only
52 * contact_id. We'll tweak this function to be more full featured over a period
53 * of time. This is the inverse function of create. It also stores all the retrieved
54 * values in the default array
56 * @param array $params (reference ) an assoc array of name/value pairs
57 * @param array $defaults (reference ) an assoc array to hold the flattened values
59 * @return object CRM_Core_BAO_UFField object
63 static function retrieve(&$params, &$defaults) {
64 return CRM_Core_DAO
::commonRetrieve('CRM_Core_DAO_UFField', $params, $defaults);
70 * @param int $id id of uf_form
72 * @return string title
78 public static function getTitle($id) {
79 return CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFField', $groupId, 'title');
83 * update the is_active flag in the db
85 * @param int $id id of the database record
86 * @param boolean $is_active value we want to set the is_active field
88 * @return Object DAO object on sucess, null otherwise
92 static function setIsActive($id, $is_active) {
93 //check if custom data profile field is disabled
95 if (CRM_Core_BAO_UFField
::checkUFStatus($id)) {
96 return CRM_Core_DAO
::setFieldValue('CRM_Core_DAO_UFField', $id, 'is_active', $is_active);
99 CRM_Core_Session
::setStatus(ts('Cannot enable this UF field since the used custom field is disabled.'), ts('Check Custom Field'), 'error');
103 return CRM_Core_DAO
::setFieldValue('CRM_Core_DAO_UFField', $id, 'is_active', $is_active);
108 * Delete the profile Field.
110 * @param int $id Field Id
118 public static function del($id) {
120 $field = new CRM_Core_DAO_UFField();
127 * Function to check duplicate for duplicate field in a group
129 * @param array $params an associative array with field and values
133 * @ids array $ids array that containd ids
138 public static function duplicateField($params, $ids) {
139 $ufField = new CRM_Core_DAO_UFField();
140 $ufField->uf_group_id
= CRM_Utils_Array
::value('uf_group', $ids);
141 $ufField->field_type
= $params['field_name'][0];
142 $ufField->field_name
= $params['field_name'][1];
143 $ufField->location_type_id
= (CRM_Utils_Array
::value(2, $params['field_name'])) ?
$params['field_name'][2] : 'NULL';
144 $ufField->phone_type_id
= CRM_Utils_Array
::value(3, $params['field_name']);
146 if (CRM_Utils_Array
::value('uf_field', $ids)) {
147 $ufField->whereAdd("id <> " . CRM_Utils_Array
::value('uf_field', $ids));
150 return $ufField->find(TRUE);
154 * Does profile consists of a multi-record custom field
156 public static function checkMultiRecordFieldExists($gId) {
157 $queryString = "SELECT f.field_name
158 FROM civicrm_uf_field f, civicrm_uf_group g
159 WHERE f.uf_group_id = g.id
160 AND g.id = %1 AND f.field_name LIKE 'custom%'";
161 $p = array(1 => array($gId, 'Integer'));
162 $dao = CRM_Core_DAO
::executeQuery($queryString, $p);
163 $customFieldIds = array();
164 $isMultiRecordFieldPresent = FALSE;
165 while ($dao->fetch()) {
166 if ($customId = CRM_Core_BAO_CustomField
::getKeyID($dao->field_name
)) {
167 if (is_numeric($customId)) {
168 $customFieldIds[] = $customId;
173 if (!empty($customFieldIds) && count($customFieldIds) == 1) {
174 $customFieldId = array_pop($customFieldIds);
175 $isMultiRecordFieldPresent = CRM_Core_BAO_CustomField
::isMultiRecordField($customFieldId);
177 elseif (count($customFieldIds) > 1) {
178 $customFieldIds = implode(", ", $customFieldIds);
181 FROM civicrm_custom_group cg
182 INNER JOIN civicrm_custom_field cf
183 ON cg.id = cf.custom_group_id
184 WHERE cf.id IN (" . $customFieldIds . ") AND is_multiple = 1 LIMIT 0,1";
186 $dao = CRM_Core_DAO
::executeQuery($queryString);
188 $isMultiRecordFieldPresent = ($dao->cgId
) ?
$dao->cgId
: FALSE;
192 return $isMultiRecordFieldPresent;
196 * function to add the UF Field
198 * @param array $params (reference) array containing the values submitted by the form
199 * @param array $ids array containing the id
201 * @return object CRM_Core_BAO_UFField object
207 static function add(&$params, $ids = array()) {
208 // set values for uf field properties and save
209 $ufField = new CRM_Core_DAO_UFField();
210 $ufField->field_type
= $params['field_name'][0];
211 $ufField->field_name
= $params['field_name'][1];
213 //should not set location type id for Primary
214 $locationTypeId = CRM_Utils_Array
::value(2, $params['field_name']);
215 if ($locationTypeId) {
216 $ufField->location_type_id
= $locationTypeId;
219 $ufField->location_type_id
= 'null';
222 $ufField->phone_type_id
= CRM_Utils_Array
::value(3, $params['field_name'], 'NULL');
223 $ufField->listings_title
= CRM_Utils_Array
::value('listings_title', $params);
224 $ufField->visibility
= CRM_Utils_Array
::value('visibility', $params);
225 $ufField->help_pre
= CRM_Utils_Array
::value('help_pre', $params);
226 $ufField->help_post
= CRM_Utils_Array
::value('help_post', $params);
227 $ufField->label
= CRM_Utils_Array
::value('label', $params);
228 $ufField->is_required
= CRM_Utils_Array
::value('is_required', $params, FALSE);
229 $ufField->is_active
= CRM_Utils_Array
::value('is_active', $params, FALSE);
230 $ufField->in_selector
= CRM_Utils_Array
::value('in_selector', $params, FALSE);
231 $ufField->is_view
= CRM_Utils_Array
::value('is_view', $params, FALSE);
232 $ufField->is_registration
= CRM_Utils_Array
::value('is_registration', $params, FALSE);
233 $ufField->is_match
= CRM_Utils_Array
::value('is_match', $params, FALSE);
234 $ufField->is_searchable
= CRM_Utils_Array
::value('is_searchable', $params, FALSE);
235 $ufField->is_multi_summary
= CRM_Utils_Array
::value('is_multi_summary', $params, FALSE);
236 $ufField->weight
= CRM_Utils_Array
::value('weight', $params, 0);
238 // need the FKEY - uf group id
239 $ufField->uf_group_id
= CRM_Utils_Array
::value('uf_group', $ids, FALSE);
240 $ufField->id
= CRM_Utils_Array
::value('uf_field', $ids, FALSE);
242 return $ufField->save();
246 * Automatically determine one weight and modify others
248 * @param array $params UFField record, e.g. with 'weight', 'uf_group_id', and 'field_id'
251 public static function autoWeight($params) {
255 if (CRM_Utils_Array
::value('field_id', $params)) {
256 $oldWeight = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFField', $params['field_id'], 'weight', 'id');
258 $fieldValues = array('uf_group_id' => $params['group_id']);
259 return CRM_Utils_Weight
::updateOtherWeights('CRM_Core_DAO_UFField', $oldWeight, CRM_Utils_Array
::value('weight', $params, 0), $fieldValues);
263 * Function to enable/disable profile field given a custom field id
265 * @param int $customFieldId custom field id
266 * @param boolean $is_active set the is_active field
272 static function setUFField($customFieldId, $is_active) {
273 //find the profile id given custom field
274 $ufField = new CRM_Core_DAO_UFField();
275 $ufField->field_name
= "custom_" . $customFieldId;
278 while ($ufField->fetch()) {
279 //enable/ disable profile
280 CRM_Core_BAO_UFField
::setIsActive($ufField->id
, $is_active);
285 * Function to copy existing profile fields to
286 * new profile from the already built profile
288 * @param int $old_id from which we need to copy
289 * @param boolean $new_id in which to copy
295 static function copy($old_id, $new_id) {
296 $ufField = new CRM_Core_DAO_UFField();
297 $ufField->uf_group_id
= $old_id;
299 while ($ufField->fetch()) {
300 //copy the field records as it is on new ufgroup id
301 $ufField->uf_group_id
= $new_id;
308 * Function to delete profile field given a custom field
310 * @param int $customFieldId ID of the custom field to be deleted
317 static function delUFField($customFieldId) {
318 //find the profile id given custom field id
319 $ufField = new CRM_Core_DAO_UFField();
320 $ufField->field_name
= "custom_" . $customFieldId;
323 while ($ufField->fetch()) {
324 //enable/ disable profile
325 CRM_Core_BAO_UFField
::del($ufField->id
);
330 * Function to enable/disable profile field given a custom group id
332 * @param int $customGroupId custom group id
333 * @param boolean $is_active value we want to set the is_active field
339 function setUFFieldStatus($customGroupId, $is_active) {
340 //find the profile id given custom group id
341 $queryString = "SELECT civicrm_custom_field.id as custom_field_id
342 FROM civicrm_custom_field, civicrm_custom_group
343 WHERE civicrm_custom_field.custom_group_id = civicrm_custom_group.id
344 AND civicrm_custom_group.id = %1";
345 $p = array(1 => array($customGroupId, 'Integer'));
346 $dao = CRM_Core_DAO
::executeQuery($queryString, $p);
348 while ($dao->fetch()) {
349 //enable/ disable profile
350 CRM_Core_BAO_UFField
::setUFField($dao->custom_field_id
, $is_active);
355 * Function to check the status of custom field used in uf fields
357 * @params int $UFFieldId uf field id
361 * @return boolean false if custom field are disabled else true
365 static function checkUFStatus($UFFieldId) {
366 $fieldName = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFField', $UFFieldId, 'field_name');
367 // return if field is not a custom field
368 if (!$customFieldId = CRM_Core_BAO_CustomField
::getKeyID($fieldName)) {
372 $customField = new CRM_Core_DAO_CustomField();
373 $customField->id
= $customFieldId;
374 // if uf field is custom field
375 if ($customField->find(TRUE)) {
376 if (!$customField->is_active
) {
386 * Function to find out whether given profile group using Activity
387 * Profile fields with contact fields
389 static function checkContactActivityProfileType($ufGroupId) {
390 $ufGroup = new CRM_Core_DAO_UFGroup();
391 $ufGroup->id
= $ufGroupId;
392 $ufGroup->find(TRUE);
394 return self
::checkContactActivityProfileTypeByGroupType($ufGroup->group_type
);
399 * @param $ufGroupType
402 public static function checkContactActivityProfileTypeByGroupType($ufGroupType) {
403 $profileTypes = array();
405 $typeParts = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $ufGroupType);
406 $profileTypes = explode(',', $typeParts[0]);
409 if (empty($profileTypes)) {
412 $components = array('Contribution', 'Participant', 'Membership');
413 if (!in_array('Activity', $profileTypes)) {
416 elseif (count($profileTypes) == 1) {
420 if ($index = array_search('Contact', $profileTypes)) {
421 unset($profileTypes[$index]);
422 if (count($profileTypes) == 1) {
427 $contactTypes = array('Individual', 'Household', 'Organization');
428 $subTypes = CRM_Contact_BAO_ContactType
::subTypes();
430 $profileTypeComponent = array_intersect($components, $profileTypes);
431 if (!empty($profileTypeComponent) ||
432 count(array_intersect($contactTypes, $profileTypes)) > 1 ||
433 count(array_intersect($subTypes, $profileTypes)) > 1
442 * Function to find out whether given profile group uses $required
443 * and/or $optional profile types
445 * @param integer $ufGroupId profile id
446 * @param array $required array of types those are required
447 * @param array $optional array of types those are optional
449 * @return boolean $valid
452 static function checkValidProfileType($ufGroupId, $required, $optional = NULL) {
453 if (!is_array($required) ||
empty($required)) {
457 $ufGroup = new CRM_Core_DAO_UFGroup();
458 $ufGroup->id
= $ufGroupId;
459 $ufGroup->find(TRUE);
461 $profileTypes = array();
462 if ($ufGroup->group_type
) {
463 $typeParts = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $ufGroup->group_type
);
464 $profileTypes = explode(',', $typeParts[0]);
467 if (empty($profileTypes)) {
472 foreach ($required as $key => $val) {
473 if (!in_array($val, $profileTypes)) {
479 if ($valid && is_array($optional)) {
480 foreach ($optional as $key => $val) {
481 if (in_array($val, $profileTypes)) {
492 * function to check for mix profile fields (eg: individual + other contact types)
494 * @params int $ufGroupId uf group id
495 * @params boolean $check this is to check mix profile (if true it will check if profile is
496 * pure ie. it contains only one contact type)
500 * @return true for mix profile else false
504 static function checkProfileType($ufGroupId) {
505 $ufGroup = new CRM_Core_DAO_UFGroup();
506 $ufGroup->id
= $ufGroupId;
507 $ufGroup->find(TRUE);
509 $profileTypes = array();
510 if ($ufGroup->group_type
) {
511 $typeParts = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $ufGroup->group_type
);
512 $profileTypes = explode(',', $typeParts[0]);
515 //early return if new profile.
516 if (empty($profileTypes)) {
520 //we need to unset Contact
521 if (count($profileTypes) > 1) {
522 $index = array_search('Contact', $profileTypes);
523 if ($index !== FALSE) {
524 unset($profileTypes[$index]);
528 // suppress any subtypes if present
529 CRM_Contact_BAO_ContactType
::suppressSubTypes($profileTypes);
531 $contactTypes = array('Contact', 'Individual', 'Household', 'Organization');
532 $components = array('Contribution', 'Participant', 'Membership', 'Activity');
535 // check for mix profile condition
536 if (count($profileTypes) > 1) {
537 //check the there are any components include in profile
538 foreach ($components as $value) {
539 if (in_array($value, $profileTypes)) {
543 //check if there are more than one contact types included in profile
544 if (count($profileTypes) > 1) {
548 elseif (count($profileTypes) == 1) {
549 // note for subtype case count would be zero
550 $profileTypes = array_values($profileTypes);
551 if (!in_array($profileTypes[0], $contactTypes)) {
560 * function to get the profile type (eg: individual/organization/household)
562 * @param int $ufGroupId uf group id
563 * @param boolean $returnMixType this is true, then field type of mix profile field is returned
564 * @param boolean $onlyPure true if only pure profiles are required
566 * @param bool $skipComponentType
568 * @return profile group_type
572 * TODO Why is this function in this class? It seems to be about the UFGroup.
574 static function getProfileType($ufGroupId, $returnMixType = TRUE, $onlyPure = FALSE, $skipComponentType = FALSE) {
575 $ufGroup = new CRM_Core_DAO_UFGroup();
576 $ufGroup->id
= $ufGroupId;
577 $ufGroup->is_active
= 1;
579 $ufGroup->find(TRUE);
580 return self
::calculateProfileType($ufGroup->group_type
, $returnMixType, $onlyPure, $skipComponentType);
584 * function to get the profile type (eg: individual/organization/household)
586 * @param $ufGroupType
587 * @param boolean $returnMixType this is true, then field type of mix profile field is returned
588 * @param boolean $onlyPure true if only pure profiles are required
590 * @param bool $skipComponentType
592 * @internal param int $ufGroupId uf group id
593 * @return profile group_type
597 * TODO Why is this function in this class? It seems to be about the UFGroup.
599 public static function calculateProfileType($ufGroupType, $returnMixType = TRUE, $onlyPure = FALSE, $skipComponentType= FALSE) {
601 $contactTypes = array('Contact', 'Individual', 'Household', 'Organization');
602 $subTypes = CRM_Contact_BAO_ContactType
::subTypes();
603 $components = array('Contribution', 'Participant', 'Membership', 'Activity');
605 $profileTypes = array();
607 $typeParts = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $ufGroupType);
608 $profileTypes = explode(',', $typeParts[0]);
612 if (count($profileTypes) == 1) {
613 return $profileTypes[0];
620 //we need to unset Contact
621 if (count($profileTypes) > 1) {
622 $index = array_search('Contact', $profileTypes);
623 if ($index !== FALSE) {
624 unset($profileTypes[$index]);
628 $profileType = $mixProfileType = NULL;
630 // this case handles pure profile
631 if (count($profileTypes) == 1) {
632 $profileType = array_pop($profileTypes);
635 //check the there are any components include in profile
636 $componentCount = array();
637 foreach ($components as $value) {
638 if (in_array($value, $profileTypes)) {
639 $componentCount[] = $value;
643 //check contact type included in profile
644 $contactTypeCount = array();
645 foreach ($contactTypes as $value) {
646 if (in_array($value, $profileTypes)) {
647 $contactTypeCount[] = $value;
651 $subTypeCount = array();
652 foreach ($subTypes as $value) {
653 if (in_array($value, $profileTypes)) {
654 $subTypeCount[] = $value;
657 if (!$skipComponentType && count($componentCount) == 1) {
658 $profileType = $componentCount[0];
660 elseif (count($componentCount) > 1) {
661 $mixProfileType = $componentCount[1];
663 elseif (count($subTypeCount) == 1) {
664 $profileType = $subTypeCount[0];
666 elseif (count($contactTypeCount) == 1) {
667 $profileType = $contactTypeCount[0];
669 elseif (count($subTypeCount) > 1) {
670 // this is mix subtype profiles
671 $mixProfileType = $subTypeCount[1];
673 elseif (count($contactTypeCount) > 1) {
674 // this is mix contact profiles
675 $mixProfileType = $contactTypeCount[1];
679 if ($mixProfileType) {
680 if ($returnMixType) {
681 return $mixProfileType;
693 * function to check for mix profiles groups (eg: individual + other contact types)
697 * @return true for mix profile group else false
701 static function checkProfileGroupType($ctype) {
702 $ufGroup = new CRM_Core_DAO_UFGroup();
706 FROM civicrm_uf_group as ufg, civicrm_uf_join as ufj
707 WHERE ufg.id = ufj.uf_group_id
708 AND ufj.module = 'User Registration'
709 AND ufg.is_active = 1 ";
711 $ufGroup = CRM_Core_DAO
::executeQuery($query);
714 $validProfiles = array('Individual', 'Organization', 'Household', 'Contribution');
715 while ($ufGroup->fetch()) {
716 $profileType = self
::getProfileType($ufGroup->id
);
717 if (in_array($profileType, $validProfiles)) {
720 elseif ($profileType) {
729 * check for searchable or in selector field for given profile.
731 * @params int $profileID profile id.
735 * @return boolean $result true/false.
737 static function checkSearchableORInSelector($profileID) {
745 From civicrm_uf_field
746 WHERE (in_selector = 1 OR is_searchable = 1)
747 AND uf_group_id = {$profileID}";
749 $ufFields = CRM_Core_DAO
::executeQuery($query);
750 while ($ufFields->fetch()) {
759 *Reset In selector and is seachable values for given $profileID.
761 * @params int $profileID profile id.
767 function resetInSelectorANDSearchable($profileID) {
771 $query = "UPDATE civicrm_uf_field SET in_selector = 0, is_searchable = 0 WHERE uf_group_id = {$profileID}";
772 CRM_Core_DAO
::executeQuery($query);
776 * Add fields to $profileAddressFields as appropriate.
777 * profileAddressFields is assigned to the template to tell it
778 * what fields are in the profile address
779 * that potentially should be copied to the Billing fields
780 * we want to give precedence to
782 * 2) then Primary designated as 'Primary
783 * 3) location_type is primary
784 * 4) if none of these apply then it just uses the first one
786 * as this will be used to
787 * transfer profile address data to billing fields
788 * http://issues.civicrm.org/jira/browse/CRM-5869
790 * @param string $key Field key - e.g. street_address-Primary, first_name
791 * @param $profileAddressFields
792 * @params array $profileAddressFields array of profile fields that relate to address fields
794 static function assignAddressField($key, &$profileAddressFields) {
795 $billing_id = CRM_Core_BAO_LocationType
::getBilling();
796 list($prefixName, $index) = CRM_Utils_System
::explode('-', $key, 2);
798 //check for valid fields ( fields that are present in billing block )
799 $validBillingFields = array(
804 'supplemental_address_1',
811 if (!in_array($prefixName, $validBillingFields)) {
815 if (!empty($index) && (
816 // it's empty so we set it OR
817 !CRM_Utils_array
::value($prefixName, $profileAddressFields)
818 //we are dealing with billing id (precedence)
819 ||
$index == $billing_id
820 // we are dealing with primary & billing not set
821 ||
($index == 'Primary' && $profileAddressFields[$prefixName] != $billing_id)
822 ||
($index == CRM_Core_BAO_LocationType
::getDefault()->id
823 && $profileAddressFields[$prefixName] != $billing_id
824 && $profileAddressFields[$prefixName] != 'Primary'
828 $profileAddressFields[$prefixName] = $index;
833 * Get a list of fields which can be added to profiles
835 * @param int $gid: UF group ID
836 * @param array $defaults: Form defaults
837 * @return array, multidimensional; e.g. $result['FieldGroup']['field_name']['label']
840 public static function getAvailableFields($gid = NULL, $defaults = array()) {
842 'Contact' => array(),
843 'Individual' => CRM_Contact_BAO_Contact
::importableFields('Individual', FALSE, FALSE, TRUE, TRUE, TRUE),
844 'Household' => CRM_Contact_BAO_Contact
::importableFields('Household', FALSE, FALSE, TRUE, TRUE, TRUE),
845 'Organization' => CRM_Contact_BAO_Contact
::importableFields('Organization', FALSE, FALSE, TRUE, TRUE, TRUE),
848 // include hook injected fields
849 $fields['Contact'] = array_merge($fields['Contact'], CRM_Contact_BAO_Query_Hook
::singleton()->getFields());
851 // add current employer for individuals
852 $fields['Individual']['current_employer'] = array(
853 'name' => 'organization_name',
854 'title' => ts('Current Employer'),
857 $addressOptions = CRM_Core_BAO_Setting
::valueOptions(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
858 'address_options', TRUE, NULL, TRUE
861 if (!$addressOptions['county']) {
862 unset($fields['Individual']['county'], $fields['Household']['county'], $fields['Organization']['county']);
865 // break out common contact fields array CRM-3037.
866 // from a UI perspective this makes very little sense
867 foreach ($fields['Individual'] as $key => $value) {
868 if (!empty($fields['Household'][$key]) && !empty($fields['Organization'][$key])) {
869 $fields['Contact'][$key] = $value;
870 unset($fields['Individual'][$key], $fields['Household'][$key], $fields['Organization'][$key]);
874 // Internal field not exposed to forms
875 unset($fields['Contact']['contact_type']);
876 unset($fields['Contact']['master_id']);
878 // convert phone extension in to psedo-field phone + phone extension
880 unset($fields['Contact']['phone_ext']);
882 $fields['Contact']['phone_and_ext'] = array(
883 'name' => 'phone_and_ext',
884 'title' => ts('Phone and Extension'),
885 'hasLocationType' => 1,
888 // include Subtypes For Profile
889 $subTypes = CRM_Contact_BAO_ContactType
::subTypeInfo();
890 foreach ($subTypes as $name => $val) {
891 //custom fields for sub type
892 $subTypeFields = CRM_Core_BAO_CustomField
::getFieldsForImport($name, FALSE, FALSE, FALSE, TRUE, TRUE);
893 if (array_key_exists($val['parent'], $fields)) {
894 $fields[$name] = $fields[$val['parent']] +
$subTypeFields;
897 $fields[$name] = $subTypeFields;
901 if (CRM_Core_Permission
::access('CiviContribute')) {
902 $contribFields = CRM_Contribute_BAO_Contribution
::getContributionFields(FALSE);
903 if (!empty($contribFields)) {
904 unset($contribFields['is_test']);
905 unset($contribFields['is_pay_later']);
906 unset($contribFields['contribution_id']);
907 $contribFields['contribution_note'] = array(
908 'name' => 'contribution_note',
909 'title' => ts('Contribution Note'),
911 if ($gid && CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $gid, 'name') == 'contribution_batch_entry') {
912 $fields['Contribution'] = array_merge($contribFields, self
::getContribBatchEntryFields());
915 $fields['Contribution'] = $contribFields;
920 if (CRM_Core_Permission
::access('CiviEvent')) {
921 $participantFields = CRM_Event_BAO_Query
::getParticipantFields();
922 if ($participantFields) {
923 // Remove fields not supported by profiles
924 CRM_Utils_Array
::remove($participantFields,
925 'external_identifier',
927 'participant_contact_id',
928 'participant_role_id',
929 'participant_status_id',
930 'participant_is_test',
931 'participant_fee_level',
933 'participant_is_pay_later',
934 'participant_campaign'
936 if (isset($participantFields['participant_campaign_id'])) {
937 $participantFields['participant_campaign_id']['title'] = ts('Campaign');
939 $fields['Participant'] = $participantFields;
943 if (CRM_Core_Permission
::access('CiviMember')) {
944 $membershipFields = CRM_Member_BAO_Membership
::getMembershipFields();
945 // Remove fields not supported by profiles
946 CRM_Utils_Array
::remove($membershipFields,
948 'membership_type_id',
952 'member_is_pay_later'
954 if ($gid && CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $gid, 'name') == 'membership_batch_entry') {
955 $fields['Membership'] = array_merge($membershipFields, self
::getMemberBatchEntryFields());
958 $fields['Membership'] = $membershipFields;
962 $activityFields = CRM_Activity_BAO_Activity
::getProfileFields();
963 if ($activityFields) {
964 // campaign related fields.
965 if (isset($activityFields['activity_campaign_id'])) {
966 $activityFields['activity_campaign_id']['title'] = ts('Campaign');
968 $fields['Activity'] = $activityFields;
971 $fields['Formatting']['format_free_html_' . rand(1000, 9999)] = array(
972 'name' => 'free_html',
975 'title' => 'Free HTML',
979 foreach ($fields as &$values) {
980 $values = CRM_Utils_Array
::crmArraySortByField($values, 'title');
983 //group selected and unwanted fields list
984 $ufFields = $gid ? CRM_Core_BAO_UFGroup
::getFields($gid, FALSE, NULL, NULL, NULL, TRUE, NULL, TRUE) : array();
985 $groupFieldList = array_merge($ufFields, array(
987 'email_greeting_custom',
988 'postal_greeting_custom',
992 //unset selected fields
993 foreach ($groupFieldList as $key => $value) {
994 if (is_integer($key)) {
995 unset($fields['Individual'][$value], $fields['Household'][$value], $fields['Organization'][$value]);
998 if (!empty($defaults['field_name'])
999 && $defaults['field_name']['0'] == $value['field_type']
1000 && $defaults['field_name']['1'] == $key
1004 unset($fields[$value['field_type']][$key]);
1011 * Get a list of fields which can be added to profiles
1013 * @param bool $force
1015 * @return array, multidimensional; e.g. $result['field_name']['label']
1018 public static function getAvailableFieldsFlat($force = FALSE) {
1019 // FIXME reset when data model changes
1020 static $result = NULL;
1021 if ($result === NULL ||
$force) {
1022 $fieldTree = self
::getAvailableFields();
1024 foreach ($fieldTree as $field_type => $fields) {
1025 foreach ($fields as $field_name => $field) {
1026 if (!isset($result[$field_name])) {
1027 $field['field_type'] = $field_type;
1028 $result[$field_name] = $field;
1037 * Determine whether the given field_name is valid
1039 * @param string $fieldName
1042 static function isValidFieldName($fieldName) {
1043 $availableFields = CRM_Core_BAO_UFField
::getAvailableFieldsFlat();
1044 return isset($availableFields[$fieldName]);
1047 static function getContribBatchEntryFields() {
1048 if (self
::$_contriBatchEntryFields === NULL) {
1049 self
::$_contriBatchEntryFields = array(
1050 'send_receipt' => array(
1051 'name' => 'send_receipt',
1052 'title' => ts('Send Receipt'),
1054 'soft_credit' => array(
1055 'name' => 'soft_credit',
1056 'title' => ts('Soft Credit'),
1058 'product_name' => array(
1059 'name' => 'product_name',
1060 'title' => ts('Premiums'),
1062 'contribution_note' => array(
1063 'name' => 'contribution_note',
1064 'title' => ts('Contribution Note'),
1068 return self
::$_contriBatchEntryFields;
1071 public static function getMemberBatchEntryFields() {
1072 if (self
::$_memberBatchEntryFields === NULL) {
1073 self
::$_memberBatchEntryFields = array(
1074 'send_receipt' => array(
1075 'name' => 'send_receipt',
1076 'title' => ts('Send Receipt'),
1078 'soft_credit' => array(
1079 'name' => 'soft_credit',
1080 'title' => ts('Soft Credit'),
1082 'product_name' => array(
1083 'name' => 'product_name',
1084 'title' => ts('Premiums'),
1086 'financial_type' => array(
1087 'name' => 'financial_type',
1088 'title' => ts('Financial Type'),
1090 'total_amount' => array(
1091 'name' => 'total_amount',
1092 'title' => ts('Total Amount'),
1094 'receive_date' => array(
1095 'name' => 'receive_date',
1096 'title' => ts('Receive Date'),
1098 'payment_instrument' => array(
1099 'name' => 'payment_instrument',
1100 'title' => ts('Payment Instrument'),
1102 'contribution_status_id' => array(
1103 'name' => 'contribution_status_id',
1104 'title' => ts('Contribution Status'),
1108 return self
::$_memberBatchEntryFields;