/** * called when action is browse. */ public function browse() { $note = new CRM_Core_DAO_Note(); $note->entity_table = 'civicrm_contact'; $note->entity_id = $this->_contactId; $note->orderBy('modified_date desc'); //CRM-4418, handling edit and delete separately. $permissions = array($this->_permission); if ($this->_permission == CRM_Core_Permission::EDIT) { //previously delete was subset of edit //so for consistency lets grant delete also. $permissions[] = CRM_Core_Permission::DELETE; } $mask = CRM_Core_Action::mask($permissions); $values = array(); $links = self::links(); $action = array_sum(array_keys($links)) & $mask; $note->find(); while ($note->fetch()) { if (!CRM_Core_BAO_Note::getNotePrivacyHidden($note)) { CRM_Core_DAO::storeValues($note, $values[$note->id]); $values[$note->id]['action'] = CRM_Core_Action::formLink($links, $action, array('id' => $note->id, 'cid' => $this->_contactId), ts('more'), FALSE, 'note.selector.row', 'Note', $note->id); $contact = new CRM_Contact_DAO_Contact(); $contact->id = $note->contact_id; $contact->find(); $contact->fetch(); $values[$note->id]['createdBy'] = $contact->display_name; $values[$note->id]['comment_count'] = CRM_Core_BAO_Note::getChildCount($note->id); // paper icon view for attachments part $paperIconAttachmentInfo = CRM_Core_BAO_File::paperIconAttachment('civicrm_note', $note->id); $values[$note->id]['attachment'] = $paperIconAttachmentInfo; } } $this->assign('notes', $values); $commentLinks = self::commentLinks(); $action = array_sum(array_keys($commentLinks)) & $mask; $commentAction = CRM_Core_Action::formLink($commentLinks, $action, array('id' => $note->id, 'pid' => $note->entity_id, 'cid' => $note->entity_id), ts('more'), FALSE, 'note.comment.action', 'Note', $note->id); $this->assign('commentAction', $commentAction); $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('note', $this->_contactId); }
/** * combine all the importable fields from the lower levels object * * The ordering is important, since currently we do not have a weight * scheme. Adding weight is super important and should be done in the * next week or so, before this can be called complete. * * @return array array of importable Fields * @access public */ function &importableFields($contacType = 'Individual', $status = true) { if (!self::$_importableFields) { if (!self::$_importableFields) { self::$_importableFields = array(); } if (!$status) { $fields = array('' => array('title' => ts('- do not import -'))); } else { $fields = array('' => array('title' => ts('- Contribution Fields -'))); } require_once 'CRM/Core/DAO/Note.php'; $note = CRM_Core_DAO_Note::import(); $tmpFields = CRM_Contribute_DAO_Contribution::import(); unset($tmpFields['option_value']); require_once 'CRM/Core/OptionValue.php'; $optionFields = CRM_Core_OptionValue::getFields($mode = 'contribute'); require_once 'CRM/Contact/BAO/Contact.php'; $contactFields = CRM_Contact_BAO_Contact::importableFields($contacType, null); // Using new Dedupe rule. $ruleParams = array('contact_type' => $contacType, 'level' => 'Strict'); require_once 'CRM/Dedupe/BAO/Rule.php'; $fieldsArray = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams); $tmpConatctField = array(); if (is_array($fieldsArray)) { foreach ($fieldsArray as $value) { //skip if there is no dupe rule if ($value == 'none') { continue; } $tmpConatctField[trim($value)] = $contactFields[trim($value)]; if (!$status) { $title = $tmpConatctField[trim($value)]['title'] . " (match to contact)"; } else { $title = $tmpConatctField[trim($value)]['title']; } $tmpConatctField[trim($value)]['title'] = $title; } } $tmpConatctField['external_identifier'] = $contactFields['external_identifier']; $tmpConatctField['external_identifier']['title'] = $contactFields['external_identifier']['title'] . " (match to contact)"; $tmpFields['contribution_contact_id']['title'] = $tmpFields['contribution_contact_id']['title'] . " (match to contact)"; $fields = array_merge($fields, $tmpConatctField); $fields = array_merge($fields, $tmpFields); $fields = array_merge($fields, $note); $fields = array_merge($fields, $optionFields); require_once 'CRM/Contribute/DAO/ContributionType.php'; $fields = array_merge($fields, CRM_Contribute_DAO_ContributionType::export()); $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Contribution')); self::$_importableFields = $fields; } return self::$_importableFields; }
/** * Combine all the importable fields from the lower levels object. * * The ordering is important, since currently we do not have a weight * scheme. Adding weight is super important and should be done in the * next week or so, before this can be called complete. * * @param string $contactType * @param bool $status * * @return array * array of importable Fields */ public static function &importableFields($contactType = 'Individual', $status = TRUE) { if (!self::$_importableFields) { if (!self::$_importableFields) { self::$_importableFields = array(); } if (!$status) { $fields = array('' => array('title' => ts('- do not import -'))); } else { $fields = array('' => array('title' => ts('- Contribution Fields -'))); } $note = CRM_Core_DAO_Note::import(); $tmpFields = CRM_Contribute_DAO_Contribution::import(); unset($tmpFields['option_value']); $optionFields = CRM_Core_OptionValue::getFields($mode = 'contribute'); $contactFields = CRM_Contact_BAO_Contact::importableFields($contactType, NULL); // Using new Dedupe rule. $ruleParams = array('contact_type' => $contactType, 'used' => 'Unsupervised'); $fieldsArray = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams); $tmpContactField = array(); if (is_array($fieldsArray)) { foreach ($fieldsArray as $value) { //skip if there is no dupe rule if ($value == 'none') { continue; } $customFieldId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $value, 'id', 'column_name'); $value = $customFieldId ? 'custom_' . $customFieldId : $value; $tmpContactField[trim($value)] = $contactFields[trim($value)]; if (!$status) { $title = $tmpContactField[trim($value)]['title'] . ' ' . ts('(match to contact)'); } else { $title = $tmpContactField[trim($value)]['title']; } $tmpContactField[trim($value)]['title'] = $title; } } $tmpContactField['external_identifier'] = $contactFields['external_identifier']; $tmpContactField['external_identifier']['title'] = $contactFields['external_identifier']['title'] . ' ' . ts('(match to contact)'); $tmpFields['contribution_contact_id']['title'] = $tmpFields['contribution_contact_id']['title'] . ' ' . ts('(match to contact)'); $fields = array_merge($fields, $tmpContactField); $fields = array_merge($fields, $tmpFields); $fields = array_merge($fields, $note); $fields = array_merge($fields, $optionFields); $fields = array_merge($fields, CRM_Financial_DAO_FinancialType::export()); $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Contribution')); self::$_importableFields = $fields; } return self::$_importableFields; }
/** * This function is called when the form is submitted * * @access public * @return None */ public function postProcess() { // store the submitted values in an array $params = $this->controller->exportValues($this->_name); $quickSave = false; if (CRM_Utils_Array::value('_qf_Relationship_refresh_save', $_POST) || CRM_Utils_Array::value('_qf_Relationship_refresh_savedetails', $_POST)) { $quickSave = true; } $this->set('searchDone', 0); $this->set('callAjax', false); if (CRM_Utils_Array::value('_qf_Relationship_refresh', $_POST) || $quickSave) { if (is_numeric($params['rel_contact_id'])) { if ($quickSave) { $params['contact_check'] = array($params['rel_contact_id'] => 1); } else { $this->search($params); $quickSave = false; } } else { $this->set('callAjax', true); $this->set('relType', $params['relationship_type_id']); $this->set('relContact', $params['rel_contact']); $quickSave = false; } $this->set('searchDone', 1); if (!$quickSave) { return; } } // action is taken depending upon the mode $ids = array(); $ids['contact'] = $this->_contactId; // modify params for ajax call $this->modifyParams($params); if ($this->_action & CRM_Core_Action::DELETE) { CRM_Contact_BAO_Relationship::del($this->_relationshipId); return; } $relationshipTypeId = str_replace(array('_a_b', '_b_a'), array('', ''), $params['relationship_type_id']); if ($this->_action & CRM_Core_Action::UPDATE) { $ids['relationship'] = $this->_relationshipId; $relation = CRM_Contact_BAO_Relationship::getContactIds($this->_relationshipId); $ids['contactTarget'] = $relation->contact_id_a == $this->_contactId ? $relation->contact_id_b : $relation->contact_id_a; //if relationship type change and previously it was //employer / emplyee relationship with current employer //than clear the current employer. CRM-3235. //make sure we has to have employer id before firing queries, CRM-7306 $employerId = CRM_Utils_Array::value('current_employee_id', $this->_values); $isDisabled = true; if (CRM_Utils_Array::value('is_active', $params)) { $isDisabled = false; } $relChanged = true; if ($relationshipTypeId == $this->_values['relationship_type_id']) { $relChanged = false; } if ($employerId && ($isDisabled || $relChanged)) { require_once 'CRM/Contact/BAO/Contact/Utils.php'; CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($this->_values['current_employee_id']); } } elseif ($quickSave) { if ($params['add_current_employee'] && $this->_allRelationshipNames[$relationshipTypeId]["name_a_b"] == 'Employee of') { $params['employee_of'] = $params['rel_contact_id']; } elseif ($params['add_current_employer'] && $this->_allRelationshipNames[$relationshipTypeId]["name_b_a"] == 'Employer of') { $params['employer_of'] = array($params['rel_contact_id'] => 1); } if (!$this->_rtype) { $this->_rtype = str_replace($relationshipTypeId . '_', '', $params['relationship_type_id']); } } $params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], null, true); $params['end_date'] = CRM_Utils_Date::processDate($params['end_date'], null, true); //special case to handle if all checkboxes are unchecked $customFields = CRM_Core_BAO_CustomField::getFields('Relationship', false, false, $relationshipTypeId); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_relationshipId, 'Relationship'); list($valid, $invalid, $duplicate, $saved, $relationshipIds) = CRM_Contact_BAO_Relationship::create($params, $ids); // if this is called from case view, //create an activity for case role removal.CRM-4480 if ($this->_caseId) { require_once "CRM/Case/BAO/Case.php"; CRM_Case_BAO_Case::createCaseRoleActivity($this->_caseId, $relationshipIds, $params['contact_check'], $this->_contactId); } $status = ''; if ($valid) { $status .= ' ' . ts('%count new relationship record created.', array('count' => $valid, 'plural' => '%count new relationship records created.')); } if ($invalid) { $status .= ' ' . ts('%count relationship record not created due to invalid target contact type.', array('count' => $invalid, 'plural' => '%count relationship records not created due to invalid target contact type.')); } if ($duplicate) { $status .= ' ' . ts('%count relationship record not created - duplicate of existing relationship.', array('count' => $duplicate, 'plural' => '%count relationship records not created - duplicate of existing relationship.')); } if ($saved) { $status .= ts('Relationship record has been updated.'); } $note = new CRM_Core_DAO_Note(); $note->entity_id = $relationshipIds[0]; $note->entity_table = 'civicrm_relationship'; $noteIds = array(); if ($note->find(true)) { $id = $note->id; $noteIds["id"] = $id; } $noteParams = array('entity_id' => $relationshipIds[0], 'entity_table' => 'civicrm_relationship', 'note' => $params['note'], 'contact_id' => $this->_contactId); CRM_Core_BAO_Note::add($noteParams, $noteIds); // Membership for related contacts CRM-1657 if (CRM_Core_Permission::access('CiviMember') && !$duplicate) { CRM_Contact_BAO_Relationship::relatedMemberships($this->_contactId, $params, $ids, $this->_action); } //handle current employee/employer relationship, CRM-3532 if ($this->_allRelationshipNames[$relationshipTypeId]["name_{$this->_rtype}"] == 'Employee of') { $orgId = null; if (CRM_Utils_Array::value('employee_of', $params)) { $orgId = $params['employee_of']; } else { if ($this->_action & CRM_Core_Action::UPDATE) { if (CRM_Utils_Array::value('is_current_employer', $params) && CRM_Utils_Array::value('is_active', $params)) { if (CRM_Utils_Array::value('contactTarget', $ids) != CRM_Utils_Array::value('current_employer_id', $this->_values)) { $orgId = CRM_Utils_Array::value('contactTarget', $ids); } } else { if (CRM_Utils_Array::value('contactTarget', $ids) == CRM_Utils_Array::value('current_employer_id', $this->_values)) { //clear current employer. require_once 'CRM/Contact/BAO/Contact/Utils.php'; CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($this->_contactId); } } } } //set current employer if ($orgId) { $currentEmpParams[$this->_contactId] = $orgId; require_once 'CRM/Contact/BAO/Contact/Utils.php'; CRM_Contact_BAO_Contact_Utils::setCurrentEmployer($currentEmpParams); } } else { if ($this->_allRelationshipNames[$relationshipTypeId]["name_{$this->_rtype}"] == 'Employer of') { $individualIds = array(); if (CRM_Utils_Array::value('employer_of', $params)) { $individualIds = array_keys($params['employer_of']); } else { if ($this->_action & CRM_Core_Action::UPDATE) { if (CRM_Utils_Array::value('is_current_employer', $params)) { if (CRM_Utils_Array::value('contactTarget', $ids) != CRM_Utils_Array::value('current_employee_id', $this->_values)) { $individualIds[] = CRM_Utils_Array::value('contactTarget', $ids); } } else { if (CRM_Utils_Array::value('contactTarget', $ids) == CRM_Utils_Array::value('current_employee_id', $this->_values)) { // clear current employee require_once 'CRM/Contact/BAO/Contact/Utils.php'; CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($ids['contactTarget']); } } } } //set current employee if (!empty($individualIds)) { //build the employee params. foreach ($individualIds as $key => $Id) { $currentEmpParams[$Id] = $this->_contactId; } require_once 'CRM/Contact/BAO/Contact/Utils.php'; CRM_Contact_BAO_Contact_Utils::setCurrentEmployer($currentEmpParams); } } } CRM_Core_Session::setStatus($status); if ($quickSave) { $session =& CRM_Core_Session::singleton(); CRM_Utils_System::redirect($session->popUserContext()); } }
/** * Combine all the importable fields from the lower levels object. * * The ordering is important, since currently we do not have a weight * scheme. Adding weight is super important * * @param int|string $contactType contact Type * @param bool $status * Status is used to manipulate first title. * @param bool $showAll * If true returns all fields (includes disabled fields). * @param bool $isProfile * If its profile mode. * @param bool $checkPermission * If false, do not include permissioning clause (for custom data). * * @param bool $withMultiCustomFields * * @return array * array of importable Fields */ public static function importableFields($contactType = 'Individual', $status = FALSE, $showAll = FALSE, $isProfile = FALSE, $checkPermission = TRUE, $withMultiCustomFields = FALSE) { if (empty($contactType)) { $contactType = 'All'; } $cacheKeyString = "importableFields {$contactType}"; $cacheKeyString .= $status ? '_1' : '_0'; $cacheKeyString .= $showAll ? '_1' : '_0'; $cacheKeyString .= $isProfile ? '_1' : '_0'; $cacheKeyString .= $checkPermission ? '_1' : '_0'; $fields = CRM_Utils_Array::value($cacheKeyString, self::$_importableFields); if (!$fields) { // check if we can retrieve from database cache $fields = CRM_Core_BAO_Cache::getItem('contact fields', $cacheKeyString); } if (!$fields) { $fields = CRM_Contact_DAO_Contact::import(); // get the fields thar are meant for contact types if (in_array($contactType, array('Individual', 'Household', 'Organization', 'All'))) { $fields = array_merge($fields, CRM_Core_OptionValue::getFields('', $contactType)); } $locationFields = array_merge(CRM_Core_DAO_Address::import(), CRM_Core_DAO_Phone::import(), CRM_Core_DAO_Email::import(), CRM_Core_DAO_IM::import(TRUE), CRM_Core_DAO_OpenID::import()); $locationFields = array_merge($locationFields, CRM_Core_BAO_CustomField::getFieldsForImport('Address', FALSE, FALSE, FALSE, FALSE)); foreach ($locationFields as $key => $field) { $locationFields[$key]['hasLocationType'] = TRUE; } $fields = array_merge($fields, $locationFields); $fields = array_merge($fields, CRM_Contact_DAO_Contact::import()); $fields = array_merge($fields, CRM_Core_DAO_Note::import()); //website fields $fields = array_merge($fields, CRM_Core_DAO_Website::import()); $fields['url']['hasWebsiteType'] = TRUE; if ($contactType != 'All') { $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport($contactType, $showAll, TRUE, FALSE, FALSE, $withMultiCustomFields)); //unset the fields, which are not related to their //contact type. $commonValues = array('Individual' => array('household_name', 'legal_name', 'sic_code', 'organization_name'), 'Household' => array('first_name', 'middle_name', 'last_name', 'formal_title', 'job_title', 'gender_id', 'prefix_id', 'suffix_id', 'birth_date', 'organization_name', 'legal_name', 'legal_identifier', 'sic_code', 'home_URL', 'is_deceased', 'deceased_date'), 'Organization' => array('first_name', 'middle_name', 'last_name', 'formal_title', 'job_title', 'gender_id', 'prefix_id', 'suffix_id', 'birth_date', 'household_name', 'is_deceased', 'deceased_date')); foreach ($commonValues[$contactType] as $value) { unset($fields[$value]); } } else { foreach (array('Individual', 'Household', 'Organization') as $type) { $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport($type, $showAll, FALSE, FALSE, FALSE, $withMultiCustomFields)); } } if ($isProfile) { $fields = array_merge($fields, array('group' => array('title' => ts('Group(s)'), 'name' => 'group'), 'tag' => array('title' => ts('Tag(s)'), 'name' => 'tag'), 'note' => array('title' => ts('Note(s)'), 'name' => 'note'), 'communication_style_id' => array('title' => ts('Communication Style'), 'name' => 'communication_style_id'))); } //Sorting fields in alphabetical order(CRM-1507) $fields = CRM_Utils_Array::crmArraySortByField($fields, 'title'); CRM_Core_BAO_Cache::setItem($fields, 'contact fields', $cacheKeyString); } self::$_importableFields[$cacheKeyString] = $fields; if (!$isProfile) { if (!$status) { $fields = array_merge(array('do_not_import' => array('title' => ts('- do not import -'))), self::$_importableFields[$cacheKeyString]); } else { $fields = array_merge(array('' => array('title' => ts('- Contact Fields -'))), self::$_importableFields[$cacheKeyString]); } } return $fields; }
/** * Given a note id, get a list of the ids of all notes that are descendents of that note * * @param int $parentId * Id of the given note. * @param array $ids * (reference) one-dimensional array to store found descendent ids. * * @return array * One-dimensional array containing ids of all desendent notes */ public static function getDescendentIds($parentId, &$ids = array()) { // get direct children of given parentId note $note = new CRM_Core_DAO_Note(); $note->entity_table = 'civicrm_note'; $note->entity_id = $parentId; $note->find(); while ($note->fetch()) { // foreach child, add to ids list, and recurse $ids[] = $note->id; self::getDescendentIds($note->id, $ids); } return $ids; }
/** * This function adds the contact variable in $values to the * parameter list $params. For most cases, $values should have length 1. If * the variable being added is a child of Location, a location_type_id must * also be included. If it is a child of phone, a phone_type must be included. * * @param array $values * The variable(s) to be added. * @param array $params * The structured parameter list. * * @return bool|CRM_Utils_Error */ function _civicrm_api3_deprecated_add_formatted_param(&$values, &$params) { // Crawl through the possible classes: // Contact // Individual // Household // Organization // Location // Address // Email // Phone // IM // Note // Custom // Cache the various object fields static $fields = NULL; if ($fields == NULL) { $fields = array(); } // first add core contact values since for other Civi modules they are not added require_once 'CRM/Contact/BAO/Contact.php'; $contactFields = CRM_Contact_DAO_Contact::fields(); _civicrm_api3_store_values($contactFields, $values, $params); if (isset($values['contact_type'])) { // we're an individual/household/org property $fields[$values['contact_type']] = CRM_Contact_DAO_Contact::fields(); _civicrm_api3_store_values($fields[$values['contact_type']], $values, $params); return TRUE; } if (isset($values['individual_prefix'])) { if (!empty($params['prefix_id'])) { $prefixes = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id'); $params['prefix'] = $prefixes[$params['prefix_id']]; } else { $params['prefix'] = $values['individual_prefix']; } return TRUE; } if (isset($values['individual_suffix'])) { if (!empty($params['suffix_id'])) { $suffixes = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id'); $params['suffix'] = $suffixes[$params['suffix_id']]; } else { $params['suffix'] = $values['individual_suffix']; } return TRUE; } // CRM-4575 if (isset($values['email_greeting'])) { if (!empty($params['email_greeting_id'])) { $emailGreetingFilter = array('contact_type' => CRM_Utils_Array::value('contact_type', $params), 'greeting_type' => 'email_greeting'); $emailGreetings = CRM_Core_PseudoConstant::greeting($emailGreetingFilter); $params['email_greeting'] = $emailGreetings[$params['email_greeting_id']]; } else { $params['email_greeting'] = $values['email_greeting']; } return TRUE; } if (isset($values['postal_greeting'])) { if (!empty($params['postal_greeting_id'])) { $postalGreetingFilter = array('contact_type' => CRM_Utils_Array::value('contact_type', $params), 'greeting_type' => 'postal_greeting'); $postalGreetings = CRM_Core_PseudoConstant::greeting($postalGreetingFilter); $params['postal_greeting'] = $postalGreetings[$params['postal_greeting_id']]; } else { $params['postal_greeting'] = $values['postal_greeting']; } return TRUE; } if (isset($values['addressee'])) { if (!empty($params['addressee_id'])) { $addresseeFilter = array('contact_type' => CRM_Utils_Array::value('contact_type', $params), 'greeting_type' => 'addressee'); $addressee = CRM_Core_PseudoConstant::addressee($addresseeFilter); $params['addressee'] = $addressee[$params['addressee_id']]; } else { $params['addressee'] = $values['addressee']; } return TRUE; } if (isset($values['gender'])) { if (!empty($params['gender_id'])) { $genders = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'); $params['gender'] = $genders[$params['gender_id']]; } else { $params['gender'] = $values['gender']; } return TRUE; } if (!empty($values['preferred_communication_method'])) { $comm = array(); $pcm = array_change_key_case(array_flip(CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method')), CASE_LOWER); $preffComm = explode(',', $values['preferred_communication_method']); foreach ($preffComm as $v) { $v = strtolower(trim($v)); if (array_key_exists($v, $pcm)) { $comm[$pcm[$v]] = 1; } } $params['preferred_communication_method'] = $comm; return TRUE; } // format the website params. if (!empty($values['url'])) { static $websiteFields; if (!is_array($websiteFields)) { require_once 'CRM/Core/DAO/Website.php'; $websiteFields = CRM_Core_DAO_Website::fields(); } if (!array_key_exists('website', $params) || !is_array($params['website'])) { $params['website'] = array(); } $websiteCount = count($params['website']); _civicrm_api3_store_values($websiteFields, $values, $params['website'][++$websiteCount]); return TRUE; } // get the formatted location blocks into params - w/ 3.0 format, CRM-4605 if (!empty($values['location_type_id'])) { _civicrm_api3_deprecated_add_formatted_location_blocks($values, $params); return TRUE; } if (isset($values['note'])) { // add a note field if (!isset($params['note'])) { $params['note'] = array(); } $noteBlock = count($params['note']) + 1; $params['note'][$noteBlock] = array(); if (!isset($fields['Note'])) { $fields['Note'] = CRM_Core_DAO_Note::fields(); } // get the current logged in civicrm user $session = CRM_Core_Session::singleton(); $userID = $session->get('userID'); if ($userID) { $values['contact_id'] = $userID; } _civicrm_api3_store_values($fields['Note'], $values, $params['note'][$noteBlock]); return TRUE; } // Check for custom field values if (empty($fields['custom'])) { $fields['custom'] =& CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('contact_type', $values), FALSE, FALSE, NULL, NULL, FALSE, FALSE, FALSE); } foreach ($values as $key => $value) { if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) { // check if it's a valid custom field id if (!array_key_exists($customFieldID, $fields['custom'])) { return civicrm_api3_create_error('Invalid custom field ID'); } else { $params[$key] = $value; } } } }
/** * This function is called when the form is submitted * * @access public * * @return None */ public function postProcess() { $quickSave = FALSE; if (CRM_Utils_Array::value('_qf_Relationship_refresh_save', $_POST) || CRM_Utils_Array::value('_qf_Relationship_refresh_savedetails', $_POST)) { //CRM-15873 //Parse custom file uploads $pageName = $this->getAttribute('name'); $data =& $this->controller->container(); foreach ($this->controller->get('uploadNames') as $name) { $this->controller->_actions['upload']->upload($this, $data, $pageName, $name); } $quickSave = TRUE; } // store the submitted values in an array $params = $this->controller->exportValues($this->_name); $this->set('searchDone', 0); $this->set('callAjax', FALSE); if (CRM_Utils_Array::value('_qf_Relationship_refresh', $_POST) || $quickSave) { if (is_numeric($params['contact_select_id'][1])) { if ($quickSave) { $params['contact_check'] = array($params['contact_select_id'][1] => 1); } } else { $this->set('callAjax', TRUE); $this->set('relType', $params['relationship_type_id']); $this->set('relContact', $params['contact'][1]); $quickSave = FALSE; } $this->set('searchDone', 1); if (!$quickSave) { return; } } // action is taken depending upon the mode $ids = array(); $ids['contact'] = $this->_contactId; // modify params for ajax call $this->modifyParams($params); if ($this->_action & CRM_Core_Action::DELETE) { CRM_Contact_BAO_Relationship::del($this->_relationshipId); return; } $relationshipTypeId = str_replace(array('_a_b', '_b_a'), array('', ''), $params['relationship_type_id']); if ($this->_action & CRM_Core_Action::UPDATE) { $ids['relationship'] = $this->_relationshipId; $relation = CRM_Contact_BAO_Relationship::getContactIds($this->_relationshipId); $ids['contactTarget'] = $relation->contact_id_a == $this->_contactId ? $relation->contact_id_b : $relation->contact_id_a; //if relationship type change and previously it was //employer / emplyee relationship with current employer //than clear the current employer. CRM-3235. //make sure we has to have employer id before firing queries, CRM-7306 $employerId = CRM_Utils_Array::value('current_employee_id', $this->_values); $isDisabled = TRUE; if (CRM_Utils_Array::value('is_active', $params)) { $isDisabled = FALSE; } $relChanged = TRUE; if ($relationshipTypeId == $this->_values['relationship_type_id']) { $relChanged = FALSE; } if ($employerId && ($isDisabled || $relChanged)) { CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($this->_values['current_employee_id']); } //if field key doesn't exists in params that means the user has unchecked checkbox, //hence fill FALSE to params $params['is_active'] = $isDisabled ? FALSE : TRUE; $params['is_permission_a_b'] = CRM_Utils_Array::value('is_permission_a_b', $params, FALSE); $params['is_permission_b_a'] = CRM_Utils_Array::value('is_permission_b_a', $params, FALSE); } elseif ($quickSave) { if (CRM_Utils_Array::value('add_current_employee', $params) && $this->_allRelationshipNames[$relationshipTypeId]['name_a_b'] == 'Employee of') { $params['employee_of'] = $params['contact_select_id'][1]; } elseif (CRM_Utils_Array::value('add_current_employer', $params) && $this->_allRelationshipNames[$relationshipTypeId]['name_b_a'] == 'Employer of') { $params['employer_of'] = array($params['contact_select_id'][1] => 1); } if (!$this->_rtype) { $this->_rtype = str_replace($relationshipTypeId . '_', '', $params['relationship_type_id']); } } if (!$params['note']) { $params['note'] = 'null'; } $params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], NULL, TRUE); $params['end_date'] = CRM_Utils_Date::processDate($params['end_date'], NULL, TRUE); //special case to handle if all checkboxes are unchecked $customFields = CRM_Core_BAO_CustomField::getFields('Relationship', FALSE, FALSE, $relationshipTypeId); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_relationshipId, 'Relationship'); list($valid, $invalid, $duplicate, $saved, $relationshipIds) = CRM_Contact_BAO_Relationship::create($params, $ids); // if this is called from case view, //create an activity for case role removal.CRM-4480 if ($this->_caseId) { CRM_Case_BAO_Case::createCaseRoleActivity($this->_caseId, $relationshipIds, $params['contact_check'], $this->_contactId); } $status = ''; if ($valid) { CRM_Core_Session::setStatus(ts('New relationship created.', array('count' => $valid, 'plural' => '%count new relationships created.')), ts('Saved'), 'success'); } if ($invalid) { CRM_Core_Session::setStatus(ts('%count relationship record was not created due to an invalid target contact type.', array('count' => $invalid, 'plural' => '%count relationship records were not created due to invalid target contact types.')), ts('%count invalid relationship record', array('count' => $invalid, 'plural' => '%count invalid relationship records'))); } if ($duplicate) { CRM_Core_Session::setStatus(ts('One relationship was not created because it already exists.', array('count' => $duplicate, 'plural' => '%count relationships were not created because they already exist.')), ts('%count duplicate relationship', array('count' => $duplicate, 'plural' => '%count duplicate relationships'))); } if ($saved) { CRM_Core_Session::setStatus(ts('Relationship record has been updated.'), ts('Saved'), 'success'); } if (!empty($relationshipIds)) { $note = new CRM_Core_DAO_Note(); $note->entity_id = $relationshipIds[0]; $note->entity_table = 'civicrm_relationship'; $noteIds = array(); if ($note->find(TRUE)) { $id = $note->id; $noteIds['id'] = $id; } $noteParams = array('entity_id' => $relationshipIds[0], 'entity_table' => 'civicrm_relationship', 'note' => $params['note'], 'contact_id' => $this->_contactId); CRM_Core_BAO_Note::add($noteParams, $noteIds); $params['relationship_ids'] = $relationshipIds; } // Membership for related contacts CRM-1657 if (CRM_Core_Permission::access('CiviMember') && !$duplicate) { if ($this->_action & CRM_Core_Action::ADD) { CRM_Contact_BAO_Relationship::relatedMemberships($this->_contactId, $params, $ids, $this->_action); } elseif ($this->_action & CRM_Core_Action::UPDATE) { //fixes for CRM-7985 //only if the relationship has been toggled to enable /disable if (CRM_Utils_Array::value('is_active', $params) != $this->_enabled) { $active = CRM_Utils_Array::value('is_active', $params) ? CRM_Core_Action::ENABLE : CRM_Core_Action::DISABLE; CRM_Contact_BAO_Relationship::disableEnableRelationship($this->_relationshipId, $active); } } } //handle current employee/employer relationship, CRM-3532 if ($this->_allRelationshipNames[$relationshipTypeId]["name_{$this->_rtype}"] == 'Employee of') { $orgId = NULL; if (CRM_Utils_Array::value('employee_of', $params)) { $orgId = $params['employee_of']; } elseif ($this->_action & CRM_Core_Action::UPDATE) { if (CRM_Utils_Array::value('is_current_employer', $params) && CRM_Utils_Array::value('is_active', $params)) { if (CRM_Utils_Array::value('contactTarget', $ids) != CRM_Utils_Array::value('current_employer_id', $this->_values)) { $orgId = CRM_Utils_Array::value('contactTarget', $ids); } } elseif (CRM_Utils_Array::value('contactTarget', $ids) == CRM_Utils_Array::value('current_employer_id', $this->_values)) { //clear current employer. CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($this->_contactId); } } //set current employer if ($orgId) { $currentEmpParams[$this->_contactId] = $orgId; CRM_Contact_BAO_Contact_Utils::setCurrentEmployer($currentEmpParams); } } elseif ($this->_allRelationshipNames[$relationshipTypeId]["name_{$this->_rtype}"] == 'Employer of') { $individualIds = array(); if (CRM_Utils_Array::value('employer_of', $params)) { $individualIds = array_keys($params['employer_of']); } elseif ($this->_action & CRM_Core_Action::UPDATE) { if (CRM_Utils_Array::value('is_current_employer', $params)) { if (CRM_Utils_Array::value('contactTarget', $ids) != CRM_Utils_Array::value('current_employee_id', $this->_values)) { $individualIds[] = CRM_Utils_Array::value('contactTarget', $ids); } } elseif (CRM_Utils_Array::value('contactTarget', $ids) == CRM_Utils_Array::value('current_employee_id', $this->_values)) { // clear current employee CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($ids['contactTarget']); } } //set current employee if (!empty($individualIds)) { //build the employee params. foreach ($individualIds as $key => $Id) { $currentEmpParams[$Id] = $this->_contactId; } CRM_Contact_BAO_Contact_Utils::setCurrentEmployer($currentEmpParams); } } if ($quickSave) { $session = CRM_Core_Session::singleton(); CRM_Utils_System::redirect($session->popUserContext()); } }
/** * Returns the list of fields that can be exported * * @param bool $prefix * * @return array */ static function &export($prefix = false) { if (!self::$_export) { self::$_export = array(); $fields = self::fields(); foreach ($fields as $name => $field) { if (CRM_Utils_Array::value('export', $field)) { if ($prefix) { self::$_export['note'] =& $fields[$name]; } else { self::$_export[$name] =& $fields[$name]; } } } } return self::$_export; }
/** * This function adds the contact variable in $values to the * parameter list $params. For most cases, $values should have length 1. If * the variable being added is a child of Location, a location_type_id must * also be included. If it is a child of phone, a phone_type must be included. * * @param array $values The variable(s) to be added * @param array $params The structured parameter list * * @return bool|CRM_Utils_Error * @access public */ function _civicrm_add_formatted_param(&$values, &$params) { /* Crawl through the possible classes: * Contact * Individual * Household * Organization * Location * Address * Email * Phone * IM * Note * Custom */ /* Cache the various object fields */ static $fields = null; if ($fields == null) { $fields = array(); } //first add core contact values since for other Civi modules they are not added require_once 'CRM/Contact/BAO/Contact.php'; $contactFields =& CRM_Contact_DAO_Contact::fields(); _civicrm_store_values($contactFields, $values, $params); if (isset($values['contact_type'])) { /* we're an individual/household/org property */ $fields[$values['contact_type']] = CRM_Contact_DAO_Contact::fields(); _civicrm_store_values($fields[$values['contact_type']], $values, $params); return true; } if (isset($values['individual_prefix'])) { if ($params['prefix_id']) { $prefixes = array(); $prefixes = CRM_Core_PseudoConstant::individualPrefix(); $params['prefix'] = $prefixes[$params['prefix_id']]; } else { $params['prefix'] = $values['individual_prefix']; } return true; } if (isset($values['individual_suffix'])) { if ($params['suffix_id']) { $suffixes = array(); $suffixes = CRM_Core_PseudoConstant::individualSuffix(); $params['suffix'] = $suffixes[$params['suffix_id']]; } else { $params['suffix'] = $values['individual_suffix']; } return true; } //CRM-4575 if (isset($values['email_greeting'])) { if ($params['email_greeting_id']) { $emailGreetings = array(); $emailGreetingFilter = array('contact_type' => CRM_Utils_Array::value('contact_type', $params), 'greeting_type' => 'email_greeting'); $emailGreetings = CRM_Core_PseudoConstant::greeting($emailGreetingFilter); $params['email_greeting'] = $emailGreetings[$params['email_greeting_id']]; } else { $params['email_greeting'] = $values['email_greeting']; } return true; } if (isset($values['postal_greeting'])) { if ($params['postal_greeting_id']) { $postalGreetings = array(); $postalGreetingFilter = array('contact_type' => CRM_Utils_Array::value('contact_type', $params), 'greeting_type' => 'postal_greeting'); $postalGreetings = CRM_Core_PseudoConstant::greeting($postalGreetingFilter); $params['postal_greeting'] = $postalGreetings[$params['postal_greeting_id']]; } else { $params['postal_greeting'] = $values['postal_greeting']; } return true; } if (isset($values['addressee'])) { if ($params['addressee_id']) { $addressee = array(); $addresseeFilter = array('contact_type' => CRM_Utils_Array::value('contact_type', $params), 'greeting_type' => 'addressee'); $addressee = CRM_Core_PseudoConstant::addressee($addresseeFilter); $params['addressee'] = $addressee[$params['addressee_id']]; } else { $params['addressee'] = $values['addressee']; } return true; } if (isset($values['gender'])) { if ($params['gender_id']) { $genders = array(); $genders = CRM_Core_PseudoConstant::gender(); $params['gender'] = $genders[$params['gender_id']]; } else { $params['gender'] = $values['gender']; } return true; } if (isset($values['preferred_communication_method'])) { $comm = array(); $preffComm = array(); $pcm = array(); $pcm = array_change_key_case(array_flip(CRM_Core_PseudoConstant::pcm()), CASE_LOWER); $preffComm = explode(',', $values['preferred_communication_method']); foreach ($preffComm as $v) { $v = strtolower(trim($v)); if (array_key_exists($v, $pcm)) { $comm[$pcm[$v]] = 1; } } $params['preferred_communication_method'] = $comm; return true; } // get the formatted location blocks into params - w/ 3.0 format, CRM-4605 if (CRM_Utils_Array::value('location_type_id', $values)) { _civicrm_add_formatted_location_blocks($values, $params); return true; } if (isset($values['note'])) { /* add a note field */ if (!isset($params['note'])) { $params['note'] = array(); } $noteBlock = count($params['note']) + 1; $params['note'][$noteBlock] = array(); if (!isset($fields['Note'])) { $fields['Note'] = CRM_Core_DAO_Note::fields(); } // get the current logged in civicrm user $session =& CRM_Core_Session::singleton(); $userID = $session->get('userID'); if ($userID) { $values['contact_id'] = $userID; } _civicrm_store_values($fields['Note'], $values, $params['note'][$noteBlock]); return true; } /* Check for custom field values */ if ($fields['custom'] == null) { $fields['custom'] =& CRM_Core_BAO_CustomField::getFields($values['contact_type']); } foreach ($values as $key => $value) { if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) { /* check if it's a valid custom field id */ if (!array_key_exists($customFieldID, $fields['custom'])) { return civicrm_create_error('Invalid custom field ID'); } else { $params[$key] = $value; } } } }
/** * This function adds the contact variable in $values to the * parameter list $params. For most cases, $values should have length 1. If * the variable being added is a child of Location, a location_type_id must * also be included. If it is a child of phone, a phone_type must be included. * * @param array $values The variable(s) to be added * @param array $params The structured parameter list * * @return bool|CRM_Utils_Error * @access public */ function _crm_add_formatted_param(&$values, &$params) { /* Crawl through the possible classes: * Contact * Individual * Household * Organization * Location * Address * Email * Phone * IM * Note * Custom */ /* Cache the various object fields */ static $fields = null; if ($fields == null) { $fields = array(); } if (isset($values['contact_type'])) { /* we're an individual/household/org property */ if (!isset($fields[$values['contact_type']])) { require_once str_replace('_', DIRECTORY_SEPARATOR, 'CRM_Contact_DAO_' . $values['contact_type']) . '.php'; eval('$fields[' . $values['contact_type'] . '] =& CRM_Contact_DAO_' . $values['contact_type'] . '::fields();'); } _crm_store_values($fields[$values['contact_type']], $values, $params); return true; } if (isset($values['individual_prefix'])) { $params['prefix'] = $values['individual_prefix']; return true; } if (isset($values['individual_suffix'])) { $params['suffix'] = $values['individual_suffix']; return true; } if (isset($values['gender'])) { $params['gender'] = $values['gender']; return true; } if (isset($values['location_type_id'])) { /* find and/or initialize the correct location block in $params */ $locBlock = null; if (!isset($params['location'])) { /* if we don't have a location field yet, make one */ $locBlock = 1; $params['location'][$locBlock] = array('location_type_id' => $values['location_type_id'], 'is_primary' => true); } else { /* search through the location array for a matching loc. type */ foreach ($params['location'] as $key => $loc) { if ($loc['location_type_id'] == $values['location_type_id']) { $locBlock = $key; } } /* if no locBlock has the correct type, make a new one */ if ($locBlock == null) { $locBlock = count($params['location']) + 1; $params['location'][$locBlock] = array('location_type_id' => $values['location_type_id']); } } //add location name if (isset($values['name'])) { $params['location'][$locBlock]['name'] = $values['name']; } /* if this is a phone value, find or create the correct block */ if (isset($values['phone'])) { if (!isset($params['location'][$locBlock]['phone'])) { /* if we don't have a phone array yet, make one */ $params['location'][$locBlock]['phone'] = array(); } /* add a new phone block to the array */ $phoneBlock = count($params['location'][$locBlock]['phone']) + 1; $params['location'][$locBlock]['phone'][$phoneBlock] = array(); if (!isset($fields['Phone'])) { $fields['Phone'] = CRM_Core_DAO_Phone::fields(); } _crm_store_values($fields['Phone'], $values, $params['location'][$locBlock]['phone'][$phoneBlock]); if ($phoneBlock == 1) { $params['location'][$locBlock]['phone'][$phoneBlock]['is_primary'] = true; } return true; } /* If this is an email value, create a new block to store it */ if (isset($values['email'])) { if (!isset($params['location'][$locBlock]['email'])) { $params['location'][$locBlock]['email'] = array(); } /* add a new email block */ $emailBlock = count($params['location'][$locBlock]['email']) + 1; $params['location'][$locBlock]['email'][$emailBlock] = array(); if (!isset($fields['Email'])) { $fields['Email'] = CRM_Core_DAO_Email::fields(); } _crm_store_values($fields['Email'], $values, $params['location'][$locBlock]['email'][$emailBlock]); if ($emailBlock == 1) { $params['location'][$locBlock]['email'][$emailBlock]['is_primary'] = true; } return true; } /* if this is an IM value, create a new block */ if (isset($values['im'])) { if (!isset($params['location'][$locBlock]['im'])) { $params['location'][$locBlock]['im'] = array(); } /* add a new IM block */ $imBlock = count($params['location'][$locBlock]['im']) + 1; $params['location'][$locBlock]['im'][$imBlock] = array(); if (!isset($fields['IM'])) { $fields['IM'] = CRM_Core_DAO_IM::fields(); } _crm_store_values($fields['IM'], $values, $params['location'][$locBlock]['im'][$imBlock]); if ($imBlock == 1) { $params['location'][$locBlock]['im'][$imBlock]['is_primary'] = true; } return true; } /* Otherwise we must be an address */ if (!isset($params['location'][$locBlock]['address'])) { $params['location'][$locBlock]['address'] = array(); } if (!isset($fields['Address'])) { $fields['Address'] = CRM_Core_DAO_Address::fields(); } _crm_store_values($fields['Address'], $values, $params['location'][$locBlock]['address']); $ids = array('county', 'country', 'state_province', 'supplemental_address_1', 'supplemental_address_2', 'StateProvince.name'); foreach ($ids as $id) { if (array_key_exists($id, $values)) { $params['location'][$locBlock]['address'][$id] = $values[$id]; } } return true; } if (isset($values['note'])) { /* add a note field */ if (!isset($params['note'])) { $params['note'] = array(); } $noteBlock = count($params['note']) + 1; $params['note'][$noteBlock] = array(); if (!isset($fields['Note'])) { $fields['Note'] = CRM_Core_DAO_Note::fields(); } _crm_store_values($fields['Note'], $values, $params['note'][$noteBlock]); return true; } /* Check for custom field values */ if ($fields['custom'] == null) { $fields['custom'] =& CRM_Core_BAO_CustomField::getFields($values['contact_type']); } foreach ($values as $key => $value) { if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) { /* check if it's a valid custom field id */ if (!array_key_exists($customFieldID, $fields['custom'])) { return _crm_error('Invalid custom field ID'); } if (!isset($params['custom'])) { $params['custom'] = array(); } // fixed for Import $newMulValues = array(); if ($fields['custom'][$customFieldID][3] == 'CheckBox' || $fields['custom'][$customFieldID][3] == 'Multi-Select') { $value = str_replace("|", ",", $value); $mulValues = explode(',', $value); $custuomOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true); foreach ($mulValues as $v1) { foreach ($custuomOption as $v2) { if (strtolower($v2['label']) == strtolower(trim($v1))) { $newMulValues[] = $v2['value']; } } } $value = implode(CRM_CORE_BAO_CUSTOMOPTION_VALUE_SEPERATOR, $newMulValues); } else { if ($fields['custom'][$customFieldID][3] == 'Select' || $fields['custom'][$customFieldID][3] == 'Radio') { $custuomOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true); foreach ($custuomOption as $v2) { if (strtolower($v2['label']) == strtolower(trim($value))) { $value = $v2['value']; break; } } } } $customBlock = count($params['custom']) + 1; $params['custom'][$customBlock] = array('custom_field_id' => $customFieldID, 'value' => $value, 'type' => $fields['custom'][$customFieldID][2], 'name' => $fields['custom'][$customFieldID][0]); } } /* Finally, check for contact fields */ if (!isset($fields['Contact'])) { $fields['Contact'] =& CRM_Contact_DAO_Contact::fields(); } _crm_store_values($fields['Contact'], $values, $params); }
/** * combine all the importable fields from the lower levels object * * The ordering is important, since currently we do not have a weight * scheme. Adding weight is super important and should be done in the * next week or so, before this can be called complete. * * @param int $contactType contact Type * @param boolean $status status is used to manipulate first title * @param boolean $showAll if true returns all fields (includes disabled fields) * @param boolean $isProfile if its profile mode * * @return array array of importable Fields * @access public */ function &importableFields($contactType = 'Individual', $status = false, $showAll = false, $isProfile = false) { if (empty($contactType)) { $contactType = 'All'; } $cacheKeyString = "importableFields {$contactType}"; $cacheKeyString .= $status ? "_1" : "_0"; $cacheKeyString .= $showAll ? "_1" : "_0"; $cacheKeyString .= $isProfile ? "_1" : "_0"; if (!self::$_importableFields || !CRM_Utils_Array::value($cacheKeyString, self::$_importableFields)) { if (!self::$_importableFields) { self::$_importableFields = array(); } // check if we can retrieve from database cache require_once 'CRM/Core/BAO/Cache.php'; $fields =& CRM_Core_BAO_Cache::getItem('contact fields', $cacheKeyString); if (!$fields) { $fields = CRM_Contact_DAO_Contact::import(); require_once "CRM/Core/OptionValue.php"; // get the fields thar are meant for contact types if (in_array($contactType, array('Individual', 'Household', 'Organization', 'All'))) { $fields = array_merge($fields, CRM_Core_OptionValue::getFields('', $contactType)); } $locationFields = array_merge(CRM_Core_DAO_Address::import(), CRM_Core_DAO_Phone::import(), CRM_Core_DAO_Email::import(), CRM_Core_DAO_IM::import(true), CRM_Core_DAO_OpenID::import()); foreach ($locationFields as $key => $field) { $locationFields[$key]['hasLocationType'] = true; } $fields = array_merge($fields, $locationFields); $fields = array_merge($fields, CRM_Contact_DAO_Contact::import()); $fields = array_merge($fields, CRM_Core_DAO_Note::import()); if ($contactType != 'All') { $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport($contactType, $showAll, true)); //unset the fields, which are not related to their //contact type. $commonValues = array('Individual' => array('household_name', 'legal_name', 'sic_code', 'organization_name'), 'Household' => array('first_name', 'middle_name', 'last_name', 'job_title', 'gender_id', 'birth_date', 'organization_name', 'legal_name', 'legal_identifier', 'sic_code', 'home_URL', 'is_deceased', 'deceased_date'), 'Organization' => array('first_name', 'middle_name', 'last_name', 'job_title', 'gender_id', 'birth_date', 'household_name', 'email_greeting', 'email_greeting_custom', 'postal_greeting', 'postal_greeting_custom', 'is_deceased', 'deceased_date')); foreach ($commonValues[$contactType] as $value) { unset($fields[$value]); } } else { foreach (array('Individual', 'Household', 'Organization') as $type) { $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport($type, $showAll)); } } if ($isProfile) { $fields = array_merge($fields, array('group' => array('title' => ts('Group(s)')), 'tag' => array('title' => ts('Tag(s)')), 'note' => array('title' => ts('Note(s)')))); } //Sorting fields in alphabetical order(CRM-1507) foreach ($fields as $k => $v) { $sortArray[$k] = $v['title']; } asort($sortArray); $fields = array_merge($sortArray, $fields); CRM_Core_BAO_Cache::setItem($fields, 'contact fields', $cacheKeyString); } self::$_importableFields[$cacheKeyString] = $fields; } if (!$isProfile) { if (!$status) { $fields = array_merge(array('do_not_import' => array('title' => ts('- do not import -'))), self::$_importableFields[$cacheKeyString]); } else { $fields = array_merge(array('' => array('title' => ts('- Contact Fields -'))), self::$_importableFields[$cacheKeyString]); } } return $fields; }
/** * Will rebook all given contributions to the given target contact * * @param $contribution_ids an array of contribution IDs * @param $contact_id the target contact ID */ static function rebook($contribution_ids, $contact_id, $redirect_url = NULL) { $contact_id = (int) $contact_id; $excludeList = array('id', 'contribution_id', 'trxn_id', 'invoice_id', 'cancel_date', 'cancel_reason', 'address_id', 'contribution_contact_id', 'contribution_status_id'); $cancelledStatus = CRM_Core_OptionGroup::getValue('contribution_status', 'Cancelled', 'name'); $completedStatus = CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name'); $contribution_fieldKeys = CRM_Contribute_DAO_Contribution::fieldKeys(); $sepa_ooff_payment_id = CRM_Core_OptionGroup::getValue('payment_instrument', 'OOFF', 'name'); $contribution_count = count($contribution_ids); $session = CRM_Core_Session::singleton(); $rebooked = 0; foreach ($contribution_ids as $contributionId) { $params = array('version' => 3, 'sequential' => 1, 'id' => $contributionId); $contribution = civicrm_api('Contribution', 'getsingle', $params); if (empty($contribution['is_error'])) { // contribution exists // cancel contribution $params = array('version' => 3, 'contribution_status_id' => $cancelledStatus, 'cancel_reason' => ts('Rebooked to CiviCRM ID %1', array(1 => $contact_id, 'domain' => 'de.systopia.donrec')), 'cancel_date' => date('YmdHis'), 'currency' => $contribution['currency'], 'id' => $contribution['id']); $cancelledContribution = civicrm_api('Contribution', 'create', $params); if (!empty($cancelledContribution['is_error']) && !empty($cancelledContribution['error_message'])) { CRM_Core_Session::setStatus($cancelledContribution['error_message'], ts("Error", array('domain' => 'de.systopia.donrec')), "error"); } // Now compile $attributes, taking the exclusionList into account $attributes = array('version' => 3, 'contribution_contact_id' => $contact_id, 'contribution_status_id' => $completedStatus, 'payment_instrument_id' => CRM_Core_OptionGroup::getValue('payment_instrument', $contribution['instrument_id'], 'id')); foreach ($contribution as $key => $value) { if (!in_array($key, $excludeList) && in_array($key, $contribution_fieldKeys)) { // to be sure that this keys really exists $attributes[$key] = $value; } if (strstr($key, 'custom')) { // get custom fields // load custom field spec for exception handling $custom_field_id = substr($key, 7); $custom_field = civicrm_api('CustomField', 'getsingle', array('id' => $custom_field_id, 'version' => 3)); // Exception 1: dates are not properly formatted if ($custom_field['data_type'] == 'Date') { if (!empty($value)) { $value = date('YmdHis', strtotime($value)); } } $attributes[$key] = $value; } } // create new contribution $newContribution = civicrm_api('Contribution', 'create', $attributes); if (!empty($newContribution['is_error']) && !empty($newContribution['error_message'])) { CRM_Core_Session::setStatus($newContribution['error_message'], ts("Error", array('domain' => 'de.systopia.donrec')), "error"); } // Exception handling for SEPA OOFF payments (org.project60.sepa extension) if (!empty($sepa_ooff_payment_id) && $attributes['payment_instrument_id'] == $sepa_ooff_payment_id) { CRM_Donrec_Form_Task_Rebook::fixOOFFMandate($contribution, $newContribution['id']); } // create rebook note $params = array('version' => 3, 'sequential' => 1, 'note' => ts('Rebooked from CiviCRM ID %1', array(1 => $contribution['contact_id'], 'domain' => 'de.systopia.donrec')), 'entity_table' => 'civicrm_contribution', 'entity_id' => $newContribution['id']); $result = civicrm_api('Note', 'create', $params); // move all notes from the old contribution $notes = civicrm_api('Note', 'get', array('entity_id' => $contributionId, 'entity_table' => 'civicrm_contribution', 'version' => 3)); if (!empty($notes['is_error'])) { CRM_Core_Error::debug_log_message("de.systopia.donrec: Error while reading notes: " . $notes['error_message']); } else { foreach ($notes['values'] as $note) { $dao = new CRM_Core_DAO_Note(); $dao->id = $note['id']; $dao->entity_id = $newContribution['id']; $dao->save(); } } $rebooked += 1; } } if ($rebooked == $contribution_count) { CRM_Core_Session::setStatus(ts('%1 contribution(s) successfully rebooked!', array(1 => $contribution_count, 'domain' => 'de.systopia.donrec')), ts('Successfully rebooked!'), 'success'); } else { CRM_Core_Error::debug_log_message("de.systopia.donrec: Only {$rebooked} of {$contribution_count} contributions rebooked.", array('domain' => 'de.systopia.donrec')); CRM_Core_Session::setStatus(ts('Please check your data and try again', array(1 => $contribution_count)), ts('Nothing rebooked!'), 'warning'); CRM_Utils_System::redirect($redirect_url); } }
/** * returns the list of fields that can be exported * * @access public * return array */ function &export($prefix = false) { if (!$GLOBALS['_CRM_CORE_DAO_NOTE']['_export']) { $GLOBALS['_CRM_CORE_DAO_NOTE']['_export'] = array(); $fields =& CRM_Core_DAO_Note::fields(); foreach ($fields as $name => $field) { if (CRM_Utils_Array::value('export', $field)) { if ($prefix) { $GLOBALS['_CRM_CORE_DAO_NOTE']['_export']['note'] =& $fields[$name]; } else { $GLOBALS['_CRM_CORE_DAO_NOTE']['_export'][$name] =& $fields[$name]; } } } } return $GLOBALS['_CRM_CORE_DAO_NOTE']['_export']; }
/** * combine all the exportable fields from the lower levels object * * currentlty we are using importable fields as exportable fields * * @param int $contactType contact Type * $param boolean $status true while exporting primary contacts * $param boolean $export true when used during export * * @return array array of exportable Fields * @access public */ function &exportableFields($contactType = 'Individual', $status = false, $export = false) { if (empty($contactType)) { $contactType = 'All'; } if (!$GLOBALS['_CRM_CONTACT_BAO_CONTACT']['_exportableFields'] || !CRM_Utils_Array::value($contactType, $GLOBALS['_CRM_CONTACT_BAO_CONTACT']['_exportableFields'])) { if (!$GLOBALS['_CRM_CONTACT_BAO_CONTACT']['_exportableFields']) { $GLOBALS['_CRM_CONTACT_BAO_CONTACT']['_exportableFields'] = array(); } if (!$status) { $fields = array(); } else { $fields = array('' => array('title' => ts('- Contact Fields -'))); } if ($contactType != 'All') { require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Contact_DAO_" . $contactType) . ".php"; eval('$fields = array_merge($fields, CRM_Contact_DAO_' . $contactType . '::export( ));'); } else { foreach (array('Individual', 'Household', 'Organization') as $type) { require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Contact_DAO_" . $type) . ".php"; eval('$fields = array_merge($fields, CRM_Contact_DAO_' . $type . '::export( ));'); if ($type == 'Individual') { $fields = array_merge($fields, CRM_Core_DAO_IndividualPrefix::export(true), CRM_Core_DAO_IndividualSuffix::export(true), CRM_Core_DAO_Gender::export(true)); } } } // the fields are only meant for Individual contact type if ($contactType == 'Individual') { $fields = array_merge($fields, CRM_Core_DAO_IndividualPrefix::export(true), CRM_Core_DAO_IndividualSuffix::export(true), CRM_Core_DAO_Gender::export(true)); } $locationType = array(); if ($status) { $locationType['location_type'] = array('name' => 'location_type', 'where' => 'civicrm_location_type.name', 'title' => 'Location Type'); } $IMProvider = array(); if ($status) { $IMProvider['im_provider'] = array('name' => 'im_provider', 'where' => 'civicrm_im_provider.name', 'title' => 'IM Provider'); } $locationFields = array_merge($locationType, CRM_Core_DAO_Location::export(), CRM_Core_DAO_Address::export(), CRM_Core_DAO_Phone::export(), CRM_Core_DAO_Email::export(), $IMProvider, CRM_Core_DAO_IM::export(true)); foreach ($locationFields as $key => $field) { $locationFields[$key]['hasLocationType'] = true; } $fields = array_merge($fields, $locationFields); $fields = array_merge($fields, CRM_Contact_DAO_Contact::export()); $fields = array_merge($fields, CRM_Core_DAO_Note::export()); if ($contactType != 'All') { $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport($contactType, $status)); } else { foreach (array('Individual', 'Household', 'Organization') as $type) { $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport($type)); } } //fix for CRM-791 if ($export) { $fields = array_merge($fields, array('groups' => array('title' => ts('Group(s)')))); $fields = array_merge($fields, array('tags' => array('title' => ts('Tag(s)')))); } else { $fields = array_merge($fields, array('group' => array('title' => ts('Group(s)')))); $fields = array_merge($fields, array('tag' => array('title' => ts('Tag(s)')))); } $GLOBALS['_CRM_CONTACT_BAO_CONTACT']['_exportableFields'][$contactType] = $fields; } return $GLOBALS['_CRM_CONTACT_BAO_CONTACT']['_exportableFields'][$contactType]; }