Пример #1
0
 /**
  * Pre processing work done here.
  *
  * gets session variables for group or field id
  *
  * @return void
  */
 public function preProcess()
 {
     // get the controller vars
     $this->_groupId = $this->get('groupId');
     $this->_fieldId = $this->get('fieldId');
     if ($this->_fieldId) {
         // field preview
         $defaults = array();
         $params = array('id' => $this->_fieldId);
         $fieldDAO = new CRM_Core_DAO_CustomField();
         CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $params, $defaults);
         if (!empty($defaults['is_view'])) {
             CRM_Core_Error::statusBounce(ts('This field is view only so it will not display on edit form.'));
         } elseif (CRM_Utils_Array::value('is_active', $defaults) == 0) {
             CRM_Core_Error::statusBounce(ts('This field is inactive so it will not display on edit form.'));
         }
         $groupTree = array();
         $groupTree[$this->_groupId]['id'] = 0;
         $groupTree[$this->_groupId]['fields'] = array();
         $groupTree[$this->_groupId]['fields'][$this->_fieldId] = $defaults;
         $this->_groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $this);
         $this->assign('preview_type', 'field');
     } else {
         $groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail($this->_groupId);
         $this->_groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, TRUE, $this);
         $this->assign('preview_type', 'group');
     }
 }
 static function preProcess(&$form, $subName = NULL, $subType = NULL, $groupCount = NULL, $type = NULL, $entityID = NULL)
 {
     if ($type) {
         $form->_type = $type;
     } else {
         $form->_type = CRM_Utils_Request::retrieve('type', 'String', $form);
     }
     if (isset($subType)) {
         $form->_subType = $subType;
     } else {
         $form->_subType = CRM_Utils_Request::retrieve('subType', 'String', $form);
     }
     if ($form->_subType == 'null') {
         $form->_subType = NULL;
     }
     if (isset($subName)) {
         $form->_subName = $subName;
     } else {
         $form->_subName = CRM_Utils_Request::retrieve('subName', 'String', $form);
     }
     if ($form->_subName == 'null') {
         $form->_subName = NULL;
     }
     if ($groupCount) {
         $form->_groupCount = $groupCount;
     } else {
         $form->_groupCount = CRM_Utils_Request::retrieve('cgcount', 'Positive', $form);
     }
     $form->assign('cgCount', $form->_groupCount);
     //carry qf key, since this form is not inhereting core form.
     if ($qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject)) {
         $form->assign('qfKey', $qfKey);
     }
     if ($entityID) {
         $form->_entityId = $entityID;
     } else {
         $form->_entityId = CRM_Utils_Request::retrieve('entityID', 'Positive', $form);
     }
     $form->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $form);
     $subType = $form->_subType;
     if (!is_array($subType) && strstr($subType, CRM_Core_DAO::VALUE_SEPARATOR)) {
         $subType = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ',', trim($subType, CRM_Core_DAO::VALUE_SEPARATOR));
     }
     $groupTree =& CRM_Core_BAO_CustomGroup::getTree($form->_type, $form, $form->_entityId, $form->_groupID, $subType, $form->_subName);
     // we should use simplified formatted groupTree
     $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, $form->_groupCount, $form);
     if (isset($form->_groupTree) && is_array($form->_groupTree)) {
         $keys = array_keys($groupTree);
         foreach ($keys as $key) {
             $form->_groupTree[$key] = $groupTree[$key];
         }
     } else {
         $form->_groupTree = $groupTree;
     }
 }
Пример #3
0
 static function preProcess(&$form, $subName = null, $subType = null, $groupCount = null, $type = null, $entityID = null)
 {
     if ($type) {
         $form->_type = $type;
     } else {
         $form->_type = CRM_Utils_Request::retrieve('type', 'String', $form);
     }
     if (isset($subType)) {
         $form->_subType = $subType;
     } else {
         $form->_subType = CRM_Utils_Request::retrieve('subType', 'String', $form);
     }
     if ($form->_subType == 'null') {
         $form->_subType = null;
     }
     if (isset($subName)) {
         $form->_subName = $subName;
     } else {
         $form->_subName = CRM_Utils_Request::retrieve('subName', 'String', $form);
     }
     if ($form->_subName == 'null') {
         $form->_subName = null;
     }
     if ($groupCount) {
         $form->_groupCount = $groupCount;
     } else {
         $form->_groupCount = CRM_Utils_Request::retrieve('cgcount', 'Positive', $form);
     }
     $form->assign('cgCount', $form->_groupCount);
     if ($entityID) {
         $form->_entityId = $entityID;
     } else {
         $form->_entityId = CRM_Utils_Request::retrieve('entityID', 'Positive', $form);
     }
     $form->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $form);
     $groupTree =& CRM_Core_BAO_CustomGroup::getTree($form->_type, $form, $form->_entityId, $form->_groupID, $form->_subType, $form->_subName);
     // we should use simplified formatted groupTree
     $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, $form->_groupCount, $form);
     if (isset($form->_groupTree) && is_array($form->_groupTree)) {
         $keys = array_keys($groupTree);
         foreach ($keys as $key) {
             $form->_groupTree[$key] = $groupTree[$key];
         }
     } else {
         $form->_groupTree = $groupTree;
     }
 }
Пример #4
0
 /**
  * Class constructor.
  *
  * @param array $formValues
  */
 public function __construct(&$formValues)
 {
     $this->_formValues = $formValues;
     /**
      * Define the columns for search result rows
      */
     $this->_columns = array(ts('Name') => 'sort_name', ts('Status') => 'activity_status', ts('Activity Type') => 'activity_type', ts('Activity Subject') => 'activity_subject', ts('Scheduled By') => 'source_contact', ts('Scheduled Date') => 'activity_date', ' ' => 'activity_id', '  ' => 'activity_type_id', '   ' => 'case_id', ts('Location') => 'location', ts('Duration') => 'duration', ts('Details') => 'details', ts('Assignee') => 'assignee');
     $this->_groupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'activity_status', 'id', 'name');
     //Add custom fields to columns array for inclusion in export
     $groupTree = CRM_Core_BAO_CustomGroup::getTree('Activity');
     //use simplified formatted groupTree
     $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree);
     //cycle through custom fields and assign to _columns array
     foreach ($groupTree as $key) {
         foreach ($key['fields'] as $field) {
             $fieldlabel = $key['title'] . ": " . $field['label'];
             $this->_columns[$fieldlabel] = $field['column_name'];
         }
     }
 }
 /**
  * pre processing work done here.
  *
  * gets session variables for table name, id of entity in table, type of entity and stores them.
  *
  * @param
  *
  * @return void
  *
  * @access public
  *
  */
 function preProcess()
 {
     $this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this, TRUE);
     $this->_entityID = CRM_Utils_Request::retrieve('entityID', 'Positive', $this, TRUE);
     $this->_subTypeID = CRM_Utils_Request::retrieve('subType', 'Positive', $this, TRUE);
     $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
     $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Case', $this, $this->_entityID, $this->_groupID, $this->_subTypeID);
     // simplified formatted groupTree
     $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $this);
     foreach ($groupTree as $groupValues) {
         $this->_customTitle = $groupValues['title'];
     }
     $this->_defaults = array();
     CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $this->_defaults);
     $this->setDefaults($this->_defaults);
     CRM_Core_BAO_CustomGroup::buildQuickForm($this, $groupTree, FALSE, 1);
     //need to assign custom data type and subtype to the template
     $this->assign('entityID', $this->_entityID);
     $this->assign('groupID', $this->_groupID);
     $this->assign('subType', $this->_subTypeID);
     $this->assign('contactID', $this->_contactID);
 }
Пример #6
0
 /**
  * Set the default form values.
  *
  *
  * @return array
  *   the default array reference
  */
 public function setDefaultValues()
 {
     if ($this->_cdType || $this->_multiRecordDisplay == 'single') {
         if ($this->_copyValueId) {
             // cached tree is fetched
             $groupTree = CRM_Core_BAO_CustomGroup::getTree($this->_type, $this, $this->_entityId, $this->_groupID);
             $valueIdDefaults = array();
             $groupTreeValueId = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, $this->_copyValueId, $this);
             CRM_Core_BAO_CustomGroup::setDefaults($groupTreeValueId, $valueIdDefaults, FALSE, FALSE, $this->get('action'));
             $tableId = $groupTreeValueId[$this->_groupID]['table_id'];
             foreach ($valueIdDefaults as $valueIdElementName => $value) {
                 // build defaults for COPY action for new record saving
                 $valueIdElementNamePieces = explode('_', $valueIdElementName);
                 $valueIdElementNamePieces[2] = "-{$this->_groupCount}";
                 $elementName = implode('_', $valueIdElementNamePieces);
                 $customDefaultValue[$elementName] = $value;
             }
         } else {
             $customDefaultValue = CRM_Custom_Form_CustomData::setDefaultValues($this);
         }
         return $customDefaultValue;
     }
     $groupTree = CRM_Core_BAO_CustomGroup::getTree($this->_contactType, $this, $this->_tableID, $this->_groupID, $this->_contactSubType);
     if (empty($_POST['hidden_custom_group_count'])) {
         // custom data building in edit mode (required to handle multi-value)
         $groupTree = CRM_Core_BAO_CustomGroup::getTree($this->_contactType, $this, $this->_tableID, $this->_groupID, $this->_contactSubType);
         $customValueCount = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, TRUE, $this->_groupID, NULL, NULL, $this->_tableID);
     } else {
         $customValueCount = $_POST['hidden_custom_group_count'][$this->_groupID];
     }
     $this->assign('customValueCount', $customValueCount);
     $defaults = array();
     return $defaults;
 }
