Example #1
0
 /** 
  * 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);
     $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('action', $this->_action);
     $this->assign('context', $this->_context);
     //check permission for action.
     if (!CRM_Core_Permission::checkActionPermission('CiviGrant', $this->_action)) {
         CRM_Core_Error::fatal(ts('You do not have permission to access this page'));
     }
     if ($this->_action & CRM_Core_Action::DELETE) {
         return;
     }
     $this->_noteId = null;
     if ($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;
         }
     }
     //build custom data
     CRM_Custom_Form_Customdata::preProcess($this, null, null, 1, 'Grant', $this->_id);
 }
Example #2
0
 /**  
  * 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);
     $context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('context', $context);
     $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']] . ')';
     $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);
     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);
 }
Example #3
0
 /**
  * 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);
 }
Example #4
0
 /**  
  * Function to set variables up before form is built  
  *                                                            
  * @return void  
  * @access public  
  */
 public function preProcess()
 {
     require_once 'CRM/Event/BAO/Participant.php';
     $values = $ids = array();
     $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)) {
         require_once 'CRM/Core/Error.php';
         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 (CRM_Utils_Array::value('fee_level', $values[$participantID])) {
         CRM_Event_BAO_Participant::fixEventLevel($values[$participantID]['fee_level']);
     }
     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);
     require_once 'CRM/Price/BAO/LineItem.php';
     // Get Line Items
     $lineItem = CRM_Price_BAO_LineItem::getLineItems($participantID);
     if (!CRM_Utils_System::isNull($lineItem)) {
         $values[$participantID]['lineItem'][] = $lineItem;
     }
     $values[$participantID]['totalAmount'] = $values[$participantID]['fee_amount'];
     // get the option value for custom data type
     $roleCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantRole', 'name');
     $eventNameCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantEventName', 'name');
     $eventTypeCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantEventType', 'name');
     $roleGroupTree =& CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID, null, $values[$participantID]['role_id'], $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));
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
     $this->assign($values[$participantID]);
     // add viewed participant to recent items list
     require_once 'CRM/Utils/Recent.php';
     require_once 'CRM/Contact/BAO/Contact.php';
     $url = CRM_Utils_System::url('civicrm/contact/view/participant', "action=view&reset=1&id={$values[$participantID]['id']}&cid={$values[$participantID]['contact_id']}&context=home");
     $participantRoles = CRM_Event_PseudoConstant::participantRole();
     $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $values[$participantID]['event_id'], 'title');
     $displayName = CRM_Contact_BAO_Contact::displayName($contactID);
     $this->assign('displayName', $displayName);
     $title = $displayName . ' (' . $participantRoles[$values[$participantID]['role_id']] . ' - ' . $eventTitle . ')';
     // add Participant to Recent Items
     CRM_Utils_Recent::add($title, $url, $values[$participantID]['id'], 'Participant', $values[$participantID]['contact_id'], null);
 }
 /**
  * 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);
     $employerId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'employer_id');
     $this->assign('isCurrentEmployer', false);
     if ($viewRelationship[$this->_id]['employer_id'] == $this->_contactId) {
         $this->assign('isCurrentEmployer', true);
     } else {
         if ($relType == 4 && $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);
     $rType = CRM_Utils_Array::value('rtype', $viewRelationship[$this->_id]);
     // 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");
     require_once 'CRM/Core/Session.php';
     require_once 'CRM/Contact/BAO/Contact/Permission.php';
     $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);
     $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);
 }
Example #6
0
 /**
  * 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);
 }
Example #7
0
 /**
  * takes an associative array and creates a note object
  *
  * the function extract all the params it needs to initialize the create a
  * note object. the params array could contain additional unused name/value
  * pairs
  *
  * @param array  $params         (reference ) an assoc array of name/value pairs
  *
  * @return object CRM_Core_BAO_Note object
  * @access public
  * @static
  */
 function &add(&$params)
 {
     $dataExists = CRM_Core_BAO_Note::dataExists($params);
     if (!$dataExists) {
         return null;
     }
     $note =& new CRM_Core_BAO_Note();
     $params['modified_date'] = date("Ymd");
     $params['entity_id'] = $params['entity_id'];
     $params['entity_table'] = $params['entity_table'];
     $note->copyValues($params);
     $session =& CRM_Core_Session::singleton();
     $note->contact_id = $session->get('userID');
     if (!$note->contact_id) {
         if ($params['entity_table'] == 'civicrm_contact') {
             $note->contact_id = $params['entity_id'];
         } else {
             CRM_Utils_System::statusBounce(ts('We could not find your logged in user ID'));
         }
     }
     $note->save();
     return $note;
 }
 /**
  * Given the component name and returns the count of participation of contact.
  *
  * @param string $component
  *   Input component name.
  * @param int $contactId
  *   Input contact id.
  * @param string $tableName
  *   Optional tableName if component is custom group.
  *
  * @return int
  *   total number in database
  */
 public static function getCountComponent($component, $contactId, $tableName = NULL)
 {
     $object = NULL;
     switch ($component) {
         case 'tag':
             return CRM_Core_BAO_EntityTag::getContactTags($contactId, TRUE);
         case 'rel':
             $result = CRM_Contact_BAO_Relationship::getRelationship($contactId, CRM_Contact_BAO_Relationship::CURRENT, 0, 1);
             return $result;
         case 'group':
             return CRM_Contact_BAO_GroupContact::getContactGroup($contactId, "Added", NULL, TRUE);
         case 'log':
             if (CRM_Core_BAO_Log::useLoggingReport()) {
                 return FALSE;
             }
             return CRM_Core_BAO_Log::getContactLogCount($contactId);
         case 'note':
             return CRM_Core_BAO_Note::getContactNoteCount($contactId);
         case 'contribution':
             return CRM_Contribute_BAO_Contribution::contributionCount($contactId);
         case 'membership':
             return CRM_Member_BAO_Membership::getContactMembershipCount($contactId, TRUE);
         case 'participant':
             return CRM_Event_BAO_Participant::getContactParticipantCount($contactId);
         case 'pledge':
             return CRM_Pledge_BAO_Pledge::getContactPledgeCount($contactId);
         case 'case':
             return CRM_Case_BAO_Case::caseCount($contactId);
         case 'grant':
             return CRM_Grant_BAO_Grant::getContactGrantCount($contactId);
         case 'activity':
             $input = array('contact_id' => $contactId, 'admin' => FALSE, 'caseId' => NULL, 'context' => 'activity');
             return CRM_Activity_BAO_Activity::getActivitiesCount($input);
         case 'mailing':
             $params = array('contact_id' => $contactId);
             return CRM_Mailing_BAO_Mailing::getContactMailingsCount($params);
         default:
             $custom = explode('_', $component);
             if ($custom['0'] = 'custom') {
                 if (!$tableName) {
                     $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $custom['1'], 'table_name');
                 }
                 $queryString = "SELECT count(id) FROM {$tableName} WHERE entity_id = {$contactId}";
                 return CRM_Core_DAO::singleValueQuery($queryString);
             }
     }
 }
