/** * build all the data structures needed to build the form * * @return void * @access public */ function preProcess() { $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, false); if ($cid) { // not sure why this is needed :( // also add the cid params to the Menu array CRM_Core_Menu::addParam('cid', $cid); // create menus .. $startWeight = CRM_Core_Menu::getMaxWeight('civicrm/contact/view'); $startWeight++; CRM_Core_BAO_CustomGroup::addMenuTabs(CRM_Contact_BAO_Contact::getContactType($cid), 'civicrm/contact/view/cd', $startWeight); $this->_contactIds = array($cid); $this->_single = true; $smsNumbers = CRM_Contact_BAO_Contact::allPhones($cid, 'Mobile'); $this->_emails = array(); $toName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'display_name'); foreach ($smsNumbers as $number => $item) { $this->_smsNumbers[$number] = '"' . $toName . '" <' . $number . '> ' . $item['locationType']; if ($item['is_primary']) { $this->_smsNumbers[$number] .= ' ' . ts('(preferred)'); } $this->_smsNumbers[$number] = htmlspecialchars($this->_emails[$email]); } } else { parent::preProcess(); } $this->assign('single', $this->_single); }
/** * View details of a relationship * * @return void * * @access public */ function view() { require_once 'CRM/Core/DAO.php'; $viewRelationship = CRM_Contact_BAO_Relationship::getRelationship($this->_contactId, null, null, null, $this->_id); //To check whether selected contact is a contact_id_a in //relationship type 'a_b' in relationship table, if yes then //revert the permissionship text in template $relationship =& new CRM_Contact_DAO_Relationship(); $relationship->id = $viewRelationship[$this->_id]['id']; if ($relationship->find(true)) { if ($viewRelationship[$this->_id]['rtype'] == 'a_b' && $this->_contactId == $relationship->contact_id_a) { $this->assign("is_contact_id_a", true); } } $relType = $viewRelationship[$this->_id]['civicrm_relationship_type_id']; $this->assign('viewRelationship', $viewRelationship); $viewNote = CRM_Core_BAO_Note::getNote($this->_id); $this->assign('viewNote', $viewNote); $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Relationship', $this, $this->_id, 0, $relType); CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree); // add viewed contribution to recent items list require_once 'CRM/Utils/Recent.php'; $url = CRM_Utils_System::url('civicrm/contact/view/rel', "action=view&reset=1&id={$viewRelationship[$this->_id]['id']}&cid={$this->_contactId}&context=home"); $title = CRM_Contact_BAO_Contact::displayName($this->_contactId) . ' (' . $viewRelationship[$this->_id]['relation'] . ' ' . CRM_Contact_BAO_Contact::displayName($viewRelationship[$this->_id]['cid']) . ')'; // add the recently viewed Relationship CRM_Utils_Recent::add($title, $url, $viewRelationship[$this->_id]['id'], 'Relationship', $this->_contactId, null); }
/** * build all the data structures needed to build the form * * @return void * @access public */ function preProcess() { $cid = CRM_Utils_Request::retrieve('cid', $this, false); if ($cid) { // not sure why this is needed :( // also add the cid params to the Menu array CRM_Utils_Menu::addParam('cid', $cid); // create menus .. $startWeight = CRM_Utils_Menu::getMaxWeight('civicrm/contact/view'); $startWeight++; CRM_Core_BAO_CustomGroup::addMenuTabs(CRM_Contact_BAO_Contact::getContactType($cid), 'civicrm/contact/view/cd', $startWeight); $this->_contactIds = array($cid); $this->_single = true; $emails = CRM_Contact_BAO_Contact::allEmails($cid); $this->_emails = array(); $toName = CRM_Contact_BAO_Contact::displayName($cid); foreach ($emails as $email => $item) { if (!$email && count($emails) <= 1) { $this->_emails[$email] = '"' . $toName . '"'; $this->_noEmails = true; } else { if ($email) { $this->_emails[$email] = '"' . $toName . '" <' . $email . '> ' . $item['locationType']; } } if ($item['is_primary']) { $this->_emails[$email] .= ' ' . ts('(preferred)'); } $this->_emails[$email] = htmlspecialchars($this->_emails[$email]); } } else { parent::preProcess(); } $this->assign('single', $this->_single); }
/** * Build the form object. * * @return void */ public function buildQuickForm() { parent::buildQuickForm(); $multipleCustomData = CRM_Core_BAO_CustomGroup::getMultipleFieldGroup(); $this->add('select', 'multipleCustomData', ts('Multi-value Custom Data'), array('' => ts('- select -')) + $multipleCustomData, TRUE); $this->addContactTypeSelector(); }
/** * Function to set variables up before form is built * * @return void * @access public */ function preProcess() { require_once 'CRM/Contribute/BAO/Contribution.php'; $values = array(); $ids = array(); $params = array('id' => $this->get('id')); CRM_Contribute_BAO_Contribution::getValues($params, $values, $ids); CRM_Contribute_BAO_Contribution::resolveDefaults($values); $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Contribution', $this->get('id')); CRM_Core_BAO_CustomGroup::buildViewHTML($this, $groupTree); $id = $this->get('id'); if ($id) { require_once 'CRM/Contribute/DAO/ContributionProduct.php'; $dao =& new CRM_Contribute_DAO_ContributionProduct(); $dao->contribution_id = $id; if ($dao->find(true)) { $premiumId = $dao->id; $productID = $dao->product_id; } } if ($premiumId) { require_once 'CRM/Contribute/DAO/Product.php'; $productDAO =& new CRM_Contribute_DAO_Product(); $productDAO->id = $productID; $productDAO->find(true); $this->assign('premium', $productDAO->name); $this->assign('option', $dao->product_option); $this->assign('fulfilled', $dao->fulfilled_date); } $this->assign($values); }
/** * View details of a recurring contribution. */ public function view() { $recur = new CRM_Contribute_DAO_ContributionRecur(); $recur->id = $this->_id; if ($recur->find(TRUE)) { $values = array(); CRM_Core_DAO::storeValues($recur, $values); // if there is a payment processor ID, get the name of the payment processor if (!empty($values['payment_processor_id'])) { $values['payment_processor'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessor', $values['payment_processor_id'], 'name'); } $idFields = array('contribution_status_id', 'campaign_id'); if (CRM_Contribute_BAO_ContributionRecur::supportsFinancialTypeChange($values['id'])) { $idFields[] = 'financial_type_id'; } foreach ($idFields as $idField) { if (!empty($values[$idField])) { $values[substr($idField, 0, -3)] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_ContributionRecur', $idField, $values[$idField]); } } // Get financial type name if (!empty($values['financial_type_id'])) { $values['financial_type_name'] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_Contribution', 'financial_type_id', $values['financial_type_id']); } // Get Paid By label if (!empty($values['payment_instrument_id'])) { $values['payment_instrument'] = CRM_Core_OptionGroup::getLabel('payment_instrument', $values['payment_instrument_id']); } $this->assign('recur', $values); $this->assign('customDataType', 'ContributionRecur'); $groupTree = CRM_Core_BAO_CustomGroup::getTree('ContributionRecur', $this, $this->_id); CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree); } }
/** * Run the page. * * This method is called after the page is created. */ public function run() { // get the emails for this contact $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST); $cgId = CRM_Utils_Request::retrieve('groupID', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST); $customRecId = CRM_Utils_Request::retrieve('customRecId', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, 1, $_REQUEST); $cgcount = CRM_Utils_Request::retrieve('cgcount', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, 1, $_REQUEST); //custom groups Inline $entityType = CRM_Contact_BAO_Contact::getContactType($contactId); $entitySubType = CRM_Contact_BAO_Contact::getContactSubType($contactId); $groupTree =& CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $contactId, $cgId, $entitySubType); $details = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $contactId); //get the fields of single custom group record if ($customRecId == 1) { $fields = reset($details[$cgId]); } else { $fields = CRM_Utils_Array::value($customRecId, $details[$cgId]); } $this->assign('cgcount', $cgcount); $this->assign('customRecId', $customRecId); $this->assign('contactId', $contactId); $this->assign('customGroupId', $cgId); $this->assign_by_ref('cd_edit', $fields); // check logged in user permission CRM_Contact_Page_View::checkUserPermission($this, $contactId); // finally call parent parent::run(); }
/** * Run the page. * * This method is called after the page is created. * * @return void * @access public * */ function run() { // get the callback, module and activity id $action = CRM_Utils_Request::retrieve('action', $this, false, 'browse'); $id = CRM_Utils_Request::retrieve('id', $this); $dao =& new CRM_Core_DAO_ActivityHistory(); $dao->activity_id = $id; $dao->activity_type = ts('SMS Sent'); if ($dao->find(true)) { $cid = $dao->entity_id; } require_once 'CRM/SMS/DAO/History.php'; $dao =& new CRM_SMS_DAO_History(); $dao->id = $id; if ($dao->find(true)) { $this->assign('fromName', CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $dao->contact_id, 'display_name')); $this->assign('toName', CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'display_name')); $this->assign('sentDate', $dao->sent_date); $this->assign('message', $dao->message); // get the display name and images for the contact list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($dao->contact_id); CRM_Utils_System::setTitle($contactImage . ' ' . $displayName); require_once 'CRM/Utils/Menu.php'; // also add the cid params to the Menu array CRM_Utils_Menu::addParam('cid', $cid); // create menus .. $startWeight = CRM_Utils_Menu::getMaxWeight('civicrm/contact/view'); $startWeight++; require_once 'CRM/Core/BAO/CustomGroup.php'; CRM_Core_BAO_CustomGroup::addMenuTabs(CRM_Contact_BAO_Contact::getContactType($cid), 'civicrm/contact/view/cd', $startWeight); } parent::run(); }
/** * Heart of the viewing process. The runner gets all the meta data for * the contact and calls the appropriate type of page to view. * * @return void * @access public * */ function preProcess() { parent::preProcess(); //Custom Groups Inline $entityType = CRM_Contact_BAO_Contact::getContactType($this->_contactId); $groupTree =& CRM_Core_BAO_CustomGroup::getTree($entityType, $this->_contactId); CRM_Core_BAO_CustomGroup::buildViewHTML($this, $groupTree); }
/** * Run the page. * * This method is called after the page is created. */ public function run() { // get the emails for this contact $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST); $locBlockNo = CRM_Utils_Request::retrieve('locno', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST); $addressId = CRM_Utils_Request::retrieve('aid', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, NULL, $_REQUEST); $address = array(); if ($addressId > 0) { $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'display_name')); $entityBlock = array('id' => $addressId); $address = CRM_Core_BAO_Address::getValues($entityBlock, FALSE, 'id'); if (!empty($address)) { foreach ($address as $key => &$value) { $value['location_type'] = $locationTypes[$value['location_type_id']]; } } } // we just need current address block $currentAddressBlock['address'][$locBlockNo] = array_pop($address); if (!empty($currentAddressBlock['address'][$locBlockNo])) { // get contact name of shared contact names $sharedAddresses = array(); $shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($currentAddressBlock['address']); foreach ($currentAddressBlock['address'] as $key => $addressValue) { if (!empty($addressValue['master_id']) && !$shareAddressContactNames[$addressValue['master_id']]['is_deleted']) { $sharedAddresses[$key]['shared_address_display'] = array('address' => $addressValue['display'], 'name' => $shareAddressContactNames[$addressValue['master_id']]['name']); } } $idValue = $currentAddressBlock['address'][$locBlockNo]['id']; if (!empty($currentAddressBlock['address'][$locBlockNo]['master_id'])) { $idValue = $currentAddressBlock['address'][$locBlockNo]['master_id']; } // add custom data of type address $groupTree = CRM_Core_BAO_CustomGroup::getTree('Address', $this, $idValue); // we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var. $currentAddressBlock['address'][$locBlockNo]['custom'] = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, "dnc_"); $this->assign("dnc_viewCustomData", NULL); $this->assign('add', $currentAddressBlock['address'][$locBlockNo]); $this->assign('sharedAddresses', $sharedAddresses); } $contact = new CRM_Contact_BAO_Contact(); $contact->id = $contactId; $contact->find(TRUE); $privacy = array(); foreach (CRM_Contact_BAO_Contact::$_commPrefs as $name) { if (isset($contact->{$name})) { $privacy[$name] = $contact->{$name}; } } $this->assign('contactId', $contactId); $this->assign('locationIndex', $locBlockNo); $this->assign('addressId', $addressId); $this->assign('privacy', $privacy); // check logged in user permission CRM_Contact_Page_View::checkUserPermission($this, $contactId); // finally call parent parent::run(); }
/** * Function to set variables up before form is built * * @return void * @access public */ function preProcess() { parent::preProcess(); $this->assign('intro_text', $this->_values['intro_text']); $this->assign('footer_text', $this->_values['footer_text']); // to process Custom data that are appended to URL require_once 'CRM/Core/BAO/CustomGroup.php'; CRM_Core_BAO_CustomGroup::extractGetParams($this, 'Contribution'); }
function __construct(&$formValues) { parent::__construct($formValues); require_once 'CRM/Core/BAO/CustomGroup.php'; $this->_groupTree = CRM_Core_BAO_CustomGroup::getTree("'Contact', 'Individual', 'Organization', 'Household'", CRM_Core_DAO::$_nullObject, NULL, -1); $this->_columns = array(ts('Contact Id') => 'contact_id', ts('Contact Type') => 'contact_type', ts('Name') => 'sort_name'); $this->_customGroupIDs = CRM_Utils_Array::value('custom_group', $formValues); if (!empty($this->_customGroupIDs)) { $this->addColumns(); } }
/** * Run the page. * * This method is called after the page is created. * * @return void * @access public * */ function run() { // get the emails for this contact $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST); $locBlockNo = CRM_Utils_Request::retrieve('locno', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST); $addressId = CRM_Utils_Request::retrieve('aid', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, NULL, $_REQUEST); $address = array(); if ($addressId > 0) { $locationTypes = CRM_Core_PseudoConstant::locationDisplayName(); $entityBlock = array('id' => $addressId); $address = CRM_Core_BAO_Address::getValues($entityBlock, FALSE, 'id'); if (!empty($address)) { foreach ($address as $key => &$value) { $value['location_type'] = $locationTypes[$value['location_type_id']]; } } } // we just need current address block $currentAddressBlock['address'][$locBlockNo] = array_pop($address); if (!empty($currentAddressBlock['address'][$locBlockNo])) { // get contact name of shared contact names $sharedAddresses = array(); $shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($currentAddressBlock['address']); foreach ($currentAddressBlock['address'] as $key => $addressValue) { if (CRM_Utils_Array::value('master_id', $addressValue) && !$shareAddressContactNames[$addressValue['master_id']]['is_deleted']) { $sharedAddresses[$key]['shared_address_display'] = array('address' => $addressValue['display'], 'name' => $shareAddressContactNames[$addressValue['master_id']]['name']); } } // add custom data of type address $groupTree = CRM_Core_BAO_CustomGroup::getTree('Address', $this, $currentAddressBlock['address'][$locBlockNo]['id']); // we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var. $currentAddressBlock['address'][$locBlockNo]['custom'] = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, "dnc_"); $this->assign("dnc_viewCustomData", NULL); $this->assign('add', $currentAddressBlock['address'][$locBlockNo]); $this->assign('sharedAddresses', $sharedAddresses); } $this->assign('contactId', $contactId); $this->assign('locationIndex', $locBlockNo); $this->assign('addressId', $addressId); $appendBlockIndex = CRM_Core_BAO_Address::getAddressCount($contactId); // check if we are adding new address, then only append add link if ($appendBlockIndex == $locBlockNo) { if ($appendBlockIndex) { $appendBlockIndex++; } } else { $appendBlockIndex = 0; } $this->assign('appendBlockIndex', $appendBlockIndex); // check logged in user permission CRM_Contact_Page_View::checkUserPermission($this, $contactId); // finally call parent parent::run(); }
/** * Function to set variables up before form is built * * @return void * @access public */ public function preProcess() { $values = $ids = array(); $params = array('id' => $this->get('id')); CRM_Pledge_BAO_Pledge::getValues($params, $values, $ids); $values['frequencyUnit'] = ts('%1(s)', array(1 => $values['frequency_unit'])); if (isset($values["honor_contact_id"]) && $values["honor_contact_id"]) { $sql = "SELECT display_name FROM civicrm_contact WHERE id = " . $values["honor_contact_id"]; $dao = new CRM_Core_DAO(); $dao->query($sql); if ($dao->fetch()) { $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$values['honor_contact_id']}"); $values["honor_display"] = "<A href = {$url}>" . $dao->display_name . "</A>"; } $honor = CRM_Core_PseudoConstant::get('CRM_Pledge_DAO_Pledge', 'honor_type_id'); $values['honor_type'] = $honor[$values['honor_type_id']]; } //handle custom data. $groupTree = CRM_Core_BAO_CustomGroup::getTree('Pledge', $this, $params['id']); CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree); if (!empty($values['contribution_page_id'])) { $values['contribution_page'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $values['contribution_page_id'], 'title'); } $values['financial_type'] = CRM_Utils_Array::value($values['financial_type_id'], CRM_Contribute_PseudoConstant::financialType()); if ($values['status_id']) { $values['pledge_status'] = CRM_Utils_Array::value($values['status_id'], CRM_Contribute_PseudoConstant::contributionStatus()); } $url = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"); $recentOther = array(); if (CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::UPDATE)) { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"); } if (CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::DELETE)) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"); } $displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']); $this->assign('displayName', $displayName); $title = $displayName . ' - (' . ts('Pledged') . ' ' . CRM_Utils_Money::format($values['pledge_amount']) . ' - ' . $values['financial_type'] . ')'; // add Pledge to Recent Items CRM_Utils_Recent::add($title, $url, $values['id'], 'Pledge', $values['contact_id'], NULL, $recentOther); // Check if this is default domain contact CRM-10482 if (CRM_Contact_BAO_Contact::checkDomainContact($values['contact_id'])) { $displayName .= ' (' . ts('default organization') . ')'; } // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container CRM_Utils_System::setTitle(ts('View Pledge by') . ' ' . $displayName); //do check for campaigns if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) { $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId); $values['campaign'] = $campaigns[$campaignId]; } $this->assign($values); }
/** * Function to set variables up before form is built * * @return void * @access public */ public function preProcess() { require_once 'CRM/Pledge/BAO/Pledge.php'; $values = $ids = array(); $params = array('id' => $this->get('id')); CRM_Pledge_BAO_Pledge::getValues($params, $values, $ids); $values['frequencyUnit'] = ts('%1(s)', array(1 => $values['frequency_unit'])); if (isset($values["honor_contact_id"]) && $values["honor_contact_id"]) { $sql = "SELECT display_name FROM civicrm_contact WHERE id = " . $values["honor_contact_id"]; $dao = new CRM_Core_DAO(); $dao->query($sql); if ($dao->fetch()) { $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$values['honor_contact_id']}"); $values["honor_display"] = "<A href = {$url}>" . $dao->display_name . "</A>"; } $honor = CRM_Core_PseudoConstant::honor(); $values['honor_type'] = $honor[$values['honor_type_id']]; } //handle custom data. $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Pledge', $this, $params['id']); CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree); if (CRM_Utils_Array::value('contribution_page_id', $values)) { $values['contribution_page'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $values['contribution_page_id'], 'title'); } $values['contribution_type'] = CRM_Utils_Array::value($values['contribution_type_id'], CRM_Contribute_PseudoConstant::contributionType()); if ($values['status_id']) { $values['pledge_status'] = CRM_Utils_Array::value($values['status_id'], CRM_Contribute_PseudoConstant::contributionStatus()); } require_once 'CRM/Utils/Recent.php'; require_once 'CRM/Contact/BAO/Contact.php'; $url = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"); $recentOther = array(); if (CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::UPDATE)) { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"); } if (CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::DELETE)) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"); } require_once 'CRM/Utils/Money.php'; $displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']); $this->assign('displayName', $displayName); $title = $displayName . ' - (' . ts('Pledged') . ' ' . CRM_Utils_Money::format($values['pledge_amount']) . ' - ' . $values['contribution_type'] . ')'; // add Pledge to Recent Items CRM_Utils_Recent::add($title, $url, $values['id'], 'Pledge', $values['contact_id'], null, $recentOther); $this->assign($values); }
/** * Function to actually build the form * * @param null * * @return void * @access public */ public function buildQuickForm() { $subTypeId = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $this->_surveyId, 'activity_type_id'); if (!CRM_Core_BAO_CustomGroup::autoCreateByActivityType($subTypeId)) { $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE, FALSE); // everything // FIXME: Displays weird "/\ Array" message; doesn't work with tabs CRM_Core_Session::setStatus(ts('There are no custom data sets for activity type "%1". To create one, <a href="%2" target="%3">click here</a>.', array(1 => $activityTypes[$subTypeId], 2 => CRM_Utils_System::url('civicrm/admin/custom/group', 'action=add&reset=1'), 3 => '_blank'))); } $allowCoreTypes = CRM_Campaign_BAO_Survey::surveyProfileTypes(); $allowSubTypes = array('ActivityType' => array($subTypeId)); $entities = array(array('entity_name' => 'contact_1', 'entity_type' => 'IndividualModel'), array('entity_name' => 'activity_1', 'entity_type' => 'ActivityModel', 'entity_sub_type' => $subTypeId)); $this->addProfileSelector('contact_profile_id', ts('Contact Info'), $allowCoreTypes, $allowSubTypes, $entities); $this->addProfileSelector('activity_profile_id', ts('Questions'), $allowCoreTypes, $allowSubTypes, $entities); // Note: Because this is in a tab, we also preload the schema via CRM_Campaign_Form_Survey::preProcess parent::buildQuickForm(); }
/** * build all the data structures needed to build the form * * @return void * @access public */ function preProcess() { $cid = CRM_Utils_Request::retrieve('cid', $this, false); if ($cid) { // not sure why this is needed :( // also add the cid params to the Menu array CRM_Utils_Menu::addParam('cid', $cid); // create menus .. $startWeight = CRM_Utils_Menu::getMaxWeight('civicrm/contact/view'); $startWeight++; CRM_Core_BAO_CustomGroup::addMenuTabs(CRM_Contact_BAO_Contact::getContactType($cid), 'civicrm/contact/view/cd', $startWeight); $this->_contactIds = array($cid); $this->_single = true; $this->assign('totalSelectedContacts', 1); } else { parent::preProcess(); } }
/** * Function to actually build the form * * @return void * @access public */ public function buildQuickForm() { $multipleCustomData = CRM_Core_BAO_CustomGroup::getMultipleFieldGroup(); $this->add('select', 'multipleCustomData', ts('Multi-value Custom Data'), array('' => ts('- select -')) + $multipleCustomData, TRUE); //Setting Upload File Size $config = CRM_Core_Config::singleton(); if ($config->maxImportFileSize >= 8388608) { $uploadFileSize = 8388608; } else { $uploadFileSize = $config->maxImportFileSize; } $uploadSize = round($uploadFileSize / (1024 * 1024), 2); $this->assign('uploadSize', $uploadSize); $this->add('file', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE); $this->addRule('uploadFile', ts('A valid file must be uploaded.'), 'uploadedfile'); $this->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', array(1 => $uploadSize, 2 => $uploadFileSize)), 'maxfilesize', $uploadFileSize); $this->setMaxFileSize($uploadFileSize); $this->addRule('uploadFile', ts('Input file must be in CSV format'), 'utf8File'); $this->addElement('checkbox', 'skipColumnHeader', ts('First row contains column headers')); //get the saved mapping details $mappingArray = CRM_Core_BAO_Mapping::getMappings(CRM_Core_OptionGroup::getValue('mapping_type', 'Import Multi value custom data', 'name')); $this->assign('savedMapping', $mappingArray); $this->add('select', 'savedMapping', ts('Mapping Option'), array('' => ts('- select -')) + $mappingArray); if ($loadeMapping = $this->get('loadedMapping')) { $this->assign('loadedMapping', $loadeMapping); $this->setDefaults(array('savedMapping' => $loadeMapping)); } //contact types option $contactOptions = array(); if (CRM_Contact_BAO_ContactType::isActive('Individual')) { $contactOptions[] = $this->createElement('radio', NULL, NULL, ts('Individual'), CRM_Import_Parser::CONTACT_INDIVIDUAL); } if (CRM_Contact_BAO_ContactType::isActive('Household')) { $contactOptions[] = $this->createElement('radio', NULL, NULL, ts('Household'), CRM_Import_Parser::CONTACT_HOUSEHOLD); } if (CRM_Contact_BAO_ContactType::isActive('Organization')) { $contactOptions[] = $this->createElement('radio', NULL, NULL, ts('Organization'), CRM_Import_Parser::CONTACT_ORGANIZATION); } $this->addGroup($contactOptions, 'contactType', ts('Contact Type')); $this->setDefaults(array('contactType' => CRM_Import_Parser::CONTACT_INDIVIDUAL)); //build date formats CRM_Core_Form_Date::buildAllowedDateFormats($this); $this->addButtons(array(array('type' => 'upload', 'name' => ts('Continue >>'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); }
/** * View details of a relationship. */ public function view() { $viewRelationship = CRM_Contact_BAO_Relationship::getRelationship($this->_contactId, NULL, NULL, NULL, $this->_id); //To check whether selected contact is a contact_id_a in //relationship type 'a_b' in relationship table, if yes then //revert the permissionship text in template $relationship = new CRM_Contact_DAO_Relationship(); $relationship->id = $viewRelationship[$this->_id]['id']; if ($relationship->find(TRUE)) { if ($viewRelationship[$this->_id]['rtype'] == 'a_b' && $this->_contactId == $relationship->contact_id_a) { $this->assign("is_contact_id_a", TRUE); } } $relType = $viewRelationship[$this->_id]['civicrm_relationship_type_id']; $this->assign('viewRelationship', $viewRelationship); $employerId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'employer_id'); $this->assign('isCurrentEmployer', FALSE); $relTypes = CRM_Utils_Array::index(array('name_a_b'), CRM_Core_PseudoConstant::relationshipType('name')); if ($viewRelationship[$this->_id]['employer_id'] == $this->_contactId) { $this->assign('isCurrentEmployer', TRUE); } elseif ($relType == $relTypes['Employee of']['id'] && $viewRelationship[$this->_id]['cid'] == $employerId) { // make sure we are viewing employee of relationship $this->assign('isCurrentEmployer', TRUE); } $viewNote = CRM_Core_BAO_Note::getNote($this->_id); $this->assign('viewNote', $viewNote); $groupTree = CRM_Core_BAO_CustomGroup::getTree('Relationship', $this, $this->_id, 0, $relType); CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_id); $rType = CRM_Utils_Array::value('rtype', $viewRelationship[$this->_id]); // add viewed contribution to recent items list $url = CRM_Utils_System::url('civicrm/contact/view/rel', "action=view&reset=1&id={$viewRelationship[$this->_id]['id']}&cid={$this->_contactId}&context=home"); $session = CRM_Core_Session::singleton(); $recentOther = array(); if ($session->get('userID') == $this->_contactId || CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) { $recentOther = array('editUrl' => CRM_Utils_System::url('civicrm/contact/view/rel', "action=update&reset=1&id={$viewRelationship[$this->_id]['id']}&cid={$this->_contactId}&rtype={$rType}&context=home"), 'deleteUrl' => CRM_Utils_System::url('civicrm/contact/view/rel', "action=delete&reset=1&id={$viewRelationship[$this->_id]['id']}&cid={$this->_contactId}&rtype={$rType}&context=home")); } $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId); $this->assign('displayName', $displayName); CRM_Utils_System::setTitle(ts('View Relationship for') . ' ' . $displayName); $title = $displayName . ' (' . $viewRelationship[$this->_id]['relation'] . ' ' . CRM_Contact_BAO_Contact::displayName($viewRelationship[$this->_id]['cid']) . ')'; // add the recently viewed Relationship CRM_Utils_Recent::add($title, $url, $viewRelationship[$this->_id]['id'], 'Relationship', $this->_contactId, NULL, $recentOther); }
/** * Run the page. * * This method is called after the page is created. * * @return void * @access public * */ function run() { // get the emails for this contact $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST); $cgId = CRM_Utils_Request::retrieve('groupID', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST); //custom groups Inline $entityType = CRM_Contact_BAO_Contact::getContactType($contactId); $entitySubType = CRM_Contact_BAO_Contact::getContactSubType($contactId); $groupTree =& CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $contactId, $cgId, $entitySubType); $details = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree); $fields = array_pop($details[$cgId]); $this->assign('contactId', $contactId); $this->assign('customGroupId', $cgId); $this->assign_by_ref('cd_edit', $fields); // check logged in user permission CRM_Contact_Page_View::checkUserPermission($this, $contactId); // finally call parent parent::run(); }
/** * Function to set variables up before form is built * * @return void * @access public */ public function preProcess() { require_once 'CRM/Event/BAO/Participant.php'; $values = $ids = array(); $params = array('id' => $this->get('id')); CRM_Event_BAO_Participant::getValues($params, $values, $ids); CRM_Event_BAO_Participant::resolveDefaults($values[$params['id']]); if (CRM_Utils_Array::value('fee_level', $values[$params['id']])) { CRM_Event_BAO_Participant::fixEventLevel($values[$params['id']]['fee_level']); } if ($values[$params['id']]['is_test']) { $values[$params['id']]['status'] .= ' (test) '; } // Get Note $noteValue = CRM_Core_BAO_Note::getNote($values[$params['id']]['id'], 'civicrm_participant'); $values[$params['id']]['note'] = array_values($noteValue); require_once 'CRM/Price/BAO/LineItem.php'; // Get Line Items $lineItem = CRM_Price_BAO_LineItem::getLineItems($params['id']); if (!CRM_Utils_System::isNull($lineItem)) { $values[$params['id']]['lineItem'][] = $lineItem; } $values[$params['id']]['totalAmount'] = $values[$params['id']]['fee_amount']; // get the option value for custom data type $roleCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantRole', 'name'); $eventNameCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantEventName', 'name'); $roleGroupTree =& CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $params['id'], null, $values[$params['id']]['role_id'], $roleCustomDataTypeID); $eventGroupTree =& CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $params['id'], null, $values[$params['id']]['event_id'], $eventNameCustomDataTypeID); $groupTree = CRM_Utils_Array::crmArrayMerge($roleGroupTree, $eventGroupTree); $groupTree = CRM_Utils_Array::crmArrayMerge($groupTree, CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $params['id'])); CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree); $this->assign($values[$params['id']]); // add viewed participant to recent items list require_once 'CRM/Utils/Recent.php'; require_once 'CRM/Contact/BAO/Contact.php'; $url = CRM_Utils_System::url('civicrm/contact/view/participant', "action=view&reset=1&id={$values[$params['id']]['id']}&cid={$values[$params['id']]['contact_id']}"); $participantRoles = CRM_Event_PseudoConstant::participantRole(); $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $values[$params['id']]['event_id'], 'title'); $title = CRM_Contact_BAO_Contact::displayName($values[$params['id']]['contact_id']) . ' (' . $participantRoles[$values[$params['id']]['role_id']] . ' - ' . $eventTitle . ')'; // add the recently created Activity CRM_Utils_Recent::add($title, $url, $values[$params['id']]['id'], 'Participant', $values[$params['id']]['contact_id'], null); }
/** * Function to set variables up before form is built * * @return void * @access public */ public function preProcess() { require_once 'CRM/Member/BAO/Membership.php'; require_once 'CRM/Member/BAO/MembershipType.php'; require_once 'CRM/Core/BAO/CustomGroup.php'; $values = array(); $id = CRM_Utils_Request::retrieve('id', 'Positive', $this); // Make sure context is assigned to template for condition where we come here view civicrm/membership/view $context = CRM_Utils_Request::retrieve('context', 'String', $this); $this->assign('context', $context); if ($id) { $params = array('id' => $id); CRM_Member_BAO_Membership::retrieve($params, $values); // build associated contributions require_once 'CRM/Member/Page/Tab.php'; CRM_Member_Page_Tab::associatedContribution($values['contact_id'], $id); //Provide information about membership source when it is the result of a relationship (CRM-1901) $values['owner_membership_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $id, 'owner_membership_id'); if (isset($values['owner_membership_id'])) { $values['owner_contact_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $values['owner_membership_id'], 'contact_id', 'id'); $values['owner_display_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['owner_contact_id'], 'display_name', 'id'); $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($values['membership_type_id']); $direction = strrev($membershipType['relationship_direction']); $values['relationship'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $membershipType['relationship_type_id'], "name_{$direction}", 'id'); } $displayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['contact_id'], 'display_name'); $this->assign('displayName', $displayName); // add viewed membership to recent items list require_once 'CRM/Utils/Recent.php'; $url = CRM_Utils_System::url('civicrm/contact/view/membership', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}"); $title = $displayName . ' - ' . ts('Membership Type:') . ' ' . $values['membership_type']; CRM_Utils_Recent::add($title, $url, $values['id'], 'Membership', $values['contact_id'], null); CRM_Member_Page_Tab::setContext($values['contact_id']); $memType = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $id, "membership_type_id"); $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Membership', $this, $id, 0, $memType); CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree); } if ($values['is_test']) { $values['membership_type'] .= ' (test) '; } $this->assign($values); }
/** * View details of a relationship * * @return void * * @access public */ function view() { require_once 'CRM/Core/DAO.php'; $viewRelationship = CRM_Contact_BAO_Relationship::getRelationship($this->_contactId, null, null, null, $this->_id); //To check whether selected contact is a contact_id_a in //relationship type 'a_b' in relationship table, if yes then //revert the permissionship text in template $relationship =& new CRM_Contact_DAO_Relationship(); $relationship->id = $viewRelationship[$this->_id]['id']; if ($relationship->find(true)) { if ($viewRelationship[$this->_id]['rtype'] == 'a_b' && $this->_contactId == $relationship->contact_id_a) { $this->assign("is_contact_id_a", true); } } $relType = $viewRelationship[$this->_id]['civicrm_relationship_type_id']; $this->assign('viewRelationship', $viewRelationship); $viewNote = CRM_Core_BAO_Note::getNote($this->_id); $this->assign('viewNote', $viewNote); $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Relationship', $this, $this->_id, 0, $relType); CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree); }
/** * Return a structure holding the supported tables, fields and their titles * * @param string $requestedType the requested contact type * * @return array a table-keyed array of field-keyed arrays holding supported fields' titles */ function &supportedFields($requestedType) { static $fields = null; if (!$fields) { // this is needed, as we're piggy-backing importableFields() below $replacements = array('civicrm_country.name' => 'civicrm_address.country_id', 'civicrm_county.name' => 'civicrm_address.county_id', 'civicrm_state_province.name' => 'civicrm_address.state_province_id', 'gender.label' => 'civicrm_contact.gender_id', 'individual_prefix.label' => 'civicrm_contact.prefix_id', 'individual_suffix.label' => 'civicrm_contact.suffix_id', 'addressee.label' => 'civicrm_contact.addressee_id', 'email_greeting.label' => 'civicrm_contact.email_greeting_id', 'postal_greeting.label' => 'civicrm_contact.postal_greeting_id'); // the table names we support in dedupe rules - a filter for importableFields() $supportedTables = array('civicrm_address', 'civicrm_contact', 'civicrm_email', 'civicrm_im', 'civicrm_note', 'civicrm_openid', 'civicrm_phone'); require_once 'CRM/Contact/BAO/Contact.php'; require_once 'CRM/Core/BAO/CustomGroup.php'; foreach (array('Individual', 'Organization', 'Household') as $ctype) { // take the table.field pairs and their titles from importableFields() if the table is supported foreach (CRM_Contact_BAO_Contact::importableFields($ctype) as $iField) { if (isset($iField['where'])) { $where = $iField['where']; if (isset($replacements[$where])) { $where = $replacements[$where]; } list($table, $field) = explode('.', $where); if (!in_array($table, $supportedTables)) { continue; } $fields[$ctype][$table][$field] = $iField['title']; } } // add custom data fields foreach (CRM_Core_BAO_CustomGroup::getTree($ctype, CRM_Core_DAO::$_nullObject, null, -1) as $key => $cg) { if (!is_int($key)) { continue; } foreach ($cg['fields'] as $cf) { $fields[$ctype][$cg['table_name']][$cf['column_name']] = $cf['label']; } } } } return $fields[$requestedType]; }
/** * Pre processing work done here. * * gets session variables for table name, id of entity in table, type of entity and stores them. */ public function preProcess() { $this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this, TRUE); $this->_entityID = CRM_Utils_Request::retrieve('entityID', 'Positive', $this, TRUE); $this->_subTypeID = CRM_Utils_Request::retrieve('subType', 'Positive', $this, TRUE); $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Case', $this, $this->_entityID, $this->_groupID, $this->_subTypeID); // simplified formatted groupTree $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $this); // Array contains only one item foreach ($groupTree as $groupValues) { $this->_customTitle = $groupValues['title']; CRM_Utils_System::setTitle(ts('Edit %1', array(1 => $groupValues['title']))); } $this->_defaults = array(); CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $this->_defaults); $this->setDefaults($this->_defaults); CRM_Core_BAO_CustomGroup::buildQuickForm($this, $groupTree); //need to assign custom data type and subtype to the template $this->assign('entityID', $this->_entityID); $this->assign('groupID', $this->_groupID); $this->assign('subType', $this->_subTypeID); $this->assign('contactID', $this->_contactID); }
/** * @param CRM_Core_Form $form */ public static function buildSearchForm(&$form) { $dataURLEventFee = CRM_Utils_System::url('civicrm/ajax/eventFee', "reset=1", FALSE, NULL, FALSE); $form->assign('dataURLEventFee', $dataURLEventFee); $form->addEntityRef('event_id', ts('Event Name'), array('entity' => 'event', 'placeholder' => ts('- any -'), 'multiple' => 1, 'select' => array('minimumInputLength' => 0))); $form->addEntityRef('event_type_id', ts('Event Type'), array('entity' => 'option_value', 'placeholder' => ts('- any -'), 'select' => array('minimumInputLength' => 0), 'api' => array('params' => array('option_group_id' => 'event_type')))); $obj = new CRM_Report_Form_Event_ParticipantListing(); $form->add('select', 'participant_fee_id', ts('Fee Level'), $obj->getPriceLevels(), FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple', 'placeholder' => ts('- any -'))); CRM_Core_Form_Date::buildDateRange($form, 'event', 1, '_start_date_low', '_end_date_high', ts('From'), FALSE); CRM_Core_Form_Date::buildDateRange($form, 'participant', 1, '_register_date_low', '_register_date_high', ts('From'), FALSE); $form->addElement('checkbox', "event_include_repeating_events", NULL, ts('Include participants from all events in the %1 series', array(1 => '<em>%1</em>'))); $form->addSelect('participant_status_id', array('entity' => 'participant', 'label' => ts('Participant Status'), 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -'))); $form->addSelect('participant_role_id', array('entity' => 'participant', 'label' => ts('Participant Role'), 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -'))); $form->addYesNo('participant_test', ts('Participant is a Test?'), TRUE); $form->addYesNo('participant_is_pay_later', ts('Participant is Pay Later?'), TRUE); $form->addElement('text', 'participant_fee_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8)); $form->addElement('text', 'participant_fee_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8)); $form->addRule('participant_fee_amount_low', ts('Please enter a valid money value.'), 'money'); $form->addRule('participant_fee_amount_high', ts('Please enter a valid money value.'), 'money'); // add all the custom searchable fields $extends = array('Participant', 'Event'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); if ($groupDetails) { $form->assign('participantGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, TRUE); } } } CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'participant_campaign_id'); $form->assign('validCiviEvent', TRUE); $form->setDefaults(array('participant_test' => 0)); }
function copyCustomValues($recurId, $targetContributionId) { if ($recurId && $targetContributionId) { // get the initial contribution id of recur id $sourceContributionId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $recurId, 'id', 'contribution_recur_id'); // if the same contribution is being proccessed then return if ($sourceContributionId == $targetContributionId) { return; } // check if proper recurring contribution record is being processed $targetConRecurId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $targetContributionId, 'contribution_recur_id'); if ($targetConRecurId != $recurId) { return; } // copy custom data $extends = array('Contribution'); $groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, NULL, $extends); if ($groupTree) { foreach ($groupTree as $groupID => $group) { $table[$groupTree[$groupID]['table_name']] = array('entity_id'); foreach ($group['fields'] as $fieldID => $field) { $table[$groupTree[$groupID]['table_name']][] = $groupTree[$groupID]['fields'][$fieldID]['column_name']; } } foreach ($table as $tableName => $tableColumns) { $insert = 'INSERT INTO ' . $tableName . ' (' . implode(', ', $tableColumns) . ') '; $tableColumns[0] = $targetContributionId; $select = 'SELECT ' . implode(', ', $tableColumns); $from = ' FROM ' . $tableName; $where = " WHERE {$tableName}.entity_id = {$sourceContributionId}"; $query = $insert . $select . $from . $where; $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); } } } }
/** * Function perform two task. * 1. Merge two duplicate contacts cases - follow CRM-5758 rules. * 2. Merge two cases of same contact - follow CRM-5598 rules. * * @param int $mainContactId contact id of main contact record. * @param int $mainCaseId case id of main case record. * @param int $otherContactId contact id of record which is going to merge. * @param int $otherCaseId case id of record which is going to merge. * * @param bool $changeClient * * @return integer|NULL * @static */ static function mergeCases($mainContactId, $mainCaseId = NULL, $otherContactId = NULL, $otherCaseId = NULL, $changeClient = FALSE) { $moveToTrash = TRUE; $duplicateContacts = FALSE; if ($mainContactId && $otherContactId && $mainContactId != $otherContactId) { $duplicateContacts = TRUE; } $duplicateCases = FALSE; if ($mainCaseId && $otherCaseId && $mainCaseId != $otherCaseId) { $duplicateCases = TRUE; } $mainCaseIds = array(); if (!$duplicateContacts && !$duplicateCases) { return $mainCaseIds; } $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name'); $activityStatuses = CRM_Core_PseudoConstant::activityStatus('name'); $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts); $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); $processCaseIds = array($otherCaseId); if ($duplicateContacts && !$duplicateCases) { if ($changeClient) { $processCaseIds = array($mainCaseId); } else { //get all case ids for other contact. $processCaseIds = self::retrieveCaseIdsByContactId($otherContactId, TRUE); } if (!is_array($processCaseIds)) { return; } } $session = CRM_Core_Session::singleton(); $currentUserId = $session->get('userID'); CRM_Utils_Hook::pre_case_merge($mainContactId, $mainCaseId, $otherContactId, $otherCaseId, $changeClient); // copy all cases and connect to main contact id. foreach ($processCaseIds as $otherCaseId) { if ($duplicateContacts) { $mainCase = CRM_Core_DAO::copyGeneric('CRM_Case_DAO_Case', array('id' => $otherCaseId)); $mainCaseId = $mainCase->id; if (!$mainCaseId) { continue; } // CRM-11662 Copy Case custom data $extends = array('case'); $groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, NULL, $extends); if ($groupTree) { foreach ($groupTree as $groupID => $group) { $table[$groupTree[$groupID]['table_name']] = array('entity_id'); foreach ($group['fields'] as $fieldID => $field) { $table[$groupTree[$groupID]['table_name']][] = $groupTree[$groupID]['fields'][$fieldID]['column_name']; } } foreach ($table as $tableName => $tableColumns) { $insert = 'INSERT INTO ' . $tableName . ' (' . implode(', ', $tableColumns) . ') '; $tableColumns[0] = $mainCaseId; $select = 'SELECT ' . implode(', ', $tableColumns); $from = ' FROM ' . $tableName; $where = " WHERE {$tableName}.entity_id = {$otherCaseId}"; $query = $insert . $select . $from . $where; $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); } } $mainCase->free(); $mainCaseIds[] = $mainCaseId; //insert record for case contact. $otherCaseContact = new CRM_Case_DAO_CaseContact(); $otherCaseContact->case_id = $otherCaseId; $otherCaseContact->find(); while ($otherCaseContact->fetch()) { $mainCaseContact = new CRM_Case_DAO_CaseContact(); $mainCaseContact->case_id = $mainCaseId; $mainCaseContact->contact_id = $otherCaseContact->contact_id; if ($mainCaseContact->contact_id == $otherContactId) { $mainCaseContact->contact_id = $mainContactId; } //avoid duplicate object. if (!$mainCaseContact->find(TRUE)) { $mainCaseContact->save(); } $mainCaseContact->free(); } $otherCaseContact->free(); } elseif (!$otherContactId) { $otherContactId = $mainContactId; } if (!$mainCaseId || !$otherCaseId || !$mainContactId || !$otherContactId) { continue; } // get all activities for other case. $otherCaseActivities = array(); CRM_Core_DAO::commonRetrieveAll('CRM_Case_DAO_CaseActivity', 'case_id', $otherCaseId, $otherCaseActivities); //for duplicate cases do not process singleton activities. $otherActivityIds = $singletonActivityIds = array(); foreach ($otherCaseActivities as $caseActivityId => $otherIds) { $otherActId = CRM_Utils_Array::value('activity_id', $otherIds); if (!$otherActId || in_array($otherActId, $otherActivityIds)) { continue; } $otherActivityIds[] = $otherActId; } if ($duplicateCases) { if ($openCaseType = array_search('Open Case', $activityTypes)) { $sql = "\nSELECT id\n FROM civicrm_activity\n WHERE activity_type_id = {$openCaseType}\n AND id IN ( " . implode(',', array_values($otherActivityIds)) . ');'; $dao = CRM_Core_DAO::executeQuery($sql); while ($dao->fetch()) { $singletonActivityIds[] = $dao->id; } $dao->free(); } } // migrate all activities and connect to main contact. $copiedActivityIds = $activityMappingIds = array(); sort($otherActivityIds); foreach ($otherActivityIds as $otherActivityId) { //for duplicate cases - //do not migrate singleton activities. if (!$otherActivityId || in_array($otherActivityId, $singletonActivityIds)) { continue; } //migrate activity record. $otherActivity = new CRM_Activity_DAO_Activity(); $otherActivity->id = $otherActivityId; if (!$otherActivity->find(TRUE)) { continue; } $mainActVals = array(); $mainActivity = new CRM_Activity_DAO_Activity(); CRM_Core_DAO::storeValues($otherActivity, $mainActVals); $mainActivity->copyValues($mainActVals); $mainActivity->id = NULL; $mainActivity->activity_date_time = CRM_Utils_Date::isoToMysql($otherActivity->activity_date_time); $mainActivity->source_record_id = CRM_Utils_Array::value($mainActivity->source_record_id, $activityMappingIds); $mainActivity->original_id = CRM_Utils_Array::value($mainActivity->original_id, $activityMappingIds); $mainActivity->parent_id = CRM_Utils_Array::value($mainActivity->parent_id, $activityMappingIds); $mainActivity->save(); $mainActivityId = $mainActivity->id; if (!$mainActivityId) { continue; } $activityMappingIds[$otherActivityId] = $mainActivityId; // insert log of all activities CRM_Activity_BAO_Activity::logActivityAction($mainActivity); $otherActivity->free(); $mainActivity->free(); $copiedActivityIds[] = $otherActivityId; //create case activity record. $mainCaseActivity = new CRM_Case_DAO_CaseActivity(); $mainCaseActivity->case_id = $mainCaseId; $mainCaseActivity->activity_id = $mainActivityId; $mainCaseActivity->save(); $mainCaseActivity->free(); //migrate source activity. $otherSourceActivity = new CRM_Activity_DAO_ActivityContact(); $otherSourceActivity->activity_id = $otherActivityId; $otherSourceActivity->record_type_id = $sourceID; $otherSourceActivity->find(); while ($otherSourceActivity->fetch()) { $mainActivitySource = new CRM_Activity_DAO_ActivityContact(); $mainActivitySource->record_type_id = $sourceID; $mainActivitySource->activity_id = $mainActivityId; $mainActivitySource->contact_id = $otherSourceActivity->contact_id; if ($mainActivitySource->contact_id == $otherContactId) { $mainActivitySource->contact_id = $mainContactId; } //avoid duplicate object. if (!$mainActivitySource->find(TRUE)) { $mainActivitySource->save(); } $mainActivitySource->free(); } $otherSourceActivity->free(); //migrate target activities. $otherTargetActivity = new CRM_Activity_DAO_ActivityContact(); $otherTargetActivity->activity_id = $otherActivityId; $otherTargetActivity->record_type_id = $targetID; $otherTargetActivity->find(); while ($otherTargetActivity->fetch()) { $mainActivityTarget = new CRM_Activity_DAO_ActivityContact(); $mainActivityTarget->record_type_id = $targetID; $mainActivityTarget->activity_id = $mainActivityId; $mainActivityTarget->contact_id = $otherTargetActivity->contact_id; if ($mainActivityTarget->contact_id == $otherContactId) { $mainActivityTarget->contact_id = $mainContactId; } //avoid duplicate object. if (!$mainActivityTarget->find(TRUE)) { $mainActivityTarget->save(); } $mainActivityTarget->free(); } $otherTargetActivity->free(); //migrate assignee activities. $otherAssigneeActivity = new CRM_Activity_DAO_ActivityContact(); $otherAssigneeActivity->activity_id = $otherActivityId; $otherAssigneeActivity->record_type_id = $assigneeID; $otherAssigneeActivity->find(); while ($otherAssigneeActivity->fetch()) { $mainAssigneeActivity = new CRM_Activity_DAO_ActivityContact(); $mainAssigneeActivity->activity_id = $mainActivityId; $mainAssigneeActivity->record_type_id = $assigneeID; $mainAssigneeActivity->contact_id = $otherAssigneeActivity->contact_id; if ($mainAssigneeActivity->contact_id == $otherContactId) { $mainAssigneeActivity->contact_id = $mainContactId; } //avoid duplicate object. if (!$mainAssigneeActivity->find(TRUE)) { $mainAssigneeActivity->save(); } $mainAssigneeActivity->free(); } $otherAssigneeActivity->free(); // copy custom fields and attachments $aparams = array('activityID' => $otherActivityId, 'mainActivityId' => $mainActivityId); CRM_Activity_BAO_Activity::copyExtendedActivityData($aparams); } //copy case relationship. if ($duplicateContacts) { //migrate relationship records. $otherRelationship = new CRM_Contact_DAO_Relationship(); $otherRelationship->case_id = $otherCaseId; $otherRelationship->find(); $otherRelationshipIds = array(); while ($otherRelationship->fetch()) { $otherRelVals = array(); $updateOtherRel = FALSE; CRM_Core_DAO::storeValues($otherRelationship, $otherRelVals); $mainRelationship = new CRM_Contact_DAO_Relationship(); $mainRelationship->copyValues($otherRelVals); $mainRelationship->id = NULL; $mainRelationship->case_id = $mainCaseId; if ($mainRelationship->contact_id_a == $otherContactId) { $updateOtherRel = TRUE; $mainRelationship->contact_id_a = $mainContactId; } //case creator change only when we merge user contact. if ($mainRelationship->contact_id_b == $otherContactId) { //do not change creator for change client. if (!$changeClient) { $updateOtherRel = TRUE; $mainRelationship->contact_id_b = $currentUserId ? $currentUserId : $mainContactId; } } $mainRelationship->end_date = CRM_Utils_Date::isoToMysql($otherRelationship->end_date); $mainRelationship->start_date = CRM_Utils_Date::isoToMysql($otherRelationship->start_date); //avoid duplicate object. if (!$mainRelationship->find(TRUE)) { $mainRelationship->save(); } $mainRelationship->free(); //get the other relationship ids to update end date. if ($updateOtherRel) { $otherRelationshipIds[$otherRelationship->id] = $otherRelationship->id; } } $otherRelationship->free(); //update other relationships end dates if (!empty($otherRelationshipIds)) { $sql = 'UPDATE civicrm_relationship SET end_date = CURDATE() WHERE id IN ( ' . implode(',', $otherRelationshipIds) . ')'; CRM_Core_DAO::executeQuery($sql); } } //move other case to trash. $mergeCase = self::deleteCase($otherCaseId, $moveToTrash); if (!$mergeCase) { continue; } $mergeActSubject = $mergeActSubjectDetails = $mergeActType = ''; if ($changeClient) { $mainContactDisplayName = CRM_Contact_BAO_Contact::displayName($mainContactId); $otherContactDisplayName = CRM_Contact_BAO_Contact::displayName($otherContactId); $mergeActType = array_search('Reassigned Case', $activityTypes); $mergeActSubject = ts("Case %1 reassigned client from %2 to %3. New Case ID is %4.", array(1 => $otherCaseId, 2 => $otherContactDisplayName, 3 => $mainContactDisplayName, 4 => $mainCaseId)); } elseif ($duplicateContacts) { $mergeActType = array_search('Merge Case', $activityTypes); $mergeActSubject = ts("Case %1 copied from contact id %2 to contact id %3 via merge. New Case ID is %4.", array(1 => $otherCaseId, 2 => $otherContactId, 3 => $mainContactId, 4 => $mainCaseId)); } else { $mergeActType = array_search('Merge Case', $activityTypes); $mergeActSubject = ts("Case %1 merged into case %2", array(1 => $otherCaseId, 2 => $mainCaseId)); if (!empty($copiedActivityIds)) { $sql = ' SELECT id, subject, activity_date_time, activity_type_id FROM civicrm_activity WHERE id IN (' . implode(',', $copiedActivityIds) . ')'; $dao = CRM_Core_DAO::executeQuery($sql); while ($dao->fetch()) { $mergeActSubjectDetails .= "{$dao->activity_date_time} :: {$activityTypes[$dao->activity_type_id]}"; if ($dao->subject) { $mergeActSubjectDetails .= " :: {$dao->subject}"; } $mergeActSubjectDetails .= "<br />"; } } } //create merge activity record. $activityParams = array('subject' => $mergeActSubject, 'details' => $mergeActSubjectDetails, 'status_id' => array_search('Completed', $activityStatuses), 'activity_type_id' => $mergeActType, 'source_contact_id' => $mainContactId, 'activity_date_time' => date('YmdHis')); $mergeActivity = CRM_Activity_BAO_Activity::create($activityParams); $mergeActivityId = $mergeActivity->id; if (!$mergeActivityId) { continue; } $mergeActivity->free(); //connect merge activity to case. $mergeCaseAct = array('case_id' => $mainCaseId, 'activity_id' => $mergeActivityId); self::processCaseActivity($mergeCaseAct); } CRM_Utils_Hook::post_case_merge($mainContactId, $mainCaseId, $otherContactId, $otherCaseId, $changeClient); return $mainCaseIds; }
/** * CRM-17797 -- Format fields and setDefaults for primary and additional participants profile * @param int $contactId * @param CRM_Core_Form $form */ public static function formatFieldsAndSetProfileDefaults($contactId, &$form) { if (!$contactId) { return; } $fields = array(); if (!empty($form->_fields)) { $removeCustomFieldTypes = array('Participant'); foreach ($form->_fields as $name => $dontCare) { if (substr($name, 0, 7) == 'custom_' && !$form->_allowConfirmation && !CRM_Core_BAO_CustomGroup::checkCustomField(substr($name, 7), $removeCustomFieldTypes) || substr($name, 0, 12) == 'participant_') { continue; } $fields[$name] = 1; } if (!empty($fields)) { CRM_Core_BAO_UFGroup::setProfileDefaults($contactId, $fields, $form->_defaults); } } }
/** * Build the search form. * * @param CRM_Core_Form $form */ public static function buildSearchForm(&$form) { $membershipStatus = CRM_Member_PseudoConstant::membershipStatus(); $form->add('select', 'membership_status_id', ts('Membership Status(s)'), $membershipStatus, FALSE, array('id' => 'membership_status_id', 'multiple' => 'multiple', 'class' => 'crm-select2')); $form->addEntityRef('membership_type_id', ts('Membership Type(s)'), array('entity' => 'MembershipType', 'multiple' => TRUE, 'placeholder' => ts('- any -'), 'select' => array('minimumInputLength' => 0))); $form->addElement('text', 'member_source', ts('Source')); CRM_Core_Form_Date::buildDateRange($form, 'member_join_date', 1, '_low', '_high', ts('From'), FALSE); CRM_Core_Form_Date::buildDateRange($form, 'member_start_date', 1, '_low', '_high', ts('From'), FALSE); CRM_Core_Form_Date::buildDateRange($form, 'member_end_date', 1, '_low', '_high', ts('From'), FALSE); $form->addYesNo('member_is_primary', ts('Primary Member?'), TRUE); $form->addYesNo('member_pay_later', ts('Pay Later?'), TRUE); $form->addYesNo('member_auto_renew', ts('Auto-Renew?'), TRUE); $form->addYesNo('member_test', ts('Membership is a Test?'), TRUE); $form->addYesNo('member_is_override', ts('Membership Status Is Override?'), TRUE); // add all the custom searchable fields $extends = array('Membership'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); if ($groupDetails) { $form->assign('membershipGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE); } } } CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'member_campaign_id'); $form->assign('validCiviMember', TRUE); $form->setDefaults(array('member_test' => 0)); }