Пример #7
0
 /**
  * This function is used to setDefault componet specific profile fields.
  * 
  * @param array  $fields      profile fields.
  * @param int    $componentId componetID
  * @param string $component   component name
  * @param array  $defaults    an array of default values.
  *
  * @return void.
  */
 function setComponentDefaults(&$fields, $componentId, $component, &$defaults)
 {
     if (!$componentId || !in_array($component, array('Contribute', 'Membership', 'Event'))) {
         return;
     }
     $componentBAO = $componentSubType = null;
     switch ($component) {
         case 'Membership':
             $componentBAO = 'CRM_Member_BAO_Membership';
             $componentBAOName = 'Membership';
             $componentSubType = array('membership_type_id');
             break;
         case 'Contribute':
             $componentBAO = 'CRM_Contribute_BAO_Contribution';
             $componentBAOName = 'Contribution';
             $componentSubType = array('contribution_type_id');
             break;
         case 'Event':
             $componentBAO = 'CRM_Event_BAO_Participant';
             $componentBAOName = 'Participant';
             $componentSubType = array('role_id', 'event_id');
             break;
     }
     $values = array();
     $params = array('id' => $componentId);
     //get the component values.
     CRM_Core_DAO::commonRetrieve($componentBAO, $params, $values);
     $formattedGroupTree = array();
     foreach ($fields as $name => $field) {
         $fldName = "field[{$componentId}][{$name}]";
         if ($name == 'participant_register_date') {
             $timefldName = "field[{$componentId}][{$name}_time]";
             list($defaults[$fldName], $defaults[$timefldName]) = CRM_Utils_Date::setDateDefaults($values[$name]);
         } else {
             if (array_key_exists($name, $values)) {
                 $defaults[$fldName] = $values[$name];
             } else {
                 if ($name == 'participant_note') {
                     require_once "CRM/Core/BAO/Note.php";
                     $noteDetails = array();
                     $noteDetails = CRM_Core_BAO_Note::getNote($componentId, 'civicrm_participant');
                     $defaults[$fldName] = array_pop($noteDetails);
                 } else {
                     if (in_array($name, array('contribution_type', 'payment_instrument'))) {
                         $defaults[$fldName] = $values["{$name}_id"];
                     } else {
                         if ($customFieldInfo = CRM_Core_BAO_CustomField::getKeyID($name, true)) {
                             if (empty($formattedGroupTree)) {
                                 //get the groupTree as per subTypes.
                                 $groupTree = array();
                                 require_once 'CRM/Core/BAO/CustomGroup.php';
                                 foreach ($componentSubType as $subType) {
                                     $subTree = CRM_Core_BAO_CustomGroup::getTree($componentBAOName, CRM_Core_DAO::$_nullObject, $componentId, 0, $values[$subType]);
                                     $groupTree = CRM_Utils_Array::crmArrayMerge($groupTree, $subTree);
                                 }
                                 $formattedGroupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, CRM_Core_DAO::$_nullObject);
                                 CRM_Core_BAO_CustomGroup::setDefaults($formattedGroupTree, $defaults);
                             }
                             //FIX ME: We need to loop defaults, but once we move to custom_1_x convention this code can be simplified.
                             foreach ($defaults as $customKey => $customValue) {
                                 if ($customFieldDetails = CRM_Core_BAO_CustomField::getKeyID($customKey, true)) {
                                     if ($name == 'custom_' . $customFieldDetails[0]) {
                                         //hack to set default for checkbox
                                         //basically this is for weired field name like field[33][custom_19]
                                         //we are converting this field name to array structure and assign value.
                                         $skipValue = false;
                                         foreach ($formattedGroupTree as $tree) {
                                             if ('CheckBox' == CRM_Utils_Array::value('html_type', $tree['fields'][$customFieldDetails[0]])) {
                                                 $skipValue = true;
                                                 $defaults['field'][$componentId][$name] = $customValue;
                                                 break;
                                             } else {
                                                 if (CRM_Utils_Array::value('data_type', $tree['fields'][$customFieldDetails[0]]) == 'Date') {
                                                     $skipValue = true;
                                                     $customValue = $tree['fields'][$customFieldDetails[0]]['element_value'];
                                                     list($defaults['field'][$componentId][$name], $defaults['field'][$componentId][$name . '_time']) = CRM_Utils_Date::setDateDefaults($customValue);
                                                 }
                                             }
                                         }
                                         if (!$skipValue) {
                                             $defaults[$fldName] = $customValue;
                                         }
                                         unset($defaults[$customKey]);
                                         break;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Пример #8
0
 public function templateCustomDataValues($templateId)
 {
     $defaults = array();
     if (!$templateId) {
         return $defaults;
     }
     // pull template custom data as a default for event, CRM-5596
     $groupTree = CRM_Core_BAO_CustomGroup::getTree($this->_type, $this, $templateId, null, $this->_subType);
     $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, $this->_groupCount, $this);
     $customValues = array();
     CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $customValues);
     foreach ($customValues as $key => $val) {
         if ($fieldKey = CRM_Core_BAO_CustomField::getKeyID($key)) {
             $defaults["custom_{$fieldKey}_-1"] = $val;
         }
     }
     return $defaults;
 }
Пример #9
0
 /**
  * @param $form
  * @param $subType
  * @param $gid
  * @param $onlySubType
  * @param $getCachedTree
  *
  * @return array
  */
 public static function setGroupTree(&$form, $subType, $gid, $onlySubType, $getCachedTree = FALSE)
 {
     $groupTree = CRM_Core_BAO_CustomGroup::getTree($form->_type, $form, $form->_entityId, $gid, $subType, $form->_subName, $getCachedTree, $onlySubType);
     if (property_exists($form, '_customValueCount') && !empty($groupTree)) {
         $form->_customValueCount = CRM_Core_BAO_CustomGroup::buildCustomDataView($form, $groupTree, TRUE, NULL, NULL);
     }
     // we should use simplified formatted groupTree
     $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, $form->_groupCount, $form);
     if (isset($form->_groupTree) && is_array($form->_groupTree)) {
         $keys = array_keys($groupTree);
         foreach ($keys as $key) {
             $form->_groupTree[$key] = $groupTree[$key];
         }
         return array($form, $groupTree);
     } else {
         $form->_groupTree = $groupTree;
         return array($form, $groupTree);
     }
 }
Пример #10
0
 /**
  * @param CRM_Core_Form $form
  * @param null|string $subName
  * @param null|string $subType
  * @param null|int $groupCount
  * @param string $type
  * @param null|int $entityID
  * @param null $onlySubType
  */
 public static function preProcess(&$form, $subName = NULL, $subType = NULL, $groupCount = NULL, $type = NULL, $entityID = NULL, $onlySubType = NULL)
 {
     if ($type) {
         $form->_type = $type;
     } else {
         $form->_type = CRM_Utils_Request::retrieve('type', 'String', $form);
     }
     if (isset($subType)) {
         $form->_subType = $subType;
     } else {
         $form->_subType = CRM_Utils_Request::retrieve('subType', 'String', $form);
     }
     if ($form->_subType == 'null') {
         $form->_subType = NULL;
     }
     if (isset($subName)) {
         $form->_subName = $subName;
     } else {
         $form->_subName = CRM_Utils_Request::retrieve('subName', 'String', $form);
     }
     if ($form->_subName == 'null') {
         $form->_subName = NULL;
     }
     if ($groupCount) {
         $form->_groupCount = $groupCount;
     } else {
         $form->_groupCount = CRM_Utils_Request::retrieve('cgcount', 'Positive', $form);
     }
     $form->assign('cgCount', $form->_groupCount);
     //carry qf key, since this form is not inhereting core form.
     if ($qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject)) {
         $form->assign('qfKey', $qfKey);
     }
     if ($entityID) {
         $form->_entityId = $entityID;
     } else {
         $form->_entityId = CRM_Utils_Request::retrieve('entityID', 'Positive', $form);
     }
     $typeCheck = CRM_Utils_Request::retrieve('type', 'String', CRM_Core_DAO::$_nullObject);
     $urlGroupId = CRM_Utils_Request::retrieve('groupID', 'Positive', CRM_Core_DAO::$_nullObject);
     if (isset($typeCheck) && $urlGroupId) {
         $form->_groupID = $urlGroupId;
     } else {
         $form->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $form);
     }
     $gid = isset($form->_groupID) ? $form->_groupID : NULL;
     $getCachedTree = isset($form->_getCachedTree) ? $form->_getCachedTree : TRUE;
     $subType = $form->_subType;
     if (!is_array($subType) && strstr($subType, CRM_Core_DAO::VALUE_SEPARATOR)) {
         $subType = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ',', trim($subType, CRM_Core_DAO::VALUE_SEPARATOR));
     }
     $groupTree =& CRM_Core_BAO_CustomGroup::getTree($form->_type, $form, $form->_entityId, $gid, $subType, $form->_subName, $getCachedTree, $onlySubType);
     if (property_exists($form, '_customValueCount') && !empty($groupTree)) {
         $form->_customValueCount = CRM_Core_BAO_CustomGroup::buildCustomDataView($form, $groupTree, TRUE, NULL, NULL);
     }
     // we should use simplified formatted groupTree
     $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, $form->_groupCount, $form);
     if (isset($form->_groupTree) && is_array($form->_groupTree)) {
         $keys = array_keys($groupTree);
         foreach ($keys as $key) {
             $form->_groupTree[$key] = $groupTree[$key];
         }
     } else {
         $form->_groupTree = $groupTree;
     }
 }
/**
 * Function to get the relationship
 *
 * @param array   $contact_a          (reference ) input parameters.
 * @param array   $contact_b          (reference ) input parameters.
 * @param array   $relationshipTypes  an array of Relationship Type Name.
 * @param string  $sort               sort all relationship by relationshipId (eg asc/desc)
 *
 * @return        Array of all relationship.
 *
 * @access  public
 */
function civicrm_contact_relationship_get($contact_a, $contact_b = NULL, $relationshipTypes = NULL, $sort = NULL)
{
    if (!is_array($contact_a)) {
        return civicrm_create_error(ts('Input parameter is not an array'));
    }
    if (!isset($contact_a['contact_id'])) {
        return civicrm_create_error(ts('Could not find contact_id in input parameters.'));
    }
    require_once 'CRM/Contact/BAO/Relationship.php';
    $contactID = $contact_a['contact_id'];
    $relationships = CRM_Contact_BAO_Relationship::getRelationship($contactID);
    if (!empty($relationshipTypes)) {
        $result = array();
        foreach ($relationshipTypes as $relationshipName) {
            foreach ($relationships as $key => $relationship) {
                if ($relationship['relation'] == $relationshipName) {
                    $result[$key] = $relationship;
                }
            }
        }
        $relationships = $result;
    }
    if (isset($contact_b['contact_id'])) {
        $cid = $contact_b['contact_id'];
        $result = array();
        foreach ($relationships as $key => $relationship) {
            if ($relationship['cid'] == $cid) {
                $result[$key] = $relationship;
            }
        }
        $relationships = $result;
    }
    //sort by relationship id
    if ($sort) {
        if (strtolower($sort) == 'asc') {
            ksort($relationships);
        } elseif (strtolower($sort) == 'desc') {
            krsort($relationships);
        }
    }
    //handle custom data.
    require_once 'CRM/Core/BAO/CustomGroup.php';
    foreach ($relationships as $relationshipId => $values) {
        $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Relationship', CRM_Core_DAO::$_nullObject, $relationshipId, FALSE, $values['civicrm_relationship_type_id']);
        $formatTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, CRM_Core_DAO::$_nullObject);
        $defaults = array();
        CRM_Core_BAO_CustomGroup::setDefaults($formatTree, $defaults);
        if (!empty($defaults)) {
            foreach ($defaults as $key => $val) {
                $relationships[$relationshipId][$key] = $val;
            }
        }
    }
    if ($relationships) {
        return civicrm_create_success($relationships);
    } else {
        return civicrm_create_error(ts('Invalid Data'));
    }
}
Пример #12
0
/**
 * Get Event record.
 * 
 *
 * @param  array  $params     an associative array of name/value property values of civicrm_event
 *
 * @return  Array of all found event property values.
 * @access public
 */
function civicrm_event_search(&$params)
{
    if (!is_array($params)) {
        return civicrm_create_error(ts('Input parameters is not an array.'));
    }
    $inputParams = array();
    $returnProperties = array();
    $returnCustomProperties = array();
    $otherVars = array('sort', 'offset', 'rowCount');
    $sort = false;
    // don't check if empty, more meaningful error for API user instead of siletn defaults
    $offset = array_key_exists('return.offset', $params) ? $params['return.offset'] : 0;
    $rowCount = array_key_exists('return.max_results', $params) ? $params['return.max_results'] : 25;
    foreach ($params as $n => $v) {
        if (substr($n, 0, 7) == 'return.') {
            if (substr($n, 0, 14) == 'return.custom_') {
                //take custom return properties separate
                $returnCustomProperties[] = substr($n, 7);
            } elseif (!in_array(substr($n, 7), array('offset', 'max_results'))) {
                $returnProperties[] = substr($n, 7);
            }
        } elseif (in_array($n, $otherVars)) {
            ${$n} = $v;
        } else {
            $inputParams[$n] = $v;
        }
    }
    if (!empty($returnProperties)) {
        $returnProperties[] = 'id';
        $returnProperties[] = 'event_type_id';
    }
    $returnProperties[] = 'is_template';
    require_once 'CRM/Core/BAO/CustomGroup.php';
    require_once 'CRM/Event/BAO/Event.php';
    $eventDAO = new CRM_Event_BAO_Event();
    $eventDAO->copyValues($inputParams);
    $event = array();
    if (!empty($returnProperties)) {
        $eventDAO->selectAdd();
        $eventDAO->selectAdd(implode(',', $returnProperties));
    }
    $eventDAO->orderBy($sort);
    $eventDAO->limit((int) $offset, (int) $rowCount);
    $eventDAO->find();
    while ($eventDAO->fetch()) {
        // ignore event templates
        // ideally need to put this in the query, but not sure how to do this with the below
        // ( ( is_template IS NULL ) OR ( is_template = 0 ) )
        // hence doing this here for now, please fix on a future rewrite
        if ($eventDAO->is_template) {
            continue;
        }
        $event[$eventDAO->id] = array();
        CRM_Core_DAO::storeValues($eventDAO, $event[$eventDAO->id]);
        $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Event', CRM_Core_DAO::$_nullObject, $eventDAO->id, false, $eventDAO->event_type_id);
        $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, CRM_Core_DAO::$_nullObject);
        $defaults = array();
        CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults);
        if (!empty($defaults)) {
            foreach ($defaults as $key => $val) {
                if (!empty($returnCustomProperties)) {
                    $customKey = explode('_', $key);
                    //show only return properties
                    if (in_array('custom_' . $customKey['1'], $returnCustomProperties)) {
                        $event[$eventDAO->id][$key] = $val;
                    }
                } else {
                    $event[$eventDAO->id][$key] = $val;
                }
            }
        }
    }
    //end of the loop
    $eventDAO->free();
    return $event;
}
Пример #13
0
/**
 * Get Event record.
 *
 *
 * @param  array  $params     an associative array of name/value property values of civicrm_event
 *
 * @return  Array of all found event property values.
 * @access public
 */