Example #9
0
 /**
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     // store the submitted values in an array
     $params = $this->exportValues();
     $session =& CRM_Core_Session::singleton();
     $params['contact_id'] = $session->get('userID');
     $params['entity_table'] = $this->_entityTable;
     $params['entity_id'] = $this->_entityId;
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Core_BAO_Note::del($this->_id);
         return;
     }
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $params['id'] = $this->_id;
     }
     $ids = array();
     require_once 'CRM/Core/BAO/Note.php';
     CRM_Core_BAO_Note::add($params, $ids);
     CRM_Core_Session::setStatus(ts('Your Note has been saved.'));
 }
Example #10
0
 /**
  * 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);
 }
Example #11
0
 /**
  * This function sets the default values for the form in edit/view mode
  * the default values are retrieved from the database
  *
  *
  * @return void
  */
 public function setDefaultValues()
 {
     if ($this->_showFeeBlock) {
         return CRM_Event_Form_EventFees::setDefaultValues($this);
     }
     $defaults = array();
     if ($this->_action & CRM_Core_Action::DELETE) {
         return $defaults;
     }
     if ($this->_id) {
         $ids = array();
         $params = array('id' => $this->_id);
         CRM_Event_BAO_Participant::getValues($params, $defaults, $ids);
         $sep = CRM_Core_DAO::VALUE_SEPARATOR;
         if ($defaults[$this->_id]['role_id']) {
             $roleIDs = explode($sep, $defaults[$this->_id]['role_id']);
         }
         $this->_contactId = $defaults[$this->_id]['contact_id'];
         $this->_statusId = $defaults[$this->_id]['participant_status_id'];
         //set defaults for note
         $noteDetails = CRM_Core_BAO_Note::getNote($this->_id, 'civicrm_participant');
         $defaults[$this->_id]['note'] = array_pop($noteDetails);
         // Check if this is a primaryParticipant (registered for others) and retrieve additional participants if true  (CRM-4859)
         if (CRM_Event_BAO_Participant::isPrimaryParticipant($this->_id)) {
             $this->assign('additionalParticipants', CRM_Event_BAO_Participant::getAdditionalParticipants($this->_id));
         }
         // Get registered_by contact ID and display_name if participant was registered by someone else (CRM-4859)
         if (!empty($defaults[$this->_id]['participant_registered_by_id'])) {
             $registered_by_contact_id = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $defaults[$this->_id]['participant_registered_by_id'], 'contact_id', 'id');
             $this->assign('participant_registered_by_id', $defaults[$this->_id]['participant_registered_by_id']);
             $this->assign('registered_by_contact_id', $registered_by_contact_id);
             $this->assign('registered_by_display_name', CRM_Contact_BAO_Contact::displayName($registered_by_contact_id));
         }
     }
     if ($this->_action & (CRM_Core_Action::VIEW | CRM_Core_Action::BROWSE)) {
         $inactiveNeeded = TRUE;
         $viewMode = TRUE;
     } else {
         $viewMode = FALSE;
         $inactiveNeeded = FALSE;
     }
     //setting default register date
     if ($this->_action == CRM_Core_Action::ADD) {
         $statuses = array_flip($this->_participantStatuses);
         $defaults[$this->_id]['status_id'] = CRM_Utils_Array::value(ts('Registered'), $statuses);
         if (!empty($defaults[$this->_id]['event_id'])) {
             $contributionTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $defaults[$this->_id]['event_id'], 'financial_type_id');
             if ($contributionTypeId) {
                 $defaults[$this->_id]['financial_type_id'] = $contributionTypeId;
             }
         }
         if ($this->_mode) {
             $fields["email-{$this->_bltID}"] = 1;
             $fields['email-Primary'] = 1;
             if ($this->_contactId) {
                 CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactId, $fields, $defaults);
             }
             if (empty($defaults["email-{$this->_bltID}"]) && !empty($defaults['email-Primary'])) {
                 $defaults[$this->_id]["email-{$this->_bltID}"] = $defaults['email-Primary'];
             }
         }
         $submittedRole = $this->getElementValue('role_id');
         if (!empty($submittedRole[0])) {
             $roleID = $submittedRole[0];
         }
         $submittedEvent = $this->getElementValue('event_id');
         if (!empty($submittedEvent[0])) {
             $eventID = $submittedEvent[0];
         }
     } else {
         $defaults[$this->_id]['record_contribution'] = 0;
         if ($defaults[$this->_id]['participant_is_pay_later']) {
             $this->assign('participant_is_pay_later', TRUE);
         }
         $this->assign('participant_status_id', $defaults[$this->_id]['participant_status_id']);
         $eventID = $defaults[$this->_id]['event_id'];
         $this->_eventTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id');
         $this->_discountId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'discount_id');
         if ($this->_discountId) {
             $this->set('discountId', $this->_discountId);
         }
     }
     list($defaults[$this->_id]['register_date'], $defaults[$this->_id]['register_date_time']) = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value('register_date', $defaults[$this->_id]), 'activityDateTime');
     //assign event and role id, this is needed for Custom data building
     $sep = CRM_Core_DAO::VALUE_SEPARATOR;
     if (!empty($defaults[$this->_id]['participant_role_id'])) {
         $roleIDs = explode($sep, $defaults[$this->_id]['participant_role_id']);
     }
     if (isset($_POST['event_id'])) {
         $eventID = $_POST['event_id'];
     }
     if ($this->_eID) {
         $eventID = $this->_eID;
         //@todo - rationalise the $this->_eID with $POST['event_id'],  $this->_eid is set when eid=x is in the url
         $roleID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_eID, 'default_role_id');
         if (empty($roleIDs)) {
             $roleIDs = (array) ($defaults[$this->_id]['participant_role_id'] = $roleID);
         }
         $defaults[$this->_id]['event_id'] = $eventID;
     }
     if (!empty($eventID)) {
         $this->_eventTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id');
     }
     //these should take precedence so we state them last
     $urlRoleIDS = CRM_Utils_Request::retrieve('roles', 'String');
     if ($urlRoleIDS) {
         $roleIDs = explode(',', $urlRoleIDS);
     }
     if (isset($roleIDs)) {
         $defaults[$this->_id]['role_id'] = implode(',', $roleIDs);
     }
     if (isset($eventID)) {
         $this->assign('eventID', $eventID);
         $this->set('eventId', $eventID);
     }
     if (isset($this->_eventTypeId)) {
         $this->assign('eventTypeID', $this->_eventTypeId);
     }
     $this->assign('event_is_test', CRM_Utils_Array::value('event_is_test', $defaults[$this->_id]));
     return $defaults[$this->_id];
 }
 /**
  *  This function is called when the form is submitted 
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     // store the submitted values in an array
     $params = $this->controller->exportValues($this->_name);
     $quickSave = false;
     if (CRM_Utils_Array::value('_qf_Relationship_refresh_save', $_POST) || CRM_Utils_Array::value('_qf_Relationship_refresh_savedetails', $_POST)) {
         $quickSave = true;
     }
     $this->set('searchDone', 0);
     $this->set('callAjax', false);
     if (CRM_Utils_Array::value('_qf_Relationship_refresh', $_POST) || $quickSave) {
         if (is_numeric($params['rel_contact_id'])) {
             if ($quickSave) {
                 $params['contact_check'] = array($params['rel_contact_id'] => 1);
             } else {
                 $this->search($params);
                 $quickSave = false;
             }
         } else {
             $this->set('callAjax', true);
             $this->set('relType', $params['relationship_type_id']);
             $this->set('relContact', $params['rel_contact']);
             $quickSave = false;
         }
         $this->set('searchDone', 1);
         if (!$quickSave) {
             return;
         }
     }
     // action is taken depending upon the mode
     $ids = array();
     $ids['contact'] = $this->_contactId;
     // modify params for ajax call
     $this->modifyParams($params);
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Contact_BAO_Relationship::del($this->_relationshipId);
         return;
     }
     $relationshipTypeId = str_replace(array('_a_b', '_b_a'), array('', ''), $params['relationship_type_id']);
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $ids['relationship'] = $this->_relationshipId;
         $relation = CRM_Contact_BAO_Relationship::getContactIds($this->_relationshipId);
         $ids['contactTarget'] = $relation->contact_id_a == $this->_contactId ? $relation->contact_id_b : $relation->contact_id_a;
         //if relationship type change and previously it was
         //employer / emplyee relationship with current employer
         //than clear the current employer. CRM-3235.
         //make sure we has to have employer id before firing queries, CRM-7306
         $employerId = CRM_Utils_Array::value('current_employee_id', $this->_values);
         $isDisabled = true;
         if (CRM_Utils_Array::value('is_active', $params)) {
             $isDisabled = false;
         }
         $relChanged = true;
         if ($relationshipTypeId == $this->_values['relationship_type_id']) {
             $relChanged = false;
         }
         if ($employerId && ($isDisabled || $relChanged)) {
             require_once 'CRM/Contact/BAO/Contact/Utils.php';
             CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($this->_values['current_employee_id']);
         }
     } elseif ($quickSave) {
         if ($params['add_current_employee'] && $this->_allRelationshipNames[$relationshipTypeId]["name_a_b"] == 'Employee of') {
             $params['employee_of'] = $params['rel_contact_id'];
         } elseif ($params['add_current_employer'] && $this->_allRelationshipNames[$relationshipTypeId]["name_b_a"] == 'Employer of') {
             $params['employer_of'] = array($params['rel_contact_id'] => 1);
         }
         if (!$this->_rtype) {
             $this->_rtype = str_replace($relationshipTypeId . '_', '', $params['relationship_type_id']);
         }
     }
     $params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], null, true);
     $params['end_date'] = CRM_Utils_Date::processDate($params['end_date'], null, true);
     //special case to handle if all checkboxes are unchecked
     $customFields = CRM_Core_BAO_CustomField::getFields('Relationship', false, false, $relationshipTypeId);
     $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_relationshipId, 'Relationship');
     list($valid, $invalid, $duplicate, $saved, $relationshipIds) = CRM_Contact_BAO_Relationship::create($params, $ids);
     // if this is called from case view,
     //create an activity for case role removal.CRM-4480
     if ($this->_caseId) {
         require_once "CRM/Case/BAO/Case.php";
         CRM_Case_BAO_Case::createCaseRoleActivity($this->_caseId, $relationshipIds, $params['contact_check'], $this->_contactId);
     }
     $status = '';
     if ($valid) {
         $status .= ' ' . ts('%count new relationship record created.', array('count' => $valid, 'plural' => '%count new relationship records created.'));
     }
     if ($invalid) {
         $status .= ' ' . ts('%count relationship record not created due to invalid target contact type.', array('count' => $invalid, 'plural' => '%count relationship records not created due to invalid target contact type.'));
     }
     if ($duplicate) {
         $status .= ' ' . ts('%count relationship record not created - duplicate of existing relationship.', array('count' => $duplicate, 'plural' => '%count relationship records not created - duplicate of existing relationship.'));
     }
     if ($saved) {
         $status .= ts('Relationship record has been updated.');
     }
     $note = new CRM_Core_DAO_Note();
     $note->entity_id = $relationshipIds[0];
     $note->entity_table = 'civicrm_relationship';
     $noteIds = array();
     if ($note->find(true)) {
         $id = $note->id;
         $noteIds["id"] = $id;
     }
     $noteParams = array('entity_id' => $relationshipIds[0], 'entity_table' => 'civicrm_relationship', 'note' => $params['note'], 'contact_id' => $this->_contactId);
     CRM_Core_BAO_Note::add($noteParams, $noteIds);
     // Membership for related contacts CRM-1657
     if (CRM_Core_Permission::access('CiviMember') && !$duplicate) {
         CRM_Contact_BAO_Relationship::relatedMemberships($this->_contactId, $params, $ids, $this->_action);
     }
     //handle current employee/employer relationship, CRM-3532
     if ($this->_allRelationshipNames[$relationshipTypeId]["name_{$this->_rtype}"] == 'Employee of') {
         $orgId = null;
         if (CRM_Utils_Array::value('employee_of', $params)) {
             $orgId = $params['employee_of'];
         } else {
             if ($this->_action & CRM_Core_Action::UPDATE) {
                 if (CRM_Utils_Array::value('is_current_employer', $params) && CRM_Utils_Array::value('is_active', $params)) {
                     if (CRM_Utils_Array::value('contactTarget', $ids) != CRM_Utils_Array::value('current_employer_id', $this->_values)) {
                         $orgId = CRM_Utils_Array::value('contactTarget', $ids);
                     }
                 } else {
                     if (CRM_Utils_Array::value('contactTarget', $ids) == CRM_Utils_Array::value('current_employer_id', $this->_values)) {
                         //clear current employer.
                         require_once 'CRM/Contact/BAO/Contact/Utils.php';
                         CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($this->_contactId);
                     }
                 }
             }
         }
         //set current employer
         if ($orgId) {
             $currentEmpParams[$this->_contactId] = $orgId;
             require_once 'CRM/Contact/BAO/Contact/Utils.php';
             CRM_Contact_BAO_Contact_Utils::setCurrentEmployer($currentEmpParams);
         }
     } else {
         if ($this->_allRelationshipNames[$relationshipTypeId]["name_{$this->_rtype}"] == 'Employer of') {
             $individualIds = array();
             if (CRM_Utils_Array::value('employer_of', $params)) {
                 $individualIds = array_keys($params['employer_of']);
             } else {
                 if ($this->_action & CRM_Core_Action::UPDATE) {
                     if (CRM_Utils_Array::value('is_current_employer', $params)) {
                         if (CRM_Utils_Array::value('contactTarget', $ids) != CRM_Utils_Array::value('current_employee_id', $this->_values)) {
                             $individualIds[] = CRM_Utils_Array::value('contactTarget', $ids);
                         }
                     } else {
                         if (CRM_Utils_Array::value('contactTarget', $ids) == CRM_Utils_Array::value('current_employee_id', $this->_values)) {
                             // clear current employee
                             require_once 'CRM/Contact/BAO/Contact/Utils.php';
                             CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($ids['contactTarget']);
                         }
                     }
                 }
             }
             //set current employee
             if (!empty($individualIds)) {
                 //build the employee params.
                 foreach ($individualIds as $key => $Id) {
                     $currentEmpParams[$Id] = $this->_contactId;
                 }
                 require_once 'CRM/Contact/BAO/Contact/Utils.php';
                 CRM_Contact_BAO_Contact_Utils::setCurrentEmployer($currentEmpParams);
             }
         }
     }
     CRM_Core_Session::setStatus($status);
     if ($quickSave) {
         $session =& CRM_Core_Session::singleton();
         CRM_Utils_System::redirect($session->popUserContext());
     }
 }
Example #13
0
 /**
  * takes an associative array and creates a participant object
  *
  * @param array $params (reference ) an assoc array of name/value pairs
  * @param array $ids    the array that holds all the db ids
  *
  * @return object CRM_Event_BAO_Participant object 
  * @access public
  * @static
  */
 static function &create(&$params)
 {
     require_once 'CRM/Utils/Date.php';
     require_once 'CRM/Core/Transaction.php';
     $transaction = new CRM_Core_Transaction();
     $status = null;
     if (CRM_Utils_Array::value('id', $params)) {
         $status = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $params['id'], 'status_id');
     }
     $participant =& self::add($params);
     if (is_a($participant, 'CRM_Core_Error')) {
         $transaction->rollback();
         return $participant;
     }
     if (!CRM_Utils_Array::value('id', $params) || $params['status_id'] != $status) {
         require_once 'CRM/Activity/BAO/Activity.php';
         CRM_Activity_BAO_Activity::addActivity($participant);
     }
     //CRM-5403
     //for update mode
     if (self::isPrimaryParticipant($participant->id) && $status) {
         self::updateParticipantStatus($participant->id, $status, $participant->status_id);
     }
     $session =& CRM_Core_Session::singleton();
     $id = $session->get('userID');
     if (!$id) {
         $id = $params['contact_id'];
     }
     // add custom field values
     if (CRM_Utils_Array::value('custom', $params) && is_array($params['custom'])) {
         require_once 'CRM/Core/BAO/CustomValueTable.php';
         CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_participant', $participant->id);
     }
     if (CRM_Utils_Array::value('note', $params) || CRM_Utils_Array::value('participant_note', $params)) {
         if (CRM_Utils_Array::value('note', $params)) {
             $note = CRM_Utils_Array::value('note', $params);
         } else {
             $note = CRM_Utils_Array::value('participant_note', $params);
         }
         $noteDetails = CRM_Core_BAO_Note::getNote($participant->id, 'civicrm_participant');
         $noteIDs = array();
         if (!empty($noteDetails)) {
             $noteIDs['id'] = array_pop(array_flip($noteDetails));
         }
         if ($note) {
             require_once 'CRM/Core/BAO/Note.php';
             $noteParams = array('entity_table' => 'civicrm_participant', 'note' => $note, 'entity_id' => $participant->id, 'contact_id' => $id, 'modified_date' => date('Ymd'));
             CRM_Core_BAO_Note::add($noteParams, $noteIDs);
         }
     }
     // Log the information on successful add/edit of Participant data.
     require_once 'CRM/Core/BAO/Log.php';
     $logParams = array('entity_table' => 'civicrm_participant', 'entity_id' => $participant->id, 'data' => CRM_Event_PseudoConstant::participantStatus($participant->status_id), 'modified_id' => $id, 'modified_date' => date('Ymd'));
     CRM_Core_BAO_Log::add($logParams);
     $params['participant_id'] = $participant->id;
     $transaction->commit();
     // do not add to recent items for import, CRM-4399
     if (!CRM_Utils_Array::value('skipRecentView', $params)) {
         require_once 'CRM/Utils/Recent.php';
         require_once 'CRM/Event/PseudoConstant.php';
         require_once 'CRM/Contact/BAO/Contact.php';
         $url = CRM_Utils_System::url('civicrm/contact/view/participant', "action=view&reset=1&id={$participant->id}&cid={$participant->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={$participant->id}&cid={$participant->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={$participant->id}&cid={$participant->contact_id}&context=home");
         }
         $participantRoles = CRM_Event_PseudoConstant::participantRole();
         if ($participant->role_id) {
             $role = explode(CRM_Core_DAO::VALUE_SEPARATOR, $participant->role_id);
             foreach ($role as $roleKey => $roleValue) {
                 if (isset($roles)) {
                     $roles .= ", " . $participantRoles[$roleValue];
                 } else {
                     $roles = $participantRoles[$roleValue];
                 }
             }
         }
         $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $participant->event_id, 'title');
         $title = CRM_Contact_BAO_Contact::displayName($participant->contact_id) . ' (' . $roles . ' - ' . $eventTitle . ')';
         // add the recently created Participant
         CRM_Utils_Recent::add($title, $url, $participant->id, 'Participant', $participant->contact_id, null, $recentOther);
     }
     return $participant;
 }
