/** * called when action is browse. * */ public function browse() { $in = CRM_Contact_BAO_GroupContact::getContactGroup($this->_contactId, 'Added'); // keep track of all 'added' contact groups so we can remove them from the smart group // section $staticGroups = array(); if (!empty($in)) { foreach ($in as $group) { $staticGroups[$group['group_id']] = 1; } } $allGroup = CRM_Contact_BAO_GroupContactCache::contactGroup($this->_contactId); $this->assign('groupSmart', NULL); $this->assign('groupParent', NULL); if (!empty($allGroup)) { $smart = $parent = array(); foreach ($allGroup['group'] as $group) { // delete all smart groups which are also in static groups if (isset($staticGroups[$group['id']])) { continue; } if (empty($group['children'])) { $smart[] = $group; } else { $parent[] = $group; } } if (!empty($smart)) { $this->assign_by_ref('groupSmart', $smart); } if (!empty($parent)) { $this->assign_by_ref('groupParent', $parent); } } }
/** * called when action is browse. * * @return void */ public function browse() { $count = CRM_Contact_BAO_GroupContact::getContactGroup($this->_contactId, NULL, NULL, TRUE, TRUE, $this->_onlyPublicGroups); $in =& CRM_Contact_BAO_GroupContact::getContactGroup($this->_contactId, 'Added', NULL, FALSE, TRUE, $this->_onlyPublicGroups); $pending =& CRM_Contact_BAO_GroupContact::getContactGroup($this->_contactId, 'Pending', NULL, FALSE, TRUE, $this->_onlyPublicGroups); $out =& CRM_Contact_BAO_GroupContact::getContactGroup($this->_contactId, 'Removed', NULL, FALSE, TRUE, $this->_onlyPublicGroups); $this->assign('groupCount', $count); $this->assign_by_ref('groupIn', $in); $this->assign_by_ref('groupPending', $pending); $this->assign_by_ref('groupOut', $out); }
/** * This function is called when action is browse * * return null * @access public */ function browse() { $count = CRM_Contact_BAO_GroupContact::getContactGroup($this->_contactId, null, null, true); $in =& CRM_Contact_BAO_GroupContact::getContactGroup($this->_contactId, 'Added'); $pending =& CRM_Contact_BAO_GroupContact::getContactGroup($this->_contactId, 'Pending'); $out =& CRM_Contact_BAO_GroupContact::getContactGroup($this->_contactId, 'Removed'); $this->assign('groupCount', $count); $this->assign_by_ref('groupIn', $in); $this->assign_by_ref('groupPending', $pending); $this->assign_by_ref('groupOut', $out); }
/** * This API will give list of the groups for particular contact * Particualr status can be sent in params array * If no status mentioned in params, by default 'added' will be used * to fetch the records * * @param array $params name value pair of contact information * * @return array list of groups, given contact subsribed to */ function civicrm_group_contact_get(&$params) { if (!is_array($params)) { return civicrm_create_error(ts('input parameter should be an array')); } if (!array_key_exists('contact_id', $params)) { return civicrm_create_error(ts('contact_id is a required field')); } $status = CRM_Utils_Array::value('status', $params, 'Added'); require_once 'CRM/Contact/BAO/GroupContact.php'; $values = CRM_Contact_BAO_GroupContact::getContactGroup($params['contact_id'], $status, NULL, FALSE, TRUE); return $values; }
/** * This API will give list of the groups for particular contact * Particualr status can be sent in params array * If no status mentioned in params, by default 'added' will be used * to fetch the records * * @param array $params name value pair of contact information * {@getfields GroupContact_get} * * @return array list of groups, given contact subsribed to */ function civicrm_api3_group_contact_get($params) { if (empty($params['contact_id'])) { if (empty($params['status'])) { //default to 'Added' $params['status'] = 'Added'; } //ie. id passed in so we have to return something return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); } $status = CRM_Utils_Array::value('status', $params, 'Added'); $values =& CRM_Contact_BAO_GroupContact::getContactGroup($params['contact_id'], $status, NULL, FALSE, TRUE); return civicrm_api3_create_success($values, $params); }
/** * Set defaults for relevant form elements. * * @param int $id * The contact id. * @param array $defaults * The defaults array to store the values in. * @param int $type * What components are we interested in. * @param string $fieldName * This is used in batch profile(i.e to build multiple blocks). * * @param string $groupElementType * * @return void */ public static function setDefaults($id, &$defaults, $type = self::ALL, $fieldName = NULL, $groupElementType = 'checkbox') { $type = (int) $type; if ($type & self::GROUP) { $fName = 'group'; if ($fieldName) { $fName = $fieldName; } $contactGroup = CRM_Contact_BAO_GroupContact::getContactGroup($id, 'Added', NULL, FALSE, TRUE); if ($contactGroup) { foreach ($contactGroup as $group) { if ($groupElementType == 'select') { $defaults[$fName][] = $group['group_id']; } else { $defaults[$fName . '[' . $group['group_id'] . ']'] = 1; } } } } if ($type & self::TAG) { $fName = 'tag'; if ($fieldName) { $fName = $fieldName; } $contactTag = CRM_Core_BAO_EntityTag::getTag($id); if ($contactTag) { foreach ($contactTag as $tag) { $defaults[$fName . '[' . $tag . ']'] = 1; } } } }
/** * set defaults for relevant form elements * * @param int $id the contact id * @param array $defaults the defaults array to store the values in * @param int $type what components are we interested in * @param string $fieldName this is used in batch profile(i.e to build multiple blocks) * * @return void * @access public * @static */ static function setDefaults($id, &$defaults, $type = CRM_Contact_Form_Edit_TagsandGroups::ALL, $fieldName = null) { $type = (int) $type; if ($type & self::GROUP) { $fName = 'group'; if ($fieldName) { $fName = $fieldName; } require_once 'CRM/Contact/BAO/GroupContact.php'; $contactGroup =& CRM_Contact_BAO_GroupContact::getContactGroup($id, 'Added', null, false, true); if ($contactGroup) { foreach ($contactGroup as $group) { $defaults[$fName . "[" . $group['group_id'] . "]"] = 1; } } } if ($type & self::TAG) { $fName = 'tag'; if ($fieldName) { $fName = $fieldName; } require_once 'CRM/Core/BAO/EntityTag.php'; $contactTag =& CRM_Core_BAO_EntityTag::getTag($id); if ($contactTag) { foreach ($contactTag as $tag) { $defaults[$fName . "[" . $tag . "]"] = 1; } } } }
/** * Fix what blocks to show/hide based on the default values set * * @param array $defaults the array of default values * @param boolean $force should we set show hide based on input defaults * * @return void */ function setShowHide(&$defaults, $force) { $this->_showHide =& new CRM_Core_ShowHideBlocks(array('commPrefs' => 1), ''); if ($this->_contactType == 'Individual') { $this->_showHide->addShow('demographics[show]'); $this->_showHide->addHide('demographics'); } // first do the defaults showing CRM_Contact_Form_Location::setShowHideDefaults($this->_showHide, CRM_CONTACT_FORM_EDIT_LOCATION_BLOCKS); if ($this->_action & CRM_CORE_ACTION_ADD) { // notes are only included in the template for New Contact $this->_showHide->addShow('notes[show]'); $this->_showHide->addHide('notes'); } //add group and tags $contactGroup = $contactTag = array(); if ($this->_contactId) { $contactGroup =& CRM_Contact_BAO_GroupContact::getContactGroup($this->_contactId, 'Added'); $contactTag =& CRM_Core_BAO_EntityTag::getTag('civicrm_contact', $this->_contactId); } if (empty($contactGroup) || empty($contactTag)) { $this->_showHide->addShow('group[show]'); $this->_showHide->addHide('group'); } else { $this->_showHide->addShow('group'); $this->_showHide->addHide('group[show]'); } // is there any demographics data? if (CRM_Utils_Array::value('gender_id', $defaults) || CRM_Utils_Array::value('is_deceased', $defaults) || CRM_Utils_Array::value('birth_date', $defaults)) { $this->_showHide->addShow('demographics'); $this->_showHide->addHide('demographics[show]'); } if ($force) { $locationDefaults = CRM_Utils_Array::value('location', $defaults); CRM_Contact_Form_Location::updateShowHide($this->_showHide, $locationDefaults, CRM_CONTACT_FORM_EDIT_LOCATION_BLOCKS); } $this->_showHide->addToTemplate(); }
/** * Given a contact id and a field set, return the values from the db * for this contact * * @param int $id the contact id * @param array $fields the profile fields of interest * @param array $values the values for the above fields * @param boolean $searchable searchable or not * @param array $componentWhere component condition * * @return void * @access public * @static */ public static function getValues($cid, &$fields, &$values, $searchable = true, $componentWhere = null) { if (empty($cid)) { return null; } $options = array(); $studentFields = array(); if (CRM_Core_Permission::access('Quest', false)) { //student fields ( check box ) require_once 'CRM/Quest/BAO/Student.php'; $studentFields = CRM_Quest_BAO_Student::$multipleSelectFields; } // get the contact details (hier) $returnProperties =& CRM_Contact_BAO_Contact::makeHierReturnProperties($fields); $params = array(array('contact_id', '=', $cid, 0, 0)); // add conditions specified by components. eg partcipant_id etc if (!empty($componentWhere)) { $params = array_merge($params, $componentWhere); } $query =& new CRM_Contact_BAO_Query($params, $returnProperties, $fields); $options =& $query->_options; $details = $query->searchQuery(); if (!$details->fetch()) { return; } $config =& CRM_Core_Config::singleton(); require_once 'CRM/Core/PseudoConstant.php'; $locationTypes = $imProviders = array(); $locationTypes = CRM_Core_PseudoConstant::locationType(); $imProviders = CRM_Core_PseudoConstant::IMProvider(); //start of code to set the default values foreach ($fields as $name => $field) { // fix for CRM-3962 if ($name == 'id') { $name = 'contact_id'; } $index = $field['title']; $params[$index] = $values[$index] = ''; $customFieldName = null; $elements = array('email_greeting_custom' => 'email_greeting', 'postal_greeting_custom' => 'postal_greeting', 'addressee_custom' => 'addressee'); if (isset($details->{$name}) || $name == 'group' || $name == 'tag') { //hack for CRM-665 // to handle gender / suffix / prefix if (in_array($name, array('gender', 'individual_prefix', 'individual_suffix'))) { $values[$index] = $details->{$name}; $name = $name . '_id'; $params[$index] = $details->{$name}; } else { if (in_array($name, array('email_greeting', 'postal_greeting', 'addressee'))) { $dname = $name . '_display'; $values[$index] = $details->{$dname}; $name = $name . '_id'; $params[$index] = $details->{$name}; } else { if (in_array($name, array('state_province', 'country', 'county'))) { $values[$index] = $details->{$name}; $idx = $name . '_id'; $params[$index] = $details->{$idx}; } else { if ($name === 'preferred_communication_method') { $communicationFields = CRM_Core_PseudoConstant::pcm(); $pref = array(); $compref = array(); $pref = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $details->{$name}); foreach ($pref as $k) { if ($k) { $compref[] = $communicationFields[$k]; } } $params[$index] = $details->{$name}; $values[$index] = implode(",", $compref); } else { if ($name == 'group') { $groups = CRM_Contact_BAO_GroupContact::getContactGroup($cid, 'Added', null, false, true); $title = array(); $ids = array(); foreach ($groups as $g) { if ($g['visibility'] != 'User and User Admin Only') { $title[] = $g['title']; if ($g['visibility'] == 'Public Pages') { $ids[] = $g['group_id']; } } } $values[$index] = implode(', ', $title); $params[$index] = implode(',', $ids); } else { if ($name == 'tag') { require_once 'CRM/Core/BAO/EntityTag.php'; $entityTags =& CRM_Core_BAO_EntityTag::getTag($cid); $allTags =& CRM_Core_PseudoConstant::tag(); $title = array(); foreach ($entityTags as $tagId) { $title[] = $allTags[$tagId]; } $values[$index] = implode(', ', $title); $params[$index] = implode(',', $entityTags); } else { if (array_key_exists($name, $studentFields)) { require_once 'CRM/Core/OptionGroup.php'; $paramsNew = array($name => $details->{$name}); if ($name == 'test_tutoring') { $names = array($name => array('newName' => $index, 'groupName' => 'test')); } else { if (substr($name, 0, 4) == 'cmr_') { //for readers group $names = array($name => array('newName' => $index, 'groupName' => substr($name, 0, -3))); } else { $names = array($name => array('newName' => $index, 'groupName' => $name)); } } CRM_Core_OptionGroup::lookupValues($paramsNew, $names, false); $values[$index] = $paramsNew[$index]; $params[$index] = $paramsNew[$name]; } else { $processed = false; if (CRM_Core_Permission::access('Quest', false)) { require_once 'CRM/Quest/BAO/Student.php'; $processed = CRM_Quest_BAO_Student::buildStudentForm($this, $field); } if (!$processed) { if (substr($name, 0, 7) === 'do_not_' or substr($name, 0, 3) === 'is_') { if ($details->{$name}) { $values[$index] = '[ x ]'; } } else { require_once 'CRM/Core/BAO/CustomField.php'; if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name)) { $htmlType = $field['html_type']; $dataType = $field['data_type']; if ($htmlType == 'File') { $fileURL = CRM_Core_BAO_CustomField::getFileURL($cid, $cfID); $params[$index] = $values[$index] = $fileURL['file_url']; } else { $customVal = null; if (isset($dao) && ($dao->data_type == 'Int' || $dao->data_type == 'Boolean')) { $customVal = (int) $details->{$name}; } else { if (isset($dao) && $dao->data_type == 'Float') { $customVal = (double) $details->{$name}; } else { if (!CRM_Utils_System::isNull(explode(CRM_Core_DAO::VALUE_SEPARATOR, $details->{$name}))) { $customVal = $details->{$name}; } } } //CRM-4582 if (CRM_Utils_System::isNull($customVal)) { continue; } $params[$index] = $customVal; $values[$index] = CRM_Core_BAO_CustomField::getDisplayValue($customVal, $cfID, $options); if ($htmlType == 'Autocomplete-Select') { $params[$index] = $values[$index]; } if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $cfID, 'is_search_range')) { $customFieldName = "{$name}_from"; } } } else { if ($name == 'home_URL' && !empty($details->{$name})) { $url = CRM_Utils_System::fixURL($details->{$name}); $values[$index] = "<a href=\"{$url}\">{$details->{$name}}</a>"; } else { if (in_array($name, array('birth_date', 'deceased_date', 'membership_start_date', 'membership_end_date', 'join_date'))) { require_once 'CRM/Utils/Date.php'; $values[$index] = CRM_Utils_Date::customFormat($details->{$name}); $params[$index] = CRM_Utils_Date::isoToMysql($details->{$name}); } else { $values[$index] = $details->{$name}; } } } } } } } } } } } } } else { if (strpos($name, '-') !== false) { list($fieldName, $id, $type) = CRM_Utils_System::explode('-', $name, 3); if ($id == 'Primary') { // fix for CRM-1543 // not sure why we'd every use Primary location type id // we need to fix the source if we are using it // $locationTypeName = CRM_Contact_BAO_Contact::getPrimaryLocationType( $cid ); $locationTypeName = 1; } else { $locationTypeName = CRM_Utils_Array::value($id, $locationTypes); } if (!$locationTypeName) { continue; } $detailName = "{$locationTypeName}-{$fieldName}"; $detailName = str_replace(' ', '_', $detailName); if (in_array($fieldName, array('phone', 'im', 'email', 'openid'))) { if ($type) { $detailName .= "-{$type}"; } } if (in_array($fieldName, array('state_province', 'country', 'county'))) { $values[$index] = $details->{$detailName}; $idx = $detailName . '_id'; $params[$index] = $details->{$idx}; } else { if ($fieldName == 'im') { $providerId = $detailName . '-provider_id'; $providerName = $imProviders[$details->{$providerId}]; if ($providerName) { $values[$index] = $details->{$detailName} . " (" . $providerName . ")"; } else { $values[$index] = $details->{$detailName}; } $params[$index] = $details->{$detailName}; } else { $values[$index] = $params[$index] = $details->{$detailName}; } } } } if ($field['visibility'] == "Public Pages and Listings" && CRM_Core_Permission::check('profile listings and forms')) { if (CRM_Utils_System::isNull($params[$index])) { $params[$index] = $values[$index]; } if (!isset($params[$index])) { continue; } $customFieldID = CRM_Core_BAO_CustomField::getKeyID($field['name']); if (!$customFieldName) { $fieldName = $field['name']; } else { $fieldName = $customFieldName; } $url = null; if (CRM_Core_BAO_CustomField::getKeyID($field['name'])) { $htmlType = $field['html_type']; if ($htmlType == 'Link') { $url = $params[$index]; } else { if (in_array($htmlType, array('CheckBox', 'Multi-Select', 'AdvMulti-Select', 'Multi-Select State/Province', 'Multi-Select Country'))) { $valSeperator = CRM_Core_BAO_CustomOption::VALUE_SEPERATOR; $selectedOptions = explode($valSeperator, $params[$index]); foreach ($selectedOptions as $key => $multiOption) { if ($multiOption) { $eachOption = $valSeperator . $multiOption . $valSeperator; $url[] = CRM_Utils_System::url('civicrm/profile', 'reset=1&force=1&gid=' . $field['group_id'] . '&' . urlencode($fieldName) . '=' . urlencode($eachOption)); } } } else { $url = CRM_Utils_System::url('civicrm/profile', 'reset=1&force=1&gid=' . $field['group_id'] . '&' . urlencode($fieldName) . '=' . urlencode($params[$index])); } } } else { $url = CRM_Utils_System::url('civicrm/profile', 'reset=1&force=1&gid=' . $field['group_id'] . '&' . urlencode($fieldName) . '=' . urlencode($params[$index])); } if ($url && !empty($values[$index]) && $searchable) { if (is_array($url) && !empty($url)) { $links = array(); $eachMultiValue = explode(', ', $values[$index]); foreach ($eachMultiValue as $key => $valueLabel) { $links[] = '<a href="' . $url[$key] . '">' . $valueLabel . '</a>'; } $values[$index] = implode(', ', $links); } else { $values[$index] = '<a href="' . $url . '">' . $values[$index] . '</a>'; } } } } }
/** * set defaults for relevant form elements * * @param int $id the contact id * @param array $defaults the defaults array to store the values in * @param int $type what components are we interested in * @param string $fieldName this is used in batch profile(i.e to build multiple blocks) * * @return void * @access public * @static */ static function setDefaults($id, &$defaults, $type = CRM_Contact_Form_Edit_TagsandGroups::ALL, $fieldName = NULL) { $type = (int) $type; if ($type & self::GROUP) { $fName = 'group'; if ($fieldName) { $fName = $fieldName; } $contactGroup = CRM_Contact_BAO_GroupContact::getContactGroup($id, 'Added', NULL, FALSE, TRUE); if ($contactGroup) { foreach ($contactGroup as $group) { $defaults[$fName . '[' . $group['group_id'] . ']'] = 1; } } } if ($type & self::TAG) { $fName = 'tag'; if ($fieldName) { $fName = $fieldName; } $contactTag = CRM_Core_BAO_EntityTag::getTag($id); if ($contactTag) { foreach ($contactTag as $tag) { $defaults[$fName . '[' . $tag . ']'] = 1; } } } }
/** * Given the component name and returns * the count of participation of contact * * @param string $component input component name * @param integer $contactId input contact id * @param string $tableName optional tableName if component is custom group * * @return total number of count of occurence in database * @access public * @static */ static function getCountComponent($component, $contactId, $tableName = null) { $object = null; switch ($component) { case 'tag': require_once 'CRM/Core/BAO/EntityTag.php'; return CRM_Core_BAO_EntityTag::getContactTags($contactId, true); case 'rel': require_once 'CRM/Contact/BAO/Relationship.php'; return count(CRM_Contact_BAO_Relationship::getRelationship($contactId)); case 'group': require_once 'CRM/Contact/BAO/GroupContact.php'; return CRM_Contact_BAO_GroupContact::getContactGroup($contactId, null, null, true); case 'log': require_once 'CRM/Core/BAO/Log.php'; return CRM_Core_BAO_Log::getContactLogCount($contactId); case 'note': require_once 'CRM/Core/BAO/Note.php'; return CRM_Core_BAO_Note::getContactNoteCount($contactId); case 'contribution': require_once 'CRM/Contribute/BAO/Contribution.php'; return CRM_Contribute_BAO_Contribution::contributionCount($contactId); case 'membership': require_once 'CRM/Member/BAO/Membership.php'; return CRM_Member_BAO_Membership::getContactMembershipCount($contactId); case 'participant': require_once 'CRM/Event/BAO/Participant.php'; return CRM_Event_BAO_Participant::getContactParticipantCount($contactId); case 'pledge': require_once 'CRM/Pledge/BAO/Pledge.php'; return CRM_Pledge_BAO_Pledge::getContactPledgeCount($contactId); case 'case': require_once 'CRM/Case/BAO/Case.php'; return CRM_Case_BAO_Case::caseCount($contactId); case 'grant': require_once 'CRM/Grant/BAO/Grant.php'; return CRM_Grant_BAO_Grant::getContactGrantCount($contactId); case 'activity': require_once 'CRM/Activity/BAO/Activity.php'; return CRM_Activity_BAO_Activity::getActivitiesCount($contactId, false, null, null); default: $custom = explode('_', $component); if ($custom['0'] = 'custom') { require_once 'CRM/Core/DAO/CustomGroup.php'; if (!$tableName) { $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $custom['1'], 'table_name'); } $queryString = "SELECT count(id) FROM {$tableName} WHERE entity_id = {$contactId}"; return CRM_Core_DAO::singleValueQuery($queryString); } } }
/** * takes an associative array and creates / removes * contacts from the groups * * * @param array $params (reference ) an assoc array of name/value pairs * @param array $contactId contact id * * @return none * @access public * @static */ static function create(&$params, $contactId, $visibility = false, $method = 'Admin') { $contactIds = array(); $contactIds[] = $contactId; if ($contactId) { $contactGroupList =& CRM_Contact_BAO_GroupContact::getContactGroup($contactId, 'Added'); if (is_array($contactGroupList)) { foreach ($contactGroupList as $key) { $groupId = $key['group_id']; $contactGroup[$groupId] = $groupId; } } } // get the list of all the groups $allGroup =& CRM_Contact_BAO_GroupContact::getGroupList(0, $visibility); // this fix is done to prevent warning generated by array_key_exits incase of empty array is given as input if (!is_array($params)) { $params = array(); } // this fix is done to prevent warning generated by array_key_exits incase of empty array is given as input if (!isset($contactGroup) || !is_array($contactGroup)) { $contactGroup = array(); } // check which values has to be add/remove contact from group foreach ($allGroup as $key => $varValue) { if (CRM_Utils_Array::value($key, $params) && !array_key_exists($key, $contactGroup)) { // add contact to group CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $key, $method); } else { if (!CRM_Utils_Array::value($key, $params) && array_key_exists($key, $contactGroup)) { // remove contact from group CRM_Contact_BAO_GroupContact::removeContactsFromGroup($contactIds, $key, $method); } } } }
/** * Form submission of new/edit contact is processed. * * @access public * @return None */ public function postProcess() { // check if dedupe button, if so return. $buttonName = $this->controller->getButtonName(); if ($buttonName == $this->_dedupeButtonName) { return; } //get the submitted values in an array $params = $this->controller->exportValues($this->_name); //get the related id for shared / current employer if (CRM_Utils_Array::value('shared_household_id', $params)) { $params['shared_household'] = $params['shared_household_id']; } if (is_numeric(CRM_Utils_Array::value('current_employer_id', $params)) && CRM_Utils_Array::value('current_employer', $params)) { $params['current_employer'] = $params['current_employer_id']; } // don't carry current_employer_id field, // since we don't want to directly update DAO object without // handling related business logic ( eg related membership ) if (isset($params['current_employer_id'])) { unset($params['current_employer_id']); } $params['contact_type'] = $this->_contactType; if ($this->_contactId) { $params['contact_id'] = $this->_contactId; } //make deceased date null when is_deceased = false if ($this->_contactType == 'Individual' && CRM_Utils_Array::value('Demographics', $this->_editOptions) && !CRM_Utils_Array::value('is_deceased', $params)) { $params['is_deceased'] = false; $params['deceased_date'] = null; } if ($this->_contactSubType && $this->_action & CRM_Core_Action::ADD) { $params['contact_sub_type'] = $this->_contactSubType; } // action is taken depending upon the mode require_once 'CRM/Utils/Hook.php'; if ($this->_action & CRM_Core_Action::UPDATE) { CRM_Utils_Hook::pre('edit', $params['contact_type'], $params['contact_id'], $params); } else { CRM_Utils_Hook::pre('create', $params['contact_type'], null, $params); } require_once 'CRM/Core/BAO/CustomField.php'; $customFields = CRM_Core_BAO_CustomField::getFields($params['contact_type'], false, true); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_contactId, $params['contact_type'], true); if (array_key_exists('CommunicationPreferences', $this->_editOptions)) { // this is a chekbox, so mark false if we dont get a POST value $params['is_opt_out'] = CRM_Utils_Array::value('is_opt_out', $params, false); } // copy household address, if use_household_address option (for individual form) is checked if ($this->_contactType == 'Individual') { if (CRM_Utils_Array::value('use_household_address', $params) && CRM_Utils_Array::value('shared_household', $params)) { if (is_numeric($params['shared_household'])) { CRM_Contact_Form_Edit_Individual::copyHouseholdAddress($params); } CRM_Contact_Form_Edit_Individual::createSharedHousehold($params); } else { $params['mail_to_household_id'] = 'null'; } } else { $params['mail_to_household_id'] = 'null'; } if (!array_key_exists('TagsAndGroups', $this->_editOptions)) { unset($params['group']); } if (CRM_Utils_Array::value('contact_id', $params) && $this->_action & CRM_Core_Action::UPDATE) { // cleanup unwanted location blocks require_once 'CRM/Core/BAO/Location.php'; CRM_Core_BAO_Location::cleanupContactLocations($params); // figure out which all groups are intended to be removed if (!empty($params['group'])) { $contactGroupList =& CRM_Contact_BAO_GroupContact::getContactGroup($params['contact_id'], 'Added'); if (is_array($contactGroupList)) { foreach ($contactGroupList as $key) { if ($params['group'][$key['group_id']] != 1) { $params['group'][$key['group_id']] = -1; } } } } } require_once 'CRM/Contact/BAO/Contact.php'; $contact =& CRM_Contact_BAO_Contact::create($params, true, false); if ($this->_contactType == 'Individual' && CRM_Utils_Array::value('use_household_address', $params) && CRM_Utils_Array::value('mail_to_household_id', $params)) { // add/edit/delete the relation of individual with household, if use-household-address option is checked/unchecked. CRM_Contact_Form_Edit_Individual::handleSharedRelation($contact->id, $params); } if ($this->_contactType == 'Household' && $this->_action & CRM_Core_Action::UPDATE) { //TO DO: commented because of schema changes require_once 'CRM/Contact/Form/Edit/Household.php'; CRM_Contact_Form_Edit_Household::synchronizeIndividualAddresses($contact->id); } if (array_key_exists('TagsAndGroups', $this->_editOptions)) { //add contact to tags require_once 'CRM/Core/BAO/EntityTag.php'; CRM_Core_BAO_EntityTag::create($params['tag'], $params['contact_id']); } // here we replace the user context with the url to view this contact $session =& CRM_Core_Session::singleton(); CRM_Core_Session::setStatus(ts('Your %1 contact record has been saved.', array(1 => $contact->contact_type_display))); $buttonName = $this->controller->getButtonName(); if ($buttonName == $this->getButtonName('next', 'new') || $buttonName == $this->getButtonName('upload', 'new')) { require_once 'CRM/Utils/Recent.php'; // add the recently viewed contact $displayName = CRM_Contact_BAO_Contact::displayName($contact->id); CRM_Utils_Recent::add($displayName, CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $contact->id), $contact->id, $this->_contactType, $contact->id, $displayName); $resetStr = "reset=1&ct={$contact->contact_type}"; $resetStr .= $this->_contactSubType ? "&cst={$this->_contactSubType}" : ''; $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/add', $resetStr)); } else { $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $contact->id)); } // now invoke the post hook if ($this->_action & CRM_Core_Action::UPDATE) { CRM_Utils_Hook::post('edit', $params['contact_type'], $contact->id, $contact); } else { CRM_Utils_Hook::post('create', $params['contact_type'], $contact->id, $contact); } }
/** * Given a contact id and a field set, return the values from the db * for this contact * * @param int $cid * @param array $fields * The profile fields of interest. * @param array $values * The values for the above fields. * @param bool $searchable * Searchable or not. * @param array $componentWhere * Component condition. * @param bool $absolute * Return urls in absolute form (useful when sending an email). * @param null $additionalWhereClause */ public static function getValues($cid, &$fields, &$values, $searchable = TRUE, $componentWhere = NULL, $absolute = FALSE, $additionalWhereClause = NULL) { if (empty($cid) && empty($componentWhere)) { return NULL; } // get the contact details (hier) $returnProperties = CRM_Contact_BAO_Contact::makeHierReturnProperties($fields); $params = $cid ? array(array('contact_id', '=', $cid, 0, 0)) : array(); // add conditions specified by components. eg partcipant_id etc if (!empty($componentWhere)) { $params = array_merge($params, $componentWhere); } $query = new CRM_Contact_BAO_Query($params, $returnProperties, $fields); $options =& $query->_options; $details = $query->searchQuery(0, 0, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, $additionalWhereClause); if (!$details->fetch()) { return; } $query->convertToPseudoNames($details); $config = CRM_Core_Config::singleton(); $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'); $websiteTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id'); $multipleFields = array('url'); //start of code to set the default values foreach ($fields as $name => $field) { // fix for CRM-3962 if ($name == 'id') { $name = 'contact_id'; } // skip fields that should not be displayed separately if (!empty($field['skipDisplay'])) { continue; } // Create a unique, non-empty index for each field. $index = $field['title']; if ($index === '') { $index = ' '; } while (array_key_exists($index, $values)) { $index .= ' '; } $params[$index] = $values[$index] = ''; $customFieldName = NULL; // hack for CRM-665 if (isset($details->{$name}) || $name == 'group' || $name == 'tag') { // to handle gender / suffix / prefix if (in_array(substr($name, 0, -3), array('gender', 'prefix', 'suffix'))) { $params[$index] = $details->{$name}; $values[$index] = $details->{$name}; } elseif (in_array($name, CRM_Contact_BAO_Contact::$_greetingTypes)) { $dname = $name . '_display'; $values[$index] = $details->{$dname}; $name = $name . '_id'; $params[$index] = $details->{$name}; } elseif (in_array($name, array('state_province', 'country', 'county'))) { $values[$index] = $details->{$name}; $idx = $name . '_id'; $params[$index] = $details->{$idx}; } elseif ($name === 'preferred_communication_method') { $communicationFields = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method'); $compref = array(); $pref = explode(CRM_Core_DAO::VALUE_SEPARATOR, $details->{$name}); foreach ($pref as $k) { if ($k) { $compref[] = $communicationFields[$k]; } } $params[$index] = $details->{$name}; $values[$index] = implode(',', $compref); } elseif ($name === 'preferred_language') { $params[$index] = $details->{$name}; $values[$index] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', 'preferred_language', $details->{$name}); } elseif ($name == 'group') { $groups = CRM_Contact_BAO_GroupContact::getContactGroup($cid, 'Added', NULL, FALSE, TRUE); $title = $ids = array(); foreach ($groups as $g) { // CRM-8362: User and User Admin visibility groups should be included in display if user has // VIEW permission on that group $groupPerm = CRM_Contact_BAO_Group::checkPermission($g['group_id'], $g['title']); if ($g['visibility'] != 'User and User Admin Only' || CRM_Utils_Array::key(CRM_Core_Permission::VIEW, $groupPerm)) { $title[] = $g['title']; if ($g['visibility'] == 'Public Pages') { $ids[] = $g['group_id']; } } } $values[$index] = implode(', ', $title); $params[$index] = implode(',', $ids); } elseif ($name == 'tag') { $entityTags = CRM_Core_BAO_EntityTag::getTag($cid); $allTags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE)); $title = array(); foreach ($entityTags as $tagId) { $title[] = $allTags[$tagId]; } $values[$index] = implode(', ', $title); $params[$index] = implode(',', $entityTags); } elseif ($name == 'activity_status_id') { $activityStatus = CRM_Core_PseudoConstant::activityStatus(); $values[$index] = $activityStatus[$details->{$name}]; $params[$index] = $details->{$name}; } elseif ($name == 'activity_date_time') { $values[$index] = CRM_Utils_Date::customFormat($details->{$name}); $params[$index] = $details->{$name}; } elseif ($name == 'contact_sub_type') { $contactSubTypeNames = explode(CRM_Core_DAO::VALUE_SEPARATOR, $details->{$name}); if (!empty($contactSubTypeNames)) { $contactSubTypeLabels = array(); // get all contact subtypes $allContactSubTypes = CRM_Contact_BAO_ContactType::subTypeInfo(); // build contact subtype labels array foreach ($contactSubTypeNames as $cstName) { if ($cstName) { $contactSubTypeLabels[] = $allContactSubTypes[$cstName]['label']; } } $values[$index] = implode(',', $contactSubTypeLabels); } $params[$index] = $details->{$name}; } else { if (substr($name, 0, 7) === 'do_not_' || substr($name, 0, 3) === 'is_') { if ($details->{$name}) { $values[$index] = '[ x ]'; } } else { if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name)) { $htmlType = $field['html_type']; // field_type is only set when we are retrieving profile values // when sending email, we call the same function to get custom field // values etc, i.e. emulating a profile $fieldType = CRM_Utils_Array::value('field_type', $field); if ($htmlType == 'File') { $entityId = $cid; if (!$cid && $fieldType == 'Activity' && !empty($componentWhere[0][2])) { $entityId = $componentWhere[0][2]; } $fileURL = CRM_Core_BAO_CustomField::getFileURL($entityId, $cfID, NULL, $absolute, $additionalWhereClause); $params[$index] = $values[$index] = $fileURL['file_url']; } else { $customVal = NULL; if (isset($dao) && property_exists($dao, 'data_type') && ($dao->data_type == 'Int' || $dao->data_type == 'Boolean')) { $customVal = (int) $details->{$name}; } elseif (isset($dao) && property_exists($dao, 'data_type') && $dao->data_type == 'Float') { $customVal = (double) $details->{$name}; } elseif (!CRM_Utils_System::isNull(explode(CRM_Core_DAO::VALUE_SEPARATOR, $details->{$name}))) { $customVal = $details->{$name}; } //CRM-4582 if (CRM_Utils_System::isNull($customVal)) { continue; } $params[$index] = $customVal; $values[$index] = CRM_Core_BAO_CustomField::getDisplayValue($customVal, $cfID, $options); if ($field['data_type'] == 'ContactReference') { $params[$index] = $values[$index]; } if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $cfID, 'is_search_range')) { $customFieldName = "{$name}_from"; } } } elseif ($name == 'image_URL') { list($width, $height) = getimagesize(CRM_Utils_String::unstupifyUrl($details->{$name})); list($thumbWidth, $thumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($width, $height); $image_URL = '<img src="' . $details->{$name} . '" height= ' . $thumbHeight . ' width= ' . $thumbWidth . ' />'; $values[$index] = "<a href='#' onclick='contactImagePopUp(\"{$details->{$name}}\", {$width}, {$height});'>{$image_URL}</a>"; } elseif (in_array($name, array('birth_date', 'deceased_date', 'membership_start_date', 'membership_end_date', 'join_date'))) { $values[$index] = CRM_Utils_Date::customFormat($details->{$name}); $params[$index] = CRM_Utils_Date::isoToMysql($details->{$name}); } else { $dao = ''; if ($index == 'Campaign') { $dao = 'CRM_Campaign_DAO_Campaign'; } elseif ($index == 'Contribution Page') { $dao = 'CRM_Contribute_DAO_ContributionPage'; } if ($dao) { $value = CRM_Core_DAO::getFieldValue($dao, $details->{$name}, 'title'); } else { $value = $details->{$name}; } $values[$index] = $value; } } } } elseif (strpos($name, '-') !== FALSE) { list($fieldName, $id, $type) = CRM_Utils_System::explode('-', $name, 3); if (!in_array($fieldName, $multipleFields)) { if ($id == 'Primary') { // fix for CRM-1543 // not sure why we'd every use Primary location type id // we need to fix the source if we are using it // $locationTypeName = CRM_Contact_BAO_Contact::getPrimaryLocationType( $cid ); $locationTypeName = 1; } else { $locationTypeName = CRM_Utils_Array::value($id, $locationTypes); } if (!$locationTypeName) { continue; } $detailName = "{$locationTypeName}-{$fieldName}"; $detailName = str_replace(' ', '_', $detailName); if (in_array($fieldName, array('phone', 'im', 'email', 'openid'))) { if ($type) { $detailName .= "-{$type}"; } } if (in_array($fieldName, array('state_province', 'country', 'county'))) { $values[$index] = $details->{$detailName}; $idx = $detailName . '_id'; $params[$index] = $details->{$idx}; } elseif ($fieldName == 'im') { $providerId = $detailName . '-provider_id'; if (isset($imProviders[$details->{$providerId}])) { $values[$index] = $details->{$detailName} . " (" . $imProviders[$details->{$providerId}] . ")"; } else { $values[$index] = $details->{$detailName}; } $params[$index] = $details->{$detailName}; } elseif ($fieldName == 'phone') { $phoneExtField = str_replace('phone', 'phone_ext', $detailName); if (isset($details->{$phoneExtField})) { $values[$index] = $details->{$detailName} . " (" . $details->{$phoneExtField} . ")"; } else { $values[$index] = $details->{$detailName}; } $params[$index] = $details->{$detailName}; } else { $values[$index] = $params[$index] = $details->{$detailName}; } } else { $detailName = "website-{$id}-{$fieldName}"; $url = CRM_Utils_System::fixURL($details->{$detailName}); if ($details->{$detailName}) { $websiteTypeId = "website-{$id}-website_type_id"; $websiteType = $websiteTypes[$details->{$websiteTypeId}]; $values[$index] = "<a href=\"{$url}\">{$details->{$detailName}} ( {$websiteType} )</a>"; } else { $values[$index] = ''; } } } if (CRM_Utils_Array::value('visibility', $field) == 'Public Pages and Listings' && CRM_Core_Permission::check('profile listings and forms')) { if (CRM_Utils_System::isNull($params[$index])) { $params[$index] = $values[$index]; } if (!isset($params[$index])) { continue; } if (!$customFieldName) { $fieldName = $field['name']; } else { $fieldName = $customFieldName; } $url = NULL; if (CRM_Core_BAO_CustomField::getKeyID($field['name'])) { $htmlType = $field['html_type']; if ($htmlType == 'Link') { $url = $params[$index]; } elseif (in_array($htmlType, array('CheckBox', 'Multi-Select', 'AdvMulti-Select', 'Multi-Select State/Province', 'Multi-Select Country'))) { $valSeperator = CRM_Core_DAO::VALUE_SEPARATOR; $selectedOptions = explode($valSeperator, $params[$index]); foreach ($selectedOptions as $key => $multiOption) { if ($multiOption) { $url[] = CRM_Utils_System::url('civicrm/profile', 'reset=1&force=1&gid=' . $field['group_id'] . '&' . urlencode($fieldName) . '=' . urlencode($multiOption)); } } } else { $url = CRM_Utils_System::url('civicrm/profile', 'reset=1&force=1&gid=' . $field['group_id'] . '&' . urlencode($fieldName) . '=' . urlencode($params[$index])); } } else { $url = CRM_Utils_System::url('civicrm/profile', 'reset=1&force=1&gid=' . $field['group_id'] . '&' . urlencode($fieldName) . '=' . urlencode($params[$index])); } if ($url && !empty($values[$index]) && $searchable) { if (is_array($url) && !empty($url)) { $links = array(); $eachMultiValue = explode(', ', $values[$index]); foreach ($eachMultiValue as $key => $valueLabel) { $links[] = '<a href="' . $url[$key] . '">' . $valueLabel . '</a>'; } $values[$index] = implode(', ', $links); } else { $values[$index] = '<a href="' . $url . '">' . $values[$index] . '</a>'; } } } } }
/** * Given the component name and returns * the count of participation of contact * * @param string $component input component name * @param integer $contactId input contact id * * @return total number of count of occurence in database * @access public * @static */ static function getCountComponent($component, $contactId) { $object = null; switch ($component) { case 'tag': require_once 'CRM/Core/BAO/EntityTag.php'; return count(CRM_Core_BAO_EntityTag::getTag($contactId)); case 'rel': require_once 'CRM/Contact/BAO/Relationship.php'; return count(CRM_Contact_BAO_Relationship::getRelationship($contactId)); case 'group': require_once 'CRM/Contact/BAO/GroupContact.php'; return CRM_Contact_BAO_GroupContact::getContactGroup($contactId, null, null, true); case 'log': case 'note': eval('$object =& new CRM_Core_DAO_' . $component . '( );'); $object->entity_table = 'civicrm_contact'; $object->entity_id = $contactId; $object->orderBy('modified_date desc'); break; case 'contribution': require_once 'CRM/Contribute/BAO/Contribution.php'; return CRM_Contribute_BAO_Contribution::contributionCount($contactId); break; case 'membership': require_once 'CRM/Member/DAO/Membership.php'; eval('$object =& new CRM_Member_DAO_Membership( );'); $object->contact_id = $contactId; $object->is_test = 0; break; case 'participant': require_once 'CRM/Event/DAO/Participant.php'; eval('$object =& new CRM_Event_DAO_Participant( );'); $object->contact_id = $contactId; $object->is_test = 0; break; case 'pledge': require_once 'CRM/Pledge/DAO/Pledge.php'; eval('$object =& new CRM_Pledge_DAO_Pledge( );'); $object->contact_id = $contactId; $object->is_test = 0; break; case 'case': require_once 'CRM/Case/BAO/Case.php'; return CRM_Case_BAO_Case::caseCount($contactId); case 'grant': require_once 'CRM/Grant/DAO/Grant.php'; eval('$object =& new CRM_Grant_DAO_Grant( );'); $object->contact_id = $contactId; break; case 'activity': require_once 'CRM/Activity/BAO/Activity.php'; return CRM_Activity_BAO_Activity::getActivitiesCount($contactId, false, null, null); default: $custom = explode('_', $component); if ($custom['0'] = 'custom') { require_once 'CRM/Core/DAO/CustomGroup.php'; $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $custom['1'], 'table_name'); $queryString = "SELECT count(id) FROM {$tableName} WHERE entity_id = {$contactId}"; return CRM_Core_DAO::singleValueQuery($queryString); } } $object->find(); return $object->N; }
/** * function to remove/ rejoin the group * * @param int $groupContactId id of crm_group_contact * @param string $status this is the status that should be updated. * * $access public */ static function del($groupContactId, $status, $contactID) { $groupId = CRM_Contact_BAO_GroupContact::getGroupId($groupContactId); switch ($status) { case 'i': $groupStatus = 'Added'; break; case 'p': $groupStatus = 'Pending'; break; case 'o': $groupStatus = 'Removed'; break; case 'd': $groupStatus = 'Deleted'; break; } $groupNum = CRM_Contact_BAO_GroupContact::getContactGroup($contactID, 'Added', NULL, TRUE, TRUE); if ($groupNum == 1 && $groupStatus == 'Removed' && CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MULTISITE_PREFERENCES_NAME, 'is_enabled')) { CRM_Core_Session::setStatus(ts('Please ensure at least one contact group association is maintained.'), ts('Could Not Remove')); return FALSE; } $ids = array($contactID); $method = 'Admin'; $session = CRM_Core_Session::singleton(); $userID = $session->get('userID'); if ($userID == $contactID) { $method = 'Web'; } CRM_Contact_BAO_GroupContact::removeContactsFromGroup($ids, $groupId, $method, $groupStatus); }
/** * set defaults for relevant form elements * * @param int $id the contact id * @param array $defaults the defaults array to store the values in * @param int $type what components are we interested in * * @return void * @access public * @static */ function setDefaults($id, &$defaults, $type = CRM_CONTACT_FORM_GROUPTAG_ALL) { $type = (int) $type; if ($type & CRM_CONTACT_FORM_GROUPTAG_GROUP) { require_once 'CRM/Contact/BAO/GroupContact.php'; $contactGroup =& CRM_Contact_BAO_GroupContact::getContactGroup($id, 'Added', null, false, true); if ($contactGroup) { foreach ($contactGroup as $group) { $defaults['group'][$group['group_id']] = 1; } } } if ($type & CRM_CONTACT_FORM_GROUPTAG_TAG) { require_once 'CRM/Core/BAO/EntityTag.php'; $contactTag =& CRM_Core_BAO_EntityTag::getTag('civicrm_contact', $id); if ($contactTag) { foreach ($contactTag as $tag) { $defaults['tag'][$tag] = 1; } } } }
/** * Get all the groups that this contact is a member of with the given status. This is used by * the Drupal module / organic group integration. Not sure why they needed a differnt twist * on the crm_contact_groups api, so here for backward compatibility * * @param int $contactId contact id * @param string $status state of membership * @param int $numGroupContact number of groups for a contact that should be shown * @param boolean $count true if we are interested only in the count * * @return array (reference )|int $values the relevant data object values for the contact or the total count when $count is true * * $access public */ function crm_contact_get_groups($contactId, $status = null, $numGroupContact = null, $count = false) { require_once 'CRM/Contact/BAO/GroupContact.php'; return CRM_Contact_BAO_GroupContact::getContactGroup($contactId, $status, $numGroupContact, $count); }
/** * Given the component name and returns the count of participation of contact. * * @param string $component * Input component name. * @param int $contactId * Input contact id. * @param string $tableName * Optional tableName if component is custom group. * * @return int * total number in database */ public static function getCountComponent($component, $contactId, $tableName = NULL) { $object = NULL; switch ($component) { case 'tag': return CRM_Core_BAO_EntityTag::getContactTags($contactId, TRUE); case 'rel': $result = CRM_Contact_BAO_Relationship::getRelationship($contactId, CRM_Contact_BAO_Relationship::CURRENT, 0, 1); return $result; case 'group': return CRM_Contact_BAO_GroupContact::getContactGroup($contactId, "Added", NULL, TRUE); case 'log': if (CRM_Core_BAO_Log::useLoggingReport()) { return FALSE; } return CRM_Core_BAO_Log::getContactLogCount($contactId); case 'note': return CRM_Core_BAO_Note::getContactNoteCount($contactId); case 'contribution': return CRM_Contribute_BAO_Contribution::contributionCount($contactId); case 'membership': return CRM_Member_BAO_Membership::getContactMembershipCount($contactId, TRUE); case 'participant': return CRM_Event_BAO_Participant::getContactParticipantCount($contactId); case 'pledge': return CRM_Pledge_BAO_Pledge::getContactPledgeCount($contactId); case 'case': return CRM_Case_BAO_Case::caseCount($contactId); case 'grant': return CRM_Grant_BAO_Grant::getContactGrantCount($contactId); case 'activity': $input = array('contact_id' => $contactId, 'admin' => FALSE, 'caseId' => NULL, 'context' => 'activity'); return CRM_Activity_BAO_Activity::getActivitiesCount($input); case 'mailing': $params = array('contact_id' => $contactId); return CRM_Mailing_BAO_Mailing::getContactMailingsCount($params); default: $custom = explode('_', $component); if ($custom['0'] = 'custom') { if (!$tableName) { $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $custom['1'], 'table_name'); } $queryString = "SELECT count(id) FROM {$tableName} WHERE entity_id = {$contactId}"; return CRM_Core_DAO::singleValueQuery($queryString); } } }
/** * function to remove/ rejoin the group * * @param int $groupContactId id of crm_group_contact * @param string $status this is the status that should be updated. * * $access public */ function del($groupContactId, $status, $contactID) { $groupId = CRM_Contact_BAO_GroupContact::getGroupId($groupContactId); switch ($status) { case 'i': $groupStatus = 'Added'; break; case 'p': $groupStatus = 'Pending'; break; case 'o': $groupStatus = 'Removed'; break; } $groupNum = CRM_Contact_BAO_GroupContact::getContactGroup($this->_contactId, 'Added', null, true, true); if (defined('CIVICRM_MULTISITE') && CIVICRM_MULTISITE && $groupNum == 1 && $groupStatus == 'Removed') { CRM_Core_Session::setStatus('make sure at least one contact group association is maintained.'); return false; } $ids = array($contactID); $method = 'Admin'; $session =& CRM_Core_Session::singleton(); $userID = $session->get('userID'); if ($userID == $contactID) { $method = 'Web'; } CRM_Contact_BAO_GroupContact::removeContactsFromGroup($ids, $groupId, $method, $groupStatus); }
/** * Takes an associative array and creates / removes * contacts from the groups * * * @param array $params * (reference ) an assoc array of name/value pairs. * @param array $contactId * Contact id. * * @param bool $visibility * @param string $method * * @return void */ public static function create(&$params, $contactId, $visibility = FALSE, $method = 'Admin') { $contactIds = array(); $contactIds[] = $contactId; //if $visibility is true we are coming in via profile mean $method = 'Web' $ignorePermission = FALSE; if ($visibility) { $ignorePermission = TRUE; } if ($contactId) { $contactGroupList =& CRM_Contact_BAO_GroupContact::getContactGroup($contactId, 'Added', NULL, FALSE, $ignorePermission); if (is_array($contactGroupList)) { foreach ($contactGroupList as $key) { $groupId = $key['group_id']; $contactGroup[$groupId] = $groupId; } } } // get the list of all the groups $allGroup = CRM_Contact_BAO_GroupContact::getGroupList(0, $visibility); // this fix is done to prevent warning generated by array_key_exits incase of empty array is given as input if (!is_array($params)) { $params = array(); } // this fix is done to prevent warning generated by array_key_exits incase of empty array is given as input if (!isset($contactGroup) || !is_array($contactGroup)) { $contactGroup = array(); } // check which values has to be add/remove contact from group foreach ($allGroup as $key => $varValue) { if (!empty($params[$key]) && !array_key_exists($key, $contactGroup)) { // add contact to group CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $key, $method); } elseif (empty($params[$key]) && array_key_exists($key, $contactGroup)) { // remove contact from group CRM_Contact_BAO_GroupContact::removeContactsFromGroup($contactIds, $key, $method); } } }
/** * Given a contact id and a field set, return the values from the db * for this contact * * @param int $id the contact id * @param array $fields the profile fields of interest * @param array $values the values for the above fields * @return void * @access public * @static */ function getValues($cid, &$fields, &$values) { $options = array(); // get the contact details (hier) $returnProperties =& CRM_Contact_BAO_Contact::makeHierReturnProperties($fields); $params = array('id' => $cid); $query =& new CRM_Contact_BAO_Query($params, $returnProperties, $fields); $options =& $query->_options; $details = $query->searchQuery(); if (!$details->fetch()) { return; } require_once 'CRM/Core/PseudoConstant.php'; $locationTypes = CRM_Core_PseudoConstant::locationType(); //start of code to set the default values foreach ($fields as $name => $field) { $index = $field['title']; $params[$index] = $values[$index] = ''; if ($details->{$name} || $name == 'group' || $name == 'tag') { //hack for CRM-665 //to handle custom data (checkbox) to be written // to handle gender / suffix / prefix if (in_array($name, array('gender', 'individual_prefix', 'individual_suffix'))) { $values[$index] = $details->{$name}; $name = $name . '_id'; $params[$index] = $details->{$name}; } else { if (in_array($name, array('state_province', 'country'))) { $values[$index] = $details->{$name}; $idx = $name . '_id'; $params[$index] = $details->{$idx}; } else { if (substr($name, 0, 7) === 'do_not_' or substr($name, 0, 3) === 'is_') { if ($details->{$name}) { $values[$index] = '[ x ]'; } } else { if ($name == 'group') { $groups = CRM_Contact_BAO_GroupContact::getContactGroup($cid, 'Added', null, false, true); $title = array(); $ids = array(); foreach ($groups as $g) { if ($g['visibility'] != 'User and User Admin Only') { $title[] = $g['title']; if ($g['visibility'] == 'Public User Pages and Listings') { $ids[] = $g['group_id']; } } } $values[$index] = implode(', ', $title); $params[$index] = implode(',', $ids); } else { if ($name == 'tag') { require_once 'CRM/Core/BAO/EntityTag.php'; $entityTags =& CRM_Core_BAO_EntityTag::getTag('civicrm_contact', $cid); $allTags =& CRM_Core_PseudoConstant::tag(); $title = array(); foreach ($entityTags as $tagId) { $title[] = $allTags[$tagId]; } $values[$index] = implode(', ', $title); $params[$index] = implode(',', $entityTags); } else { require_once 'CRM/Core/BAO/CustomField.php'; if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name)) { $params[$index] = $details->{$name}; $values[$index] = CRM_Core_BAO_CustomField::getDisplayValue($details->{$name}, $cfID, $options); } else { $values[$index] = $details->{$name}; } } } } } } } else { if (strpos($name, '-') !== false) { list($fieldName, $id, $type) = explode('-', $name); $locationTypeName = CRM_Utils_Array::value($id, $locationTypes); if (!$locationTypeName) { continue; } $detailName = "{$locationTypeName}-{$fieldName}"; if (in_array($fieldName, array('phone', 'im', 'email'))) { if ($type) { $detailName .= "-{$type}"; } else { $detailName .= '-1'; } } if (in_array($fieldName, array('state_province', 'country'))) { $values[$index] = $details->{$detailName}; $idx = $detailName . '_id'; $params[$index] = $details->{$idx}; } else { $values[$index] = $params[$index] = $details->{$detailName}; } } } if ($field['visibility'] == "Public User Pages and Listings" && CRM_Utils_System::checkPermission('profile listings and forms')) { if (CRM_Utils_System::isNull($params[$index])) { $params[$index] = $values[$index]; } if (empty($params[$index])) { continue; } $fieldName = $field['name']; $url = CRM_Utils_System::url('civicrm/profile', 'reset=1&force=1&gid=' . $field['group_id'] . '&' . urlencode($fieldName) . '=' . urlencode($params[$index])); if (!empty($values[$index])) { $values[$index] = '<a href="' . $url . '">' . $values[$index] . '</a>'; } } } }
/** * Form submission of new/edit contact is processed. */ public function postProcess() { // check if dedupe button, if so return. $buttonName = $this->controller->getButtonName(); if ($buttonName == $this->_dedupeButtonName) { return; } //get the submitted values in an array $params = $this->controller->exportValues($this->_name); $group = CRM_Utils_Array::value('group', $params); if (!empty($group) && is_array($group)) { unset($params['group']); foreach ($group as $key => $value) { $params['group'][$value] = 1; } } CRM_Contact_BAO_Contact_Optimizer::edit($params, $this->_preEditValues); if (!empty($params['image_URL'])) { CRM_Contact_BAO_Contact::processImageParams($params); } if (is_numeric(CRM_Utils_Array::value('current_employer_id', $params)) && !empty($params['current_employer'])) { $params['current_employer'] = $params['current_employer_id']; } // don't carry current_employer_id field, // since we don't want to directly update DAO object without // handling related business logic ( eg related membership ) if (isset($params['current_employer_id'])) { unset($params['current_employer_id']); } $params['contact_type'] = $this->_contactType; if (empty($params['contact_sub_type']) && $this->_isContactSubType) { $params['contact_sub_type'] = array($this->_contactSubType); } if ($this->_contactId) { $params['contact_id'] = $this->_contactId; } //make deceased date null when is_deceased = false if ($this->_contactType == 'Individual' && !empty($this->_editOptions['Demographics']) && empty($params['is_deceased'])) { $params['is_deceased'] = FALSE; $params['deceased_date'] = NULL; } if (isset($params['contact_id'])) { // process membership status for deceased contact $deceasedParams = array('contact_id' => CRM_Utils_Array::value('contact_id', $params), 'is_deceased' => CRM_Utils_Array::value('is_deceased', $params, FALSE), 'deceased_date' => CRM_Utils_Array::value('deceased_date', $params, NULL)); $updateMembershipMsg = $this->updateMembershipStatus($deceasedParams); } // action is taken depending upon the mode if ($this->_action & CRM_Core_Action::UPDATE) { CRM_Utils_Hook::pre('edit', $params['contact_type'], $params['contact_id'], $params); } else { CRM_Utils_Hook::pre('create', $params['contact_type'], NULL, $params); } $customFields = CRM_Core_BAO_CustomField::getFields($params['contact_type'], FALSE, TRUE); //CRM-5143 //if subtype is set, send subtype as extend to validate subtype customfield $customFieldExtends = CRM_Utils_Array::value('contact_sub_type', $params) ? $params['contact_sub_type'] : $params['contact_type']; $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $this->_contactId, $customFieldExtends, TRUE); if ($this->_contactId && !empty($this->_oldSubtypes)) { CRM_Contact_BAO_ContactType::deleteCustomSetForSubtypeMigration($this->_contactId, $params['contact_type'], $this->_oldSubtypes, $params['contact_sub_type']); } if (array_key_exists('CommunicationPreferences', $this->_editOptions)) { // this is a chekbox, so mark false if we dont get a POST value $params['is_opt_out'] = CRM_Utils_Array::value('is_opt_out', $params, FALSE); } // process shared contact address. CRM_Contact_BAO_Contact_Utils::processSharedAddress($params['address']); if (!array_key_exists('TagsAndGroups', $this->_editOptions) && !empty($params['group'])) { unset($params['group']); } if (!empty($params['contact_id']) && $this->_action & CRM_Core_Action::UPDATE && !empty($params['group'])) { // figure out which all groups are intended to be removed $contactGroupList = CRM_Contact_BAO_GroupContact::getContactGroup($params['contact_id'], 'Added'); if (is_array($contactGroupList)) { foreach ($contactGroupList as $key) { if ((!array_key_exists($key['group_id'], $params['group']) || $params['group'][$key['group_id']] != 1) && empty($key['is_hidden'])) { $params['group'][$key['group_id']] = -1; } } } } // parse street address, CRM-5450 $parseStatusMsg = NULL; if ($this->_parseStreetAddress) { $parseResult = self::parseAddress($params); $parseStatusMsg = self::parseAddressStatusMsg($parseResult); } // Allow un-setting of location info, CRM-5969 $params['updateBlankLocInfo'] = TRUE; $contact = CRM_Contact_BAO_Contact::create($params, TRUE, FALSE, TRUE); // status message if ($this->_contactId) { $message = ts('%1 has been updated.', array(1 => $contact->display_name)); } else { $message = ts('%1 has been created.', array(1 => $contact->display_name)); } // set the contact ID $this->_contactId = $contact->id; if (array_key_exists('TagsAndGroups', $this->_editOptions)) { //add contact to tags CRM_Core_BAO_EntityTag::create($params['tag'], 'civicrm_contact', $params['contact_id']); //save free tags if (isset($params['contact_taglist']) && !empty($params['contact_taglist'])) { CRM_Core_Form_Tag::postProcess($params['contact_taglist'], $params['contact_id'], 'civicrm_contact', $this); } } if (!empty($parseStatusMsg)) { $message .= "<br />{$parseStatusMsg}"; } if (!empty($updateMembershipMsg)) { $message .= "<br />{$updateMembershipMsg}"; } $session = CRM_Core_Session::singleton(); $session->setStatus($message, ts('Contact Saved'), 'success'); // add the recently viewed contact $recentOther = array(); if ($session->get('userID') == $contact->id || CRM_Contact_BAO_Contact_Permission::allow($contact->id, CRM_Core_Permission::EDIT)) { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/add', 'reset=1&action=update&cid=' . $contact->id); } if ($session->get('userID') != $this->_contactId && CRM_Core_Permission::check('delete contacts')) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/delete', 'reset=1&delete=1&cid=' . $contact->id); } CRM_Utils_Recent::add($contact->display_name, CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $contact->id), $contact->id, $this->_contactType, $contact->id, $contact->display_name, $recentOther); // here we replace the user context with the url to view this contact $buttonName = $this->controller->getButtonName(); if ($buttonName == $this->getButtonName('upload', 'new')) { $contactSubTypes = array_filter(explode(CRM_Core_DAO::VALUE_SEPARATOR, $this->_contactSubType)); $resetStr = "reset=1&ct={$contact->contact_type}"; $resetStr .= count($contactSubTypes) == 1 ? "&cst=" . array_pop($contactSubTypes) : ''; $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/add', $resetStr)); } else { $context = CRM_Utils_Request::retrieve('context', 'String', $this); $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); //validate the qfKey $urlParams = 'reset=1&cid=' . $contact->id; if ($context) { $urlParams .= "&context={$context}"; } if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= "&key={$qfKey}"; } $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', $urlParams)); } // now invoke the post hook if ($this->_action & CRM_Core_Action::UPDATE) { CRM_Utils_Hook::post('edit', $params['contact_type'], $contact->id, $contact); } else { CRM_Utils_Hook::post('create', $params['contact_type'], $contact->id, $contact); } }
/** * Form submission of new/edit contact is processed. * * @access public * @return None */ public function postProcess() { // check if dedupe button, if so return. $buttonName = $this->controller->getButtonName(); if ($buttonName == $this->_dedupeButtonName) { return; } //get the submitted values in an array $params = $this->controller->exportValues($this->_name); if (CRM_Utils_Array::value('image_URL', $params)) { CRM_Contact_BAO_Contact::processImageParams($params); } if (is_numeric(CRM_Utils_Array::value('current_employer_id', $params)) && CRM_Utils_Array::value('current_employer', $params)) { $params['current_employer'] = $params['current_employer_id']; } // don't carry current_employer_id field, // since we don't want to directly update DAO object without // handling related business logic ( eg related membership ) if (isset($params['current_employer_id'])) { unset($params['current_employer_id']); } $params['contact_type'] = $this->_contactType; if ($this->_contactSubType && !CRM_Utils_Array::value('contact_sub_type', $params)) { $params['contact_sub_type'] = $this->_contactSubType; } if ($this->_contactId) { $params['contact_id'] = $this->_contactId; } //make deceased date null when is_deceased = false if ($this->_contactType == 'Individual' && CRM_Utils_Array::value('Demographics', $this->_editOptions) && !CRM_Utils_Array::value('is_deceased', $params)) { $params['is_deceased'] = false; $params['deceased_date'] = null; } // process membership status for deceased contact $deceasedParams = array('contact_id' => $params['contact_id'], 'is_deceased' => $params['is_deceased'], 'deceased_date' => $params['deceased_date']); $updateMembershipMsg = $this->updateMembershipStatus($deceasedParams); // action is taken depending upon the mode require_once 'CRM/Utils/Hook.php'; if ($this->_action & CRM_Core_Action::UPDATE) { CRM_Utils_Hook::pre('edit', $params['contact_type'], $params['contact_id'], $params); } else { CRM_Utils_Hook::pre('create', $params['contact_type'], null, $params); } require_once 'CRM/Core/BAO/CustomField.php'; $customFields = CRM_Core_BAO_CustomField::getFields($params['contact_type'], false, true); //CRM-5143 //if subtype is set, send subtype as extend to validate subtype customfield $customFieldExtends = CRM_Utils_Array::value('contact_sub_type', $params) ? $params['contact_sub_type'] : $params['contact_type']; $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_contactId, $customFieldExtends, true); if (array_key_exists('CommunicationPreferences', $this->_editOptions)) { // this is a chekbox, so mark false if we dont get a POST value $params['is_opt_out'] = CRM_Utils_Array::value('is_opt_out', $params, false); } // process shared contact address. require_once 'CRM/Contact/BAO/Contact/Utils.php'; CRM_Contact_BAO_Contact_Utils::processSharedAddress($params['address']); if (!array_key_exists('TagsAndGroups', $this->_editOptions)) { unset($params['group']); } if (CRM_Utils_Array::value('contact_id', $params) && $this->_action & CRM_Core_Action::UPDATE) { // figure out which all groups are intended to be removed if (!empty($params['group'])) { $contactGroupList =& CRM_Contact_BAO_GroupContact::getContactGroup($params['contact_id'], 'Added'); if (is_array($contactGroupList)) { foreach ($contactGroupList as $key) { if ($params['group'][$key['group_id']] != 1) { $params['group'][$key['group_id']] = -1; } } } } } // parse street address, CRM-5450 $parseStatusMsg = null; if ($this->_parseStreetAddress) { $parseResult = $this->parseAddress($params); $parseStatusMsg = $this->parseAddressStatusMsg($parseResult); } // Allow un-setting of location info, CRM-5969 $params['updateBlankLocInfo'] = true; require_once 'CRM/Contact/BAO/Contact.php'; $contact =& CRM_Contact_BAO_Contact::create($params, true, false, true); // set the contact ID $this->_contactId = $contact->id; if (array_key_exists('TagsAndGroups', $this->_editOptions)) { //add contact to tags require_once 'CRM/Core/BAO/EntityTag.php'; CRM_Core_BAO_EntityTag::create($params['tag'], 'civicrm_contact', $params['contact_id']); //save free tags if (isset($params['taglist']) && !empty($params['taglist'])) { require_once 'CRM/Core/Form/Tag.php'; CRM_Core_Form_Tag::postProcess($params['taglist'], $params['contact_id'], 'civicrm_contact', $this); } } $statusMsg = ts('Your %1 contact record has been saved.', array(1 => $contact->contact_type_display)); if ($parseStatusMsg) { $statusMsg = "{$statusMsg} <br > {$parseStatusMsg}"; } if ($uploadFailMsg) { $statusMsg = "{$statusMsg} <br > {$uploadFailMsg}"; } if ($updateMembershipMsg) { $statusMsg = "{$statusMsg} <br > {$updateMembershipMsg}"; } $session = CRM_Core_Session::singleton(); CRM_Core_Session::setStatus($statusMsg); require_once 'CRM/Utils/Recent.php'; // add the recently viewed contact $displayName = CRM_Contact_BAO_Contact::displayName($contact->id); require_once 'CRM/Contact/BAO/Contact/Permission.php'; $recentOther = array(); if ($session->get('userID') == $contact->id || CRM_Contact_BAO_Contact_Permission::allow($contact->id, CRM_Core_Permission::EDIT)) { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/add', 'reset=1&action=update&cid=' . $contact->id); } if ($session->get('userID') != $this->_contactId && CRM_Core_Permission::check('delete contacts')) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/delete', 'reset=1&delete=1&cid=' . $contact->id); } CRM_Utils_Recent::add($displayName, CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $contact->id), $contact->id, $this->_contactType, $contact->id, $displayName, $recentOther); // here we replace the user context with the url to view this contact $buttonName = $this->controller->getButtonName(); if ($buttonName == $this->getButtonName('upload', 'new')) { $resetStr = "reset=1&ct={$contact->contact_type}"; $resetStr .= $this->_contactSubType ? "&cst={$this->_contactSubType}" : ''; $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/add', $resetStr)); } else { $context = CRM_Utils_Request::retrieve('context', 'String', $this); $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); //validate the qfKey require_once 'CRM/Utils/Rule.php'; $urlParams = 'reset=1&cid=' . $contact->id; if ($context) { $urlParams .= "&context={$context}"; } if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= "&key={$qfKey}"; } $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', $urlParams)); } // now invoke the post hook if ($this->_action & CRM_Core_Action::UPDATE) { CRM_Utils_Hook::post('edit', $params['contact_type'], $contact->id, $contact); } else { CRM_Utils_Hook::post('create', $params['contact_type'], $contact->id, $contact); } }