function civicrm_event_search(&$params)
{
    if (!is_array($params)) {
        return civicrm_create_error(ts('Input parameters is not an array.'));
    }
    $inputParams = array();
    $returnProperties = array();
    $returnCustomProperties = array();
    $otherVars = array('sort', 'offset', 'rowCount', 'isCurrent');
    $sort = array_key_exists('return.sort', $params) ? $params['return.sort'] : FALSE;
    // don't check if empty, more meaningful error for API user instead of silent defaults
    $offset = array_key_exists('return.offset', $params) ? $params['return.offset'] : 0;
    $rowCount = array_key_exists('return.max_results', $params) ? $params['return.max_results'] : 25;
    $isCurrent = array_key_exists('isCurrent', $params) ? $params['isCurrent'] : 0;
    foreach ($params as $n => $v) {
        if (substr($n, 0, 7) == 'return.') {
            if (substr($n, 0, 14) == 'return.custom_') {
                //take custom return properties separate
                $returnCustomProperties[] = substr($n, 7);
            } elseif (!in_array(substr($n, 7), array('sort', 'offset', 'max_results'))) {
                $returnProperties[] = substr($n, 7);
            }
        } elseif (in_array($n, $otherVars)) {
            ${$n} = $v;
        } else {
            $inputParams[$n] = $v;
        }
    }
    if (!empty($returnProperties)) {
        $returnProperties[] = 'id';
        $returnProperties[] = 'event_type_id';
    }
    require_once 'CRM/Core/BAO/CustomGroup.php';
    require_once 'CRM/Event/BAO/Event.php';
    $eventDAO = new CRM_Event_BAO_Event();
    $eventDAO->copyValues($inputParams);
    $event = array();
    if (!empty($returnProperties)) {
        $eventDAO->selectAdd();
        $eventDAO->selectAdd(implode(',', $returnProperties));
    }
    $eventDAO->whereAdd('( is_template IS NULL ) OR ( is_template = 0 )');
    if ($isCurrent) {
        $eventDAO->whereAdd('(start_date >= CURDATE() || end_date >= CURDATE())');
    }
    $eventDAO->orderBy($sort);
    $eventDAO->limit((int) $offset, (int) $rowCount);
    $eventDAO->find();
    while ($eventDAO->fetch()) {
        $event[$eventDAO->id] = array();
        CRM_Core_DAO::storeValues($eventDAO, $event[$eventDAO->id]);
        $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Event', CRM_Core_DAO::$_nullObject, $eventDAO->id, FALSE, $eventDAO->event_type_id);
        $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, CRM_Core_DAO::$_nullObject);
        $defaults = array();
        CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults);
        if (!empty($defaults)) {
            foreach ($defaults as $key => $val) {
                if (!empty($returnCustomProperties)) {
                    $customKey = explode('_', $key);
                    //show only return properties
                    if (in_array('custom_' . $customKey['1'], $returnCustomProperties)) {
                        $event[$eventDAO->id][$key] = $val;
                    }
                } else {
                    $event[$eventDAO->id][$key] = $val;
                }
            }
        }
    }
    //end of the loop
    $eventDAO->free();
    return $event;
}
Пример #14
0
 /**
  * build form for address input fields 
  *
  * @param object $form - CRM_Core_Form (or subclass)
  * @param array reference $location - location array
  * @param int $locationId - location id whose block needs to be built.
  * @return none
  *
  * @access public
  * @static
  */
 static function buildQuickForm(&$form, $addressBlockCount = null)
 {
     // passing this via the session is AWFUL. we need to fix this
     if (!$addressBlockCount) {
         $blockId = $form->get('Address_Block_Count') ? $form->get('Address_Block_Count') : 1;
     } else {
         $blockId = $addressBlockCount;
     }
     $config = CRM_Core_Config::singleton();
     $countryDefault = $config->defaultContactCountry;
     $form->applyFilter('__ALL__', 'trim');
     $js = array('onChange' => 'checkLocation( this.id );');
     $form->addElement('select', "address[{$blockId}][location_type_id]", ts('Location Type'), array('' => ts('- select -')) + CRM_Core_PseudoConstant::locationType(), $js);
     $js = array('id' => "Address_" . $blockId . "_IsPrimary", 'onClick' => 'singleSelect( this.id );');
     $form->addElement('checkbox', "address[{$blockId}][is_primary]", ts('Primary location for this contact'), ts('Primary location for this contact'), $js);
     $js = array('id' => "Address_" . $blockId . "_IsBilling", 'onClick' => 'singleSelect( this.id );');
     $form->addElement('checkbox', "address[{$blockId}][is_billing]", ts('Billing location for this contact'), ts('Billing location for this contact'), $js);
     // hidden element to store master address id
     $form->addElement('hidden', "address[{$blockId}][master_id]");
     require_once 'CRM/Core/BAO/Preferences.php';
     $addressOptions = CRM_Core_BAO_Preferences::valueOptions('address_options', true, null, true);
     $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address');
     $elements = array('address_name' => array(ts('Address Name'), $attributes['address_name'], null), 'street_address' => array(ts('Street Address'), $attributes['street_address'], null), 'supplemental_address_1' => array(ts('Addt\'l Address 1'), $attributes['supplemental_address_1'], null), 'supplemental_address_2' => array(ts('Addt\'l Address 2'), $attributes['supplemental_address_2'], null), 'city' => array(ts('City'), $attributes['city'], null), 'postal_code' => array(ts('Zip / Postal Code'), $attributes['postal_code'], null), 'postal_code_suffix' => array(ts('Postal Code Suffix'), array('size' => 4, 'maxlength' => 12), null), 'county_id' => array(ts('County'), $attributes['county_id'], 'county'), 'state_province_id' => array(ts('State / Province'), $attributes['state_province_id'], null), 'country_id' => array(ts('Country'), $attributes['country_id'], null), 'geo_code_1' => array(ts('Latitude'), array('size' => 9, 'maxlength' => 10), null), 'geo_code_2' => array(ts('Longitude'), array('size' => 9, 'maxlength' => 10), null), 'street_number' => array(ts('Street Number'), $attributes['street_number'], null), 'street_name' => array(ts('Street Name'), $attributes['street_name'], null), 'street_unit' => array(ts('Apt/Unit/Suite'), $attributes['street_unit'], null));
     $stateCountryMap = array();
     foreach ($elements as $name => $v) {
         list($title, $attributes, $select) = $v;
         $nameWithoutID = strpos($name, '_id') !== false ? substr($name, 0, -3) : $name;
         if (!CRM_Utils_Array::value($nameWithoutID, $addressOptions)) {
             $continue = true;
             if (in_array($nameWithoutID, array('street_number', 'street_name', 'street_unit')) && CRM_Utils_Array::value('street_address_parsing', $addressOptions)) {
                 $continue = false;
             }
             if ($continue) {
                 continue;
             }
         }
         if (!$attributes) {
             $attributes = $attributes[$name];
         }
         //build normal select if country is not present in address block
         if ($name == 'state_province_id' && !$addressOptions['country']) {
             $select = 'stateProvince';
         }
         if (!$select) {
             if ($name == 'country_id' || $name == 'state_province_id') {
                 if ($name == 'country_id') {
                     $stateCountryMap[$blockId]['country'] = "address_{$blockId}_{$name}";
                     $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
                 } else {
                     $stateCountryMap[$blockId]['state_province'] = "address_{$blockId}_{$name}";
                     if ($countryDefault) {
                         $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault);
                     } else {
                         $selectOptions = array('' => ts('- select a country -'));
                     }
                 }
                 $form->addElement('select', "address[{$blockId}][{$name}]", $title, $selectOptions);
             } else {
                 if ($name == 'address_name') {
                     $name = "name";
                 }
                 $form->addElement('text', "address[{$blockId}][{$name}]", $title, $attributes);
             }
         } else {
             $form->addElement('select', "address[{$blockId}][{$name}]", $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select());
         }
     }
     require_once 'CRM/Core/BAO/Address.php';
     require_once 'CRM/Core/BAO/CustomGroup.php';
     CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
     $entityId = null;
     if (!empty($form->_values['address'])) {
         $entityId = $form->_values['address'][$blockId]['id'];
     }
     // Process any address custom data -
     $groupTree = CRM_Core_BAO_CustomGroup::getTree('Address', $form, $entityId);
     if (isset($groupTree) && is_array($groupTree)) {
         // use simplified formatted groupTree
         $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $form);
         // make sure custom fields are added /w element-name in the format - 'address[$blockId][custom-X]'
         foreach ($groupTree as $id => $group) {
             foreach ($group['fields'] as $fldId => $field) {
                 $groupTree[$id]['fields'][$fldId]['element_custom_name'] = $field['element_name'];
                 $groupTree[$id]['fields'][$fldId]['element_name'] = "address[{$blockId}][{$field['element_name']}]";
             }
         }
         $defaults = array();
         CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults);
         // For some of the custom fields like checkboxes, the defaults doesn't populate
         // in proper format due to the different element-name format - 'address[$blockId][custom-X]'.
         // Below eval() fixes this issue.
         $address = array();
         foreach ($defaults as $key => $val) {
             eval("\${$key} = " . (!is_array($val) ? "'{$val}'" : var_export($val, true)) . ";");
         }
         $defaults = array('address' => $address);
         $form->setDefaults($defaults);
         // we setting the prefix to 'dnc_' below, so that we don't overwrite smarty's grouptree var.
         // And we can't set it to 'address_' because we want to set it in a slightly different format.
         CRM_Core_BAO_CustomGroup::buildQuickForm($form, $groupTree, false, 1, "dnc_");
         $template =& CRM_Core_Smarty::singleton();
         $tplGroupTree = $template->get_template_vars('address_groupTree');
         $tplGroupTree = empty($tplGroupTree) ? array() : $tplGroupTree;
         $form->assign("address_groupTree", $tplGroupTree + array($blockId => $groupTree));
         $form->assign("dnc_groupTree", null);
         // unset the temp smarty var that got created
     }
     // address custom data processing ends ..
     // shared address
     $form->addElement('checkbox', "address[{$blockId}][use_shared_address]", null, ts('Share Address With'));
     // get the reserved for address
     $profileId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'shared_address', 'id', 'name');
     if (!$profileId) {
         CRM_Core_Error::fatal(ts('Your install is missing required "Shared Address" profile.'));
     }
     require_once 'CRM/Contact/Form/NewContact.php';
     CRM_Contact_Form_NewContact::buildQuickForm($form, $blockId, array($profileId));
 }
