/** * Pre processing work done here. * * gets session variables for table name, id of entity in table, type of entity and stores them. */ 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); // Array contains only one item foreach ($groupTree as $groupValues) { $this->_customTitle = $groupValues['title']; CRM_Utils_System::setTitle(ts('Edit %1', array(1 => $groupValues['title']))); } $this->_defaults = array(); CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $this->_defaults); $this->setDefaults($this->_defaults); CRM_Core_BAO_CustomGroup::buildQuickForm($this, $groupTree); //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); }
/** * Set the default form values * * @param null * * @return array the default array reference * @access protected */ function &setDefaultValues() { $defaults = array(); require_once 'CRM/Core/BAO/CustomGroup.php'; CRM_Core_BAO_CustomGroup::setDefaults($this->_groupTree, $defaults, false, false); return $defaults; }
function setDefaultValues() { $defaults = array(); $params = array(); if (isset($this->_id)) { $params = array('id' => $this->_id); CRM_Contact_BAO_Group::retrieve($params, $defaults); } if (isset($this->_groupTree)) { CRM_Core_BAO_CustomGroup::setDefaults($this->_groupTree, $defaults, $viewMode, $inactiveNeeded); } return $defaults; }
/** * 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)); } }
/** * format params for update and fill mode * * @param $params array referance to an array containg all the * values for import * @param $onDuplicate int * @param $cid int contact id */ function formatParams(&$params, $onDuplicate, $cid) { if ($onDuplicate == CRM_Import_Parser::DUPLICATE_SKIP) { return; } $contactParams = array('contact_id' => $cid); $defaults = array(); $contactObj = CRM_Contact_BAO_Contact::retrieve($contactParams, $defaults); $modeUpdate = $modeFill = false; if ($onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE) { $modeUpdate = true; } if ($onDuplicate == CRM_Import_Parser::DUPLICATE_FILL) { $modeFill = true; } require_once 'CRM/Core/BAO/CustomGroup.php'; $groupTree = CRM_Core_BAO_CustomGroup::getTree($params['contact_type'], CRM_Core_DAO::$_nullObject, $cid, 0, null); CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults, false, false); $contact = get_object_vars($contactObj); $location = null; foreach ($params as $key => $value) { if ($key == 'id' || $key == 'contact_type') { continue; } if ($key == 'location') { $location = true; } else { if (in_array($key, array('email_greeting', 'postal_greeting', 'addressee'))) { // CRM-4575, need to null custom if ($params["{$key}_id"] != 4) { $params["{$key}_custom"] = 'null'; } unset($params[$key]); } else { if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key)) { $custom = true; } else { $getValue = CRM_Utils_Array::retrieveValueRecursive($contact, $key); if ($key == 'contact_source') { $params['source'] = $params[$key]; unset($params[$key]); } if ($modeFill && isset($getValue)) { unset($params[$key]); } } } } } if ($location) { for ($loc = 1; $loc <= count($params['location']); $loc++) { //if location block is already present for the contact //then do not fill any data for that location type, CRM-4424 if ($modeFill) { foreach ($contact['location'] as $location => $locationDetails) { $getValue = CRM_Utils_Array::value('location_type_id', $locationDetails); if (isset($getValue) && $getValue == $params['location'][$loc]['location_type_id']) { unset($params['location'][$loc]); break; } } } if (array_key_exists('address', $contact['location'][$loc])) { $fields = array('street_address', 'city', 'state_province_id', 'postal_code', 'postal_code_suffix', 'country_id'); foreach ($fields as $field) { $getValue = CRM_Utils_Array::retrieveValueRecursive($contact['location'][$loc]['address'], $field); if ($modeFill && isset($getValue)) { unset($params['location'][$loc]['address'][$field]); } } } $fields = array('email' => 'email', 'phone' => 'phone', 'im' => 'name'); foreach ($fields as $key => $field) { if (array_key_exists($key, $contact['location'][$loc])) { for ($c = 1; $c <= count($params['location'][$loc][$key]); $c++) { $getValue = CRM_Utils_Array::retrieveValueRecursive($contact['location'][$loc][$key][$c], $field); if ($modeFill && isset($getValue)) { unset($params['location'][$loc][$key][$c][$field]); } } } } } } }
/** * 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; }
/** * 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; } } } } } }
/** * This function sets the default values for the form. For edit/view mode * the default values are retrieved from the database * * @access public * @return None */ function setDefaultValues() { $defaults = array(); $params = array(); if (isset($this->_id)) { $params = array('id' => $this->_id); require_once str_replace('_', DIRECTORY_SEPARATOR, $this->_BAOName) . ".php"; eval($this->_BAOName . '::retrieve( $params, $defaults );'); $sourceName = CRM_Contact_BAO_Contact::displayName($defaults['source_contact_id']); $targetName = CRM_Contact_BAO_Contact::displayName($defaults['target_entity_id']); $this->assign('sourceName', $sourceName); $this->assign('targetName', $targetName); } if ($this->_action == CRM_CORE_ACTION_DELETE) { $this->assign('delName', $defaults['subject']); } if ($this->_log) { $defaults['status'] = 'Completed'; } // set the default date if we are creating a new meeting/call or // marking one as complete if ($this->_log || !isset($this->_id)) { // rounding of minutes $min = (int) (date("i") / 15) * 15; $defaults['scheduled_date_time'] = array('Y' => date('Y'), 'M' => date('m'), 'd' => date('d'), 'h' => date('h'), 'i' => $min, 'A' => date('A')); } if ($this->_action & (CRM_CORE_ACTION_VIEW | CRM_CORE_ACTION_BROWSE)) { $inactiveNeeded = true; $viewMode = true; } else { $viewMode = false; $inactiveNeeded = false; } if (isset($this->_groupTree)) { CRM_Core_BAO_CustomGroup::setDefaults($this->_groupTree, $defaults, $viewMode, $inactiveNeeded); } return $defaults; }
/** * 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')); } }
/** * 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; }
static function setDefaultValues(&$form) { $defaults = array(); CRM_Core_BAO_CustomGroup::setDefaults($form->_groupTree, $defaults); return $defaults; }
/** * This function sets the default values for the form. Note that in edit/view mode * the default values are retrieved from the database * * @access public * @return None */ function setDefaultValues() { $defaults = array(); $params = array(); if ($this->_action & CRM_CORE_ACTION_ADD) { // set group and tag defaults if any if ($this->_gid) { $defaults['group'][$this->_gid] = 1; } if ($this->_tid) { $defaults['tag'][$this->_tid] = 1; } if (CRM_CONTACT_FORM_EDIT_LOCATION_BLOCKS >= 1) { // set the is_primary location for the first location $defaults['location'] = array(); $locationTypeKeys = array_filter(array_keys(CRM_Core_PseudoConstant::locationType()), 'is_int'); sort($locationTypeKeys); // also set the location types for each location block for ($i = 0; $i < CRM_CONTACT_FORM_EDIT_LOCATION_BLOCKS; $i++) { $defaults['location'][$i + 1] = array(); //$defaults['location'][$i+1]['location_type_id'] = $locationTypeKeys[$i]; if ($i == 0) { $defaultLocation =& new CRM_Core_BAO_LocationType(); $locationType = $defaultLocation->getDefault(); $defaults['location'][$i + 1]['location_type_id'] = $locationType->id; } else { $defaults['location'][$i + 1]['location_type_id'] = $locationTypeKeys[$i]; } $defaults['location'][$i + 1]['address'] = array(); $config =& CRM_Core_Config::singleton(); $countryIsoCodes =& CRM_Core_PseudoConstant::countryIsoCode(); $defaultCountryId = array_search($config->defaultContactCountry, $countryIsoCodes); $defaults['location'][$i + 1]['address']['country_id'] = $defaultCountryId; } $defaults['location'][1]['is_primary'] = true; } } else { // this is update mode // get values from contact table $params['id'] = $params['contact_id'] = $this->_contactId; $ids = array(); $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, $ids); $this->set('ids', $ids); $this->assign('contactId', $this->_contactId); // also set contact_type, since this is used in showHide routines // to decide whether to display certain blocks (demographics) $this->_contactType = CRM_Utils_Array::value('contact_type', $defaults); // set the group and tag ids CRM_Contact_Form_GroupTag::setDefaults($this->_contactId, $defaults, CRM_CONTACT_FORM_GROUPTAG_ALL); } // use most recently posted values if any to display show hide blocks $params = $this->controller->exportValues($this->_name); if (!empty($params)) { $this->setShowHide($params, true); } else { $this->setShowHide($defaults, false); } // do we need inactive options ? if ($this->_action & (CRM_CORE_ACTION_VIEW | CRM_CORE_ACTION_BROWSE)) { $inactiveNeeded = true; $viewMode = true; } else { $viewMode = false; $inactiveNeeded = false; } CRM_Core_BAO_CustomGroup::setDefaults($this->_groupTree, $defaults, $viewMode, $inactiveNeeded); return $defaults; }
/** * 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; }
/** * 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)); }
/** * 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; } } } } } } } } } }
/** * Format params for update and fill mode. * * @param array $params * reference to an array containing all the. * values for import * @param int $onDuplicate * @param int $cid * contact id. */ public function formatParams(&$params, $onDuplicate, $cid) { if ($onDuplicate == CRM_Import_Parser::DUPLICATE_SKIP) { return; } $contactParams = array('contact_id' => $cid); $defaults = array(); $contactObj = CRM_Contact_BAO_Contact::retrieve($contactParams, $defaults); $modeUpdate = $modeFill = FALSE; if ($onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE) { $modeUpdate = TRUE; } if ($onDuplicate == CRM_Import_Parser::DUPLICATE_FILL) { $modeFill = TRUE; } $groupTree = CRM_Core_BAO_CustomGroup::getTree($params['contact_type'], CRM_Core_DAO::$_nullObject, $cid, 0, NULL); CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults, FALSE, FALSE); $locationFields = array('email' => 'email', 'phone' => 'phone', 'im' => 'name', 'website' => 'website', 'address' => 'address'); $contact = get_object_vars($contactObj); foreach ($params as $key => $value) { if ($key == 'id' || $key == 'contact_type') { continue; } if (array_key_exists($key, $locationFields)) { continue; } elseif (in_array($key, array('email_greeting', 'postal_greeting', 'addressee'))) { // CRM-4575, need to null custom if ($params["{$key}_id"] != 4) { $params["{$key}_custom"] = 'null'; } unset($params[$key]); } elseif ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key)) { $custom = TRUE; } else { $getValue = CRM_Utils_Array::retrieveValueRecursive($contact, $key); if ($key == 'contact_source') { $params['source'] = $params[$key]; unset($params[$key]); } if ($modeFill && isset($getValue)) { unset($params[$key]); } } } foreach ($locationFields as $locKeys) { if (is_array(CRM_Utils_Array::value($locKeys, $params))) { foreach ($params[$locKeys] as $key => $value) { if ($modeFill) { $getValue = CRM_Utils_Array::retrieveValueRecursive($contact, $locKeys); if (isset($getValue)) { foreach ($getValue as $cnt => $values) { if ($locKeys == 'website') { if ($getValue[$cnt]['website_type_id'] == $params[$locKeys][$key]['website_type_id']) { unset($params[$locKeys][$key]); } } else { if (!empty($getValue[$cnt]['location_type_id']) && !empty($params[$locKeys][$key]['location_type_id']) && $getValue[$cnt]['location_type_id'] == $params[$locKeys][$key]['location_type_id']) { unset($params[$locKeys][$key]); } } } } } } if (count($params[$locKeys]) == 0) { unset($params[$locKeys]); } } } }
function setDefaultValues() { $defaults = array(); if ($this->_action & CRM_CORE_ACTION_DELETE) { return $defaults; } if ($this->_id) { $ids = array(); $params = array('id' => $this->_id); CRM_Contribute_BAO_Contribution::getValues($params, $defaults, $ids); $this->_contactID = $defaults['contact_id']; } else { $now = date("Y-m-d"); $defaults['receive_date'] = $now; } if (isset($this->_groupTree)) { CRM_Core_BAO_CustomGroup::setDefaults($this->_groupTree, $defaults, false, false); } $this->assign('showOption', true); // for Premium section if ($this->_premiumId) { $this->assign('showOption', false); require_once 'CRM/Contribute/DAO/ContributionProduct.php'; $dao =& new CRM_Contribute_DAO_ContributionProduct(); $dao->id = $this->_premiumId; $dao->find(true); //if($this->_options[$dao->product_id];) $options = $this->_options[$dao->product_id]; if (!$options) { $this->assign('showOption', true); } $options_key = CRM_Utils_Array::key($dao->product_option, $options); if ($options_key) { $defaults['product_name'] = array($dao->product_id, trim($options_key)); } else { $defaults['product_name'] = array($dao->product_id); } $defaults['fulfilled_date'] = $dao->fulfilled_date; } return $defaults; }
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; } } } }
/** * 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; }
/** * 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'); } } } }
/** * Set the default form values. * * @return array * the default array reference */ public function setDefaultValues() { $defaults = array(); CRM_Core_BAO_CustomGroup::setDefaults($this->_groupTree, $defaults, FALSE, FALSE); return $defaults; }
/** * 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; }
/** * @param CRM_Core_Form $form * * @return array */ public static function setDefaultValues(&$form) { $defaults = array(); CRM_Core_BAO_CustomGroup::setDefaults($form->_groupTree, $defaults, FALSE, FALSE, $form->get('action')); return $defaults; }
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; }
/** * 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)); } }
/** * Set the default form values * * @access protected * @return array the default array reference */ function &setDefaultValues() { $defaults = array(); // do we need inactive options ? if ($this->_action & (CRM_CORE_ACTION_VIEW | CRM_CORE_ACTION_BROWSE)) { $inactiveNeeded = true; $viewMode = true; } else { $viewMode = false; $inactiveNeeded = false; } CRM_Core_BAO_CustomGroup::setDefaults($this->_groupTree, $defaults, $viewMode, $inactiveNeeded); return $defaults; }