/** * 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(); }
/** * 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); }
/** * 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); } }
/** * 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(); }
static function preProcess(&$form, $subName = NULL, $subType = NULL, $groupCount = NULL, $type = NULL, $entityID = NULL) { if ($type) { $form->_type = $type; } else { $form->_type = CRM_Utils_Request::retrieve('type', 'String', $form); } if (isset($subType)) { $form->_subType = $subType; } else { $form->_subType = CRM_Utils_Request::retrieve('subType', 'String', $form); } if ($form->_subType == 'null') { $form->_subType = NULL; } if (isset($subName)) { $form->_subName = $subName; } else { $form->_subName = CRM_Utils_Request::retrieve('subName', 'String', $form); } if ($form->_subName == 'null') { $form->_subName = NULL; } if ($groupCount) { $form->_groupCount = $groupCount; } else { $form->_groupCount = CRM_Utils_Request::retrieve('cgcount', 'Positive', $form); } $form->assign('cgCount', $form->_groupCount); //carry qf key, since this form is not inhereting core form. if ($qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject)) { $form->assign('qfKey', $qfKey); } if ($entityID) { $form->_entityId = $entityID; } else { $form->_entityId = CRM_Utils_Request::retrieve('entityID', 'Positive', $form); } $form->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $form); $subType = $form->_subType; if (!is_array($subType) && strstr($subType, CRM_Core_DAO::VALUE_SEPARATOR)) { $subType = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ',', trim($subType, CRM_Core_DAO::VALUE_SEPARATOR)); } $groupTree =& CRM_Core_BAO_CustomGroup::getTree($form->_type, $form, $form->_entityId, $form->_groupID, $subType, $form->_subName); // we should use simplified formatted groupTree $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, $form->_groupCount, $form); if (isset($form->_groupTree) && is_array($form->_groupTree)) { $keys = array_keys($groupTree); foreach ($keys as $key) { $form->_groupTree[$key] = $groupTree[$key]; } } else { $form->_groupTree = $groupTree; } }
/** * 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 __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(); } }
/** * 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); }
/** * 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(); //retrieve inline custom data $entityType = $this->get('contactType'); $entitySubType = $this->get('contactSubtype'); $groupTree =& CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $this->_contactId, null, $entitySubType); CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree); // also create the form element for the activity links box $controller = new CRM_Core_Controller_Simple('CRM_Activity_Form_ActivityLinks', ts('Activity Links'), null); $controller->setEmbedded(true); $controller->run(); }
static function preProcess(&$form, $subName = null, $subType = null, $groupCount = null, $type = null, $entityID = null) { if ($type) { $form->_type = $type; } else { $form->_type = CRM_Utils_Request::retrieve('type', 'String', $form); } if (isset($subType)) { $form->_subType = $subType; } else { $form->_subType = CRM_Utils_Request::retrieve('subType', 'String', $form); } if ($form->_subType == 'null') { $form->_subType = null; } if (isset($subName)) { $form->_subName = $subName; } else { $form->_subName = CRM_Utils_Request::retrieve('subName', 'String', $form); } if ($form->_subName == 'null') { $form->_subName = null; } if ($groupCount) { $form->_groupCount = $groupCount; } else { $form->_groupCount = CRM_Utils_Request::retrieve('cgcount', 'Positive', $form); } $form->assign('cgCount', $form->_groupCount); if ($entityID) { $form->_entityId = $entityID; } else { $form->_entityId = CRM_Utils_Request::retrieve('entityID', 'Positive', $form); } $form->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $form); $groupTree =& CRM_Core_BAO_CustomGroup::getTree($form->_type, $form, $form->_entityId, $form->_groupID, $form->_subType, $form->_subName); // we should use simplified formatted groupTree $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, $form->_groupCount, $form); if (isset($form->_groupTree) && is_array($form->_groupTree)) { $keys = array_keys($groupTree); foreach ($keys as $key) { $form->_groupTree[$key] = $groupTree[$key]; } } else { $form->_groupTree = $groupTree; } }
/** * 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); }
/** * Test getTree(). */ public function testGetTree() { $params = array(); $contactId = Contact::createIndividual(); $customGrouptitle = 'My Custom Group'; $groupParams = array('title' => $customGrouptitle, 'name' => 'my_custom_group', 'style' => 'Tab', 'extends' => 'Individual', 'is_active' => 1, 'version' => 3); $customGroup = Custom::createGroup($groupParams); $customGroupId = $customGroup->id; $fields = array('groupId' => $customGroupId, 'dataType' => 'String', 'htmlType' => 'Text'); $customField = Custom::createField($params, $fields); $formParams = NULL; $getTree = CRM_Core_BAO_CustomGroup::getTree('Individual', $formParams, $customGroupId); $dbCustomGroupTitle = $this->assertDBNotNull('CRM_Core_DAO_CustomGroup', $customGroupId, 'title', 'id', 'Database check for custom group record.'); Custom::deleteField($customField); Custom::deleteGroup($customGroup); Contact::delete($contactId); $customGroup->free(); }
/** * 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() { $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this); $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); $values = array(); $params['id'] = $this->_id; require_once 'CRM/Grant/BAO/Grant.php'; CRM_Grant_BAO_Grant::retrieve($params, $values); require_once 'CRM/Grant/PseudoConstant.php'; $grantType = CRM_Grant_PseudoConstant::grantType(); $grantStatus = CRM_Grant_PseudoConstant::grantStatus(); $this->assign('grantType', $grantType[$values['grant_type_id']]); $this->assign('grantStatus', $grantStatus[$values['status_id']]); $grantTokens = array('amount_total', 'amount_requested', 'amount_granted', 'rationale', 'grant_report_received', 'application_received_date', 'decision_date', 'money_transfer_date', 'grant_due_date'); foreach ($grantTokens as $token) { $this->assign($token, CRM_Utils_Array::value($token, $values)); } if (isset($this->_id)) { require_once 'CRM/Core/BAO/Note.php'; $noteDAO =& new CRM_Core_BAO_Note(); $noteDAO->entity_table = 'civicrm_grant'; $noteDAO->entity_id = $this->_id; if ($noteDAO->find(true)) { $this->_noteId = $noteDAO->id; } } if (isset($this->_noteId)) { $this->assign('note', CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Note', $this->_noteId, 'note')); } // add Grant to Recent Items require_once 'CRM/Utils/Recent.php'; require_once 'CRM/Contact/BAO/Contact.php'; require_once 'CRM/Utils/Money.php'; $url = CRM_Utils_System::url('civicrm/contact/view/grant', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}"); $title = CRM_Contact_BAO_Contact::displayName($values['contact_id']) . ' - ' . ts('Grant') . ': ' . CRM_Utils_Money::format($values['amount_total']) . ' (' . $grantType[$values['grant_type_id']] . ')'; CRM_Utils_Recent::add($title, $url, $values['id'], 'Grant', $values['contact_id'], null); require_once 'CRM/Core/BAO/File.php'; $attachment = CRM_Core_BAO_File::attachmentInfo('civicrm_grant', $this->_id); $this->assign('attachment', $attachment); $groupTree =& CRM_Core_BAO_CustomGroup::getTree("Grant", $this, $this->_id, 0); CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree); }
/** * 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); }
/** * Function to build the form * * @return None * @access public */ function buildQuickForm() { parent::buildQuickForm(); if ($this->_action & CRM_CORE_ACTION_DELETE) { return; } $this->applyFilter('__ALL__', 'trim'); $this->add('text', 'subject', ts('Subject'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Meeting', 'subject')); $this->addRule('subject', ts('Please enter a valid subject.'), 'required'); $this->addElement('date', 'scheduled_date_time', ts('Date and Time'), CRM_Core_SelectValues::date('datetime')); $this->addRule('scheduled_date_time', ts('Select a valid date.'), 'qfDate'); $this->addRule('scheduled_date_time', ts('Please select Scheduled Date.'), 'required'); $this->add('select', 'duration_hours', ts('Duration'), CRM_Core_SelectValues::getHours()); $this->add('select', 'duration_minutes', null, CRM_Core_SelectValues::getMinutes()); $this->add('text', 'location', ts('Location'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Meeting', 'location')); $this->add('textarea', 'details', ts('Details'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Meeting', 'details')); $status =& $this->add('select', 'status', ts('Status'), CRM_Core_SelectValues::activityStatus()); $this->addRule('status', ts('Please select status.'), 'required'); $this->_groupTree =& CRM_Core_BAO_CustomGroup::getTree('Meeting', $this->_id, 0); CRM_Core_BAO_CustomGroup::buildQuickForm($this, $this->_groupTree, 'showBlocks1', 'hideBlocks1'); }
/** * pre processing work done here. * * gets session variables for table name, id of entity in table, type of entity and stores them. * * @param * * @return void * * @access public * */ function preProcess() { $this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this, TRUE); $this->_entityID = CRM_Utils_Request::retrieve('entityID', 'Positive', $this, TRUE); $this->_subTypeID = CRM_Utils_Request::retrieve('subType', 'Positive', $this, TRUE); $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Case', $this, $this->_entityID, $this->_groupID, $this->_subTypeID); // simplified formatted groupTree $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $this); foreach ($groupTree as $groupValues) { $this->_customTitle = $groupValues['title']; } $this->_defaults = array(); CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $this->_defaults); $this->setDefaults($this->_defaults); CRM_Core_BAO_CustomGroup::buildQuickForm($this, $groupTree, FALSE, 1); //need to assign custom data type and subtype to the template $this->assign('entityID', $this->_entityID); $this->assign('groupID', $this->_groupID); $this->assign('subType', $this->_subTypeID); $this->assign('contactID', $this->_contactID); }
/** * 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]; }
/** * Set variables up before form is built. * * @return void */ public function preProcess() { $values = $ids = array(); $participantID = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE); $contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); $params = array('id' => $participantID); CRM_Event_BAO_Participant::getValues($params, $values, $ids); if (empty($values)) { CRM_Core_Error::statusBounce(ts('The requested participant record does not exist (possibly the record was deleted).')); } CRM_Event_BAO_Participant::resolveDefaults($values[$participantID]); if (!empty($values[$participantID]['fee_level'])) { CRM_Event_BAO_Participant::fixEventLevel($values[$participantID]['fee_level']); } $this->assign('contactId', $contactID); $this->assign('participantId', $participantID); $paymentId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $participantID, 'id', 'participant_id'); $this->assign('hasPayment', $paymentId); if ($parentParticipantId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $participantID, 'registered_by_id')) { $parentHasPayment = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $parentParticipantId, 'id', 'participant_id'); $this->assign('parentHasPayment', $parentHasPayment); } $statusId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $participantID, 'status_id', 'id'); $status = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantStatusType', $statusId, 'name', 'id'); $status = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantStatusType', $statusId, 'name', 'id'); if ($status == 'Transferred') { $transferId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $participantID, 'transferred_to_contact_id', 'id'); $pid = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $transferId, 'id', 'contact_id'); $transferName = current(CRM_Contact_BAO_Contact::getContactDetails($transferId)); $this->assign('pid', $pid); $this->assign('transferId', $transferId); $this->assign('transferName', $transferName); } $participantStatuses = CRM_Event_PseudoConstant::participantStatus(); if ($values[$participantID]['is_test']) { $values[$participantID]['status'] .= ' (test) '; } // Get Note $noteValue = CRM_Core_BAO_Note::getNote($participantID, 'civicrm_participant'); $values[$participantID]['note'] = array_values($noteValue); // Get Line Items $lineItem = CRM_Price_BAO_LineItem::getLineItems($participantID); if (!CRM_Utils_System::isNull($lineItem)) { $values[$participantID]['lineItem'][] = $lineItem; } $values[$participantID]['totalAmount'] = CRM_Utils_Array::value('fee_amount', $values[$participantID]); // Get registered_by contact ID and display_name if participant was registered by someone else (CRM-4859) if (!empty($values[$participantID]['participant_registered_by_id'])) { $values[$participantID]['registered_by_contact_id'] = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Participant", $values[$participantID]['participant_registered_by_id'], 'contact_id', 'id'); $values[$participantID]['registered_by_display_name'] = CRM_Contact_BAO_Contact::displayName($values[$participantID]['registered_by_contact_id']); } // Check if this is a primaryParticipant (registered for others) and retrieve additional participants if true (CRM-4859) if (CRM_Event_BAO_Participant::isPrimaryParticipant($participantID)) { $values[$participantID]['additionalParticipants'] = CRM_Event_BAO_Participant::getAdditionalParticipants($participantID); } // 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'); $eventTypeCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantEventType', 'name'); $allRoleIDs = explode(CRM_Core_DAO::VALUE_SEPARATOR, $values[$participantID]['role_id']); $groupTree = array(); $finalTree = array(); foreach ($allRoleIDs as $k => $v) { $roleGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID, NULL, $v, $roleCustomDataTypeID); $eventGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID, NULL, $values[$participantID]['event_id'], $eventNameCustomDataTypeID); $eventTypeID = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $values[$participantID]['event_id'], 'event_type_id', 'id'); $eventTypeGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID, NULL, $eventTypeID, $eventTypeCustomDataTypeID); $groupTree = CRM_Utils_Array::crmArrayMerge($roleGroupTree, $eventGroupTree); $groupTree = CRM_Utils_Array::crmArrayMerge($groupTree, $eventTypeGroupTree); $groupTree = CRM_Utils_Array::crmArrayMerge($groupTree, CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID)); foreach ($groupTree as $treeId => $trees) { $finalTree[$treeId] = $trees; } } CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $finalTree, FALSE, NULL, NULL, NULL, $participantID); $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $values[$participantID]['event_id'], 'title'); //CRM-7150, show event name on participant view even if the event is disabled if (empty($values[$participantID]['event'])) { $values[$participantID]['event'] = $eventTitle; } //do check for campaigns if ($campaignId = CRM_Utils_Array::value('campaign_id', $values[$participantID])) { $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId); $values[$participantID]['campaign'] = $campaigns[$campaignId]; } $this->assign($values[$participantID]); // add viewed participant to recent items list $url = CRM_Utils_System::url('civicrm/contact/view/participant', "action=view&reset=1&id={$values[$participantID]['id']}&cid={$values[$participantID]['contact_id']}&context=home"); $recentOther = array(); if (CRM_Core_Permission::check('edit event participants')) { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/participant', "action=update&reset=1&id={$values[$participantID]['id']}&cid={$values[$participantID]['contact_id']}&context=home"); } if (CRM_Core_Permission::check('delete in CiviEvent')) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/participant', "action=delete&reset=1&id={$values[$participantID]['id']}&cid={$values[$participantID]['contact_id']}&context=home"); } $participantRoles = CRM_Event_PseudoConstant::participantRole(); $displayName = CRM_Contact_BAO_Contact::displayName($values[$participantID]['contact_id']); $participantCount = array(); $invoiceSettings = Civi::settings()->get('contribution_invoice_settings'); $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings); $totalTaxAmount = 0; foreach ($lineItem as $k => $v) { if (CRM_Utils_Array::value('participant_count', $lineItem[$k]) > 0) { $participantCount[] = $lineItem[$k]['participant_count']; } $totalTaxAmount = $v['tax_amount'] + $totalTaxAmount; } if ($invoicing) { $this->assign('totalTaxAmount', $totalTaxAmount); } if ($participantCount) { $this->assign('pricesetFieldsCount', $participantCount); } $this->assign('displayName', $displayName); // 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 Event Registration for') . ' ' . $displayName); $roleId = CRM_Utils_Array::value('role_id', $values[$participantID]); $title = $displayName . ' (' . CRM_Utils_Array::value($roleId, $participantRoles) . ' - ' . $eventTitle . ')'; $sep = CRM_Core_DAO::VALUE_SEPARATOR; $viewRoles = array(); foreach (explode($sep, $values[$participantID]['role_id']) as $k => $v) { $viewRoles[] = $participantRoles[$v]; } $values[$participantID]['role_id'] = implode(', ', $viewRoles); $this->assign('role', $values[$participantID]['role_id']); // add Participant to Recent Items CRM_Utils_Recent::add($title, $url, $values[$participantID]['id'], 'Participant', $values[$participantID]['contact_id'], NULL, $recentOther); }
/** * Construct the search query */ function all($offset = 0, $rowcount = 0, $sort = NULL, $includeContactIDs = FALSE, $justIDs = FALSE) { // SELECT clause must include contact_id as an alias for civicrm_contact.id if ($justIDs) { $select = 'contact_a.id as contact_id'; } else { $select = ' contact_a.id as contact_id, contact_a.sort_name as sort_name, contact_a.contact_type as contact_type, activity.id as activity_id, activity.activity_type_id as activity_type_id, contact_b.sort_name as source_contact, ov1.label as activity_type, activity.subject as activity_subject, activity.activity_date_time as activity_date, ov2.label as activity_status, cca.case_id as case_id, activity.location as location, activity.duration as duration, activity.details as details, assignment.activity_id as assignment_activity, contact_c.display_name as assignee '; } $from = $this->from(); $where = $this->where($includeContactIDs); if (!empty($where)) { $where = "WHERE {$where}"; } // add custom group fields to SELECT and FROM clause $groupTree = CRM_Core_BAO_CustomGroup::getTree('Activity', $form, NULL, NULL, '', NULL); foreach ($groupTree as $key) { if (!empty($key['extends']) && $key['extends'] == 'Activity') { $select .= ", " . $key['table_name'] . ".*"; $from .= " LEFT JOIN " . $key['table_name'] . " ON " . $key['table_name'] . ".entity_id = activity.id"; } } // end custom groups add $sql = " SELECT {$select} FROM {$from} {$where} "; //no need to add order when only contact Ids. if (!$justIDs) { // Define ORDER BY for query in $sort, with default value if (!empty($sort)) { if (is_string($sort)) { $sort = CRM_Utils_Type::escape($sort, 'String'); $sql .= " ORDER BY {$sort} "; } else { $sql .= ' ORDER BY ' . trim($sort->orderBy()); } } else { $sql .= 'ORDER BY contact_a.sort_name, activity.activity_date_time DESC, activity.activity_type_id, activity.status_id, activity.subject'; } } else { //CRM-14107, since there could be multiple activities against same contact, //we need to provide GROUP BY on contact id to prevent duplicacy on prev/next entries $sql .= 'GROUP BY contact_a.id ORDER BY contact_a.sort_name'; } if ($rowcount > 0 && $offset >= 0) { $offset = CRM_Utils_Type::escape($offset, 'Int'); $rowcount = CRM_Utils_Type::escape($rowcount, 'Int'); $sql .= " LIMIT {$offset}, {$rowcount} "; } return $sql; }
/** * Build form for address input fields. * * @param CRM_Core_Form $form * @param int $addressBlockCount * The index of the address array (if multiple addresses on a page). * @param bool $sharing * False, if we want to skip the address sharing features. * @param bool $inlineEdit * True when edit used in inline edit. */ public static function buildQuickForm(&$form, $addressBlockCount = NULL, $sharing = TRUE, $inlineEdit = FALSE) { // passing this via the session is AWFUL. we need to fix this if (!$addressBlockCount) { $blockId = $form->get('Address_Block_Count') ? $form->get('Address_Block_Count') : 1; } else { $blockId = $addressBlockCount; } $config = CRM_Core_Config::singleton(); $countryDefault = $config->defaultContactCountry; $form->applyFilter('__ALL__', 'trim'); $js = array(); if (!$inlineEdit) { $js = array('onChange' => 'checkLocation( this.id );', 'placeholder' => NULL); } //make location type required for inline edit $form->addField("address[{$blockId}][location_type_id]", array('entity' => 'address', 'class' => 'eight') + $js, $inlineEdit); if (!$inlineEdit) { $js = array('id' => 'Address_' . $blockId . '_IsPrimary', 'onClick' => 'singleSelect( this.id );'); } $form->addField("address[{$blockId}][is_primary]", array('entity' => 'address', 'label' => ts('Primary location for this contact'), 'text' => ts('Primary location for this contact')) + $js); if (!$inlineEdit) { $js = array('id' => 'Address_' . $blockId . '_IsBilling', 'onClick' => 'singleSelect( this.id );'); } $form->addField("address[{$blockId}][is_billing]", array('entity' => 'address', 'label' => ts('Primary location for this contact'), 'text' => ts('Primary location for this contact')) + $js); // hidden element to store master address id $form->addField("address[{$blockId}][master_id]", array('entity' => 'address', 'type' => 'hidden')); $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE); $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address'); $elements = array('address_name', 'street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'postal_code_suffix', 'country_id', 'state_province_id', 'county_id', 'geo_code_1', 'geo_code_2', 'street_number', 'street_name', 'street_unit'); foreach ($elements as $name) { //Remove id from name, to allow comparison against enabled addressOtions. $nameWithoutID = strpos($name, '_id') !== FALSE ? substr($name, 0, -3) : $name; // Skip fields which are not enabled in the address options. if (empty($addressOptions[$nameWithoutID])) { $continue = TRUE; //Don't skip street parsed fields when parsing is enabled. if (in_array($nameWithoutID, array('street_number', 'street_name', 'street_unit')) && !empty($addressOptions['street_address_parsing'])) { $continue = FALSE; } if ($continue) { continue; } } if ($name == 'address_name') { $name = 'name'; } $params = array('entity' => 'address'); if ($name == 'postal_code_suffix') { $params['label'] = ts('Suffix'); } $form->addField("address[{$blockId}][{$name}]", $params); } $entityId = NULL; if (!empty($form->_values['address']) && !empty($form->_values['address'][$blockId])) { $entityId = $form->_values['address'][$blockId]['id']; } // CRM-11665 geocode override option $geoCode = FALSE; if (!empty($config->geocodeMethod)) { $geoCode = TRUE; $form->addElement('checkbox', "address[{$blockId}][manual_geo_code]", ts('Override automatic geocoding')); } $form->assign('geoCode', $geoCode); // Process any address custom data - $groupTree = CRM_Core_BAO_CustomGroup::getTree('Address', $form, $entityId); if (isset($groupTree) && is_array($groupTree)) { // use simplified formatted groupTree $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $form); // make sure custom fields are added /w element-name in the format - 'address[$blockId][custom-X]' foreach ($groupTree as $id => $group) { foreach ($group['fields'] as $fldId => $field) { $groupTree[$id]['fields'][$fldId]['element_custom_name'] = $field['element_name']; $groupTree[$id]['fields'][$fldId]['element_name'] = "address[{$blockId}][{$field['element_name']}]"; } } $defaults = array(); CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults); // since we change element name for address custom data, we need to format the setdefault values $addressDefaults = array(); foreach ($defaults as $key => $val) { if (empty($val)) { continue; } // inorder to set correct defaults for checkbox custom data, we need to converted flat key to array // this works for all types custom data $keyValues = explode('[', str_replace(']', '', $key)); $addressDefaults[$keyValues[0]][$keyValues[1]][$keyValues[2]] = $val; } $form->setDefaults($addressDefaults); // we setting the prefix to 'dnc_' below, so that we don't overwrite smarty's grouptree var. // And we can't set it to 'address_' because we want to set it in a slightly different format. CRM_Core_BAO_CustomGroup::buildQuickForm($form, $groupTree, FALSE, 'dnc_'); // during contact editing : if no address is filled // required custom data must not produce 'required' form rule error // more handling done in formRule func if (!$inlineEdit) { CRM_Contact_Form_Edit_Address::storeRequiredCustomDataInfo($form, $groupTree); } $template = CRM_Core_Smarty::singleton(); $tplGroupTree = $template->get_template_vars('address_groupTree'); $tplGroupTree = empty($tplGroupTree) ? array() : $tplGroupTree; $form->assign('address_groupTree', $tplGroupTree + array($blockId => $groupTree)); // unset the temp smarty var that got created $form->assign('dnc_groupTree', NULL); } // address custom data processing ends .. if ($sharing) { // shared address $form->addElement('checkbox', "address[{$blockId}][use_shared_address]", NULL, ts('Use another contact\'s address')); // Override the default profile links to add address form $profileLinks = CRM_Core_BAO_UFGroup::getCreateLinks(array('new_individual', 'new_organization', 'new_household'), 'shared_address'); $form->addEntityRef("address[{$blockId}][master_contact_id]", ts('Share With'), array('create' => $profileLinks)); } }
/** * format params for update and fill mode * * @param $params array referance to an array containg all the * values for import * @param $onDuplicate int * @param $cid int contact id */ function formatParams(&$params, $onDuplicate, $cid) { if ($onDuplicate == CRM_Import_Parser::DUPLICATE_SKIP) { return; } $contactParams = array('contact_id' => $cid); $defaults = array(); $contactObj = CRM_Contact_BAO_Contact::retrieve($contactParams, $defaults); $modeUpdate = $modeFill = false; if ($onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE) { $modeUpdate = true; } if ($onDuplicate == CRM_Import_Parser::DUPLICATE_FILL) { $modeFill = true; } require_once 'CRM/Core/BAO/CustomGroup.php'; $groupTree = CRM_Core_BAO_CustomGroup::getTree($params['contact_type'], CRM_Core_DAO::$_nullObject, $cid, 0, null); CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults, false, false); $contact = get_object_vars($contactObj); $location = null; foreach ($params as $key => $value) { if ($key == 'id' || $key == 'contact_type') { continue; } if ($key == 'location') { $location = true; } else { if (in_array($key, array('email_greeting', 'postal_greeting', 'addressee'))) { // CRM-4575, need to null custom if ($params["{$key}_id"] != 4) { $params["{$key}_custom"] = 'null'; } unset($params[$key]); } else { if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key)) { $custom = true; } else { $getValue = CRM_Utils_Array::retrieveValueRecursive($contact, $key); if ($key == 'contact_source') { $params['source'] = $params[$key]; unset($params[$key]); } if ($modeFill && isset($getValue)) { unset($params[$key]); } } } } } if ($location) { for ($loc = 1; $loc <= count($params['location']); $loc++) { //if location block is already present for the contact //then do not fill any data for that location type, CRM-4424 if ($modeFill) { foreach ($contact['location'] as $location => $locationDetails) { $getValue = CRM_Utils_Array::value('location_type_id', $locationDetails); if (isset($getValue) && $getValue == $params['location'][$loc]['location_type_id']) { unset($params['location'][$loc]); break; } } } if (array_key_exists('address', $contact['location'][$loc])) { $fields = array('street_address', 'city', 'state_province_id', 'postal_code', 'postal_code_suffix', 'country_id'); foreach ($fields as $field) { $getValue = CRM_Utils_Array::retrieveValueRecursive($contact['location'][$loc]['address'], $field); if ($modeFill && isset($getValue)) { unset($params['location'][$loc]['address'][$field]); } } } $fields = array('email' => 'email', 'phone' => 'phone', 'im' => 'name'); foreach ($fields as $key => $field) { if (array_key_exists($key, $contact['location'][$loc])) { for ($c = 1; $c <= count($params['location'][$loc][$key]); $c++) { $getValue = CRM_Utils_Array::retrieveValueRecursive($contact['location'][$loc][$key][$c], $field); if ($modeFill && isset($getValue)) { unset($params['location'][$loc][$key][$c][$field]); } } } } } } }
/** * Build the form object. */ public function preProcess() { CRM_Core_Form_RecurringEntity::preProcess('civicrm_activity'); $this->_atypefile = CRM_Utils_Array::value('atypefile', $_GET); $this->assign('atypefile', FALSE); if ($this->_atypefile) { $this->assign('atypefile', TRUE); } $session = CRM_Core_Session::singleton(); $this->_currentUserId = $session->get('userID'); $this->_currentlyViewedContactId = $this->get('contactId'); if (!$this->_currentlyViewedContactId) { $this->_currentlyViewedContactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this); } $this->assign('contactId', $this->_currentlyViewedContactId); // Give the context. if (!isset($this->_context)) { $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this); if (CRM_Contact_Form_Search::isSearchContext($this->_context)) { $this->_context = 'search'; } elseif (!in_array($this->_context, array('dashlet', 'dashletFullscreen')) && $this->_currentlyViewedContactId) { $this->_context = 'activity'; } $this->_compContext = CRM_Utils_Request::retrieve('compContext', 'String', $this); } $this->assign('context', $this->_context); $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this); if ($this->_action & CRM_Core_Action::DELETE) { if (!CRM_Core_Permission::check('delete activities')) { CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); } } // CRM-6957 // When we come from contact search, activity id never comes. // So don't try to get from object, it might gives you wrong one. // if we're not adding new one, there must be an id to // an activity we're trying to work on. if ($this->_action != CRM_Core_Action::ADD && get_class($this->controller) != 'CRM_Contact_Controller_Search') { $this->_activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this); } $this->_activityTypeId = CRM_Utils_Request::retrieve('atype', 'Positive', $this); $this->assign('atype', $this->_activityTypeId); $this->assign('activityId', $this->_activityId); // Check for required permissions, CRM-6264. if ($this->_activityId && in_array($this->_action, array(CRM_Core_Action::UPDATE, CRM_Core_Action::VIEW)) && !CRM_Activity_BAO_Activity::checkPermission($this->_activityId, $this->_action)) { CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); } if ($this->_action & CRM_Core_Action::VIEW && CRM_Activity_BAO_Activity::checkPermission($this->_activityId, CRM_Core_Action::UPDATE)) { $this->assign('permission', 'edit'); } if (!$this->_activityTypeId && $this->_activityId) { $this->_activityTypeId = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $this->_activityId, 'activity_type_id'); } // Assigning Activity type name. if ($this->_activityTypeId) { $activityTName = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, 'AND v.value = ' . $this->_activityTypeId, 'label'); if ($activityTName[$this->_activityTypeId]) { $this->_activityTypeName = $activityTName[$this->_activityTypeId]; $this->assign('activityTName', $activityTName[$this->_activityTypeId]); } } // Set title. if (isset($activityTName)) { $activityName = CRM_Utils_Array::value($this->_activityTypeId, $activityTName); $this->assign('pageTitle', ts('%1 Activity', array(1 => $activityName))); if ($this->_currentlyViewedContactId) { $displayName = CRM_Contact_BAO_Contact::displayName($this->_currentlyViewedContactId); // Check if this is default domain contact CRM-10482. if (CRM_Contact_BAO_Contact::checkDomainContact($this->_currentlyViewedContactId)) { $displayName .= ' (' . ts('default organization') . ')'; } CRM_Utils_System::setTitle($displayName . ' - ' . $activityName); } else { CRM_Utils_System::setTitle(ts('%1 Activity', array(1 => $activityName))); } } // Check the mode when this form is called either single or as // search task action. if ($this->_activityTypeId || $this->_context == 'standalone' || $this->_currentlyViewedContactId) { $this->_single = TRUE; $this->assign('urlPath', 'civicrm/activity'); } else { // Set the appropriate action. $url = CRM_Utils_System::currentPath(); $urlArray = explode('/', $url); $searchPath = array_pop($urlArray); $searchType = 'basic'; $this->_action = CRM_Core_Action::BASIC; switch ($searchPath) { case 'basic': $searchType = $searchPath; $this->_action = CRM_Core_Action::BASIC; break; case 'advanced': $searchType = $searchPath; $this->_action = CRM_Core_Action::ADVANCED; break; case 'builder': $searchType = $searchPath; $this->_action = CRM_Core_Action::PROFILE; break; case 'custom': $this->_action = CRM_Core_Action::COPY; $searchType = $searchPath; break; } parent::preProcess(); $this->_single = FALSE; $this->assign('urlPath', "civicrm/contact/search/{$searchType}"); $this->assign('urlPathVar', "_qf_Activity_display=true&qfKey={$this->controller->_key}"); } $this->assign('single', $this->_single); $this->assign('action', $this->_action); if ($this->_action & CRM_Core_Action::VIEW) { // Get the tree of custom fields. $this->_groupTree =& CRM_Core_BAO_CustomGroup::getTree('Activity', $this, $this->_activityId, 0, $this->_activityTypeId); } if ($this->_activityTypeId) { // Set activity type name and description to template. list($this->_activityTypeName, $activityTypeDescription) = CRM_Core_BAO_OptionValue::getActivityTypeDetails($this->_activityTypeId); $this->assign('activityTypeName', $this->_activityTypeName); $this->assign('activityTypeDescription', $activityTypeDescription); } // set user context $urlParams = $urlString = NULL; $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); if (!$qfKey) { $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); } // Validate the qfKey. if (!CRM_Utils_Rule::qfKey($qfKey)) { $qfKey = NULL; } if ($this->_context == 'fulltext') { $keyName = '&qfKey'; $urlParams = 'force=1'; $urlString = 'civicrm/contact/search/custom'; if ($this->_action == CRM_Core_Action::UPDATE) { $keyName = '&key'; $urlParams .= '&context=fulltext&action=view'; $urlString = 'civicrm/contact/view/activity'; } if ($qfKey) { $urlParams .= "{$keyName}={$qfKey}"; } $this->assign('searchKey', $qfKey); } elseif (in_array($this->_context, array('standalone', 'home', 'dashlet', 'dashletFullscreen'))) { $urlParams = 'reset=1'; $urlString = 'civicrm/dashboard'; } elseif ($this->_context == 'search') { $urlParams = 'force=1'; if ($qfKey) { $urlParams .= "&qfKey={$qfKey}"; } $path = CRM_Utils_System::currentPath(); if ($this->_compContext == 'advanced') { $urlString = 'civicrm/contact/search/advanced'; } elseif ($path == 'civicrm/group/search' || $path == 'civicrm/contact/search' || $path == 'civicrm/contact/search/advanced' || $path == 'civicrm/contact/search/custom' || $path == 'civicrm/group/search') { $urlString = $path; } else { $urlString = 'civicrm/activity/search'; } $this->assign('searchKey', $qfKey); } elseif ($this->_context != 'caseActivity') { $urlParams = "action=browse&reset=1&cid={$this->_currentlyViewedContactId}&selectedChild=activity"; $urlString = 'civicrm/contact/view'; } if ($urlString) { $session->pushUserContext(CRM_Utils_System::url($urlString, $urlParams)); } // hack to retrieve activity type id from post variables if (!$this->_activityTypeId) { $this->_activityTypeId = CRM_Utils_Array::value('activity_type_id', $_POST); } // when custom data is included in this page if (!empty($_POST['hidden_custom'])) { // We need to set it in the session for the code below to work. // CRM-3014 // Need to assign custom data subtype to the template. $this->set('type', 'Activity'); $this->set('subType', $this->_activityTypeId); $this->set('entityId', $this->_activityId); CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_activityTypeId, 1, 'Activity', $this->_activityId); CRM_Custom_Form_CustomData::buildQuickForm($this); CRM_Custom_Form_CustomData::setDefaultValues($this); } // add attachments part CRM_Core_BAO_File::buildAttachment($this, 'civicrm_activity', $this->_activityId, NULL, TRUE); // figure out the file name for activity type, if any if ($this->_activityTypeId && ($this->_activityTypeFile = CRM_Activity_BAO_Activity::getFileForActivityTypeId($this->_activityTypeId, $this->_crmDir))) { $this->assign('activityTypeFile', $this->_activityTypeFile); $this->assign('crmDir', $this->_crmDir); } $this->setFields(); if ($this->_activityTypeFile) { $className = "CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}"; $className::preProcess($this); } $this->_values = $this->get('values'); if (!is_array($this->_values)) { $this->_values = array(); if (isset($this->_activityId) && $this->_activityId) { $params = array('id' => $this->_activityId); CRM_Activity_BAO_Activity::retrieve($params, $this->_values); } $this->set('values', $this->_values); } if ($this->_action & CRM_Core_Action::UPDATE) { CRM_Core_Form_RecurringEntity::preProcess('civicrm_activity'); } }
/** * Function to send Acknowledgment and create activity. * * @param object $form form object. * @param array $params (reference ) an assoc array of name/value pairs. * @access public * * @return None. */ function sendAcknowledgment(&$form, $params) { //handle Acknowledgment. $allPayments = $payments = array(); //get All Payments status types. $paymentStatusTypes = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); $returnProperties = array('status_id', 'scheduled_amount', 'scheduled_date', 'contribution_id'); //get all paymnets details. CRM_Core_DAO::commonRetrieveAll('CRM_Pledge_DAO_PledgePayment', 'pledge_id', $params['id'], $allPayments, $returnProperties); if (!empty($allPayments)) { foreach ($allPayments as $payID => $values) { $contributionValue = $contributionStatus = array(); if (isset($values['contribution_id'])) { $contributionParams = array('id' => $values['contribution_id']); $returnProperties = array('contribution_status_id', 'receive_date'); CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_Contribution', $contributionParams, $contributionStatus, $returnProperties); $contributionValue = array('status' => CRM_Utils_Array::value('contribution_status_id', $contributionStatus), 'receive_date' => CRM_Utils_Array::value('receive_date', $contributionStatus)); } $payments[$payID] = array_merge($contributionValue, array('amount' => CRM_Utils_Array::value('scheduled_amount', $values), 'due_date' => CRM_Utils_Array::value('scheduled_date', $values))); //get the first valid payment id. if (!isset($form->paymentId) && ($paymentStatusTypes[$values['status_id']] == 'Pending' || $paymentStatusTypes[$values['status_id']] == 'Overdue')) { $form->paymentId = $values['id']; } } } //end //assign pledge fields value to template. $pledgeFields = array('create_date', 'total_pledge_amount', 'frequency_interval', 'frequency_unit', 'installments', 'frequency_day', 'scheduled_amount', 'currency'); foreach ($pledgeFields as $field) { if (CRM_Utils_Array::value($field, $params)) { $form->assign($field, $params[$field]); } } //assign all payments details. if ($payments) { $form->assign('payments', $payments); } //assign honor fields. $honor_block_is_active = FALSE; //make sure we have values for it if (CRM_Utils_Array::value('honor_type_id', $params) && (!empty($params['honor_first_name']) && !empty($params['honor_last_name']) || !empty($params['honor_email']))) { $honor_block_is_active = TRUE; $prefix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id'); $honor = CRM_Core_PseudoConstant::get('CRM_Pledge_DAO_Pledge', 'honor_type_id'); $form->assign('honor_type', $honor[$params['honor_type_id']]); $form->assign('honor_prefix', $prefix[$params['honor_prefix_id']]); $form->assign('honor_first_name', $params['honor_first_name']); $form->assign('honor_last_name', $params['honor_last_name']); $form->assign('honor_email', $params['honor_email']); } $form->assign('honor_block_is_active', $honor_block_is_active); //handle domain token values $domain = CRM_Core_BAO_Domain::getDomain(); $tokens = array('domain' => array('name', 'phone', 'address', 'email'), 'contact' => CRM_Core_SelectValues::contactTokens()); $domainValues = array(); foreach ($tokens['domain'] as $token) { $domainValues[$token] = CRM_Utils_Token::getDomainTokenReplacement($token, $domain); } $form->assign('domain', $domainValues); //handle contact token values. $ids = array($params['contact_id']); $fields = array_merge(array_keys(CRM_Contact_BAO_Contact::importableFields()), array('display_name', 'checksum', 'contact_id')); foreach ($fields as $key => $val) { $returnProperties[$val] = TRUE; } $details = CRM_Utils_Token::getTokenDetails($ids, $returnProperties, TRUE, TRUE, NULL, $tokens, get_class($form)); $form->assign('contact', $details[0][$params['contact_id']]); //handle custom data. if (CRM_Utils_Array::value('hidden_custom', $params)) { $groupTree = CRM_Core_BAO_CustomGroup::getTree('Pledge', CRM_Core_DAO::$_nullObject, $params['id']); $pledgeParams = array(array('pledge_id', '=', $params['id'], 0, 0)); $customGroup = array(); // retrieve custom data foreach ($groupTree as $groupID => $group) { $customFields = $customValues = array(); if ($groupID == 'info') { continue; } foreach ($group['fields'] as $k => $field) { $field['title'] = $field['label']; $customFields["custom_{$k}"] = $field; } //to build array of customgroup & customfields in it CRM_Core_BAO_UFGroup::getValues($params['contact_id'], $customFields, $customValues, FALSE, $pledgeParams); $customGroup[$group['title']] = $customValues; } $form->assign('customGroup', $customGroup); } //handle acknowledgment email stuff. list($pledgerDisplayName, $pledgerEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($params['contact_id']); //check for online pledge. $session = CRM_Core_Session::singleton(); if (CRM_Utils_Array::value('receipt_from_email', $params)) { $userName = CRM_Utils_Array::value('receipt_from_name', $params); $userEmail = CRM_Utils_Array::value('receipt_from_email', $params); } elseif (CRM_Utils_Array::value('from_email_id', $params)) { $receiptFrom = $params['from_email_id']; } elseif ($userID = $session->get('userID')) { //check for loged in user. list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID); } else { //set the domain values. $userName = CRM_Utils_Array::value('name', $domainValues); $userEmail = CRM_Utils_Array::value('email', $domainValues); } if (!isset($receiptFrom)) { $receiptFrom = "{$userName} <{$userEmail}>"; } list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate(array('groupName' => 'msg_tpl_workflow_pledge', 'valueName' => 'pledge_acknowledge', 'contactId' => $params['contact_id'], 'from' => $receiptFrom, 'toName' => $pledgerDisplayName, 'toEmail' => $pledgerEmail)); //check if activity record exist for this pledge //Acknowledgment, if exist do not add activity. $activityType = 'Pledge Acknowledgment'; $activity = new CRM_Activity_DAO_Activity(); $activity->source_record_id = $params['id']; $activity->activity_type_id = CRM_Core_OptionGroup::getValue('activity_type', $activityType, 'name'); $config = CRM_Core_Config::singleton(); $details = 'Total Amount ' . CRM_Utils_Money::format($params['total_pledge_amount'], CRM_Utils_Array::value('currency', $params)) . ' To be paid in ' . $params['installments'] . ' installments of ' . CRM_Utils_Money::format($params['scheduled_amount'], CRM_Utils_Array::value('currency', $params)) . ' every ' . $params['frequency_interval'] . ' ' . $params['frequency_unit'] . '(s)'; if (!$activity->find()) { $activityParams = array('subject' => $subject, 'source_contact_id' => $params['contact_id'], 'source_record_id' => $params['id'], 'activity_type_id' => CRM_Core_OptionGroup::getValue('activity_type', $activityType, 'name'), 'activity_date_time' => CRM_Utils_Date::isoToMysql($params['acknowledge_date']), 'is_test' => $params['is_test'], 'status_id' => 2, 'details' => $details, 'campaign_id' => CRM_Utils_Array::value('campaign_id', $params)); //lets insert assignee record. if (CRM_Utils_Array::value('contact_id', $params)) { $activityParams['assignee_contact_id'] = $params['contact_id']; } if (is_a(CRM_Activity_BAO_Activity::create($activityParams), 'CRM_Core_Error')) { CRM_Core_Error::fatal("Failed creating Activity for acknowledgment"); } } }
/** * Gather values for contribution mail - this function has been created * as part of CRM-9996 refactoring as a step towards simplifying the composeMessage function * Values related to the contribution in question are gathered * * @param array $input * Input into function (probably from payment processor). * @param array $values * @param array $ids * The set of ids related to the input. * * @return array */ public function _gatherMessageValues($input, &$values, $ids = array()) { // set display address of contributor if ($this->address_id) { $addressParams = array('id' => $this->address_id); $addressDetails = CRM_Core_BAO_Address::getValues($addressParams, FALSE, 'id'); $addressDetails = array_values($addressDetails); $values['address'] = $addressDetails[0]['display']; } if ($this->_component == 'contribute') { if (isset($this->contribution_page_id)) { CRM_Contribute_BAO_ContributionPage::setValues($this->contribution_page_id, $values); if ($this->contribution_page_id) { // CRM-8254 - override default currency if applicable $config = CRM_Core_Config::singleton(); $config->defaultCurrency = CRM_Utils_Array::value('currency', $values, $config->defaultCurrency); } } else { // Handle re-print receipt for offline contributions (call from PDF.php - no contribution_page_id) $values['is_email_receipt'] = 1; $values['title'] = 'Contribution'; } // set lineItem for contribution if ($this->id) { $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->id, 'contribution', 1); if (!empty($lineItem)) { $itemId = key($lineItem); foreach ($lineItem as &$eachItem) { if (is_array($this->_relatedObjects['membership']) && array_key_exists($eachItem['membership_type_id'], $this->_relatedObjects['membership'])) { $eachItem['join_date'] = CRM_Utils_Date::customFormat($this->_relatedObjects['membership'][$eachItem['membership_type_id']]->join_date); $eachItem['start_date'] = CRM_Utils_Date::customFormat($this->_relatedObjects['membership'][$eachItem['membership_type_id']]->start_date); $eachItem['end_date'] = CRM_Utils_Date::customFormat($this->_relatedObjects['membership'][$eachItem['membership_type_id']]->end_date); } } $values['lineItem'][0] = $lineItem; $values['priceSetID'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $lineItem[$itemId]['price_field_id'], 'price_set_id'); } } $relatedContact = CRM_Contribute_BAO_Contribution::getOnbehalfIds($this->id, $this->contact_id); // if this is onbehalf of contribution then set related contact if (!empty($relatedContact['individual_id'])) { $values['related_contact'] = $ids['related_contact'] = $relatedContact['individual_id']; } } else { // event $eventParams = array('id' => $this->_relatedObjects['event']->id); $values['event'] = array(); CRM_Event_BAO_Event::retrieve($eventParams, $values['event']); // add custom fields for event $eventGroupTree = CRM_Core_BAO_CustomGroup::getTree('Event', $this->_relatedObjects['event'], $this->_relatedObjects['event']->id); $eventCustomGroup = array(); foreach ($eventGroupTree as $key => $group) { if ($key === 'info') { continue; } foreach ($group['fields'] as $k => $customField) { $groupLabel = $group['title']; if (!empty($customField['customValue'])) { foreach ($customField['customValue'] as $customFieldValues) { $eventCustomGroup[$groupLabel][$customField['label']] = CRM_Utils_Array::value('data', $customFieldValues); } } } } $values['event']['customGroup'] = $eventCustomGroup; //get participant details $participantParams = array('id' => $this->_relatedObjects['participant']->id); $values['participant'] = array(); CRM_Event_BAO_Participant::getValues($participantParams, $values['participant'], $participantIds); // add custom fields for event $participantGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', $this->_relatedObjects['participant'], $this->_relatedObjects['participant']->id); $participantCustomGroup = array(); foreach ($participantGroupTree as $key => $group) { if ($key === 'info') { continue; } foreach ($group['fields'] as $k => $customField) { $groupLabel = $group['title']; if (!empty($customField['customValue'])) { foreach ($customField['customValue'] as $customFieldValues) { $participantCustomGroup[$groupLabel][$customField['label']] = CRM_Utils_Array::value('data', $customFieldValues); } } } } $values['participant']['customGroup'] = $participantCustomGroup; //get location details $locationParams = array('entity_id' => $this->_relatedObjects['event']->id, 'entity_table' => 'civicrm_event'); $values['location'] = CRM_Core_BAO_Location::getValues($locationParams); $ufJoinParams = array('entity_table' => 'civicrm_event', 'entity_id' => $ids['event'], 'module' => 'CiviEvent'); list($custom_pre_id, $custom_post_ids) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); $values['custom_pre_id'] = $custom_pre_id; $values['custom_post_id'] = $custom_post_ids; // set lineItem for event contribution if ($this->id) { $participantIds = CRM_Event_BAO_Participant::getParticipantIds($this->id); if (!empty($participantIds)) { foreach ($participantIds as $pIDs) { $lineItem = CRM_Price_BAO_LineItem::getLineItems($pIDs); if (!CRM_Utils_System::isNull($lineItem)) { $values['lineItem'][] = $lineItem; } } } } } $groupTree = CRM_Core_BAO_CustomGroup::getTree('Contribution', $this, $this->id); $customGroup = array(); foreach ($groupTree as $key => $group) { if ($key === 'info') { continue; } foreach ($group['fields'] as $k => $customField) { $groupLabel = $group['title']; if (!empty($customField['customValue'])) { foreach ($customField['customValue'] as $customFieldValues) { $customGroup[$groupLabel][$customField['label']] = CRM_Utils_Array::value('data', $customFieldValues); } } } } $values['customGroup'] = $customGroup; return $values; }