Пример #15
0
/**
 * Get contact membership record.
 * 
 * This api is used for finding an existing membership record.
 * This api will also return the mebership records for the contacts
 * having mebership based on the relationship with the direct members.
 * 
 * @param  Array $params key/value pairs for contact_id and some
 *          options affecting the desired results; has legacy support
 *          for just passing the contact_id itself as the argument
 *
 * @return  Array of all found membership property values.
 * @access public
 */
function civicrm_membership_contact_get(&$params)
{
    _civicrm_initialize();
    $activeOnly = false;
    if (is_array($params)) {
        $contactID = CRM_Utils_Array::value('contact_id', $params);
        $activeOnly = CRM_Utils_Array::value('active_only', $params, false);
        if ($activeOnly == 1) {
            $activeOnly = true;
        } else {
            $activeOnly = false;
        }
    } elseif (CRM_Utils_Rule::integer($params)) {
        $contactID = $params;
    } else {
        return civicrm_create_error('Paramers can be only of type array or integer');
    }
    if (empty($contactID)) {
        return civicrm_create_error('Invalid value for ContactID.');
    }
    // get the membership for the given contact ID
    require_once 'CRM/Member/BAO/Membership.php';
    $membership = array('contact_id' => $contactID);
    $membershipValues = array();
    CRM_Member_BAO_Membership::getValues($membership, $membershipValues, $activeOnly);
    $recordCount = 0;
    if (empty($membershipValues)) {
        # No results is NOT an error!
        # return civicrm_create_error('No memberships for this contact.');
        $membershipValues['record_count'] = $recordCount;
        return $membershipValues;
    }
    $members[$contactID] = array();
    $relationships = array();
    foreach ($membershipValues as $membershipId => $values) {
        // populate the membership type name for the membership type id
        require_once 'CRM/Member/BAO/MembershipType.php';
        $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($values['membership_type_id']);
        $membershipValues[$membershipId]['membership_name'] = $membershipType['name'];
        if (CRM_Utils_Array::value('relationship_type_id', $membershipType)) {
            $relationships[$membershipType['relationship_type_id']] = $membershipId;
        }
        // populating relationship type name.
        require_once 'CRM/Contact/BAO/RelationshipType.php';
        $relationshipType = new CRM_Contact_BAO_RelationshipType();
        $relationshipType->id = CRM_Utils_Array::value('relationship_type_id', $membershipType);
        if ($relationshipType->find(true)) {
            $membershipValues[$membershipId]['relationship_name'] = $relationshipType->name_a_b;
        }
        require_once 'CRM/Core/BAO/CustomGroup.php';
        $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Membership', CRM_Core_DAO::$_nullObject, $membershipId, false, $values['membership_type_id']);
        $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, CRM_Core_DAO::$_nullObject);
        $defaults = array();
        CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults);
        if (!empty($defaults)) {
            foreach ($defaults as $key => $val) {
                $membershipValues[$membershipId][$key] = $val;
            }
        }
        $recordCount++;
    }
    $members[$contactID] = $membershipValues;
    // populating contacts in members array based on their relationship with direct members.
    require_once 'CRM/Contact/BAO/Relationship.php';
    if (!empty($relationships)) {
        foreach ($relationships as $relTypeId => $membershipId) {
            // As members are not direct members, there should not be
            // membership id in the result array.
            unset($membershipValues[$membershipId]['id']);
            $relationship = new CRM_Contact_BAO_Relationship();
            $relationship->contact_id_b = $contactID;
            $relationship->relationship_type_id = $relTypeId;
            if ($relationship->find()) {
                while ($relationship->fetch()) {
                    clone $relationship;
                    $membershipValues[$membershipId]['contact_id'] = $relationship->contact_id_a;
                    $members[$contactID][$relationship->contact_id_a] = $membershipValues[$membershipId];
                }
            }
            $recordCount++;
        }
    }
    $members['record_count'] = $recordCount;
    return $members;
}
Пример #16
0
 /**
  * setDefault componet specific profile fields.
  *
  * @param array $fields
  *   Profile fields.
  * @param int $componentId
  *   ComponetID.
  * @param string $component
  *   Component name.
  * @param array $defaults
  *   An array of default values.
  *
  * @param bool $isStandalone
  */
 public static function setComponentDefaults(&$fields, $componentId, $component, &$defaults, $isStandalone = FALSE)
 {
     if (!$componentId || !in_array($component, array('Contribute', 'Membership', 'Event', 'Activity'))) {
         return;
     }
     $componentBAO = $componentSubType = NULL;
     switch ($component) {
         case 'Membership':
             $componentBAO = 'CRM_Member_BAO_Membership';
             $componentBAOName = 'Membership';
             $componentSubType = array('membership_type_id');
             break;
         case 'Contribute':
             $componentBAO = 'CRM_Contribute_BAO_Contribution';
             $componentBAOName = 'Contribution';
             $componentSubType = array('financial_type_id');
             break;
         case 'Event':
             $componentBAO = 'CRM_Event_BAO_Participant';
             $componentBAOName = 'Participant';
             $componentSubType = array('role_id', 'event_id', 'event_type_id');
             break;
         case 'Activity':
             $componentBAO = 'CRM_Activity_BAO_Activity';
             $componentBAOName = 'Activity';
             $componentSubType = array('activity_type_id');
             break;
     }
     $values = array();
     $params = array('id' => $componentId);
     //get the component values.
     CRM_Core_DAO::commonRetrieve($componentBAO, $params, $values);
     if ($componentBAOName == 'Participant') {
         $values += array('event_type_id' => CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $values['event_id'], 'event_type_id'));
     }
     $formattedGroupTree = array();
     $dateTimeFields = array('participant_register_date', 'activity_date_time', 'receive_date', 'receipt_date', 'cancel_date', 'thankyou_date', 'membership_start_date', 'membership_end_date', 'join_date');
     foreach ($fields as $name => $field) {
         $fldName = $isStandalone ? $name : "field[{$componentId}][{$name}]";
         if (in_array($name, $dateTimeFields)) {
             $timefldName = $isStandalone ? "{$name}_time" : "field[{$componentId}][{$name}_time]";
             if (!empty($values[$name])) {
                 list($defaults[$fldName], $defaults[$timefldName]) = CRM_Utils_Date::setDateDefaults($values[$name]);
             }
         } elseif (array_key_exists($name, $values)) {
             $defaults[$fldName] = $values[$name];
         } elseif ($name == 'participant_note') {
             $noteDetails = CRM_Core_BAO_Note::getNote($componentId, 'civicrm_participant');
             $defaults[$fldName] = array_pop($noteDetails);
         } elseif (in_array($name, array('financial_type', 'payment_instrument', 'participant_status', 'participant_role'))) {
             $defaults[$fldName] = $values["{$name}_id"];
         } elseif ($name == 'membership_type') {
             // since membership_type field is a hierselect -
             $defaults[$fldName][0] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $values['membership_type_id'], 'member_of_contact_id', 'id');
             $defaults[$fldName][1] = $values['membership_type_id'];
         } elseif ($name == 'membership_status') {
             $defaults[$fldName] = $values['status_id'];
         } elseif ($customFieldInfo = CRM_Core_BAO_CustomField::getKeyID($name, TRUE)) {
             if (empty($formattedGroupTree)) {
                 //get the groupTree as per subTypes.
                 $groupTree = array();
                 foreach ($componentSubType as $subType) {
                     $subTree = CRM_Core_BAO_CustomGroup::getTree($componentBAOName, CRM_Core_DAO::$_nullObject, $componentId, 0, $values[$subType]);
                     $groupTree = CRM_Utils_Array::crmArrayMerge($groupTree, $subTree);
                 }
                 $formattedGroupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, CRM_Core_DAO::$_nullObject);
                 CRM_Core_BAO_CustomGroup::setDefaults($formattedGroupTree, $defaults);
             }
             //FIX ME: We need to loop defaults, but once we move to custom_1_x convention this code can be simplified.
             foreach ($defaults as $customKey => $customValue) {
                 if ($customFieldDetails = CRM_Core_BAO_CustomField::getKeyID($customKey, TRUE)) {
                     if ($name == 'custom_' . $customFieldDetails[0]) {
                         //hack to set default for checkbox
                         //basically this is for weired field name like field[33][custom_19]
                         //we are converting this field name to array structure and assign value.
                         $skipValue = FALSE;
                         foreach ($formattedGroupTree as $tree) {
                             if (!empty($tree['fields'][$customFieldDetails[0]])) {
                                 if ('CheckBox' == CRM_Utils_Array::value('html_type', $tree['fields'][$customFieldDetails[0]])) {
                                     $skipValue = TRUE;
                                     $defaults['field'][$componentId][$name] = $customValue;
                                     break;
                                 } elseif (CRM_Utils_Array::value('data_type', $tree['fields'][$customFieldDetails[0]]) == 'Date') {
                                     $skipValue = TRUE;
                                     // CRM-6681, $default contains formatted date, time values.
                                     $defaults[$fldName] = $customValue;
                                     if (!empty($defaults[$customKey . '_time'])) {
                                         $defaults['field'][$componentId][$name . '_time'] = $defaults[$customKey . '_time'];
                                     }
                                 }
                             }
                         }
                         if (!$skipValue || $isStandalone) {
                             $defaults[$fldName] = $customValue;
                         }
                         unset($defaults[$customKey]);
                         break;
                     }
                 }
             }
         }
     }
 }