Example #14
0
 /**  
  * Function to set variables up before form is built  
  *                                                            
  * @return void  
  * @access public  
  */
 public function preProcess()
 {
     $id = $this->get('id');
     $values = $ids = array();
     $params = array('id' => $id);
     require_once 'CRM/Contribute/BAO/Contribution.php';
     CRM_Contribute_BAO_Contribution::getValues($params, $values, $ids);
     $softParams = array('contribution_id' => $values['contribution_id']);
     if ($softContribution = CRM_Contribute_BAO_Contribution::getSoftContribution($softParams, true)) {
         $values = array_merge($values, $softContribution);
     }
     CRM_Contribute_BAO_Contribution::resolveDefaults($values);
     if (CRM_Utils_Array::value('honor_contact_id', $values)) {
         $sql = "SELECT display_name FROM civicrm_contact WHERE id = %1";
         $params = array(1 => array($values['honor_contact_id'], 'Integer'));
         $dao = CRM_Core_DAO::executeQuery($sql, $params);
         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']];
     }
     if (CRM_Utils_Array::value('contribution_recur_id', $values)) {
         $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, $values['contribution_type_id']);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
     $premiumId = null;
     if ($id) {
         require_once 'CRM/Contribute/DAO/ContributionProduct.php';
         $dao =& new CRM_Contribute_DAO_ContributionProduct();
         $dao->contribution_id = $id;
         if ($dao->find(true)) {
             $premiumId = $dao->id;
             $productID = $dao->product_id;
         }
     }
     if ($premiumId) {
         require_once 'CRM/Contribute/DAO/Product.php';
         $productDAO =& new CRM_Contribute_DAO_Product();
         $productDAO->id = $productID;
         $productDAO->find(true);
         $this->assign('premium', $productDAO->name);
         $this->assign('option', $dao->product_option);
         $this->assign('fulfilled', $dao->fulfilled_date);
     }
     // Get Note
     $noteValue = CRM_Core_BAO_Note::getNote($values['id'], 'civicrm_contribution');
     $values['note'] = array_values($noteValue);
     // show billing address location details, if exists
     if (CRM_Utils_Array::value('address_id', $values)) {
         $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'];
     }
     //get soft credit record if exists.
     if ($softContribution = CRM_Contribute_BAO_Contribution::getSoftContribution($softParams)) {
         $softContribution['softCreditToName'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $softContribution['soft_credit_to'], 'display_name');
         //hack to avoid dispalyName conflict
         //for viewing softcredit record.
         $softContribution['displayName'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['contact_id'], 'display_name');
         $values = array_merge($values, $softContribution);
     }
     require_once 'CRM/Price/BAO/Set.php';
     $lineItems = array();
     if ($id && CRM_Price_BAO_Set::getFor('civicrm_contribution', $id)) {
         require_once 'CRM/Price/BAO/LineItem.php';
         $lineItems[] = CRM_Price_BAO_LineItem::getLineItems($id, 'contribution');
     }
     $this->assign('lineItem', empty($lineItems) ? false : $lineItems);
     $values['totalAmount'] = $values['total_amount'];
     // assign values to the template
     $this->assign($values);
     // add viewed contribution to recent items list
     require_once 'CRM/Utils/Recent.php';
     require_once 'CRM/Utils/Money.php';
     require_once 'CRM/Contact/BAO/Contact.php';
     $url = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}");
     $title = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['contact_id'], 'display_name') . ' - (' . CRM_Utils_Money::format($values['total_amount']) . ' ' . ' - ' . $values['contribution_type'] . ')';
     CRM_Utils_Recent::add($title, $url, $values['id'], 'Contribution', $values['contact_id'], null);
 }
