public function testAddCaseToContact() { $params = array('case_id' => 1, 'contact_id' => 17); CRM_Case_BAO_CaseContact::create($params); $recent = CRM_Utils_Recent::get(); $this->assertEquals('Test Contact - Housing Support', $recent[0]['title']); }
/** * 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 */ public function preProcess() { $this->_contactID = $this->get('cid'); $this->_caseID = $this->get('id'); $this->assign('caseID', $this->_caseID); $this->assign('contactID', $this->_contactID); //retrieve details about case $params = array('id' => $this->_caseID); $returnProperties = array('case_type_id', 'subject', 'status_id', 'start_date'); CRM_Core_DAO::commonRetrieve('CRM_Case_BAO_Case', $params, $values, $returnProperties); $values['case_type_id'] = explode(CRM_Case_BAO_Case::VALUE_SEPERATOR, CRM_Utils_Array::value('case_type_id', $values)); $statuses = CRM_Case_PseudoConstant::caseStatus(); $caseTypeName = CRM_Case_PseudoConstant::caseTypeName($this->_caseID); $caseType = CRM_Core_OptionGroup::getLabel('case_type', $caseTypeName['id']); $this->_caseDetails = array('case_type' => $caseType, 'case_status' => $statuses[$values['case_status_id']], 'case_subject' => CRM_Utils_Array::value('subject', $values), 'case_start_date' => $values['case_start_date']); $this->_caseType = $caseTypeName['name']; $this->assign('caseDetails', $this->_caseDetails); $newActivityUrl = CRM_Utils_System::url('civicrm/case/activity', "action=add&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype=", false, null, false); $this->assign('newActivityUrl', $newActivityUrl); $reportUrl = CRM_Utils_System::url('civicrm/case/report', "reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&asn=", false, null, false); $this->assign('reportUrl', $reportUrl); // add to recently viewed require_once 'CRM/Utils/Recent.php'; require_once 'CRM/Contact/BAO/Contact.php'; $url = CRM_Utils_System::url('civicrm/contact/view/case', "action=view&reset=1&id={$this->_caseID}&cid={$this->_contactID}&context=home"); $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactID); $this->assign('displayName', $displayName); $title = $displayName . ' - ' . $caseType; // add the recently created case CRM_Utils_Recent::add($title, $url, $this->_caseID, 'Case', $this->_contactID, null); }
/** * 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); }
/** * Set variables up before form is built. * * @return void */ public function preProcess() { $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this); $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); $context = CRM_Utils_Request::retrieve('context', 'String', $this); $this->assign('context', $context); $values = array(); $params['id'] = $this->_id; CRM_Grant_BAO_Grant::retrieve($params, $values); $grantType = CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'grant_type_id'); $grantStatus = CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'status_id'); $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)) { $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 $url = CRM_Utils_System::url('civicrm/contact/view/grant', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"); $title = CRM_Contact_BAO_Contact::displayName($values['contact_id']) . ' - ' . ts('Grant') . ': ' . CRM_Utils_Money::format($values['amount_total']) . ' (' . $grantType[$values['grant_type_id']] . ')'; $recentOther = array(); if (CRM_Core_Permission::checkActionPermission('CiviGrant', CRM_Core_Action::UPDATE)) { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/grant', "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"); } if (CRM_Core_Permission::checkActionPermission('CiviGrant', CRM_Core_Action::DELETE)) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/grant', "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"); } CRM_Utils_Recent::add($title, $url, $values['id'], 'Grant', $values['contact_id'], NULL, $recentOther); $attachment = CRM_Core_BAO_File::attachmentInfo('civicrm_grant', $this->_id); $this->assign('attachment', $attachment); $grantType = CRM_Core_DAO::getFieldValue("CRM_Grant_DAO_Grant", $this->_id, "grant_type_id"); $groupTree =& CRM_Core_BAO_CustomGroup::getTree("Grant", $this, $this->_id, 0, $grantType); CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_id); $this->assign('id', $this->_id); $this->setPageTitle(ts('Grant')); }
/** * Create case contact record. * * @param array $params * case_id, contact_id * * @return CRM_Case_BAO_CaseContact */ public static function create($params) { $caseContact = new self(); $caseContact->copyValues($params); $caseContact->save(); // add to recently viewed $caseType = CRM_Case_BAO_Case::getCaseType($caseContact->case_id); $url = CRM_Utils_System::url('civicrm/contact/view/case', "action=view&reset=1&id={$caseContact->case_id}&cid={$caseContact->contact_id}&context=home"); $title = CRM_Contact_BAO_Contact::displayName($caseContact->contact_id) . ' - ' . $caseType; $recentOther = array(); if (CRM_Core_Permission::checkActionPermission('CiviCase', CRM_Core_Action::DELETE)) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/case', "action=delete&reset=1&id={$caseContact->case_id}&cid={$caseContact->contact_id}&context=home"); } // add the recently created case CRM_Utils_Recent::add($title, $url, $caseContact->case_id, 'Case', $caseContact->contact_id, NULL, $recentOther); return $caseContact; }
/** * class constructor * * @return CRM_Core_Smarty * @access private */ function CRM_Core_Smarty() { parent::Smarty(); $config =& CRM_Core_Config::singleton(); $this->template_dir = $config->templateDir; $this->compile_dir = $config->templateCompileDir; $this->use_sub_dirs = true; $this->plugins_dir = array($config->smartyDir . 'plugins', $config->pluginsDir); // add the session and the config here $config =& CRM_Core_Config::singleton(); $session =& CRM_Core_Session::singleton(); $recent =& CRM_Utils_Recent::get(); $this->assign_by_ref('config', $config); $this->assign_by_ref('session', $session); $this->assign_by_ref('recentlyViewed', $recent); $this->assign('displayRecent', true); $this->register_function('crmURL', array('CRM_Utils_System', 'crmURL')); }
/** * 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']}&context=home"); $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); $this->assign('id', $this->_id); }
/** * 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); }
/** * 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'])); $values['eachPaymentAmount'] = floor($values['amount'] / $values['installments']); 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"); 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); $this->assign($values); }
function preProcess() { $params = array(); $defaults = array(); $ids = array(); $session =& CRM_Core_Session::singleton(); $uid = $session->get('userID'); if (!$uid) { require_once 'CRM/Utils/System.php'; CRM_Utils_System::setUFMessage(ts('We could not find a user id. You must be logged in to access the CiviCRM Home Page and menus.')); CRM_Core_Error::statusBounce(ts('We could not find a user id. You must be logged in to access the CiviCRM Home Page and menus.')); } $this->assign('contactId', $uid); $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'view'); $this->assign('action', $this->_action); // a user can always view their own activity history // if they have access CiviCRM permission $this->_permission = CRM_Core_Permission::VIEW; // make the permission edit if the user has edit permission on the contact require_once 'CRM/Contact/BAO/Contact/Permission.php'; if (CRM_Contact_BAO_Contact_Permission::allow($uid, CRM_Core_Permission::EDIT)) { $this->_permission = CRM_Core_Permission::EDIT; } $displayName = $this->get('displayName'); list($displayName, $contactImage, $contactType) = CRM_Contact_BAO_Contact::getDisplayAndImage($uid, true); $this->set('displayName', $displayName); $this->set('contactImage', $contactImage); CRM_Utils_System::setTitle($contactImage . ' ' . $displayName, $displayName); CRM_Utils_Recent::add($displayName, CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $uid), $uid, $contactType, $uid, $displayName); // call hook to get html from other modules require_once 'CRM/Utils/Hook.php'; $contentPlacement = CRM_Utils_Hook::DASHBOARD_BELOW; // ignored but needed to prevent warnings $html = CRM_Utils_Hook::dashboard($uid, $contentPlacement); if (is_array($html)) { $this->assign_by_ref('hookContent', $html); $this->assign('hookContentPlacement', $contentPlacement); } }
/** * Set variables up before form is built. * * @return void */ public function preProcess() { $id = $this->get('id'); $values = $ids = array(); $params = array('id' => $id); $context = CRM_Utils_Request::retrieve('context', 'String', $this); $this->assign('context', $context); CRM_Contribute_BAO_Contribution::getValues($params, $values, $ids); CRM_Contribute_BAO_Contribution::resolveDefaults($values); $cancelledStatus = TRUE; $status = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); if (CRM_Utils_Array::value('contribution_status_id', $values) == array_search('Cancelled', $status)) { $cancelledStatus = FALSE; } $this->assign('cancelledStatus', $cancelledStatus); if (!empty($values['contribution_page_id'])) { $contribPages = CRM_Contribute_PseudoConstant::contributionPage(NULL, TRUE); $values['contribution_page_title'] = CRM_Utils_Array::value(CRM_Utils_Array::value('contribution_page_id', $values), $contribPages); } // get recieved into i.e to_financial_account_id from last trxn $financialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($values['contribution_id'], 'DESC'); $values['to_financial_account'] = ''; if (!empty($financialTrxnId['financialTrxnId'])) { $values['to_financial_account_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $financialTrxnId['financialTrxnId'], 'to_financial_account_id'); if ($values['to_financial_account_id']) { $values['to_financial_account'] = CRM_Contribute_PseudoConstant::financialAccount($values['to_financial_account_id']); } $values['payment_processor_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $financialTrxnId['financialTrxnId'], 'payment_processor_id'); if ($values['payment_processor_id']) { $values['payment_processor_name'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessor', $values['payment_processor_id'], 'name'); } } if (!empty($values['contribution_recur_id'])) { $sql = "SELECT installments, frequency_interval, frequency_unit FROM civicrm_contribution_recur WHERE id = %1"; $params = array(1 => array($values['contribution_recur_id'], 'Integer')); $dao = CRM_Core_DAO::executeQuery($sql, $params); if ($dao->fetch()) { $values['recur_installments'] = $dao->installments; $values['recur_frequency_unit'] = $dao->frequency_unit; $values['recur_frequency_interval'] = $dao->frequency_interval; } } $groupTree = CRM_Core_BAO_CustomGroup::getTree('Contribution', $this, $id, 0, CRM_Utils_Array::value('financial_type_id', $values)); CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree); $premiumId = NULL; if ($id) { $dao = new CRM_Contribute_DAO_ContributionProduct(); $dao->contribution_id = $id; if ($dao->find(TRUE)) { $premiumId = $dao->id; $productID = $dao->product_id; } } if ($premiumId) { $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); } // Get Note $noteValue = CRM_Core_BAO_Note::getNote(CRM_Utils_Array::value('id', $values), 'civicrm_contribution'); $values['note'] = array_values($noteValue); // show billing address location details, if exists if (!empty($values['address_id'])) { $addressParams = array('id' => CRM_Utils_Array::value('address_id', $values)); $addressDetails = CRM_Core_BAO_Address::getValues($addressParams, FALSE, 'id'); $addressDetails = array_values($addressDetails); $values['billing_address'] = $addressDetails[0]['display']; } //assign soft credit record if exists. $SCRecords = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($values['contribution_id'], TRUE); if (!empty($SCRecords['soft_credit'])) { $this->assign('softContributions', $SCRecords['soft_credit']); unset($SCRecords['soft_credit']); } //assign pcp record if exists foreach ($SCRecords as $name => $value) { $this->assign($name, $value); } $lineItems = array(); if ($id) { $lineItem = CRM_Price_BAO_LineItem::getLineItems($id, 'contribution', 1, TRUE, TRUE); if (!empty($lineItem)) { $lineItems[] = $lineItem; } } $this->assign('lineItem', empty($lineItems) ? FALSE : $lineItems); $values['totalAmount'] = $values['total_amount']; //do check for campaigns if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) { $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId); $values['campaign'] = $campaigns[$campaignId]; } // assign values to the template $this->assign($values); $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings'); $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings); $this->assign('invoicing', $invoicing); if ($invoicing && isset($values['tax_amount'])) { $this->assign('totalTaxAmount', $values['tax_amount']); } $displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']); $this->assign('displayName', $displayName); // 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 Contribution from') . ' ' . $displayName); // add viewed contribution to recent items list $url = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"); $title = $displayName . ' - (' . CRM_Utils_Money::format($values['total_amount']) . ' ' . ' - ' . $values['financial_type'] . ')'; $recentOther = array(); if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::UPDATE)) { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"); } if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::DELETE)) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"); } CRM_Utils_Recent::add($title, $url, $values['id'], 'Contribution', $values['contact_id'], NULL, $recentOther); }
/** * Process the activities. * * @param array $params * Associated array of the submitted values. * * @throws CRM_Core_Exception * * @return CRM_Activity_BAO_Activity|null|object */ public static function create(&$params) { // check required params if (!self::dataExists($params)) { throw new CRM_Core_Exception('Not enough data to create activity object'); } $activity = new CRM_Activity_DAO_Activity(); if (isset($params['id']) && empty($params['id'])) { unset($params['id']); } if (empty($params['status_id']) && empty($params['activity_status_id']) && empty($params['id'])) { if (isset($params['activity_date_time']) && strcmp($params['activity_date_time'], CRM_Utils_Date::processDate(date('Ymd')) == -1)) { $params['status_id'] = 2; } else { $params['status_id'] = 1; } } // Set priority to Normal for Auto-populated activities (for Cases) if (CRM_Utils_Array::value('priority_id', $params) === NULL && !CRM_Utils_Array::value('id', $params)) { $priority = CRM_Core_PseudoConstant::get('CRM_Activity_DAO_Activity', 'priority_id'); $params['priority_id'] = array_search('Normal', $priority); } if (!empty($params['target_contact_id']) && is_array($params['target_contact_id'])) { $params['target_contact_id'] = array_unique($params['target_contact_id']); } if (!empty($params['assignee_contact_id']) && is_array($params['assignee_contact_id'])) { $params['assignee_contact_id'] = array_unique($params['assignee_contact_id']); } // CRM-9137 if (!empty($params['id'])) { CRM_Utils_Hook::pre('edit', 'Activity', $activity->id, $params); } else { CRM_Utils_Hook::pre('create', 'Activity', NULL, $params); } $activity->copyValues($params); if (isset($params['case_id'])) { // CRM-8708, preserve case ID even though it's not part of the SQL model $activity->case_id = $params['case_id']; } elseif (is_numeric($activity->id)) { // CRM-8708, preserve case ID even though it's not part of the SQL model $activity->case_id = CRM_Case_BAO_Case::getCaseIdByActivityId($activity->id); } // start transaction $transaction = new CRM_Core_Transaction(); $result = $activity->save(); if (is_a($result, 'CRM_Core_Error')) { $transaction->rollback(); return $result; } $activityId = $activity->id; $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); if (isset($params['source_contact_id'])) { $acParams = array('activity_id' => $activityId, 'contact_id' => $params['source_contact_id'], 'record_type_id' => $sourceID); self::deleteActivityContact($activityId, $sourceID); CRM_Activity_BAO_ActivityContact::create($acParams); } // check and attach and files as needed CRM_Core_BAO_File::processAttachment($params, 'civicrm_activity', $activityId); // attempt to save activity assignment $resultAssignment = NULL; if (!empty($params['assignee_contact_id'])) { $assignmentParams = array('activity_id' => $activityId); if (is_array($params['assignee_contact_id'])) { if (CRM_Utils_Array::value('deleteActivityAssignment', $params, TRUE)) { // first delete existing assignments if any self::deleteActivityContact($activityId, $assigneeID); } $values = array(); foreach ($params['assignee_contact_id'] as $acID) { if ($acID) { $values[] = "( {$activityId}, {$acID}, {$assigneeID} )"; } } while (!empty($values)) { $input = array_splice($values, 0, CRM_Core_DAO::BULK_INSERT_COUNT); $str = implode(',', $input); $sql = "INSERT IGNORE INTO civicrm_activity_contact ( activity_id, contact_id, record_type_id ) VALUES {$str};"; CRM_Core_DAO::executeQuery($sql); } } else { $assignmentParams['contact_id'] = $params['assignee_contact_id']; $assignmentParams['record_type_id'] = $assigneeID; if (!empty($params['id'])) { $assignment = new CRM_Activity_BAO_ActivityContact(); $assignment->activity_id = $activityId; $assignment->record_type_id = $assigneeID; $assignment->find(TRUE); if ($assignment->contact_id != $params['assignee_contact_id']) { $assignmentParams['id'] = $assignment->id; $resultAssignment = CRM_Activity_BAO_ActivityContact::create($assignmentParams); } } else { $resultAssignment = CRM_Activity_BAO_ActivityContact::create($assignmentParams); } } } else { if (CRM_Utils_Array::value('deleteActivityAssignment', $params, TRUE)) { self::deleteActivityContact($activityId, $assigneeID); } } if (is_a($resultAssignment, 'CRM_Core_Error')) { $transaction->rollback(); return $resultAssignment; } // attempt to save activity targets $resultTarget = NULL; if (!empty($params['target_contact_id'])) { $targetParams = array('activity_id' => $activityId); $resultTarget = array(); if (is_array($params['target_contact_id'])) { if (CRM_Utils_Array::value('deleteActivityTarget', $params, TRUE)) { // first delete existing targets if any self::deleteActivityContact($activityId, $targetID); } $values = array(); foreach ($params['target_contact_id'] as $tid) { if ($tid) { $values[] = "( {$activityId}, {$tid}, {$targetID} )"; } } while (!empty($values)) { $input = array_splice($values, 0, CRM_Core_DAO::BULK_INSERT_COUNT); $str = implode(',', $input); $sql = "INSERT IGNORE INTO civicrm_activity_contact ( activity_id, contact_id, record_type_id ) VALUES {$str};"; CRM_Core_DAO::executeQuery($sql); } } else { $targetParams['contact_id'] = $params['target_contact_id']; $targetParams['record_type_id'] = $targetID; if (!empty($params['id'])) { $target = new CRM_Activity_BAO_ActivityContact(); $target->activity_id = $activityId; $target->record_type_id = $targetID; $target->find(TRUE); if ($target->contact_id != $params['target_contact_id']) { $targetParams['id'] = $target->id; $resultTarget = CRM_Activity_BAO_ActivityContact::create($targetParams); } } else { $resultTarget = CRM_Activity_BAO_ActivityContact::create($targetParams); } } } else { if (CRM_Utils_Array::value('deleteActivityTarget', $params, TRUE)) { self::deleteActivityContact($activityId, $targetID); } } // write to changelog before transaction is committed/rolled // back (and prepare status to display) if (!empty($params['id'])) { $logMsg = "Activity (id: {$result->id} ) updated with "; } else { $logMsg = "Activity created for "; } $msgs = array(); if (isset($params['source_contact_id'])) { $msgs[] = "source={$params['source_contact_id']}"; } if (!empty($params['target_contact_id'])) { if (is_array($params['target_contact_id']) && !CRM_Utils_array::crmIsEmptyArray($params['target_contact_id'])) { $msgs[] = "target=" . implode(',', $params['target_contact_id']); // take only first target // will be used for recently viewed display $t = array_slice($params['target_contact_id'], 0, 1); $recentContactId = $t[0]; } elseif (isset($params['target_contact_id']) && !is_array($params['target_contact_id'])) { $msgs[] = "target={$params['target_contact_id']}"; // will be used for recently viewed display $recentContactId = $params['target_contact_id']; } } else { // at worst, take source for recently viewed display $recentContactId = CRM_Utils_Array::value('source_contact_id', $params); } if (isset($params['assignee_contact_id'])) { if (is_array($params['assignee_contact_id'])) { $msgs[] = "assignee=" . implode(',', $params['assignee_contact_id']); } else { $msgs[] = "assignee={$params['assignee_contact_id']}"; } } $logMsg .= implode(', ', $msgs); self::logActivityAction($result, $logMsg); if (!empty($params['custom']) && is_array($params['custom'])) { CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_activity', $result->id); } $transaction->commit(); if (empty($params['skipRecentView'])) { $recentOther = array(); if (!empty($params['case_id'])) { $caseContactID = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseContact', $params['case_id'], 'contact_id', 'case_id'); $url = CRM_Utils_System::url('civicrm/case/activity/view', "reset=1&aid={$activity->id}&cid={$caseContactID}&caseID={$params['case_id']}&context=home"); } else { $q = "action=view&reset=1&id={$activity->id}&atype={$activity->activity_type_id}&cid=" . CRM_Utils_Array::value('source_contact_id', $params) . "&context=home"; if ($activity->activity_type_id != CRM_Core_OptionGroup::getValue('activity_type', 'Email', 'name')) { $url = CRM_Utils_System::url('civicrm/activity', $q); if ($activity->activity_type_id == CRM_Core_OptionGroup::getValue('activity_type', 'Print PDF Letter', 'name')) { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/activity/pdf/add', "action=update&reset=1&id={$activity->id}&atype={$activity->activity_type_id}&cid={$params['source_contact_id']}&context=home"); } else { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/activity/add', "action=update&reset=1&id={$activity->id}&atype={$activity->activity_type_id}&cid=" . CRM_Utils_Array::value('source_contact_id', $params) . "&context=home"); } if (CRM_Core_Permission::check("delete activities")) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/activity', "action=delete&reset=1&id={$activity->id}&atype={$activity->activity_type_id}&cid=" . CRM_Utils_Array::value('source_contact_id', $params) . "&context=home"); } } else { $url = CRM_Utils_System::url('civicrm/activity/view', $q); if (CRM_Core_Permission::check('delete activities')) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/activity', "action=delete&reset=1&id={$activity->id}&atype={$activity->activity_type_id}&cid=" . CRM_Utils_Array::value('source_contact_id', $params) . "&context=home"); } } } if (!isset($activity->parent_id)) { $recentContactDisplay = CRM_Contact_BAO_Contact::displayName($recentContactId); // add the recently created Activity $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE); $activitySubject = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $activity->id, 'subject'); $title = ""; if (isset($activitySubject)) { $title = $activitySubject . ' - '; } $title = $title . $recentContactDisplay; if (!empty($activityTypes[$activity->activity_type_id])) { $title .= ' (' . $activityTypes[$activity->activity_type_id] . ')'; } CRM_Utils_Recent::add($title, $url, $activity->id, 'Activity', $recentContactId, $recentContactDisplay, $recentOther); } } // reset the group contact cache since smart groups might be affected due to this CRM_Contact_BAO_GroupContactCache::remove(); if (!empty($params['id'])) { CRM_Utils_Hook::post('edit', 'Activity', $activity->id, $activity); } else { CRM_Utils_Hook::post('create', 'Activity', $activity->id, $activity); } // if the subject contains a ‘[case #…]’ string, file that activity on the related case (CRM-5916) $matches = array(); if (preg_match('/\\[case #([0-9a-h]{7})\\]/', CRM_Utils_Array::value('subject', $params), $matches)) { $key = CRM_Core_DAO::escapeString(CIVICRM_SITE_KEY); $hash = $matches[1]; $query = "SELECT id FROM civicrm_case WHERE SUBSTR(SHA1(CONCAT('{$key}', id)), 1, 7) = '{$hash}'"; $caseParams = array('activity_id' => $activity->id, 'case_id' => CRM_Core_DAO::singleValueQuery($query)); if ($caseParams['case_id']) { CRM_Case_BAO_Case::processCaseActivity($caseParams); } else { self::logActivityAction($activity, "unknown case hash encountered: {$hash}"); } } return $result; }
/** * Function to delete the pledge * * @param int $id pledge id * * @access public * @static * */ static function deletePledge($id) { CRM_Utils_Hook::pre('delete', 'Pledge', $id, CRM_Core_DAO::$_nullArray); $transaction = new CRM_Core_Transaction(); //check for no Completed Payment records with the pledge $payment = new CRM_Pledge_DAO_PledgePayment(); $payment->pledge_id = $id; $payment->find(); while ($payment->fetch()) { //also delete associated contribution. if ($payment->contribution_id) { CRM_Contribute_BAO_Contribution::deleteContribution($payment->contribution_id); } $payment->delete(); } $dao = new CRM_Pledge_DAO_Pledge(); $dao->id = $id; $results = $dao->delete(); $transaction->commit(); CRM_Utils_Hook::post('delete', 'Pledge', $dao->id, $dao); // delete the recently created Pledge $pledgeRecent = array('id' => $id, 'type' => 'Pledge'); CRM_Utils_Recent::del($pledgeRecent); return $results; }
/** * Delete the indirect records associated with this contribution first. * * @param int $id * * @return mixed|null * $results no of deleted Contribution on success, false otherwise */ public static function deleteContribution($id) { CRM_Utils_Hook::pre('delete', 'Contribution', $id, CRM_Core_DAO::$_nullArray); $transaction = new CRM_Core_Transaction(); $results = NULL; //delete activity record $params = array('source_record_id' => $id, 'activity_type_id' => 6); CRM_Activity_BAO_Activity::deleteActivity($params); //delete billing address if exists for this contribution. self::deleteAddress($id); //update pledge and pledge payment, CRM-3961 CRM_Pledge_BAO_PledgePayment::resetPledgePayment($id); // remove entry from civicrm_price_set_entity, CRM-5095 if (CRM_Price_BAO_PriceSet::getFor('civicrm_contribution', $id)) { CRM_Price_BAO_PriceSet::removeFrom('civicrm_contribution', $id); } // cleanup line items. $participantId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $id, 'participant_id', 'contribution_id'); // delete any related entity_financial_trxn, financial_trxn and financial_item records. CRM_Core_BAO_FinancialTrxn::deleteFinancialTrxn($id); if ($participantId) { CRM_Price_BAO_LineItem::deleteLineItems($participantId, 'civicrm_participant'); } else { CRM_Price_BAO_LineItem::deleteLineItems($id, 'civicrm_contribution'); } //delete note. $note = CRM_Core_BAO_Note::getNote($id, 'civicrm_contribution'); $noteId = key($note); if ($noteId) { CRM_Core_BAO_Note::del($noteId, FALSE); } $dao = new CRM_Contribute_DAO_Contribution(); $dao->id = $id; $results = $dao->delete(); $transaction->commit(); CRM_Utils_Hook::post('delete', 'Contribution', $dao->id, $dao); // delete the recently created Contribution $contributionRecent = array('id' => $id, 'type' => 'Contribution'); CRM_Utils_Recent::del($contributionRecent); return $results; }
/** * Delete membership. * * @param int $membershipId * Membership id that needs to be deleted. * * @return int * Id of deleted Membership on success, false otherwise. */ public static function deleteMembership($membershipId) { // CRM-12147, retrieve membership data before we delete it for hooks $params = array('id' => $membershipId); $memValues = array(); $memberships = self::getValues($params, $memValues); $membership = $memberships[$membershipId]; CRM_Utils_Hook::pre('delete', 'Membership', $membershipId, $memValues); $transaction = new CRM_Core_Transaction(); $results = NULL; //delete activity record $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, FALSE, FALSE, 'name'); $params = array(); $deleteActivity = FALSE; $membershipActivities = array('Membership Signup', 'Membership Renewal', 'Change Membership Status', 'Change Membership Type', 'Membership Renewal Reminder'); foreach ($membershipActivities as $membershipActivity) { $activityId = array_search($membershipActivity, $activityTypes); if ($activityId) { $params['activity_type_id'][] = $activityId; $deleteActivity = TRUE; } } if ($deleteActivity) { $params['source_record_id'] = $membershipId; CRM_Activity_BAO_Activity::deleteActivity($params); } self::deleteMembershipPayment($membershipId); $results = $membership->delete(); $transaction->commit(); CRM_Utils_Hook::post('delete', 'Membership', $membership->id, $membership); // delete the recently created Membership $membershipRecent = array('id' => $membershipId, 'type' => 'Membership'); CRM_Utils_Recent::del($membershipRecent); return $results; }
/** * Delete the record that are associated with this case * record are deleted from case * * @param int $caseId id of the case to delete * * @param bool $moveToTrash * * @return bool is successful * @access public * @static */ static function deleteCase($caseId, $moveToTrash = FALSE) { CRM_Utils_Hook::pre('delete', 'Case', $caseId, CRM_Core_DAO::$_nullArray); //delete activities $activities = self::getCaseActivityDates($caseId); if ($activities) { foreach ($activities as $value) { CRM_Activity_BAO_Activity::deleteActivity($value, $moveToTrash); } } if (!$moveToTrash) { $transaction = new CRM_Core_Transaction(); } $case = new CRM_Case_DAO_Case(); $case->id = $caseId; if (!$moveToTrash) { $result = $case->delete(); $transaction->commit(); } else { $result = $case->is_deleted = 1; $case->save(); } if ($result) { // CRM-7364, disable relationships self::enableDisableCaseRelationships($caseId, FALSE); CRM_Utils_Hook::post('delete', 'Case', $caseId, $case); // remove case from recent items. $caseRecent = array('id' => $caseId, 'type' => 'Case'); CRM_Utils_Recent::del($caseRecent); return TRUE; } return FALSE; }
/** * Delete the records that are associated with this participation. * * @param int $id * Id of the participation to delete. * * @return \CRM_Event_DAO_Participant */ public static function deleteParticipant($id) { CRM_Utils_Hook::pre('delete', 'Participant', $id, CRM_Core_DAO::$_nullArray); $transaction = new CRM_Core_Transaction(); //delete activity record $params = array('source_record_id' => $id, 'activity_type_id' => 5); CRM_Activity_BAO_Activity::deleteActivity($params); // delete the participant payment record // we need to do this since the cascaded constraints // dont work with join tables $p = array('participant_id' => $id); CRM_Event_BAO_ParticipantPayment::deleteParticipantPayment($p); // cleanup line items. $participantsId = array(); $participantsId = self::getAdditionalParticipantIds($id); $participantsId[] = $id; CRM_Price_BAO_LineItem::deleteLineItems($participantsId, 'civicrm_participant'); //delete note when participant deleted. $note = CRM_Core_BAO_Note::getNote($id, 'civicrm_participant'); $noteId = key($note); if ($noteId) { CRM_Core_BAO_Note::del($noteId, FALSE); } $participant = new CRM_Event_DAO_Participant(); $participant->id = $id; $participant->delete(); $transaction->commit(); CRM_Utils_Hook::post('delete', 'Participant', $participant->id, $participant); // delete the recently created Participant $participantRecent = array('id' => $id, 'type' => 'Participant'); CRM_Utils_Recent::del($participantRecent); return $participant; }
/** * 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); }
/** * Delete the indirect records associated with this contribution first * * @return $results no of deleted Contribution on success, false otherwise * @access public * @static */ static function deleteContribution($id) { require_once 'CRM/Utils/Hook.php'; CRM_Utils_Hook::pre('delete', 'Contribution', $id, CRM_Core_DAO::$_nullArray); require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); $results = null; //delete activity record require_once "CRM/Activity/BAO/Activity.php"; $params = array('source_record_id' => $id, 'activity_type_id' => 6); // activity type id for contribution CRM_Activity_BAO_Activity::deleteActivity($params); //delete billing address if exists for this contribution. self::deleteAddress($id); //update pledge and pledge payment, CRM-3961 require_once 'CRM/Pledge/BAO/Payment.php'; CRM_Pledge_BAO_Payment::resetPledgePayment($id); // remove entry from civicrm_price_set_entity, CRM-5095 require_once 'CRM/Price/BAO/Set.php'; if (CRM_Price_BAO_Set::getFor('civicrm_contribution', $id)) { CRM_Price_BAO_Set::removeFrom('civicrm_contribution', $id); } // cleanup line items. require_once 'CRM/Price/BAO/Field.php'; require_once 'CRM/Event/BAO/ParticipantPayment.php'; $participantId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $id, 'participant_id', 'contribution_id'); // delete any related entity_financial_trxn and financial_trxn records. require_once 'CRM/Core/BAO/FinancialTrxn.php'; CRM_Core_BAO_FinancialTrxn::deleteFinancialTrxn($id, 'civicrm_contribution'); if ($participantId) { require_once 'CRM/Price/BAO/LineItem.php'; CRM_Price_BAO_LineItem::deleteLineItems($participantId, 'civicrm_participant'); } else { require_once 'CRM/Price/BAO/LineItem.php'; CRM_Price_BAO_LineItem::deleteLineItems($id, 'civicrm_contribution'); } $dao = new CRM_Contribute_DAO_Contribution(); $dao->id = $id; $results = $dao->delete(); $transaction->commit(); CRM_Utils_Hook::post('delete', 'Contribution', $dao->id, $dao); // delete the recently created Contribution require_once 'CRM/Utils/Recent.php'; $contributionRecent = array('id' => $id, 'type' => 'Contribution'); CRM_Utils_Recent::del($contributionRecent); return $results; }
/** * Form submission of new/edit contact is processed. * * @access public * @return None */ public function postProcess() { // check if dedupe button, if so return. $buttonName = $this->controller->getButtonName(); if ($buttonName == $this->_dedupeButtonName) { return; } //get the submitted values in an array $params = $this->controller->exportValues($this->_name); //get the related id for shared / current employer if (CRM_Utils_Array::value('shared_household_id', $params)) { $params['shared_household'] = $params['shared_household_id']; } if (is_numeric(CRM_Utils_Array::value('current_employer_id', $params)) && CRM_Utils_Array::value('current_employer', $params)) { $params['current_employer'] = $params['current_employer_id']; } // don't carry current_employer_id field, // since we don't want to directly update DAO object without // handling related business logic ( eg related membership ) if (isset($params['current_employer_id'])) { unset($params['current_employer_id']); } $params['contact_type'] = $this->_contactType; if ($this->_contactId) { $params['contact_id'] = $this->_contactId; } //make deceased date null when is_deceased = false if ($this->_contactType == 'Individual' && CRM_Utils_Array::value('Demographics', $this->_editOptions) && !CRM_Utils_Array::value('is_deceased', $params)) { $params['is_deceased'] = false; $params['deceased_date'] = null; } if ($this->_contactSubType && $this->_action & CRM_Core_Action::ADD) { $params['contact_sub_type'] = $this->_contactSubType; } // action is taken depending upon the mode require_once 'CRM/Utils/Hook.php'; if ($this->_action & CRM_Core_Action::UPDATE) { CRM_Utils_Hook::pre('edit', $params['contact_type'], $params['contact_id'], $params); } else { CRM_Utils_Hook::pre('create', $params['contact_type'], null, $params); } require_once 'CRM/Core/BAO/CustomField.php'; $customFields = CRM_Core_BAO_CustomField::getFields($params['contact_type'], false, true); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_contactId, $params['contact_type'], true); if (array_key_exists('CommunicationPreferences', $this->_editOptions)) { // this is a chekbox, so mark false if we dont get a POST value $params['is_opt_out'] = CRM_Utils_Array::value('is_opt_out', $params, false); } // copy household address, if use_household_address option (for individual form) is checked if ($this->_contactType == 'Individual') { if (CRM_Utils_Array::value('use_household_address', $params) && CRM_Utils_Array::value('shared_household', $params)) { if (is_numeric($params['shared_household'])) { CRM_Contact_Form_Edit_Individual::copyHouseholdAddress($params); } CRM_Contact_Form_Edit_Individual::createSharedHousehold($params); } else { $params['mail_to_household_id'] = 'null'; } } else { $params['mail_to_household_id'] = 'null'; } if (!array_key_exists('TagsAndGroups', $this->_editOptions)) { unset($params['group']); } if (CRM_Utils_Array::value('contact_id', $params) && $this->_action & CRM_Core_Action::UPDATE) { // cleanup unwanted location blocks require_once 'CRM/Core/BAO/Location.php'; CRM_Core_BAO_Location::cleanupContactLocations($params); // figure out which all groups are intended to be removed if (!empty($params['group'])) { $contactGroupList =& CRM_Contact_BAO_GroupContact::getContactGroup($params['contact_id'], 'Added'); if (is_array($contactGroupList)) { foreach ($contactGroupList as $key) { if ($params['group'][$key['group_id']] != 1) { $params['group'][$key['group_id']] = -1; } } } } } require_once 'CRM/Contact/BAO/Contact.php'; $contact =& CRM_Contact_BAO_Contact::create($params, true, false); if ($this->_contactType == 'Individual' && CRM_Utils_Array::value('use_household_address', $params) && CRM_Utils_Array::value('mail_to_household_id', $params)) { // add/edit/delete the relation of individual with household, if use-household-address option is checked/unchecked. CRM_Contact_Form_Edit_Individual::handleSharedRelation($contact->id, $params); } if ($this->_contactType == 'Household' && $this->_action & CRM_Core_Action::UPDATE) { //TO DO: commented because of schema changes require_once 'CRM/Contact/Form/Edit/Household.php'; CRM_Contact_Form_Edit_Household::synchronizeIndividualAddresses($contact->id); } if (array_key_exists('TagsAndGroups', $this->_editOptions)) { //add contact to tags require_once 'CRM/Core/BAO/EntityTag.php'; CRM_Core_BAO_EntityTag::create($params['tag'], $params['contact_id']); } // here we replace the user context with the url to view this contact $session =& CRM_Core_Session::singleton(); CRM_Core_Session::setStatus(ts('Your %1 contact record has been saved.', array(1 => $contact->contact_type_display))); $buttonName = $this->controller->getButtonName(); if ($buttonName == $this->getButtonName('next', 'new') || $buttonName == $this->getButtonName('upload', 'new')) { require_once 'CRM/Utils/Recent.php'; // add the recently viewed contact $displayName = CRM_Contact_BAO_Contact::displayName($contact->id); CRM_Utils_Recent::add($displayName, CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $contact->id), $contact->id, $this->_contactType, $contact->id, $displayName); $resetStr = "reset=1&ct={$contact->contact_type}"; $resetStr .= $this->_contactSubType ? "&cst={$this->_contactSubType}" : ''; $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/add', $resetStr)); } else { $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $contact->id)); } // now invoke the post hook if ($this->_action & CRM_Core_Action::UPDATE) { CRM_Utils_Hook::post('edit', $params['contact_type'], $contact->id, $contact); } else { CRM_Utils_Hook::post('create', $params['contact_type'], $contact->id, $contact); } }
/** * Set the post action values for the block. * * php is lame and u cannot call functions from static initializers * hence this hack * * @param int $id * * @return void */ private static function setTemplateValues($id) { switch ($id) { case self::CREATE_NEW: self::setTemplateShortcutValues(); break; case self::DASHBOARD: self::setTemplateDashboardValues(); break; case self::ADD: $defaultLocation = CRM_Core_BAO_LocationType::getDefault(); $defaultPrimaryLocationId = $defaultLocation->id; $values = array('postURL' => CRM_Utils_System::url('civicrm/contact/add', 'reset=1&ct=Individual'), 'primaryLocationType' => $defaultPrimaryLocationId); foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) { $values[$greeting . '_id'] = CRM_Contact_BAO_Contact_Utils::defaultGreeting('Individual', $greeting); } self::setProperty(self::ADD, 'templateValues', $values); break; case self::LANGSWITCH: // gives the currentPath without trailing empty lcMessages to be completed $values = array('queryString' => CRM_Utils_System::getLinksUrl('lcMessages', TRUE, FALSE, FALSE)); self::setProperty(self::LANGSWITCH, 'templateValues', $values); break; case self::FULLTEXT_SEARCH: $urlArray = array('fullTextSearchID' => CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', 'CRM_Contact_Form_Search_Custom_FullText', 'value', 'name')); self::setProperty(self::FULLTEXT_SEARCH, 'templateValues', $urlArray); break; case self::RECENTLY_VIEWED: $recent = CRM_Utils_Recent::get(); self::setProperty(self::RECENTLY_VIEWED, 'templateValues', array('recentlyViewed' => $recent)); break; case self::EVENT: self::setTemplateEventValues(); break; } }
/** * 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); }
/** * Function to delete membership. * * @param int $membershipId membership id that needs to be deleted * * @static * @return $results no of deleted Membership on success, false otherwise * @access public */ static function deleteMembership($membershipId) { require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); $results = null; //delete activity record $activityTypes = CRM_Core_Pseudoconstant::activityType(true, false, false, 'name'); require_once "CRM/Activity/BAO/Activity.php"; $params = array('source_record_id' => $membershipId, 'activity_type_id' => array(array_search('Membership Signup', $activityTypes), array_search('Membership Renewal', $activityTypes))); CRM_Activity_BAO_Activity::deleteActivity($params); self::deleteMembershipPayment($membershipId); require_once 'CRM/Member/DAO/Membership.php'; $membership = new CRM_Member_DAO_Membership(); $membership->id = $membershipId; $results = $membership->delete(); $transaction->commit(); // delete the recently created Membership require_once 'CRM/Utils/Recent.php'; $membershipRecent = array('id' => $membershipId, 'type' => 'Membership'); CRM_Utils_Recent::del($membershipRecent); return $results; }
/** * Heart of the viewing process. * * The runner gets all the meta data for the contact and calls the appropriate type of page to view. */ public function preProcess() { // process url params $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); $this->assign('id', $this->_id); $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); //validate the qfKey if (!CRM_Utils_Rule::qfKey($qfKey)) { $qfKey = NULL; } $this->assign('searchKey', $qfKey); // retrieve the group contact id, so that we can get contact id $gcid = CRM_Utils_Request::retrieve('gcid', 'Positive', $this); if (!$gcid) { $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); } else { $this->_contactId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_GroupContact', $gcid, 'contact_id'); } if (!$this->_contactId) { CRM_Core_Error::statusBounce(ts('We could not find a contact id.'), CRM_Utils_System::url('civicrm/dashboard', 'reset=1')); } // ensure that the id does exist if (CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'id') != $this->_contactId) { CRM_Core_Error::statusBounce(ts('A Contact with that ID does not exist: %1', array(1 => $this->_contactId)), CRM_Utils_System::url('civicrm/dashboard', 'reset=1')); } $this->assign('contactId', $this->_contactId); // see if we can get prev/next positions from qfKey $navContacts = array('prevContactID' => NULL, 'prevContactName' => NULL, 'nextContactID' => NULL, 'nextContactName' => NULL, 'nextPrevError' => 0); if ($qfKey) { $pos = CRM_Core_BAO_PrevNextCache::getPositions("civicrm search {$qfKey}", $this->_contactId, $this->_contactId); $found = FALSE; if (isset($pos['prev'])) { $navContacts['prevContactID'] = $pos['prev']['id1']; $navContacts['prevContactName'] = $pos['prev']['data']; $found = TRUE; } if (isset($pos['next'])) { $navContacts['nextContactID'] = $pos['next']['id1']; $navContacts['nextContactName'] = $pos['next']['data']; $found = TRUE; } $context = CRM_Utils_Array::value('context', $_GET); if (!$found) { // seems like we did not find any contacts // maybe due to bug CRM-9096 // however we should account for 1 contact results (which dont have prev next) if (!$pos['foundEntry']) { $navContacts['nextPrevError'] = 1; } } elseif ($context) { $this->assign('context', $context); CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Search Results'), 'url' => CRM_Utils_System::url("civicrm/contact/search/{$context}", array('qfKey' => $qfKey))))); } } $this->assign($navContacts); $path = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId); CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('View Contact'), 'url' => $path))); if ($image_URL = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'image_URL')) { //CRM-7265 --time being fix. $config = CRM_Core_Config::singleton(); $image_URL = str_replace('https://', 'http://', $image_URL); if (Civi::settings()->get('enableSSL')) { $image_URL = str_replace('http://', 'https://', $image_URL); } list($imageWidth, $imageHeight) = getimagesize(CRM_Utils_String::unstupifyUrl($image_URL)); list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight); $this->assign("imageWidth", $imageWidth); $this->assign("imageHeight", $imageHeight); $this->assign("imageThumbWidth", $imageThumbWidth); $this->assign("imageThumbHeight", $imageThumbHeight); $this->assign("imageURL", $image_URL); } // also store in session for future use $session = CRM_Core_Session::singleton(); $session->set('view.id', $this->_contactId); $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); $this->assign('action', $this->_action); // check logged in user permission self::checkUserPermission($this); list($displayName, $contactImage, $contactType, $contactSubtype, $contactImageUrl) = self::getContactDetails($this->_contactId); $this->assign('displayName', $displayName); $this->set('contactType', $contactType); // note: there could still be multiple subtypes. We just trimming the outer separator. $this->set('contactSubtype', trim($contactSubtype, CRM_Core_DAO::VALUE_SEPARATOR)); // add to recently viewed block $isDeleted = (bool) CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'is_deleted'); $recentOther = array('imageUrl' => $contactImageUrl, 'subtype' => $contactSubtype, 'isDeleted' => $isDeleted); if (CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/add', "reset=1&action=update&cid={$this->_contactId}"); } if ($session->get('userID') != $this->_contactId && CRM_Core_Permission::check('delete contacts') && !$isDeleted) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/delete', "reset=1&delete=1&cid={$this->_contactId}"); } CRM_Utils_Recent::add($displayName, CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_contactId}"), $this->_contactId, $contactType, $this->_contactId, $displayName, $recentOther); $this->assign('isDeleted', $isDeleted); // set page title $title = self::setTitle($this->_contactId, $isDeleted); $this->assign('title', $title); // Check if this is default domain contact CRM-10482 if (CRM_Contact_BAO_Contact::checkDomainContact($this->_contactId)) { $this->assign('domainContact', TRUE); } else { $this->assign('domainContact', FALSE); } // Add links for actions menu self::addUrls($this, $this->_contactId); if ($contactType == 'Organization' && CRM_Core_Permission::check('administer Multiple Organizations') && Civi::settings()->get('is_enabled')) { //check is any relationship between the organization and groups $groupOrg = CRM_Contact_BAO_GroupOrganization::hasGroupAssociated($this->_contactId); if ($groupOrg) { $groupOrganizationUrl = CRM_Utils_System::url('civicrm/group', "reset=1&oid={$this->_contactId}"); $this->assign('groupOrganizationUrl', $groupOrganizationUrl); } } }
/** * Delete a contact and all its associated records. * * @param int $id * Id of the contact to delete. * @param bool $restore * Whether to actually restore, not delete. * @param bool $skipUndelete * Whether to force contact delete or not. * * @return bool * Was contact deleted? */ public static function deleteContact($id, $restore = FALSE, $skipUndelete = FALSE) { if (!$id) { return FALSE; } // If trash is disabled in system settings then we always skip if (!CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_undelete', NULL, 1)) { $skipUndelete = TRUE; } // make sure we have edit permission for this contact // before we delete if ($skipUndelete && !CRM_Core_Permission::check('delete contacts') || $restore && !CRM_Core_Permission::check('access deleted contacts')) { return FALSE; } // CRM-12929 // Restrict contact to be delete if contact has financial trxns $error = NULL; if ($skipUndelete && CRM_Financial_BAO_FinancialItem::checkContactPresent(array($id), $error)) { return FALSE; } // make sure this contact_id does not have any membership types $membershipTypeID = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $id, 'id', 'member_of_contact_id'); if ($membershipTypeID) { return FALSE; } $contact = new CRM_Contact_DAO_Contact(); $contact->id = $id; if (!$contact->find(TRUE)) { return FALSE; } $contactType = $contact->contact_type; // currently we only clear employer cache. // we are now deleting inherited membership if any. if ($contact->contact_type == 'Organization') { $action = $restore ? CRM_Core_Action::ENABLE : CRM_Core_Action::DISABLE; $relationshipDtls = CRM_Contact_BAO_Relationship::getRelationship($id); if (!empty($relationshipDtls)) { foreach ($relationshipDtls as $rId => $details) { CRM_Contact_BAO_Relationship::disableEnableRelationship($rId, $action); } } CRM_Contact_BAO_Contact_Utils::clearAllEmployee($id); } if ($restore) { return self::contactTrashRestore($contact, TRUE); } // start a new transaction $transaction = new CRM_Core_Transaction(); if ($skipUndelete) { CRM_Utils_Hook::pre('delete', $contactType, $id, CRM_Core_DAO::$_nullArray); //delete billing address if exists. CRM_Contribute_BAO_Contribution::deleteAddress(NULL, $id); // delete the log entries since we dont have triggers enabled as yet $logDAO = new CRM_Core_DAO_Log(); $logDAO->entity_table = 'civicrm_contact'; $logDAO->entity_id = $id; $logDAO->delete(); // delete contact participants CRM-12155 CRM_Event_BAO_Participant::deleteContactParticipant($id); // delete contact contributions CRM-12155 CRM_Contribute_BAO_Contribution::deleteContactContribution($id); // do activity cleanup, CRM-5604 CRM_Activity_BAO_Activity::cleanupActivity($id); // delete all notes related to contact CRM_Core_BAO_Note::cleanContactNotes($id); // delete cases related to contact $contactCases = CRM_Case_BAO_Case::retrieveCaseIdsByContactId($id); if (!empty($contactCases)) { foreach ($contactCases as $caseId) { //check if case is associate with other contact or not. $caseContactId = CRM_Case_BAO_Case::getCaseClients($caseId); if (count($caseContactId) <= 1) { CRM_Case_BAO_Case::deleteCase($caseId); } } } $contact->delete(); } else { self::contactTrashRestore($contact); } //delete the contact id from recently view CRM_Utils_Recent::delContact($id); // Update the group contact cache if ($restore) { CRM_Contact_BAO_GroupContactCache::remove(); } else { CRM_Contact_BAO_GroupContactCache::removeContact($id); } // delete any dupe cache entry CRM_Core_BAO_PrevNextCache::deleteItem($id); $transaction->commit(); if ($skipUndelete) { CRM_Utils_Hook::post('delete', $contactType, $contact->id, $contact); } // also reset the DB_DO global array so we can reuse the memory // http://issues.civicrm.org/jira/browse/CRM-4387 CRM_Core_DAO::freeResult(); return TRUE; }
/** * Form submission of new/edit contact is processed. */ public function postProcess() { // check if dedupe button, if so return. $buttonName = $this->controller->getButtonName(); if ($buttonName == $this->_dedupeButtonName) { return; } //get the submitted values in an array $params = $this->controller->exportValues($this->_name); $group = CRM_Utils_Array::value('group', $params); if (!empty($group) && is_array($group)) { unset($params['group']); foreach ($group as $key => $value) { $params['group'][$value] = 1; } } CRM_Contact_BAO_Contact_Optimizer::edit($params, $this->_preEditValues); if (!empty($params['image_URL'])) { CRM_Contact_BAO_Contact::processImageParams($params); } if (is_numeric(CRM_Utils_Array::value('current_employer_id', $params)) && !empty($params['current_employer'])) { $params['current_employer'] = $params['current_employer_id']; } // don't carry current_employer_id field, // since we don't want to directly update DAO object without // handling related business logic ( eg related membership ) if (isset($params['current_employer_id'])) { unset($params['current_employer_id']); } $params['contact_type'] = $this->_contactType; if (empty($params['contact_sub_type']) && $this->_isContactSubType) { $params['contact_sub_type'] = array($this->_contactSubType); } if ($this->_contactId) { $params['contact_id'] = $this->_contactId; } //make deceased date null when is_deceased = false if ($this->_contactType == 'Individual' && !empty($this->_editOptions['Demographics']) && empty($params['is_deceased'])) { $params['is_deceased'] = FALSE; $params['deceased_date'] = NULL; } if (isset($params['contact_id'])) { // process membership status for deceased contact $deceasedParams = array('contact_id' => CRM_Utils_Array::value('contact_id', $params), 'is_deceased' => CRM_Utils_Array::value('is_deceased', $params, FALSE), 'deceased_date' => CRM_Utils_Array::value('deceased_date', $params, NULL)); $updateMembershipMsg = $this->updateMembershipStatus($deceasedParams); } // action is taken depending upon the mode if ($this->_action & CRM_Core_Action::UPDATE) { CRM_Utils_Hook::pre('edit', $params['contact_type'], $params['contact_id'], $params); } else { CRM_Utils_Hook::pre('create', $params['contact_type'], NULL, $params); } $customFields = CRM_Core_BAO_CustomField::getFields($params['contact_type'], FALSE, TRUE); //CRM-5143 //if subtype is set, send subtype as extend to validate subtype customfield $customFieldExtends = CRM_Utils_Array::value('contact_sub_type', $params) ? $params['contact_sub_type'] : $params['contact_type']; $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $this->_contactId, $customFieldExtends, TRUE); if ($this->_contactId && !empty($this->_oldSubtypes)) { CRM_Contact_BAO_ContactType::deleteCustomSetForSubtypeMigration($this->_contactId, $params['contact_type'], $this->_oldSubtypes, $params['contact_sub_type']); } if (array_key_exists('CommunicationPreferences', $this->_editOptions)) { // this is a chekbox, so mark false if we dont get a POST value $params['is_opt_out'] = CRM_Utils_Array::value('is_opt_out', $params, FALSE); } // process shared contact address. CRM_Contact_BAO_Contact_Utils::processSharedAddress($params['address']); if (!array_key_exists('TagsAndGroups', $this->_editOptions) && !empty($params['group'])) { unset($params['group']); } if (!empty($params['contact_id']) && $this->_action & CRM_Core_Action::UPDATE && !empty($params['group'])) { // figure out which all groups are intended to be removed $contactGroupList = CRM_Contact_BAO_GroupContact::getContactGroup($params['contact_id'], 'Added'); if (is_array($contactGroupList)) { foreach ($contactGroupList as $key) { if ((!array_key_exists($key['group_id'], $params['group']) || $params['group'][$key['group_id']] != 1) && empty($key['is_hidden'])) { $params['group'][$key['group_id']] = -1; } } } } // parse street address, CRM-5450 $parseStatusMsg = NULL; if ($this->_parseStreetAddress) { $parseResult = self::parseAddress($params); $parseStatusMsg = self::parseAddressStatusMsg($parseResult); } // Allow un-setting of location info, CRM-5969 $params['updateBlankLocInfo'] = TRUE; $contact = CRM_Contact_BAO_Contact::create($params, TRUE, FALSE, TRUE); // status message if ($this->_contactId) { $message = ts('%1 has been updated.', array(1 => $contact->display_name)); } else { $message = ts('%1 has been created.', array(1 => $contact->display_name)); } // set the contact ID $this->_contactId = $contact->id; if (array_key_exists('TagsAndGroups', $this->_editOptions)) { //add contact to tags CRM_Core_BAO_EntityTag::create($params['tag'], 'civicrm_contact', $params['contact_id']); //save free tags if (isset($params['contact_taglist']) && !empty($params['contact_taglist'])) { CRM_Core_Form_Tag::postProcess($params['contact_taglist'], $params['contact_id'], 'civicrm_contact', $this); } } if (!empty($parseStatusMsg)) { $message .= "<br />{$parseStatusMsg}"; } if (!empty($updateMembershipMsg)) { $message .= "<br />{$updateMembershipMsg}"; } $session = CRM_Core_Session::singleton(); $session->setStatus($message, ts('Contact Saved'), 'success'); // add the recently viewed contact $recentOther = array(); if ($session->get('userID') == $contact->id || CRM_Contact_BAO_Contact_Permission::allow($contact->id, CRM_Core_Permission::EDIT)) { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/add', 'reset=1&action=update&cid=' . $contact->id); } if ($session->get('userID') != $this->_contactId && CRM_Core_Permission::check('delete contacts')) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/delete', 'reset=1&delete=1&cid=' . $contact->id); } CRM_Utils_Recent::add($contact->display_name, CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $contact->id), $contact->id, $this->_contactType, $contact->id, $contact->display_name, $recentOther); // here we replace the user context with the url to view this contact $buttonName = $this->controller->getButtonName(); if ($buttonName == $this->getButtonName('upload', 'new')) { $contactSubTypes = array_filter(explode(CRM_Core_DAO::VALUE_SEPARATOR, $this->_contactSubType)); $resetStr = "reset=1&ct={$contact->contact_type}"; $resetStr .= count($contactSubTypes) == 1 ? "&cst=" . array_pop($contactSubTypes) : ''; $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/add', $resetStr)); } else { $context = CRM_Utils_Request::retrieve('context', 'String', $this); $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); //validate the qfKey $urlParams = 'reset=1&cid=' . $contact->id; if ($context) { $urlParams .= "&context={$context}"; } if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= "&key={$qfKey}"; } $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', $urlParams)); } // now invoke the post hook if ($this->_action & CRM_Core_Action::UPDATE) { CRM_Utils_Hook::post('edit', $params['contact_type'], $contact->id, $contact); } else { CRM_Utils_Hook::post('create', $params['contact_type'], $contact->id, $contact); } }
/** * Set variables up before form is built. * * @return void */ public function preProcess() { $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); $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($values['membership_type_id']); // Do the action on related Membership if needed $relAction = CRM_Utils_Request::retrieve('relAction', 'String', $this); if ($relAction) { $this->relAction($relAction, $values); } // build associated contributions $this->assign('accessContribution', FALSE); if (CRM_Core_Permission::access('CiviContribute')) { $this->assign('accessContribution', TRUE); 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'); $direction = strrev($membershipType['relationship_direction']); // To display relationship type in view membership page $relTypeIds = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ",", $membershipType['relationship_type_id']); $sql = "\nSELECT relationship_type_id,\n CASE\n WHEN contact_id_a = {$values['owner_contact_id']} AND contact_id_b = {$values['contact_id']} THEN 'b_a'\n WHEN contact_id_b = {$values['owner_contact_id']} AND contact_id_a = {$values['contact_id']} THEN 'a_b'\nEND AS 'relType'\n FROM civicrm_relationship\n WHERE relationship_type_id IN ({$relTypeIds})"; $dao = CRM_Core_DAO::executeQuery($sql); $values['relationship'] = NULL; while ($dao->fetch()) { $typeId = $dao->relationship_type_id; $direction = $dao->relType; if ($direction && $typeId) { if ($values['relationship']) { $values['relationship'] .= ','; } $values['relationship'] .= CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $typeId, "name_{$direction}", 'id'); } } } $this->assign('has_related', FALSE); // if membership can be granted, and we are the owner of the membership if (!empty($membershipType['relationship_type_id']) && empty($values['owner_membership_id'])) { // display related contacts/membership block $this->assign('has_related', TRUE); $this->assign('max_related', CRM_Utils_Array::value('max_related', $values, ts('Unlimited'))); // split the relations in 2 arrays based on direction $relTypeId = explode(CRM_Core_DAO::VALUE_SEPARATOR, $membershipType['relationship_type_id']); $relDirection = explode(CRM_Core_DAO::VALUE_SEPARATOR, $membershipType['relationship_direction']); foreach ($relTypeId as $rid) { $dir = each($relDirection); $relTypeDir[substr($dir['value'], 0, 1)][] = $rid; } // build query in 2 parts with a UNION if necessary // _x and _y are replaced with _a and _b first, then vice-versa // comment is a qualifier for the relationship - now just job_title $select = "\nSELECT r.id, c.id as cid, c.display_name as name, c.job_title as comment,\n rt.name_x_y as relation, r.start_date, r.end_date,\n m.id as mid, ms.is_current_member, ms.label as status\n FROM civicrm_relationship r\n LEFT JOIN civicrm_relationship_type rt ON rt.id = r.relationship_type_id\n LEFT JOIN civicrm_contact c ON c.id = r.contact_id_x\n LEFT JOIN civicrm_membership m ON (m.owner_membership_id = {$values['id']}\n AND m.contact_id = r.contact_id_x AND m.is_test = 0)\n LEFT JOIN civicrm_membership_status ms ON ms.id = m.status_id\n WHERE r.contact_id_y = {$values['contact_id']} AND r.is_active = 1 AND c.is_deleted = 0"; $query = ''; foreach (array('a', 'b') as $dir) { if (isset($relTypeDir[$dir])) { $query .= ($query ? ' UNION ' : '') . str_replace('_y', '_' . $dir, str_replace('_x', '_' . ($dir == 'a' ? 'b' : 'a'), $select)) . ' AND r.relationship_type_id IN (' . implode(',', $relTypeDir[$dir]) . ')'; } } $query .= " ORDER BY is_current_member DESC"; $dao = CRM_Core_DAO::executeQuery($query); $related = array(); $relatedRemaining = CRM_Utils_Array::value('max_related', $values, PHP_INT_MAX); $rowElememts = array('id', 'cid', 'name', 'comment', 'relation', 'mid', 'start_date', 'end_date', 'is_current_member', 'status'); while ($dao->fetch()) { $row = array(); foreach ($rowElememts as $field) { $row[$field] = $dao->{$field}; } if ($row['mid'] && $row['is_current_member'] == 1) { $relatedRemaining--; $row['action'] = CRM_Core_Action::formLink(self::links(), CRM_Core_Action::DELETE, array('id' => CRM_Utils_Request::retrieve('id', 'Positive', $this), 'cid' => $row['cid'], 'mid' => $row['mid']), ts('more'), FALSE, 'membership.relationship.action', 'Relationship', CRM_Utils_Request::retrieve('id', 'Positive', $this)); } else { if ($relatedRemaining > 0) { $row['action'] = CRM_Core_Action::formLink(self::links(), CRM_Core_Action::ADD, array('id' => CRM_Utils_Request::retrieve('id', 'Positive', $this), 'cid' => $row['cid'], 'rid' => $row['cid']), ts('more'), FALSE, 'membership.relationship.action', 'Relationship', CRM_Utils_Request::retrieve('id', 'Positive', $this)); } } $related[] = $row; } $this->assign('related', $related); if ($relatedRemaining <= 0) { $this->assign('related_text', ts('None available')); } else { if ($relatedRemaining < 100000) { $this->assign('related_text', ts('%1 available', array(1 => $relatedRemaining))); } else { $this->assign('related_text', ts('Unlimited', array(1 => $relatedRemaining))); } } } $displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']); $this->assign('displayName', $displayName); // 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 crm-container CRM_Utils_System::setTitle(ts('View Membership for') . ' ' . $displayName); // add viewed membership to recent items list $recentTitle = $displayName . ' - ' . ts('Membership Type:') . ' ' . $values['membership_type']; $url = CRM_Utils_System::url('civicrm/contact/view/membership', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"); $recentOther = array(); if (CRM_Core_Permission::checkActionPermission('CiviMember', CRM_Core_Action::UPDATE)) { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/membership', "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"); } if (CRM_Core_Permission::checkActionPermission('CiviMember', CRM_Core_Action::DELETE)) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/membership', "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"); } CRM_Utils_Recent::add($recentTitle, $url, $values['id'], 'Membership', $values['contact_id'], NULL, $recentOther); CRM_Member_Page_Tab::setContext($this, $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); $isRecur = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $id, 'contribution_recur_id'); $autoRenew = $isRecur ? TRUE : FALSE; } if (!empty($values['is_test'])) { $values['membership_type'] .= ' (test) '; } $subscriptionCancelled = CRM_Member_BAO_Membership::isSubscriptionCancelled($id); $values['auto_renew'] = $autoRenew && !$subscriptionCancelled ? 'Yes' : 'No'; //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); }
/** * Process the view. * * * @return void */ public function preProcess() { $contactID = CRM_Utils_Request::retrieve('cid', 'Integer', $this, TRUE); $activityID = CRM_Utils_Request::retrieve('aid', 'Integer', $this, TRUE); $revs = CRM_Utils_Request::retrieve('revs', 'Boolean', CRM_Core_DAO::$_nullObject); $caseID = CRM_Utils_Request::retrieve('caseID', 'Boolean', CRM_Core_DAO::$_nullObject); $activitySubject = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $activityID, 'subject'); //check for required permissions, CRM-6264 if ($activityID && !CRM_Activity_BAO_Activity::checkPermission($activityID, CRM_Core_Action::VIEW)) { CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); } $this->assign('contactID', $contactID); $this->assign('caseID', $caseID); // CRM-9145 $this->assign('activityID', $activityID); $xmlProcessor = new CRM_Case_XMLProcessor_Report(); $report = $xmlProcessor->getActivityInfo($contactID, $activityID, TRUE); $attachmentUrl = CRM_Core_BAO_File::attachmentInfo('civicrm_activity', $activityID); if ($attachmentUrl) { $report['fields'][] = array('label' => 'Attachment(s)', 'value' => $attachmentUrl, 'type' => 'Link'); } $tags = CRM_Core_BAO_EntityTag::getTag($activityID, 'civicrm_activity'); if (!empty($tags)) { $allTag = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE)); foreach ($tags as $tid) { $tags[$tid] = $allTag[$tid]; } $report['fields'][] = array('label' => 'Tags', 'value' => implode('<br />', $tags), 'type' => 'String'); } $this->assign('report', $report); $latestRevisionID = CRM_Activity_BAO_Activity::getLatestActivityId($activityID); $viewPriorActivities = array(); $priorActivities = CRM_Activity_BAO_Activity::getPriorAcitivities($activityID); foreach ($priorActivities as $activityId => $activityValues) { if (CRM_Case_BAO_Case::checkPermission($activityId, 'view', NULL, $contactID)) { $viewPriorActivities[$activityId] = $activityValues; } } if ($revs) { CRM_Utils_System::setTitle(ts('Activity Revision History')); $this->assign('revs', $revs); $this->assign('result', $viewPriorActivities); $this->assign('subject', $activitySubject); $this->assign('latestRevisionID', $latestRevisionID); } else { if (count($viewPriorActivities) > 1) { $this->assign('activityID', $activityID); } if ($latestRevisionID != $activityID) { $this->assign('latestRevisionID', $latestRevisionID); } } $parentID = CRM_Activity_BAO_Activity::getParentActivity($activityID); if ($parentID) { $this->assign('parentID', $parentID); } //viewing activity should get diplayed in recent list.CRM-4670 $activityTypeID = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $activityID, 'activity_type_id'); $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); $activityTargetContacts = CRM_Activity_BAO_ActivityContact::retrieveContactIdsByActivityId($activityID, $targetID); if (!empty($activityTargetContacts)) { $recentContactId = $activityTargetContacts[0]; } else { $recentContactId = $contactID; } if (!isset($caseID)) { $caseID = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseActivity', $activityID, 'case_id', 'activity_id'); } $url = CRM_Utils_System::url('civicrm/case/activity/view', "reset=1&aid={$activityID}&cid={$recentContactId}&caseID={$caseID}&context=home"); $recentContactDisplay = CRM_Contact_BAO_Contact::displayName($recentContactId); // add the recently created Activity $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE); $title = ""; if (isset($activitySubject)) { $title = $activitySubject . ' - '; } $title = $title . $recentContactDisplay . ' (' . $activityTypes[$activityTypeID] . ')'; $recentOther = array(); if (CRM_Case_BAO_Case::checkPermission($activityID, 'edit')) { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/case/activity', "reset=1&action=update&id={$activityID}&cid={$recentContactId}&caseid={$caseID}&context=home"); } if (CRM_Case_BAO_Case::checkPermission($activityID, 'delete')) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/case/activity', "reset=1&action=delete&id={$activityID}&cid={$recentContactId}&caseid={$caseID}&context=home"); } CRM_Utils_Recent::add($title, $url, $activityID, 'Activity', $recentContactId, $recentContactDisplay, $recentOther); }
/** * Delete the relationship. * * @param int $id * Relationship id. * * @return null */ public static function del($id) { // delete from relationship table CRM_Utils_Hook::pre('delete', 'Relationship', $id, CRM_Core_DAO::$_nullArray); $relationship = self::clearCurrentEmployer($id, CRM_Core_Action::DELETE); if (CRM_Core_Permission::access('CiviMember')) { // create $params array which isrequired to delete memberships // of the related contacts. $params = array('relationship_type_id' => "{$relationship->relationship_type_id}_a_b", 'contact_check' => array($relationship->contact_id_b => 1)); $ids = array(); // calling relatedMemberships to delete the memberships of // related contacts. self::relatedMemberships($relationship->contact_id_a, $params, $ids, CRM_Core_Action::DELETE, FALSE); } $relationship->delete(); CRM_Core_Session::setStatus(ts('Selected relationship has been deleted successfully.'), ts('Record Deleted'), 'success'); CRM_Utils_Hook::post('delete', 'Relationship', $id, $relationship); // delete the recently created Relationship $relationshipRecent = array('id' => $id, 'type' => 'Relationship'); CRM_Utils_Recent::del($relationshipRecent); return $relationship; }