Пример #17
0
function _civicrm_api3_custom_data_get(&$returnArray, $entity, $entity_id, $groupID = NULL, $subType = NULL, $subName = NULL)
{
    require_once 'CRM/Core/BAO/CustomGroup.php';
    require_once 'CRM/Core/BAO/CustomField.php';
    $groupTree =& CRM_Core_BAO_CustomGroup::getTree($entity, CRM_Core_DAO::$_nullObject, $entity_id, $groupID, $subType, $subName);
    $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, CRM_Core_DAO::$_nullObject);
    $customValues = array();
    CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $customValues);
    if (!empty($customValues)) {
        foreach ($customValues as $key => $val) {
            if (strstr($key, '_id')) {
                $idkey = substr($key, 0, -3);
                $returnArray['custom_' . (CRM_Core_BAO_CustomField::getKeyID($idkey) . "_id")] = $val;
                $returnArray[$key] = $val;
            } else {
                // per standard - return custom_fieldID
                $returnArray['custom_' . CRM_Core_BAO_CustomField::getKeyID($key)] = $val;
                //not standard - but some api did this so guess we should keep - cheap as chips
                $returnArray[$key] = $val;
            }
        }
    }
}
Пример #18
0
/**
 * Get custom data for the given entity & Add it to the returnArray.
 *
 * This looks like 'custom_123' = 'custom string' AND
 * 'custom_123_1' = 'custom string'
 * Where 123 is field value & 1 is the id within the custom group data table (value ID)
 *
 * @param array $returnArray
 *   Array to append custom data too - generally $result[4] where 4 is the entity id.
 * @param string $entity
 *   E.g membership, event.
 * @param int $entity_id
 * @param int $groupID
 *   Per CRM_Core_BAO_CustomGroup::getTree.
 * @param int $subType
 *   E.g. membership_type_id where custom data doesn't apply to all membership types.
 * @param string $subName
 *   Subtype of entity.
 */