Example #15
0
 /**
  * This function is used to setDefault componet specific profile fields.
  * 
  * @param array  $fields      profile fields.
  * @param int    $componentId componetID
  * @param string $component   component name
  * @param array  $defaults    an array of default values.
  *
  * @return void.
  */
 function setComponentDefaults(&$fields, $componentId, $component, &$defaults)
 {
     if (!$componentId || !in_array($component, array('Contribute', 'Membership', 'Event'))) {
         return;
     }
     $componentBAO = $componentSubType = null;
     switch ($component) {
         case 'Membership':
             $componentBAO = 'CRM_Member_BAO_Membership';
             $componentBAOName = 'Membership';
             $componentSubType = array('membership_type_id');
             break;
         case 'Contribute':
             $componentBAO = 'CRM_Contribute_BAO_Contribution';
             $componentBAOName = 'Contribution';
             $componentSubType = array('contribution_type_id');
             break;
         case 'Event':
             $componentBAO = 'CRM_Event_BAO_Participant';
             $componentBAOName = 'Participant';
             $componentSubType = array('role_id', 'event_id');
             break;
     }
     $values = array();
     $params = array('id' => $componentId);
     //get the component values.
     CRM_Core_DAO::commonRetrieve($componentBAO, $params, $values);
     $formattedGroupTree = array();
     foreach ($fields as $name => $field) {
         $fldName = "field[{$componentId}][{$name}]";
         if ($name == 'participant_register_date') {
             $timefldName = "field[{$componentId}][{$name}_time]";
             list($defaults[$fldName], $defaults[$timefldName]) = CRM_Utils_Date::setDateDefaults($values[$name]);
         } else {
             if (array_key_exists($name, $values)) {
                 $defaults[$fldName] = $values[$name];
             } else {
                 if ($name == 'participant_note') {
                     require_once "CRM/Core/BAO/Note.php";
                     $noteDetails = array();
                     $noteDetails = CRM_Core_BAO_Note::getNote($componentId, 'civicrm_participant');
                     $defaults[$fldName] = array_pop($noteDetails);
                 } else {
                     if (in_array($name, array('contribution_type', 'payment_instrument'))) {
                         $defaults[$fldName] = $values["{$name}_id"];
                     } else {
                         if ($customFieldInfo = CRM_Core_BAO_CustomField::getKeyID($name, true)) {
                             if (empty($formattedGroupTree)) {
                                 //get the groupTree as per subTypes.
                                 $groupTree = array();
                                 require_once 'CRM/Core/BAO/CustomGroup.php';
                                 foreach ($componentSubType as $subType) {
                                     $subTree = CRM_Core_BAO_CustomGroup::getTree($componentBAOName, CRM_Core_DAO::$_nullObject, $componentId, 0, $values[$subType]);
                                     $groupTree = CRM_Utils_Array::crmArrayMerge($groupTree, $subTree);
                                 }
                                 $formattedGroupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, CRM_Core_DAO::$_nullObject);
                                 CRM_Core_BAO_CustomGroup::setDefaults($formattedGroupTree, $defaults);
                             }
                             //FIX ME: We need to loop defaults, but once we move to custom_1_x convention this code can be simplified.
                             foreach ($defaults as $customKey => $customValue) {
                                 if ($customFieldDetails = CRM_Core_BAO_CustomField::getKeyID($customKey, true)) {
                                     if ($name == 'custom_' . $customFieldDetails[0]) {
                                         //hack to set default for checkbox
                                         //basically this is for weired field name like field[33][custom_19]
                                         //we are converting this field name to array structure and assign value.
                                         $skipValue = false;
                                         foreach ($formattedGroupTree as $tree) {
                                             if ('CheckBox' == CRM_Utils_Array::value('html_type', $tree['fields'][$customFieldDetails[0]])) {
                                                 $skipValue = true;
                                                 $defaults['field'][$componentId][$name] = $customValue;
                                                 break;
                                             } else {
                                                 if (CRM_Utils_Array::value('data_type', $tree['fields'][$customFieldDetails[0]]) == 'Date') {
                                                     $skipValue = true;
                                                     $customValue = $tree['fields'][$customFieldDetails[0]]['element_value'];
                                                     list($defaults['field'][$componentId][$name], $defaults['field'][$componentId][$name . '_time']) = CRM_Utils_Date::setDateDefaults($customValue);
                                                 }
                                             }
                                         }
                                         if (!$skipValue) {
                                             $defaults[$fldName] = $customValue;
                                         }
                                         unset($defaults[$customKey]);
                                         break;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Example #16
0
 /**
  * delete the note object from the db
  *
  * @return void
  * @access public
  */
 function delete()
 {
     CRM_Core_BAO_Note::del($this->_id);
 }
 /**
  * Process the Note.
  *
  *
  * @param array $params
  * @param int $contactID
  * @param int $contributionID
  * @param int $contributionNoteID
  */
 public static function processNote($params, $contactID, $contributionID, $contributionNoteID = NULL)
 {
     //process note
     $noteParams = array('entity_table' => 'civicrm_contribution', 'note' => $params['note'], 'entity_id' => $contributionID, 'contact_id' => $contactID);
     $noteID = array();
     if ($contributionNoteID) {
         $noteID = array("id" => $contributionNoteID);
         $noteParams['note'] = $noteParams['note'] ? $noteParams['note'] : "null";
     }
     CRM_Core_BAO_Note::add($noteParams, $noteID);
 }
Example #18
0
 /**
  * Handle the values in import mode.
  *
  * @param int $onDuplicate
  *   The code for what action to take on duplicates.
  * @param array $values
  *   The array of values belonging to this line.
  *
  * @return bool
  *   the result of this processing
  */
 public function import($onDuplicate, &$values)
 {
     // first make sure this is a valid line
     $response = $this->summary($values);
     if ($response != CRM_Import_Parser::VALID) {
         return $response;
     }
     $params =& $this->getActiveFieldParams();
     $formatted = array('version' => 3);
     // don't add to recent items, CRM-4399
     $formatted['skipRecentView'] = TRUE;
     //for date-Formats
     $session = CRM_Core_Session::singleton();
     $dateType = $session->get('dateTypes');
     $customDataType = !empty($params['contact_type']) ? $params['contact_type'] : 'Contribution';
     $customFields = CRM_Core_BAO_CustomField::getFields($customDataType);
     //CRM-10994
     if (isset($params['total_amount']) && $params['total_amount'] == 0) {
         $params['total_amount'] = '0.00';
     }
     foreach ($params as $key => $val) {
         if ($val) {
             switch ($key) {
                 case 'receive_date':
                 case 'cancel_date':
                 case 'receipt_date':
                 case 'thankyou_date':
                     $params[$key] = CRM_Utils_Date::formatDate($params[$key], $dateType);
                     break;
                 case 'pledge_payment':
                     $params[$key] = CRM_Utils_String::strtobool($val);
                     break;
             }
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
                 if ($customFields[$customFieldID]['data_type'] == 'Date') {
                     CRM_Contact_Import_Parser_Contact::formatCustomDate($params, $formatted, $dateType, $key);
                     unset($params[$key]);
                 } elseif ($customFields[$customFieldID]['data_type'] == 'Boolean') {
                     $params[$key] = CRM_Utils_String::strtoboolstr($val);
                 }
             }
         }
     }
     //date-Format part ends
     static $indieFields = NULL;
     if ($indieFields == NULL) {
         $tempIndieFields = CRM_Contribute_DAO_Contribution::import();
         $indieFields = $tempIndieFields;
     }
     $paramValues = array();
     foreach ($params as $key => $field) {
         if ($field == NULL || $field === '') {
             continue;
         }
         $paramValues[$key] = $field;
     }
     //import contribution record according to select contact type
     if ($onDuplicate == CRM_Import_Parser::DUPLICATE_SKIP && (!empty($paramValues['contribution_contact_id']) || !empty($paramValues['external_identifier']))) {
         $paramValues['contact_type'] = $this->_contactType;
     } elseif ($onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE && (!empty($paramValues['contribution_id']) || !empty($values['trxn_id']) || !empty($paramValues['invoice_id']))) {
         $paramValues['contact_type'] = $this->_contactType;
     } elseif (!empty($params['soft_credit'])) {
         $paramValues['contact_type'] = $this->_contactType;
     } elseif (!empty($paramValues['pledge_payment'])) {
         $paramValues['contact_type'] = $this->_contactType;
     }
     //need to pass $onDuplicate to check import mode.
     if (!empty($paramValues['pledge_payment'])) {
         $paramValues['onDuplicate'] = $onDuplicate;
     }
     require_once 'CRM/Utils/DeprecatedUtils.php';
     $formatError = _civicrm_api3_deprecated_formatted_param($paramValues, $formatted, TRUE, $onDuplicate);
     if ($formatError) {
         array_unshift($values, $formatError['error_message']);
         if (CRM_Utils_Array::value('error_data', $formatError) == 'soft_credit') {
             return CRM_Contribute_Import_Parser::SOFT_CREDIT_ERROR;
         } elseif (CRM_Utils_Array::value('error_data', $formatError) == 'pledge_payment') {
             return CRM_Contribute_Import_Parser::PLEDGE_PAYMENT_ERROR;
         }
         return CRM_Import_Parser::ERROR;
     }
     if ($onDuplicate != CRM_Import_Parser::DUPLICATE_UPDATE) {
         $formatted['custom'] = CRM_Core_BAO_CustomField::postProcess($formatted, NULL, 'Contribution');
     } else {
         //fix for CRM-2219 - Update Contribution
         // onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE
         if (!empty($paramValues['invoice_id']) || !empty($paramValues['trxn_id']) || !empty($paramValues['contribution_id'])) {
             $dupeIds = array('id' => CRM_Utils_Array::value('contribution_id', $paramValues), 'trxn_id' => CRM_Utils_Array::value('trxn_id', $paramValues), 'invoice_id' => CRM_Utils_Array::value('invoice_id', $paramValues));
             $ids['contribution'] = CRM_Contribute_BAO_Contribution::checkDuplicateIds($dupeIds);
             if ($ids['contribution']) {
                 $formatted['id'] = $ids['contribution'];
                 $formatted['custom'] = CRM_Core_BAO_CustomField::postProcess($formatted, $formatted['id'], 'Contribution');
                 //process note
                 if (!empty($paramValues['note'])) {
                     $noteID = array();
                     $contactID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $ids['contribution'], 'contact_id');
                     $daoNote = new CRM_Core_BAO_Note();
                     $daoNote->entity_table = 'civicrm_contribution';
                     $daoNote->entity_id = $ids['contribution'];
                     if ($daoNote->find(TRUE)) {
                         $noteID['id'] = $daoNote->id;
                     }
                     $noteParams = array('entity_table' => 'civicrm_contribution', 'note' => $paramValues['note'], 'entity_id' => $ids['contribution'], 'contact_id' => $contactID);
                     CRM_Core_BAO_Note::add($noteParams, $noteID);
                     unset($formatted['note']);
                 }
                 //need to check existing soft credit contribution, CRM-3968
                 if (!empty($formatted['soft_credit'])) {
                     $dupeSoftCredit = array('contact_id' => $formatted['soft_credit'], 'contribution_id' => $ids['contribution']);
                     //Delete all existing soft Contribution from contribution_soft table for pcp_id is_null
                     $existingSoftCredit = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($dupeSoftCredit['contribution_id']);
                     if (isset($existingSoftCredit['soft_credit']) && !empty($existingSoftCredit['soft_credit'])) {
                         foreach ($existingSoftCredit['soft_credit'] as $key => $existingSoftCreditValues) {
                             if (!empty($existingSoftCreditValues['soft_credit_id'])) {
                                 $deleteParams = array('id' => $existingSoftCreditValues['soft_credit_id'], 'pcp_id' => NULL);
                                 CRM_Contribute_BAO_ContributionSoft::del($deleteParams);
                             }
                         }
                     }
                 }
                 $newContribution = CRM_Contribute_BAO_Contribution::create($formatted, $ids);
                 $this->_newContributions[] = $newContribution->id;
                 //return soft valid since we need to show how soft credits were added
                 if (!empty($formatted['soft_credit'])) {
                     return CRM_Contribute_Import_Parser::SOFT_CREDIT;
                 }
                 // process pledge payment assoc w/ the contribution
                 return self::processPledgePayments($formatted);
                 return CRM_Import_Parser::VALID;
             } else {
                 $labels = array('id' => 'Contribution ID', 'trxn_id' => 'Transaction ID', 'invoice_id' => 'Invoice ID');
                 foreach ($dupeIds as $k => $v) {
                     if ($v) {
                         $errorMsg[] = "{$labels[$k]} {$v}";
                     }
                 }
                 $errorMsg = implode(' AND ', $errorMsg);
                 array_unshift($values, 'Matching Contribution record not found for ' . $errorMsg . '. Row was skipped.');
                 return CRM_Import_Parser::ERROR;
             }
         }
     }
     if ($this->_contactIdIndex < 0) {
         // set the contact type if its not set
         if (!isset($paramValues['contact_type'])) {
             $paramValues['contact_type'] = $this->_contactType;
         }
         $paramValues['version'] = 3;
         //retrieve contact id using contact dedupe rule
         require_once 'CRM/Utils/DeprecatedUtils.php';
         $error = _civicrm_api3_deprecated_check_contact_dedupe($paramValues);
         if (CRM_Core_Error::isAPIError($error, CRM_Core_ERROR::DUPLICATE_CONTACT)) {
             $matchedIDs = explode(',', $error['error_message']['params'][0]);
             if (count($matchedIDs) > 1) {
                 array_unshift($values, 'Multiple matching contact records detected for this row. The contribution was not imported');
                 return CRM_Import_Parser::ERROR;
             } else {
                 $cid = $matchedIDs[0];
                 $formatted['contact_id'] = $cid;
                 $newContribution = civicrm_api('contribution', 'create', $formatted);
                 if (civicrm_error($newContribution)) {
                     if (is_array($newContribution['error_message'])) {
                         array_unshift($values, $newContribution['error_message']['message']);
                         if ($newContribution['error_message']['params'][0]) {
                             return CRM_Import_Parser::DUPLICATE;
                         }
                     } else {
                         array_unshift($values, $newContribution['error_message']);
                         return CRM_Import_Parser::ERROR;
                     }
                 }
                 $this->_newContributions[] = $newContribution['id'];
                 $formatted['contribution_id'] = $newContribution['id'];
                 //return soft valid since we need to show how soft credits were added
                 if (!empty($formatted['soft_credit'])) {
                     return CRM_Contribute_Import_Parser::SOFT_CREDIT;
                 }
                 // process pledge payment assoc w/ the contribution
                 return self::processPledgePayments($formatted);
                 return CRM_Import_Parser::VALID;
             }
         } else {
             // Using new Dedupe rule.
             $ruleParams = array('contact_type' => $this->_contactType, 'used' => 'Unsupervised');
             $fieldsArray = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams);
             $disp = NULL;
             foreach ($fieldsArray as $value) {
                 if (array_key_exists(trim($value), $params)) {
                     $paramValue = $params[trim($value)];
                     if (is_array($paramValue)) {
                         $disp .= $params[trim($value)][0][trim($value)] . " ";
                     } else {
                         $disp .= $params[trim($value)] . " ";
                     }
                 }
             }
             if (!empty($params['external_identifier'])) {
                 if ($disp) {
                     $disp .= "AND {$params['external_identifier']}";
                 } else {
                     $disp = $params['external_identifier'];
                 }
             }
             array_unshift($values, 'No matching Contact found for (' . $disp . ')');
             return CRM_Import_Parser::ERROR;
         }
     } else {
         if (!empty($paramValues['external_identifier'])) {
             $checkCid = new CRM_Contact_DAO_Contact();
             $checkCid->external_identifier = $paramValues['external_identifier'];
             $checkCid->find(TRUE);
             if ($checkCid->id != $formatted['contact_id']) {
                 array_unshift($values, 'Mismatch of External ID:' . $paramValues['external_identifier'] . ' and Contact Id:' . $formatted['contact_id']);
                 return CRM_Import_Parser::ERROR;
             }
         }
         $newContribution = civicrm_api('contribution', 'create', $formatted);
         if (civicrm_error($newContribution)) {
             if (is_array($newContribution['error_message'])) {
                 array_unshift($values, $newContribution['error_message']['message']);
                 if ($newContribution['error_message']['params'][0]) {
                     return CRM_Import_Parser::DUPLICATE;
                 }
             } else {
                 array_unshift($values, $newContribution['error_message']);
                 return CRM_Import_Parser::ERROR;
             }
         }
         $this->_newContributions[] = $newContribution['id'];
         $formatted['contribution_id'] = $newContribution['id'];
         //return soft valid since we need to show how soft credits were added
         if (!empty($formatted['soft_credit'])) {
             return CRM_Contribute_Import_Parser::SOFT_CREDIT;
         }
         // process pledge payment assoc w/ the contribution
         return self::processPledgePayments($formatted);
         return CRM_Import_Parser::VALID;
     }
 }
Example #19
0
 /**
  * Process the contribution
  *
  * @param $form
  * @param $params
  * @param $result
  * @param $contactID
  * @param $contributionType
  * @param bool $deductibleMode
  * @param bool $pending
  * @param bool $online
  *
  * @return CRM_Contribute_DAO_Contribution
  * @access public
  */
 static function processContribution(&$form, $params, $result, $contactID, $contributionType, $deductibleMode = TRUE, $pending = FALSE, $online = TRUE)
 {
     $transaction = new CRM_Core_Transaction();
     $className = get_class($form);
     $recurringContributionID = NULL;
     // add these values for the recurringContrib function ,CRM-10188
     $params['financial_type_id'] = $contributionType->id;
     //@todo - this is being set from the form to resolve CRM-10188 - an
     // eNotice caused by it not being set @ the front end
     // however, we then get it being over-written with null for backend contributions
     // a better fix would be to set the values in the respective forms rather than require
     // a function being shared by two forms to deal with their respective values
     // moving it to the BAO & not taking the $form as a param would make sense here.
     if (!isset($params['is_email_receipt'])) {
         $params['is_email_receipt'] = CRM_Utils_Array::value('is_email_receipt', $form->_values);
     }
     $recurringContributionID = self::processRecurringContribution($form, $params, $contactID, $contributionType, $online);
     $config = CRM_Core_Config::singleton();
     // CRM-11885
     // if non_deductible_amount exists i.e. Additional Details fieldset was opened [and staff typed something] -> keep it.
     if (isset($params['non_deductible_amount']) && !empty($params['non_deductible_amount'])) {
         $nonDeductibleAmount = $params['non_deductible_amount'];
     } else {
         //if ($contributionType->is_deductible && $deductibleMode) {
         if ($contributionType->is_deductible) {
             if ($online && isset($params['selectProduct'])) {
                 $selectProduct = CRM_Utils_Array::value('selectProduct', $params);
             }
             if (!$online && isset($params['product_name'][0])) {
                 $selectProduct = $params['product_name'][0];
             }
             // if there is a product - compare the value to the contribution amount
             if (isset($selectProduct) && $selectProduct != 'no_thanks') {
                 $productDAO = new CRM_Contribute_DAO_Product();
                 $productDAO->id = $selectProduct;
                 $productDAO->find(TRUE);
                 // product value exceeds contribution amount
                 if ($params['amount'] < $productDAO->price) {
                     $nonDeductibleAmount = $params['amount'];
                 } else {
                     $nonDeductibleAmount = $productDAO->price;
                 }
             } else {
                 $nonDeductibleAmount = '0.00';
             }
         } else {
             $nonDeductibleAmount = $params['amount'];
         }
     }
     $now = date('YmdHis');
     $receiptDate = CRM_Utils_Array::value('receipt_date', $params);
     if (!empty($form->_values['is_email_receipt'])) {
         $receiptDate = $now;
     }
     //get the contrib page id.
     $campaignId = $contributionPageId = NULL;
     if ($online) {
         $contributionPageId = $form->_id;
         $campaignId = CRM_Utils_Array::value('campaign_id', $params);
         if (!array_key_exists('campaign_id', $params)) {
             $campaignId = CRM_Utils_Array::value('campaign_id', $form->_values);
         }
     } else {
         //also for offline we do support - CRM-7290
         $contributionPageId = CRM_Utils_Array::value('contribution_page_id', $params);
         $campaignId = CRM_Utils_Array::value('campaign_id', $params);
     }
     // first create the contribution record
     $contribParams = array('contact_id' => $contactID, 'financial_type_id' => $contributionType->id, 'contribution_page_id' => $contributionPageId, 'receive_date' => CRM_Utils_Array::value('receive_date', $params) ? CRM_Utils_Date::processDate($params['receive_date']) : date('YmdHis'), 'non_deductible_amount' => $nonDeductibleAmount, 'total_amount' => $params['amount'], 'amount_level' => CRM_Utils_Array::value('amount_level', $params), 'invoice_id' => $params['invoiceID'], 'currency' => $params['currencyID'], 'source' => !$online || !empty($params['source']) ? CRM_Utils_Array::value('source', $params) : CRM_Utils_Array::value('description', $params), 'is_pay_later' => CRM_Utils_Array::value('is_pay_later', $params, 0), 'cancel_reason' => CRM_Utils_Array::value('cancel_reason', $params, 0), 'cancel_date' => isset($params['cancel_date']) ? CRM_Utils_Date::format($params['cancel_date']) : NULL, 'thankyou_date' => isset($params['thankyou_date']) ? CRM_Utils_Date::format($params['thankyou_date']) : NULL, 'campaign_id' => $campaignId);
     if (!$online && isset($params['thankyou_date'])) {
         $contribParams['thankyou_date'] = $params['thankyou_date'];
     }
     if (!$online || $form->_values['is_monetary']) {
         if (empty($params['is_pay_later'])) {
             $contribParams['payment_instrument_id'] = 1;
         }
     }
     if (!$pending && $result) {
         $contribParams += array('fee_amount' => CRM_Utils_Array::value('fee_amount', $result), 'net_amount' => CRM_Utils_Array::value('net_amount', $result, $params['amount']), 'trxn_id' => $result['trxn_id'], 'receipt_date' => $receiptDate, 'trxn_result_code' => CRM_Utils_Array::value('trxn_result_code', $result), 'payment_processor' => CRM_Utils_Array::value('payment_processor', $result));
     }
     if ($recurringContributionID) {
         $contribParams['contribution_recur_id'] = $recurringContributionID;
     }
     $contribParams['contribution_status_id'] = $pending ? 2 : 1;
     $contribParams['is_test'] = 0;
     if ($form->_mode == 'test') {
         $contribParams['is_test'] = 1;
     }
     $ids = array();
     if (isset($contribParams['invoice_id'])) {
         $contribID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contribParams['invoice_id'], 'id', 'invoice_id');
         if (isset($contribID)) {
             $ids['contribution'] = $contribID;
             $contribParams['id'] = $contribID;
         }
     }
     //create an contribution address
     if ($form->_contributeMode != 'notify' && empty($params['is_pay_later']) && !empty($form->_values['is_monetary'])) {
         $contribParams['address_id'] = CRM_Contribute_BAO_Contribution::createAddress($params, $form->_bltID);
     }
     // CRM-4038: for non-en_US locales, CRM_Contribute_BAO_Contribution::add() expects localised amounts
     $contribParams['non_deductible_amount'] = trim(CRM_Utils_Money::format($contribParams['non_deductible_amount'], ' '));
     $contribParams['total_amount'] = trim(CRM_Utils_Money::format($contribParams['total_amount'], ' '));
     // Prepare soft contribution due to pcp or Submit Credit / Debit Card Contribution by admin.
     if (!empty($params['pcp_made_through_id']) || !empty($params['soft_credit_to'])) {
         // if its due to pcp
         if (!empty($params['pcp_made_through_id'])) {
             $contribSoftContactId = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $params['pcp_made_through_id'], 'contact_id');
         } else {
             $contribSoftContactId = CRM_Utils_Array::value('soft_credit_to', $params);
         }
         // Pass these details onto with the contribution to make them
         // available at hook_post_process, CRM-8908
         $contribParams['soft_credit_to'] = $params['soft_credit_to'] = $contribSoftContactId;
     }
     if (isset($params['amount'])) {
         $contribParams['line_item'] = $form->_lineItem;
         //add contribution record
         $contribution = CRM_Contribute_BAO_Contribution::add($contribParams, $ids);
         if (is_a($contribution, 'CRM_Core_Error')) {
             $message = CRM_Core_Error::getMessages($contribution);
             CRM_Core_Error::fatal($message);
         }
         // lets store it in the form variable so postProcess hook can get to this and use it
         $form->_contributionID = $contribution->id;
     }
     //CRM-13981, processing honor contact into soft-credit contribution
     CRM_Contact_Form_ProfileContact::postProcess($form);
     // process soft credit / pcp pages
     CRM_Contribute_Form_Contribution_Confirm::processPcpSoft($params, $contribution);
     //handle pledge stuff.
     if (empty($form->_params['separate_membership_payment']) && !empty($form->_values['pledge_block_id']) && (!empty($form->_params['is_pledge']) || !empty($form->_values['pledge_id']))) {
         if (!empty($form->_values['pledge_id'])) {
             //when user doing pledge payments.
             //update the schedule when payment(s) are made
             foreach ($form->_params['pledge_amount'] as $paymentId => $dontCare) {
                 $scheduledAmount = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $paymentId, 'scheduled_amount', 'id');
                 $pledgePaymentParams = array('id' => $paymentId, 'contribution_id' => $contribution->id, 'status_id' => $contribution->contribution_status_id, 'actual_amount' => $scheduledAmount);
                 CRM_Pledge_BAO_PledgePayment::add($pledgePaymentParams);
             }
             //update pledge status according to the new payment statuses
             CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($form->_values['pledge_id']);
         } else {
             //when user creating pledge record.
             $pledgeParams = array();
             $pledgeParams['contact_id'] = $contribution->contact_id;
             $pledgeParams['installment_amount'] = $pledgeParams['actual_amount'] = $contribution->total_amount;
             $pledgeParams['contribution_id'] = $contribution->id;
             $pledgeParams['contribution_page_id'] = $contribution->contribution_page_id;
             $pledgeParams['financial_type_id'] = $contribution->financial_type_id;
             $pledgeParams['frequency_interval'] = $params['pledge_frequency_interval'];
             $pledgeParams['installments'] = $params['pledge_installments'];
             $pledgeParams['frequency_unit'] = $params['pledge_frequency_unit'];
             if ($pledgeParams['frequency_unit'] == 'month') {
                 $pledgeParams['frequency_day'] = intval(date("d"));
             } else {
                 $pledgeParams['frequency_day'] = 1;
             }
             $pledgeParams['create_date'] = $pledgeParams['start_date'] = $pledgeParams['scheduled_date'] = date("Ymd");
             $pledgeParams['status_id'] = $contribution->contribution_status_id;
             $pledgeParams['max_reminders'] = $form->_values['max_reminders'];
             $pledgeParams['initial_reminder_day'] = $form->_values['initial_reminder_day'];
             $pledgeParams['additional_reminder_day'] = $form->_values['additional_reminder_day'];
             $pledgeParams['is_test'] = $contribution->is_test;
             $pledgeParams['acknowledge_date'] = date('Ymd');
             $pledgeParams['original_installment_amount'] = $pledgeParams['installment_amount'];
             //inherit campaign from contirb page.
             $pledgeParams['campaign_id'] = $campaignId;
             $pledge = CRM_Pledge_BAO_Pledge::create($pledgeParams);
             $form->_params['pledge_id'] = $pledge->id;
             //send acknowledgment email. only when pledge is created
             if ($pledge->id) {
                 //build params to send acknowledgment.
                 $pledgeParams['id'] = $pledge->id;
                 $pledgeParams['receipt_from_name'] = $form->_values['receipt_from_name'];
                 $pledgeParams['receipt_from_email'] = $form->_values['receipt_from_email'];
                 //scheduled amount will be same as installment_amount.
                 $pledgeParams['scheduled_amount'] = $pledgeParams['installment_amount'];
                 //get total pledge amount.
                 $pledgeParams['total_pledge_amount'] = $pledge->amount;
                 CRM_Pledge_BAO_Pledge::sendAcknowledgment($form, $pledgeParams);
             }
         }
     }
     if ($online && $contribution) {
         CRM_Core_BAO_CustomValueTable::postProcess($form->_params, CRM_Core_DAO::$_nullArray, 'civicrm_contribution', $contribution->id, 'Contribution');
     } elseif ($contribution) {
         //handle custom data.
         $params['contribution_id'] = $contribution->id;
         if (!empty($params['custom']) && is_array($params['custom']) && !is_a($contribution, 'CRM_Core_Error')) {
             CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_contribution', $contribution->id);
         }
     }
     // Save note
     if ($contribution && !empty($params['contribution_note'])) {
         $noteParams = array('entity_table' => 'civicrm_contribution', 'note' => $params['contribution_note'], 'entity_id' => $contribution->id, 'contact_id' => $contribution->contact_id, 'modified_date' => date('Ymd'));
         CRM_Core_BAO_Note::add($noteParams, array());
     }
     if (isset($params['related_contact'])) {
         $contactID = $params['related_contact'];
     } elseif (isset($params['cms_contactID'])) {
         $contactID = $params['cms_contactID'];
     }
     //create contribution activity w/ individual and target
     //activity w/ organisation contact id when onbelf, CRM-4027
     $targetContactID = NULL;
     if (!empty($params['hidden_onbehalf_profile'])) {
         $targetContactID = $contribution->contact_id;
         $contribution->contact_id = $contactID;
     }
     // create an activity record
     if ($contribution) {
         CRM_Activity_BAO_Activity::addActivity($contribution, NULL, $targetContactID);
     }
     $transaction->commit();
     // CRM-13074 - create the CMSUser after the transaction is completed as it
     // is not appropriate to delete a valid contribution if a user create problem occurs
     CRM_Contribute_BAO_Contribution_Utils::createCMSUser($params, $contactID, 'email-' . $form->_bltID);
     return $contribution;
 }
Example #20
0
/**
 * Get all descendents of given note
 *
 * @param array $params Associative array; only required 'id' parameter is used
 *
 * @return array Nested associative array beginning with direct children of given note.
 */
function &civicrm_api3_note_tree_get($params)
{
    civicrm_api3_verify_mandatory($params, NULL, array('id'));
    if (!is_numeric($params['id'])) {
        return civicrm_api3_create_error(ts("Invalid note ID"));
    }
    if (!isset($params['max_depth'])) {
        $params['max_depth'] = 0;
    }
    if (!isset($params['snippet'])) {
        $params['snippet'] = FALSE;
    }
    $noteTree = CRM_Core_BAO_Note::getNoteTree($params['id'], $params['max_depth'], $params['snippet']);
    return civicrm_api3_create_success($noteTree, $params);
}
 /**
  * @param int $id
  * @param $values
  */
 public function buildValuesAndAssignOnline_Note_Type($id, &$values)
 {
     $ids = array();
     $params = array('id' => $id);
     CRM_Contribute_BAO_Contribution::getValues($params, $values, $ids);
     //Check if this is an online transaction (financial_trxn.payment_processor_id NOT NULL)
     $this->_online = FALSE;
     $fids = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($id);
     if (!empty($fids['financialTrxnId'])) {
         $this->_online = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $fids['financialTrxnId'], 'payment_processor_id');
     }
     // Also don't allow user to update some fields for recurring contributions.
     if (!$this->_online) {
         $this->_online = CRM_Utils_Array::value('contribution_recur_id', $values);
     }
     $this->assign('isOnline', $this->_online ? TRUE : FALSE);
     //to get note id
     $daoNote = new CRM_Core_BAO_Note();
     $daoNote->entity_table = 'civicrm_contribution';
     $daoNote->entity_id = $id;
     if ($daoNote->find(TRUE)) {
         $this->_noteID = $daoNote->id;
         $values['note'] = $daoNote->note;
     }
     $this->_contributionType = $values['financial_type_id'];
 }
Example #22
0
 /**
  * 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;
 }
Example #23
0
 /**
  * Process the contribution.
  *
  * @param CRM_Core_Form $form
  * @param array $params
  * @param array $result
  * @param array $contributionParams
  *   Parameters to be passed to contribution create action.
  *   This differs from params in that we are currently adding params to it and 1) ensuring they are being
  *   passed consistently & 2) documenting them here.
  *   - contact_id
  *   - line_item
  *   - is_test
  *   - campaign_id
  *   - contribution_page_id
  *   - source
  *   - payment_type_id
  *   - thankyou_date (not all forms will set this)
  *
  * @param CRM_Financial_DAO_FinancialType $financialType
  * @param bool $online
  *   Is the form a front end form? If so set a bunch of unpredictable things that should be passed in from the form.
  *
  * @param int $billingLocationID
  *   ID of billing location type.
  * @param bool $isRecur
  *   Is this recurring?
  *
  * @return \CRM_Contribute_DAO_Contribution
  * @throws \Exception
  */
 public static function processFormContribution(&$form, $params, $result, $contributionParams, $financialType, $online, $billingLocationID, $isRecur)
 {
     $transaction = new CRM_Core_Transaction();
     $contactID = $contributionParams['contact_id'];
     $isEmailReceipt = !empty($form->_values['is_email_receipt']);
     $isSeparateMembershipPayment = empty($params['separate_membership_payment']) ? FALSE : TRUE;
     $pledgeID = !empty($params['pledge_id']) ? $params['pledge_id'] : CRM_Utils_Array::value('pledge_id', $form->_values);
     if (!$isSeparateMembershipPayment && !empty($form->_values['pledge_block_id']) && (!empty($params['is_pledge']) || $pledgeID)) {
         $isPledge = TRUE;
     } else {
         $isPledge = FALSE;
     }
     // add these values for the recurringContrib function ,CRM-10188
     $params['financial_type_id'] = $financialType->id;
     $contributionParams['address_id'] = CRM_Contribute_BAO_Contribution::createAddress($params, $billingLocationID);
     //@todo - this is being set from the form to resolve CRM-10188 - an
     // eNotice caused by it not being set @ the front end
     // however, we then get it being over-written with null for backend contributions
     // a better fix would be to set the values in the respective forms rather than require
     // a function being shared by two forms to deal with their respective values
     // moving it to the BAO & not taking the $form as a param would make sense here.
     if (!isset($params['is_email_receipt']) && $isEmailReceipt) {
         $params['is_email_receipt'] = $isEmailReceipt;
     }
     $params['is_recur'] = $isRecur;
     $recurringContributionID = self::processRecurringContribution($form, $params, $contactID, $financialType);
     $nonDeductibleAmount = self::getNonDeductibleAmount($params, $financialType, $online);
     $now = date('YmdHis');
     $receiptDate = CRM_Utils_Array::value('receipt_date', $params);
     if ($isEmailReceipt) {
         $receiptDate = $now;
     }
     if (isset($params['amount'])) {
         $contributionParams = array_merge(self::getContributionParams($params, $financialType->id, $nonDeductibleAmount, TRUE, $result, $receiptDate, $recurringContributionID), $contributionParams);
         $contribution = CRM_Contribute_BAO_Contribution::add($contributionParams);
         $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
         $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
         if ($invoicing) {
             $dataArray = array();
             // @todo - interrogate the line items passed in on the params array.
             // No reason to assume line items will be set on the form.
             foreach ($form->_lineItem as $lineItemKey => $lineItemValue) {
                 foreach ($lineItemValue as $key => $value) {
                     if (isset($value['tax_amount']) && isset($value['tax_rate'])) {
                         if (isset($dataArray[$value['tax_rate']])) {
                             $dataArray[$value['tax_rate']] = $dataArray[$value['tax_rate']] + CRM_Utils_Array::value('tax_amount', $value);
                         } else {
                             $dataArray[$value['tax_rate']] = CRM_Utils_Array::value('tax_amount', $value);
                         }
                     }
                 }
             }
             $smarty = CRM_Core_Smarty::singleton();
             $smarty->assign('dataArray', $dataArray);
             $smarty->assign('totalTaxAmount', $params['tax_amount']);
         }
         if (is_a($contribution, 'CRM_Core_Error')) {
             $message = CRM_Core_Error::getMessages($contribution);
             CRM_Core_Error::fatal($message);
         }
         // lets store it in the form variable so postProcess hook can get to this and use it
         $form->_contributionID = $contribution->id;
     }
     // process soft credit / pcp params first
     CRM_Contribute_BAO_ContributionSoft::formatSoftCreditParams($params, $form);
     //CRM-13981, processing honor contact into soft-credit contribution
     CRM_Contribute_BAO_ContributionSoft::processSoftContribution($params, $contribution);
     //handle pledge stuff.
     if ($isPledge) {
         if ($pledgeID) {
             //when user doing pledge payments.
             //update the schedule when payment(s) are made
             $amount = $params['amount'];
             $pledgePaymentParams = array();
             foreach ($params['pledge_amount'] as $paymentId => $dontCare) {
                 $scheduledAmount = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $paymentId, 'scheduled_amount', 'id');
                 $pledgePayment = $amount >= $scheduledAmount ? $scheduledAmount : $amount;
                 if ($pledgePayment > 0) {
                     $pledgePaymentParams[] = array('id' => $paymentId, 'contribution_id' => $contribution->id, 'status_id' => $contribution->contribution_status_id, 'actual_amount' => $pledgePayment);
                     $amount -= $pledgePayment;
                 }
             }
             if ($amount > 0 && count($pledgePaymentParams)) {
                 $pledgePaymentParams[count($pledgePaymentParams) - 1]['actual_amount'] += $amount;
             }
             foreach ($pledgePaymentParams as $p) {
                 CRM_Pledge_BAO_PledgePayment::add($p);
             }
             //update pledge status according to the new payment statuses
             CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($pledgeID);
         } else {
             //when user creating pledge record.
             $pledgeParams = array();
             $pledgeParams['contact_id'] = $contribution->contact_id;
             $pledgeParams['installment_amount'] = $pledgeParams['actual_amount'] = $contribution->total_amount;
             $pledgeParams['contribution_id'] = $contribution->id;
             $pledgeParams['contribution_page_id'] = $contribution->contribution_page_id;
             $pledgeParams['financial_type_id'] = $contribution->financial_type_id;
             $pledgeParams['frequency_interval'] = $params['pledge_frequency_interval'];
             $pledgeParams['installments'] = $params['pledge_installments'];
             $pledgeParams['frequency_unit'] = $params['pledge_frequency_unit'];
             if ($pledgeParams['frequency_unit'] == 'month') {
                 $pledgeParams['frequency_day'] = intval(date("d"));
             } else {
                 $pledgeParams['frequency_day'] = 1;
             }
             $pledgeParams['create_date'] = $pledgeParams['start_date'] = $pledgeParams['scheduled_date'] = date("Ymd");
             $pledgeParams['status_id'] = $contribution->contribution_status_id;
             $pledgeParams['max_reminders'] = $form->_values['max_reminders'];
             $pledgeParams['initial_reminder_day'] = $form->_values['initial_reminder_day'];
             $pledgeParams['additional_reminder_day'] = $form->_values['additional_reminder_day'];
             $pledgeParams['is_test'] = $contribution->is_test;
             $pledgeParams['acknowledge_date'] = date('Ymd');
             $pledgeParams['original_installment_amount'] = $pledgeParams['installment_amount'];
             //inherit campaign from contirb page.
             $pledgeParams['campaign_id'] = CRM_Utils_Array::value('campaign_id', $contributionParams);
             $pledge = CRM_Pledge_BAO_Pledge::create($pledgeParams);
             $form->_params['pledge_id'] = $pledge->id;
             //send acknowledgment email. only when pledge is created
             if ($pledge->id) {
                 //build params to send acknowledgment.
                 $pledgeParams['id'] = $pledge->id;
                 $pledgeParams['receipt_from_name'] = $form->_values['receipt_from_name'];
                 $pledgeParams['receipt_from_email'] = $form->_values['receipt_from_email'];
                 //scheduled amount will be same as installment_amount.
                 $pledgeParams['scheduled_amount'] = $pledgeParams['installment_amount'];
                 //get total pledge amount.
                 $pledgeParams['total_pledge_amount'] = $pledge->amount;
                 CRM_Pledge_BAO_Pledge::sendAcknowledgment($form, $pledgeParams);
             }
         }
     }
     if ($online && $contribution) {
         CRM_Core_BAO_CustomValueTable::postProcess($params, 'civicrm_contribution', $contribution->id, 'Contribution');
     } elseif ($contribution) {
         //handle custom data.
         $params['contribution_id'] = $contribution->id;
         if (!empty($params['custom']) && is_array($params['custom']) && !is_a($contribution, 'CRM_Core_Error')) {
             CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_contribution', $contribution->id);
         }
     }
     // Save note
     if ($contribution && !empty($params['contribution_note'])) {
         $noteParams = array('entity_table' => 'civicrm_contribution', 'note' => $params['contribution_note'], 'entity_id' => $contribution->id, 'contact_id' => $contribution->contact_id, 'modified_date' => date('Ymd'));
         CRM_Core_BAO_Note::add($noteParams, array());
     }
     if (isset($params['related_contact'])) {
         $contactID = $params['related_contact'];
     } elseif (isset($params['cms_contactID'])) {
         $contactID = $params['cms_contactID'];
     }
     //create contribution activity w/ individual and target
     //activity w/ organisation contact id when onbelf, CRM-4027
     $targetContactID = NULL;
     if (!empty($params['hidden_onbehalf_profile'])) {
         $targetContactID = $contribution->contact_id;
         $contribution->contact_id = $contactID;
     }
     // create an activity record
     if ($contribution) {
         CRM_Activity_BAO_Activity::addActivity($contribution, NULL, $targetContactID);
     }
     $transaction->commit();
     // CRM-13074 - create the CMSUser after the transaction is completed as it
     // is not appropriate to delete a valid contribution if a user create problem occurs
     CRM_Contribute_BAO_Contribution_Utils::createCMSUser($params, $contactID, 'email-' . $billingLocationID);
     return $contribution;
 }
Example #24
0
 /**
  * Given the list of params in the params array, fetch the object
  * and store the values in the values array
  *
  * @param array $params
  *   Input parameters to find object.
  * @param array $values
  *   Output values of the object.
  * @param int $numNotes
  *   The maximum number of notes to return (0 if all).
  *
  * @return object
  *   $notes  Object of CRM_Core_BAO_Note
  */
 public static function &getValues(&$params, &$values, $numNotes = self::MAX_NOTES)
 {
     if (empty($params)) {
         return NULL;
     }
     $note = new CRM_Core_BAO_Note();
     $note->entity_id = $params['contact_id'];
     $note->entity_table = 'civicrm_contact';
     // get the total count of notes
     $values['noteTotalCount'] = $note->count();
     // get only 3 recent notes
     $note->orderBy('modified_date desc');
     $note->limit($numNotes);
     $note->find();
     $notes = array();
     $count = 0;
     while ($note->fetch()) {
         $values['note'][$note->id] = array();
         CRM_Core_DAO::storeValues($note, $values['note'][$note->id]);
         $notes[] = $note;
         $count++;
         // if we have collected the number of notes, exit loop
         if ($numNotes > 0 && $count >= $numNotes) {
             break;
         }
     }
     return $notes;
 }
Example #25
0
 /**
  * Test case for retrieve( ).
  *
  * Test with all values.
  */
 public function testRetrieve()
 {
     //take the common contact params
     $params = $this->contactParams();
     $params['note'] = 'test note';
     //create the contact with given params.
     $contact = CRM_Contact_BAO_Contact::create($params);
     //Now check $contact is object of contact DAO..
     $this->assertInstanceOf('CRM_Contact_DAO_Contact', $contact, 'Check for created object');
     $contactId = $contact->id;
     //create the organization contact with the given params.
     $orgParams = array('organization_name' => 'Test Organization ' . substr(sha1(rand()), 0, 4), 'contact_type' => 'Organization');
     $orgContact = CRM_Contact_BAO_Contact::add($orgParams);
     $this->assertInstanceOf('CRM_Contact_DAO_Contact', $orgContact, 'Check for created object');
     //create employee of relationship.
     CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($contactId, $orgContact->id);
     //retrieve the contact values from database.
     $values = array();
     $searchParams = array('contact_id' => $contactId);
     $retrieveContact = CRM_Contact_BAO_Contact::retrieve($searchParams, $values);
     //Now check $retrieveContact is object of contact DAO..
     $this->assertInstanceOf('CRM_Contact_DAO_Contact', $retrieveContact, 'Check for retrieve object');
     //Now check the ids.
     $this->assertEquals($contactId, $retrieveContact->id, 'Check for contact id');
     //Now check values retrieve from database with params.
     $this->assertEquals($params['first_name'], $values['first_name'], 'Check for first name creation.');
     $this->assertEquals($params['last_name'], $values['last_name'], 'Check for last name creation.');
     $this->assertEquals($params['contact_type'], $values['contact_type'], 'Check for contact type creation.');
     //Now check values of address
     $this->assertAttributesEquals(CRM_Utils_Array::value('1', $params['address']), CRM_Utils_Array::value('1', $values['address']));
     //Now check values of email
     $this->assertAttributesEquals(CRM_Utils_Array::value('1', $params['email']), CRM_Utils_Array::value('1', $values['email']));
     //Now check values of phone
     $this->assertAttributesEquals(CRM_Utils_Array::value('1', $params['phone']), CRM_Utils_Array::value('1', $values['phone']));
     //Now check values of mobile
     $this->assertAttributesEquals(CRM_Utils_Array::value('2', $params['phone']), CRM_Utils_Array::value('2', $values['phone']));
     //Now check values of openid
     $this->assertAttributesEquals(CRM_Utils_Array::value('1', $params['openid']), CRM_Utils_Array::value('1', $values['openid']));
     //Now check values of im
     $this->assertAttributesEquals(CRM_Utils_Array::value('1', $params['im']), CRM_Utils_Array::value('1', $values['im']));
     //Now check values of Note Count.
     $this->assertEquals(1, $values['noteTotalCount'], 'Check for total note count');
     foreach ($values['note'] as $key => $val) {
         $retrieveNote = CRM_Utils_Array::value('note', $val);
         //check the note value
         $this->assertEquals($params['note'], $retrieveNote, 'Check for note');
     }
     //Now check values of Relationship Count.
     $this->assertEquals(1, $values['relationship']['totalCount'], 'Check for total relationship count');
     foreach ($values['relationship']['data'] as $key => $val) {
         //Now check values of Relationship organization.
         $this->assertEquals($orgContact->id, $val['contact_id_b'], 'Check for organization');
         //Now check values of Relationship type.
         $this->assertEquals('Employee of', $val['relation'], 'Check for relationship type');
         //delete the organization.
         $this->contactDelete(CRM_Utils_Array::value('contact_id_b', $val));
     }
     //delete all notes related to contact
     CRM_Core_BAO_Note::cleanContactNotes($contactId);
     //cleanup DB by deleting the contact
     $this->contactDelete($contactId);
     $this->quickCleanup(array('civicrm_contact'));
 }
Example #26
0
 /**
  * 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);
 }
 /**
  * takes an associative array and creates a contribution object
  *
  * @param array $params (reference ) an assoc array of name/value pairs
  * @param array $ids    the array that holds all the db ids
  *
  * @return object CRM_Contribute_BAO_Contribution object 
  * @access public
  * @static
  */
 static function &create(&$params, &$ids)
 {
     require_once 'CRM/Utils/Money.php';
     require_once 'CRM/Utils/Date.php';
     require_once 'CRM/Contribute/PseudoConstant.php';
     // FIXME: a cludgy hack to fix the dates to MySQL format
     $dateFields = array('receive_date', 'cancel_date', 'receipt_date', 'thankyou_date');
     foreach ($dateFields as $df) {
         if (isset($params[$df])) {
             $params[$df] = CRM_Utils_Date::isoToMysql($params[$df]);
         }
     }
     require_once 'CRM/Core/Transaction.php';
     $transaction = new CRM_Core_Transaction();
     $contribution = self::add($params, $ids);
     if (is_a($contribution, 'CRM_Core_Error')) {
         $transaction->rollback();
         return $contribution;
     }
     $params['contribution_id'] = $contribution->id;
     if (CRM_Utils_Array::value('custom', $params) && is_array($params['custom'])) {
         require_once 'CRM/Core/BAO/CustomValueTable.php';
         CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_contribution', $contribution->id);
     }
     $session =& CRM_Core_Session::singleton();
     if (CRM_Utils_Array::value('note', $params)) {
         require_once 'CRM/Core/BAO/Note.php';
         $noteParams = array('entity_table' => 'civicrm_contribution', 'note' => $params['note'], 'entity_id' => $contribution->id, 'contact_id' => $session->get('userID'), 'modified_date' => date('Ymd'));
         if (!$noteParams['contact_id']) {
             $noteParams['contact_id'] = $params['contact_id'];
         }
         CRM_Core_BAO_Note::add($noteParams, CRM_Utils_Array::value('note', $ids));
     }
     // check if activity record exist for this contribution, if
     // not add activity
     require_once "CRM/Activity/DAO/Activity.php";
     $activity = new CRM_Activity_DAO_Activity();
     $activity->source_record_id = $contribution->id;
     $activity->activity_type_id = CRM_Core_OptionGroup::getValue('activity_type', 'Contribution', 'name');
     if (!$activity->find()) {
         require_once "CRM/Activity/BAO/Activity.php";
         CRM_Activity_BAO_Activity::addActivity($contribution, 'Offline');
     }
     if (CRM_Utils_Array::value('soft_credit_to', $params)) {
         $csParams = array();
         if ($id = CRM_Utils_Array::value('softID', $params)) {
             $csParams['id'] = $params['softID'];
         }
         $csParams['pcp_display_in_roll'] = $params['pcp_display_in_roll'] ? 1 : 0;
         foreach (array('pcp_roll_nickname', 'pcp_personal_note') as $val) {
             if (CRM_Utils_Array::value($val, $params)) {
                 $csParams[$val] = $params[$val];
             }
         }
         $csParams['contribution_id'] = $contribution->id;
         $csParams['contact_id'] = $params['soft_credit_to'];
         // first stage: we register whole amount as credited to given person
         $csParams['amount'] = $contribution->total_amount;
         self::addSoftContribution($csParams);
     }
     $transaction->commit();
     // do not add to recent items for import, CRM-4399
     if (!CRM_Utils_Array::value('skipRecentView', $params)) {
         require_once 'CRM/Utils/Recent.php';
         require_once 'CRM/Contribute/PseudoConstant.php';
         require_once 'CRM/Contact/BAO/Contact.php';
         $url = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=view&reset=1&id={$contribution->id}&cid={$contribution->contact_id}&context=home");
         $contributionTypes = CRM_Contribute_PseudoConstant::contributionType();
         $title = CRM_Contact_BAO_Contact::displayName($contribution->contact_id) . ' - (' . CRM_Utils_Money::format($contribution->total_amount, $contribution->currency) . ' ' . ' - ' . $contributionTypes[$contribution->contribution_type_id] . ')';
         $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={$contribution->id}&cid={$contribution->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={$contribution->id}&cid={$contribution->contact_id}&context=home");
         }
         // add the recently created Contribution
         CRM_Utils_Recent::add($title, $url, $contribution->id, 'Contribution', $contribution->contact_id, null, $recentOther);
     }
     return $contribution;
 }
Example #28
0
 /**
  * setDefault componet specific profile fields.
  *
  * @param array $fields
  *   Profile fields.
  * @param int $componentId
  *   ComponetID.
  * @param string $component
  *   Component name.
  * @param array $defaults
  *   An array of default values.
  *
  * @param bool $isStandalone
  */
 public static function setComponentDefaults(&$fields, $componentId, $component, &$defaults, $isStandalone = FALSE)
 {
     if (!$componentId || !in_array($component, array('Contribute', 'Membership', 'Event', 'Activity'))) {
         return;
     }
     $componentBAO = $componentSubType = NULL;
     switch ($component) {
         case 'Membership':
             $componentBAO = 'CRM_Member_BAO_Membership';
             $componentBAOName = 'Membership';
             $componentSubType = array('membership_type_id');
             break;
         case 'Contribute':
             $componentBAO = 'CRM_Contribute_BAO_Contribution';
             $componentBAOName = 'Contribution';
             $componentSubType = array('financial_type_id');
             break;
         case 'Event':
             $componentBAO = 'CRM_Event_BAO_Participant';
             $componentBAOName = 'Participant';
             $componentSubType = array('role_id', 'event_id', 'event_type_id');
             break;
         case 'Activity':
             $componentBAO = 'CRM_Activity_BAO_Activity';
             $componentBAOName = 'Activity';
             $componentSubType = array('activity_type_id');
             break;
     }
     $values = array();
     $params = array('id' => $componentId);
     //get the component values.
     CRM_Core_DAO::commonRetrieve($componentBAO, $params, $values);
     if ($componentBAOName == 'Participant') {
         $values += array('event_type_id' => CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $values['event_id'], 'event_type_id'));
     }
     $formattedGroupTree = array();
     $dateTimeFields = array('participant_register_date', 'activity_date_time', 'receive_date', 'receipt_date', 'cancel_date', 'thankyou_date', 'membership_start_date', 'membership_end_date', 'join_date');
     foreach ($fields as $name => $field) {
         $fldName = $isStandalone ? $name : "field[{$componentId}][{$name}]";
         if (in_array($name, $dateTimeFields)) {
             $timefldName = $isStandalone ? "{$name}_time" : "field[{$componentId}][{$name}_time]";
             if (!empty($values[$name])) {
                 list($defaults[$fldName], $defaults[$timefldName]) = CRM_Utils_Date::setDateDefaults($values[$name]);
             }
         } elseif (array_key_exists($name, $values)) {
             $defaults[$fldName] = $values[$name];
         } elseif ($name == 'participant_note') {
             $noteDetails = CRM_Core_BAO_Note::getNote($componentId, 'civicrm_participant');
             $defaults[$fldName] = array_pop($noteDetails);
         } elseif (in_array($name, array('financial_type', 'payment_instrument', 'participant_status', 'participant_role'))) {
             $defaults[$fldName] = $values["{$name}_id"];
         } elseif ($name == 'membership_type') {
             // since membership_type field is a hierselect -
             $defaults[$fldName][0] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $values['membership_type_id'], 'member_of_contact_id', 'id');
             $defaults[$fldName][1] = $values['membership_type_id'];
         } elseif ($name == 'membership_status') {
             $defaults[$fldName] = $values['status_id'];
         } elseif ($customFieldInfo = CRM_Core_BAO_CustomField::getKeyID($name, TRUE)) {
             if (empty($formattedGroupTree)) {
                 //get the groupTree as per subTypes.
                 $groupTree = array();
                 foreach ($componentSubType as $subType) {
                     $subTree = CRM_Core_BAO_CustomGroup::getTree($componentBAOName, CRM_Core_DAO::$_nullObject, $componentId, 0, $values[$subType]);
                     $groupTree = CRM_Utils_Array::crmArrayMerge($groupTree, $subTree);
                 }
                 $formattedGroupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, CRM_Core_DAO::$_nullObject);
                 CRM_Core_BAO_CustomGroup::setDefaults($formattedGroupTree, $defaults);
             }
             //FIX ME: We need to loop defaults, but once we move to custom_1_x convention this code can be simplified.
             foreach ($defaults as $customKey => $customValue) {
                 if ($customFieldDetails = CRM_Core_BAO_CustomField::getKeyID($customKey, TRUE)) {
                     if ($name == 'custom_' . $customFieldDetails[0]) {
                         //hack to set default for checkbox
                         //basically this is for weired field name like field[33][custom_19]
                         //we are converting this field name to array structure and assign value.
                         $skipValue = FALSE;
                         foreach ($formattedGroupTree as $tree) {
                             if (!empty($tree['fields'][$customFieldDetails[0]])) {
                                 if ('CheckBox' == CRM_Utils_Array::value('html_type', $tree['fields'][$customFieldDetails[0]])) {
                                     $skipValue = TRUE;
                                     $defaults['field'][$componentId][$name] = $customValue;
                                     break;
                                 } elseif (CRM_Utils_Array::value('data_type', $tree['fields'][$customFieldDetails[0]]) == 'Date') {
                                     $skipValue = TRUE;
                                     // CRM-6681, $default contains formatted date, time values.
                                     $defaults[$fldName] = $customValue;
                                     if (!empty($defaults[$customKey . '_time'])) {
                                         $defaults['field'][$componentId][$name . '_time'] = $defaults[$customKey . '_time'];
                                     }
                                 }
                             }
                         }
                         if (!$skipValue || $isStandalone) {
                             $defaults[$fldName] = $customValue;
                         }
                         unset($defaults[$customKey]);
                         break;
                     }
                 }
             }
         }
     }
 }