function _civicrm_api3_custom_data_get(&$returnArray, $entity, $entity_id, $groupID = NULL, $subType = NULL, $subName = NULL)
{
    $groupTree = CRM_Core_BAO_CustomGroup::getTree($entity, CRM_Core_DAO::$_nullObject, $entity_id, $groupID, $subType, $subName);
    $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, CRM_Core_DAO::$_nullObject);
    $customValues = array();
    CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $customValues);
    $fieldInfo = array();
    foreach ($groupTree as $set) {
        $fieldInfo += $set['fields'];
    }
    if (!empty($customValues)) {
        foreach ($customValues as $key => $val) {
            // per standard - return custom_fieldID
            $id = CRM_Core_BAO_CustomField::getKeyID($key);
            $returnArray['custom_' . $id] = $val;
            //not standard - but some api did this so guess we should keep - cheap as chips
            $returnArray[$key] = $val;
            // Shim to restore legacy behavior of ContactReference custom fields
            if (!empty($fieldInfo[$id]) && $fieldInfo[$id]['data_type'] == 'ContactReference') {
                $returnArray['custom_' . $id . '_id'] = $returnArray[$key . '_id'] = $val;
                $returnArray['custom_' . $id] = $returnArray[$key] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $val, 'sort_name');
            }
        }
    }
}
Пример #19
0
 /**
  * process the form after the input has been submitted and validated
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     //get the submitted values in an array
     $params = $this->controller->exportValues($this->_name);
     require_once 'CRM/Activity/BAO/Activity.php';
     require_once 'CRM/Contact/BAO/Contact.php';
     require_once 'CRM/Core/BAO/CustomField.php';
     require_once 'CRM/Core/BAO/CustomGroup.php';
     require_once 'CRM/Core/BAO/CustomValueTable.php';
     $this->_groupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', 'civicrm_value_survey_activity_details', 'id', 'table_name');
     $groupTree = CRM_Core_BAO_CustomGroup::getTree('Activity', $this, null, $this->_groupId);
     $this->_surveyId = CRM_Utils_Array::value('survey_id', $params);
     $activityGroupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $this);
     $fieldMapper = array();
     foreach ($activityGroupTree[$this->_groupId]['fields'] as $fieldId => $field) {
         $fieldMapper[$field['column_name']] = $field['element_name'];
     }
     $duplicateContacts = array();
     $query = "SELECT DISTINCT(target.target_contact_id) as contact_id FROM " . self::ACTIVITY_SURVEY_DETAIL_TABLE . " survey INNER JOIN civicrm_activity_target target ON ( target.activity_id = survey.entity_id ) WHERE survey.status_id = 'H' AND survey.survey_id = %1  AND target.target_contact_id IN (" . implode(',', $this->_contactIds) . ") ";
     $findDuplicate = CRM_Core_DAO::executeQuery($query, array(1 => array($this->_surveyId, 'Integer')));
     while ($findDuplicate->fetch()) {
         $duplicateContacts[$findDuplicate->contact_id] = $findDuplicate->contact_id;
     }
     $customFields = CRM_Core_BAO_CustomField::getFields('Activity');
     $surveyDetails = $this->_surveyDetails;
     $maxVoters = $surveyDetails->max_number_of_contacts;
     list($cName, $cEmail, $doNotEmail, $onHold, $isDeceased) = CRM_Contact_BAO_Contact::getContactDetails($this->_interviewerId);
     $fieldParams[$fieldMapper['survey_id']] = $this->_surveyId;
     $fieldParams[$fieldMapper['status_id']] = 'H';
     $fieldParams[$fieldMapper['interviewer_id']] = $this->_interviewerId;
     $fieldParams[$fieldMapper['interviewer_display_name']] = CRM_Utils_Type::escape($cName, 'String');
     $fieldParams[$fieldMapper['interviewer_email']] = CRM_Utils_Type::escape($cEmail, 'String');
     $fieldParams[$fieldMapper['interviewer_ip']] = CRM_Utils_Type::escape($_SERVER['REMOTE_ADDR'], 'String');
     $countVoters = 0;
     foreach ($this->_contactIds as $cid) {
         if ($maxVoters && $maxVoters <= $this->_numVoters + $countVoters) {
             break;
         }
         if (in_array($cid, $duplicateContacts)) {
             continue;
         }
         $countVoters++;
         $activityParams = array();
         $activityParams['source_contact_id'] = $this->_interviewerId;
         $activityParams['assignee_contact_id'] = array($this->_interviewerId);
         $activityParams['target_contact_id'] = array($cid);
         $activityParams['activity_type_id'] = $surveyDetails->survey_type_id;
         $activityParams['subject'] = ts('Voter Reservation');
         $activityParams['status_id'] = 1;
         $activityParams['campaign_id'] = $surveyDetails->campaign_id;
         $result = CRM_Activity_BAO_Activity::create($activityParams);
         $fieldParams[$fieldMapper['subject_display_name']] = CRM_Contact_BAO_Contact::displayName($cid);
         if ($result) {
             CRM_Core_BAO_CustomValueTable::postProcess($fieldParams, $customFields, 'civicrm_activity', $result->id, 'Activity');
         }
     }
     $status = array();
     if ($countVoters > 0) {
         $status[] = ts('Voter Reservation has been added for %1 Contact(s).', array(1 => $countVoters));
     }
     if (count($this->_contactIds) > $countVoters) {
         $status[] = ts('Voter Reservation did not add for %1 Contact(s).', array(1 => count($this->_contactIds) - $countVoters));
     }
     if (!empty($status)) {
         CRM_Core_Session::setStatus(implode('&nbsp;', $status));
     }
 }
Пример #20
0
 /**
  * build form for address input fields
  *
  * @param object  $form - CRM_Core_Form (or subclass)
  * @param int     $addressBlockCount - the index of the address array (if multiple addresses on a page)
  * @param boolean $sharing - false, if we want to skip the address sharing features
  * @param boolean $inlineEdit true when edit used in inline edit
  *
  * @return void
  *
  * @access public
  * @static
  */
 static function buildQuickForm(&$form, $addressBlockCount = NULL, $sharing = TRUE, $inlineEdit = FALSE)
 {
     // passing this via the session is AWFUL. we need to fix this
     if (!$addressBlockCount) {
         $blockId = $form->get('Address_Block_Count') ? $form->get('Address_Block_Count') : 1;
     } else {
         $blockId = $addressBlockCount;
     }
     $config = CRM_Core_Config::singleton();
     $countryDefault = $config->defaultContactCountry;
     $form->applyFilter('__ALL__', 'trim');
     $js = array();
     if (!$inlineEdit) {
         $js = array('onChange' => 'checkLocation( this.id );');
     }
     $form->addSelect("address[{$blockId}][location_type_id]", array('entity' => 'address', 'class' => 'eight') + $js);
     if (!$inlineEdit) {
         $js = array('id' => 'Address_' . $blockId . '_IsPrimary', 'onClick' => 'singleSelect( this.id );');
     } else {
         //make location type required for inline edit
         $form->addRule("address[{$blockId}][location_type_id]", ts('%1 is a required field.', array(1 => ts('Location Type'))), 'required');
     }
     $form->addElement('checkbox', "address[{$blockId}][is_primary]", ts('Primary location for this contact'), ts('Primary location for this contact'), $js);
     if (!$inlineEdit) {
         $js = array('id' => 'Address_' . $blockId . '_IsBilling', 'onClick' => 'singleSelect( this.id );');
     }
     $form->addElement('checkbox', "address[{$blockId}][is_billing]", ts('Billing location for this contact'), ts('Billing location for this contact'), $js);
     // hidden element to store master address id
     $form->addElement('hidden', "address[{$blockId}][master_id]");
     $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE);
     $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address');
     $elements = array('address_name' => array(ts('Address Name'), $attributes['address_name'], NULL), 'street_address' => array(ts('Street Address'), $attributes['street_address'], NULL), 'supplemental_address_1' => array(ts('Supplemental Address 1'), $attributes['supplemental_address_1'], NULL), 'supplemental_address_2' => array(ts('Supplemental Address 2'), $attributes['supplemental_address_2'], NULL), 'city' => array(ts('City'), $attributes['city'], NULL), 'postal_code' => array(ts('Zip / Postal Code'), array_merge($attributes['postal_code'], array('class' => 'crm_postal_code')), NULL), 'postal_code_suffix' => array(ts('Postal Code Suffix'), array('size' => 4, 'maxlength' => 12, 'class' => 'crm_postal_code_suffix'), NULL), 'county_id' => array(ts('County'), $attributes['county_id'], NULL), 'state_province_id' => array(ts('State / Province'), $attributes['state_province_id'], NULL), 'country_id' => array(ts('Country'), $attributes['country_id'], NULL), 'geo_code_1' => array(ts('Latitude'), array('size' => 9, 'maxlength' => 11), NULL), 'geo_code_2' => array(ts('Longitude'), array('size' => 9, 'maxlength' => 11), NULL), 'street_number' => array(ts('Street Number'), $attributes['street_number'], NULL), 'street_name' => array(ts('Street Name'), $attributes['street_name'], NULL), 'street_unit' => array(ts('Apt/Unit/Suite'), $attributes['street_unit'], NULL));
     $stateCountryMap = array();
     foreach ($elements as $name => $v) {
         list($title, $attributes, $select) = $v;
         $nameWithoutID = strpos($name, '_id') !== FALSE ? substr($name, 0, -3) : $name;
         if (empty($addressOptions[$nameWithoutID])) {
             $continue = TRUE;
             if (in_array($nameWithoutID, array('street_number', 'street_name', 'street_unit')) && !empty($addressOptions['street_address_parsing'])) {
                 $continue = FALSE;
             }
             if ($continue) {
                 continue;
             }
         }
         if (!$attributes) {
             $attributes = $attributes[$name];
         }
         //build normal select if country is not present in address block
         if ($name == 'state_province_id' && !$addressOptions['country']) {
             $select = 'stateProvince';
         }
         if (!$select) {
             if ($name == 'country_id' || $name == 'state_province_id' || $name == 'county_id') {
                 if ($name == 'country_id') {
                     $stateCountryMap[$blockId]['country'] = "address_{$blockId}_{$name}";
                     $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
                 } elseif ($name == 'state_province_id') {
                     $stateCountryMap[$blockId]['state_province'] = "address_{$blockId}_{$name}";
                     if ($countryDefault) {
                         $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault);
                     } else {
                         $selectOptions = array('' => ts('- select a country -'));
                     }
                 } elseif ($name == 'county_id') {
                     $stateCountryMap[$blockId]['county'] = "address_{$blockId}_{$name}";
                     if ($form->getSubmitValue("address[{$blockId}][state_province_id]")) {
                         $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::countyForState($form->getSubmitValue("address[{$blockId}][state_province_id]"));
                     } elseif ($form->getSubmitValue("address[{$blockId}][county_id]")) {
                         $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::county();
                     } else {
                         $selectOptions = array('' => ts('- select a state -'));
                     }
                 }
                 $form->addElement('select', "address[{$blockId}][{$name}]", $title, $selectOptions);
             } else {
                 if ($name == 'address_name') {
                     $name = 'name';
                 }
                 $form->addElement('text', "address[{$blockId}][{$name}]", $title, $attributes);
             }
         } else {
             if ($name == 'state_province_id') {
                 $stateCountryMap[$blockId]['state_province'] = "address_{$blockId}_{$name}";
             }
             $form->addElement('select', "address[{$blockId}][{$name}]", $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select());
         }
     }
     CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
     $entityId = NULL;
     if (!empty($form->_values['address']) && !empty($form->_values['address'][$blockId])) {
         $entityId = $form->_values['address'][$blockId]['id'];
     }
     // CRM-11665 geocode override option
     $geoCode = FALSE;
     if (!empty($config->geocodeMethod)) {
         $geoCode = TRUE;
         $form->addElement('checkbox', "address[{$blockId}][manual_geo_code]", ts('Override automatic geocoding'));
     }
     $form->assign('geoCode', $geoCode);
     // Process any address custom data -
     $groupTree = CRM_Core_BAO_CustomGroup::getTree('Address', $form, $entityId);
     if (isset($groupTree) && is_array($groupTree)) {
         // use simplified formatted groupTree
         $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $form);
         // make sure custom fields are added /w element-name in the format - 'address[$blockId][custom-X]'
         foreach ($groupTree as $id => $group) {
             foreach ($group['fields'] as $fldId => $field) {
                 $groupTree[$id]['fields'][$fldId]['element_custom_name'] = $field['element_name'];
                 $groupTree[$id]['fields'][$fldId]['element_name'] = "address[{$blockId}][{$field['element_name']}]";
             }
         }
         $defaults = array();
         CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults);
         // since we change element name for address custom data, we need to format the setdefault values
         $addressDefaults = array();
         foreach ($defaults as $key => $val) {
             if (empty($val)) {
                 continue;
             }
             // inorder to set correct defaults for checkbox custom data, we need to converted flat key to array
             // this works for all types custom data
             $keyValues = explode('[', str_replace(']', '', $key));
             $addressDefaults[$keyValues[0]][$keyValues[1]][$keyValues[2]] = $val;
         }
         $form->setDefaults($addressDefaults);
         // we setting the prefix to 'dnc_' below, so that we don't overwrite smarty's grouptree var.
         // And we can't set it to 'address_' because we want to set it in a slightly different format.
         CRM_Core_BAO_CustomGroup::buildQuickForm($form, $groupTree, FALSE, 'dnc_');
         // during contact editing : if no address is filled
         // required custom data must not produce 'required' form rule error
         // more handling done in formRule func
         if (!$inlineEdit) {
             CRM_Contact_Form_Edit_Address::storeRequiredCustomDataInfo($form, $groupTree);
         }
         $template = CRM_Core_Smarty::singleton();
         $tplGroupTree = $template->get_template_vars('address_groupTree');
         $tplGroupTree = empty($tplGroupTree) ? array() : $tplGroupTree;
         $form->assign('address_groupTree', $tplGroupTree + array($blockId => $groupTree));
         // unset the temp smarty var that got created
         $form->assign('dnc_groupTree', NULL);
     }
     // address custom data processing ends ..
     if ($sharing) {
         // shared address
         $form->addElement('checkbox', "address[{$blockId}][use_shared_address]", NULL, ts('Use another contact\'s address'));
         // get the reserved for address
         $profileId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'shared_address', 'id', 'name');
         if (!$profileId) {
             CRM_Core_Error::fatal(ts('Your install is missing required "Shared Address" profile.'));
         }
         CRM_Contact_Form_NewContact::buildQuickForm($form, $blockId, array($profileId));
     }
 }
Пример #21
0
/**
 * Function retrieve actiovity custom data.
 * @param  array  $params key => value array.
 * @return array  $customData activity custom data 
 *
 * @access public
 */
function civicrm_activity_custom_get($params)
{
    $customData = array();
    if (!CRM_Utils_Array::value('activity_id', $params)) {
        return $customData;
    }
    require_once 'CRM/Core/BAO/CustomGroup.php';
    $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Activity', CRM_Core_DAO::$_nullObject, $params['activity_id'], null, CRM_Utils_Array::value('activity_type_id', $params));
    //get the group count.
    $groupCount = 0;
    foreach ($groupTree as $key => $value) {
        if ($key === 'info') {
            continue;
        }
        $groupCount++;
    }
    $formattedGroupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, $groupCount, CRM_Core_DAO::$_nullObject);
    $defaults = array();
    CRM_Core_BAO_CustomGroup::setDefaults($formattedGroupTree, $defaults);
    if (!empty($defaults)) {
        foreach ($defaults as $key => $val) {
            $customData[$key] = $val;
        }
    }
    return $customData;
}
Пример #22
0
 /**
  * Build form for address input fields.
  *
  * @param CRM_Core_Form $form
  * @param int $addressBlockCount
  *   The index of the address array (if multiple addresses on a page).
  * @param bool $sharing
  *   False, if we want to skip the address sharing features.
  * @param bool $inlineEdit
  *   True when edit used in inline edit.
  */
 public static function buildQuickForm(&$form, $addressBlockCount = NULL, $sharing = TRUE, $inlineEdit = FALSE)
 {
     // passing this via the session is AWFUL. we need to fix this
     if (!$addressBlockCount) {
         $blockId = $form->get('Address_Block_Count') ? $form->get('Address_Block_Count') : 1;
     } else {
         $blockId = $addressBlockCount;
     }
     $config = CRM_Core_Config::singleton();
     $countryDefault = $config->defaultContactCountry;
     $form->applyFilter('__ALL__', 'trim');
     $js = array();
     if (!$inlineEdit) {
         $js = array('onChange' => 'checkLocation( this.id );', 'placeholder' => NULL);
     }
     //make location type required for inline edit
     $form->addField("address[{$blockId}][location_type_id]", array('entity' => 'address', 'class' => 'eight') + $js, $inlineEdit);
     if (!$inlineEdit) {
         $js = array('id' => 'Address_' . $blockId . '_IsPrimary', 'onClick' => 'singleSelect( this.id );');
     }
     $form->addField("address[{$blockId}][is_primary]", array('entity' => 'address', 'label' => ts('Primary location for this contact'), 'text' => ts('Primary location for this contact')) + $js);
     if (!$inlineEdit) {
         $js = array('id' => 'Address_' . $blockId . '_IsBilling', 'onClick' => 'singleSelect( this.id );');
     }
     $form->addField("address[{$blockId}][is_billing]", array('entity' => 'address', 'label' => ts('Primary location for this contact'), 'text' => ts('Primary location for this contact')) + $js);
     // hidden element to store master address id
     $form->addField("address[{$blockId}][master_id]", array('entity' => 'address', 'type' => 'hidden'));
     $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE);
     $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address');
     $elements = array('address_name', 'street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'postal_code_suffix', 'country_id', 'state_province_id', 'county_id', 'geo_code_1', 'geo_code_2', 'street_number', 'street_name', 'street_unit');
     foreach ($elements as $name) {
         //Remove id from name, to allow comparison against enabled addressOtions.
         $nameWithoutID = strpos($name, '_id') !== FALSE ? substr($name, 0, -3) : $name;
         // Skip fields which are not enabled in the address options.
         if (empty($addressOptions[$nameWithoutID])) {
             $continue = TRUE;
             //Don't skip street parsed fields when parsing is enabled.
             if (in_array($nameWithoutID, array('street_number', 'street_name', 'street_unit')) && !empty($addressOptions['street_address_parsing'])) {
                 $continue = FALSE;
             }
             if ($continue) {
                 continue;
             }
         }
         if ($name == 'address_name') {
             $name = 'name';
         }
         $params = array('entity' => 'address');
         if ($name == 'postal_code_suffix') {
             $params['label'] = ts('Suffix');
         }
         $form->addField("address[{$blockId}][{$name}]", $params);
     }
     $entityId = NULL;
     if (!empty($form->_values['address']) && !empty($form->_values['address'][$blockId])) {
         $entityId = $form->_values['address'][$blockId]['id'];
     }
     // CRM-11665 geocode override option
     $geoCode = FALSE;
     if (!empty($config->geocodeMethod)) {
         $geoCode = TRUE;
         $form->addElement('checkbox', "address[{$blockId}][manual_geo_code]", ts('Override automatic geocoding'));
     }
     $form->assign('geoCode', $geoCode);
     // Process any address custom data -
     $groupTree = CRM_Core_BAO_CustomGroup::getTree('Address', $form, $entityId);
     if (isset($groupTree) && is_array($groupTree)) {
         // use simplified formatted groupTree
         $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $form);
         // make sure custom fields are added /w element-name in the format - 'address[$blockId][custom-X]'
         foreach ($groupTree as $id => $group) {
             foreach ($group['fields'] as $fldId => $field) {
                 $groupTree[$id]['fields'][$fldId]['element_custom_name'] = $field['element_name'];
                 $groupTree[$id]['fields'][$fldId]['element_name'] = "address[{$blockId}][{$field['element_name']}]";
             }
         }
         $defaults = array();
         CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults);
         // since we change element name for address custom data, we need to format the setdefault values
         $addressDefaults = array();
         foreach ($defaults as $key => $val) {
             if (empty($val)) {
                 continue;
             }
             // inorder to set correct defaults for checkbox custom data, we need to converted flat key to array
             // this works for all types custom data
             $keyValues = explode('[', str_replace(']', '', $key));
             $addressDefaults[$keyValues[0]][$keyValues[1]][$keyValues[2]] = $val;
         }
         $form->setDefaults($addressDefaults);
         // we setting the prefix to 'dnc_' below, so that we don't overwrite smarty's grouptree var.
         // And we can't set it to 'address_' because we want to set it in a slightly different format.
         CRM_Core_BAO_CustomGroup::buildQuickForm($form, $groupTree, FALSE, 'dnc_');
         // during contact editing : if no address is filled
         // required custom data must not produce 'required' form rule error
         // more handling done in formRule func
         if (!$inlineEdit) {
             CRM_Contact_Form_Edit_Address::storeRequiredCustomDataInfo($form, $groupTree);
         }
         $template = CRM_Core_Smarty::singleton();
         $tplGroupTree = $template->get_template_vars('address_groupTree');
         $tplGroupTree = empty($tplGroupTree) ? array() : $tplGroupTree;
         $form->assign('address_groupTree', $tplGroupTree + array($blockId => $groupTree));
         // unset the temp smarty var that got created
         $form->assign('dnc_groupTree', NULL);
     }
     // address custom data processing ends ..
     if ($sharing) {
         // shared address
         $form->addElement('checkbox', "address[{$blockId}][use_shared_address]", NULL, ts('Use another contact\'s address'));
         // Override the default profile links to add address form
         $profileLinks = CRM_Core_BAO_UFGroup::getCreateLinks(array('new_individual', 'new_organization', 'new_household'), 'shared_address');
         $form->addEntityRef("address[{$blockId}][master_contact_id]", ts('Share With'), array('create' => $profileLinks));
     }
 }