Example #29
0
 /**
  * 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;
 }
Example #30
0
 /**
  * This function sets the default values for the form in edit/view mode
  * the default values are retrieved from the database
  * 
  * @access public
  * @return None
  */
 public function setDefaultValues()
 {
     if ($this->_showFeeBlock) {
         return CRM_Event_Form_EventFees::setDefaultValues($this);
     }
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     $defaults = array();
     if ($this->_action & CRM_Core_Action::DELETE) {
         return $defaults;
     }
     if ($this->_participantId) {
         $ids = array();
         $params = array('id' => $this->_participantId);
         require_once "CRM/Event/BAO/Participant.php";
         CRM_Event_BAO_Participant::getValues($params, $defaults, $ids);
         $this->_contactID = $defaults[$this->_participantId]['contact_id'];
         $this->_statusId = $defaults[$this->_participantId]['participant_status_id'];
         //set defaults for note
         $noteDetails = CRM_Core_BAO_Note::getNote($this->_participantId, 'civicrm_participant');
         $defaults[$this->_participantId]['note'] = array_pop($noteDetails);
     }
     if ($this->_action & (CRM_Core_Action::VIEW | CRM_Core_Action::BROWSE)) {
         $inactiveNeeded = true;
         $viewMode = true;
     } else {
         $viewMode = false;
         $inactiveNeeded = false;
     }
     //setting default register date
     if ($this->_action == CRM_Core_Action::ADD) {
         if (CRM_Utils_Array::value('event_id', $defaults[$this->_participantId])) {
             $contributionTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $defaults[$this->_participantId]['event_id'], 'contribution_type_id');
             if ($contributionTypeId) {
                 $defaults[$this->_participantId]['contribution_type_id'] = $contributionTypeId;
             }
         }
         if ($this->_mode) {
             $fields["email-{$this->_bltID}"] = 1;
             $fields["email-Primary"] = 1;
             require_once "CRM/Core/BAO/UFGroup.php";
             if ($this->_contactID) {
                 require_once "CRM/Core/BAO/UFGroup.php";
                 CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactID, $fields, $defaults);
             }
             if (empty($defaults["email-{$this->_bltID}"]) && !empty($defaults["email-Primary"])) {
                 $defaults[$this->_participantId]["email-{$this->_bltID}"] = $defaults["email-Primary"];
             }
         }
         $submittedRole = $this->getElementValue('role_id');
         if ($submittedRole[0]) {
             $roleID = $submittedRole[0];
         }
         $submittedEvent = $this->getElementValue('event_id');
         if ($submittedEvent[0]) {
             $eventID = $submittedEvent[0];
         }
     } else {
         $defaults[$this->_participantId]['record_contribution'] = 0;
         $recordContribution = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $defaults[$this->_participantId]['id'], 'contribution_id', 'participant_id');
         //contribution record exists for this participation
         if ($recordContribution) {
             foreach (array('contribution_type_id', 'payment_instrument_id', 'contribution_status_id', 'receive_date') as $field) {
                 $defaults[$this->_participantId][$field] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $recordContribution, $field);
             }
         }
         if ($defaults[$this->_participantId]['participant_is_pay_later']) {
             $this->assign('participant_is_pay_later', true);
         }
         $this->assign('participant_status_id', $defaults[$this->_participantId]['participant_status_id']);
         $roleID = $defaults[$this->_participantId]['participant_role_id'];
         $eventID = $defaults[$this->_participantId]['event_id'];
         $this->_discountId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_participantId, 'discount_id');
         if ($this->_discountId) {
             $this->set('discountId', $this->_discountId);
         }
     }
     list($defaults[$this->_participantId]['register_date'], $defaults[$this->_participantId]['register_date_time']) = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value('register_date', $defaults[$this->_participantId]));
     //assign event and role id, this is needed for Custom data building
     if (isset($_POST['role_id'])) {
         $roleID = $_POST['role_id'];
     }
     if (isset($roleID)) {
         $this->assign('roleID', $roleID);
     }
     if (isset($_POST['event_id'])) {
         $eventID = $_POST['event_id'];
     }
     if (isset($eventID)) {
         $this->assign('eventID', $eventID);
         $this->set('eventId', $eventID);
     }
     $this->assign('event_is_test', CRM_Utils_Array::value('event_is_test', $defaults[$this->_participantId]));
     return $defaults[$this->_participantId];
 }