Пример #23
0
 /**
  * @param $form
  * @param $subType
  * @param $gid
  * @param $onlySubType
  * @param $getCachedTree
  *
  * @return array
  */
 public static function setGroupTree(&$form, $subType, $gid, $onlySubType = NULL, $getCachedTree = FALSE)
 {
     $singleRecord = NULL;
     if (!empty($form->_groupCount) && !empty($form->_multiRecordDisplay) && $form->_multiRecordDisplay == 'single') {
         $singleRecord = $form->_groupCount;
     }
     $mode = CRM_Utils_Request::retrieve('mode', 'String', $form);
     // when a new record is being added for multivalued custom fields.
     if (isset($form->_groupCount) && $form->_groupCount == 0 && $mode == 'add' && !empty($form->_multiRecordDisplay) && $form->_multiRecordDisplay == 'single') {
         $singleRecord = 'new';
     }
     $groupTree = CRM_Core_BAO_CustomGroup::getTree($form->_type, $form, $form->_entityId, $gid, $subType, $form->_subName, $getCachedTree, $onlySubType, FALSE, TRUE, $singleRecord);
     if (property_exists($form, '_customValueCount') && !empty($groupTree)) {
         $form->_customValueCount = CRM_Core_BAO_CustomGroup::buildCustomDataView($form, $groupTree, TRUE, NULL, NULL, NULL, $form->_entityId);
     }
     // we should use simplified formatted groupTree
     $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, $form->_groupCount, $form);
     if (isset($form->_groupTree) && is_array($form->_groupTree)) {
         $keys = array_keys($groupTree);
         foreach ($keys as $key) {
             $form->_groupTree[$key] = $groupTree[$key];
         }
         return array($form, $groupTree);
     } else {
         $form->_groupTree = $groupTree;
         return array($form, $groupTree);
     }
 }