示例#1
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);
 }
示例#2
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);
 }
示例#4
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);
 }
示例#5
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];
 }
示例#6
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;
 }
示例#7
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];
 }
示例#8
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;
                     }
                 }
             }
         }
     }
 }
示例#9
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);
 }
示例#10
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;
 }
示例#11
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;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
示例#12
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->_id) {
         $ids = array();
         $params = array('id' => $this->_id);
         require_once "CRM/Event/BAO/Participant.php";
         CRM_Event_BAO_Participant::getValues($params, $defaults, $ids);
         $sep = CRM_Core_DAO::VALUE_SEPARATOR;
         if ($defaults[$this->_id]['role_id']) {
             foreach (explode($sep, $defaults[$this->_id]['role_id']) as $k => $v) {
                 $defaults[$this->_id]["role_id[{$v}]"] = 1;
             }
             unset($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 (CRM_Utils_Array::value('participant_registered_by_id', $defaults[$this->_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);
             require_once 'CRM/Contact/BAO/Contact.php';
             $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 (CRM_Utils_Array::value('event_id', $defaults[$this->_id])) {
             $contributionTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $defaults[$this->_id]['event_id'], 'contribution_type_id');
             if ($contributionTypeId) {
                 $defaults[$this->_id]['contribution_type_id'] = $contributionTypeId;
             }
         }
         if ($this->_mode) {
             $fields["email-{$this->_bltID}"] = 1;
             $fields["email-Primary"] = 1;
             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->_id]["email-{$this->_bltID}"] = $defaults["email-Primary"];
             }
         }
         $submittedRole = $this->getElementValue('role_id');
         if (CRM_Utils_Array::value(0, $submittedRole)) {
             $roleID = $submittedRole[0];
         }
         $submittedEvent = $this->getElementValue('event_id');
         if ($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']);
         $roleID = $defaults[$this->_id]['participant_role_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 (CRM_Utils_Array::value('participant_role_id', $defaults[$this->_id])) {
         $roleIDs = explode($sep, $defaults[$this->_id]['participant_role_id']);
     }
     if (isset($roleIDs)) {
         $this->assign('roleID', $roleIDs);
     }
     if (isset($_POST['event_id'])) {
         $eventID = $_POST['event_id'];
         if ($eventID) {
             $this->_eventTypeId = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $eventID, 'event_type_id', 'id');
         }
     }
     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];
 }
 /**
  * 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);
     $context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('context', $context);
     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('contribution_page_id', $values)) {
         $contribPages = CRM_Contribute_PseudoConstant::contributionPage(NULL, TRUE);
         $values['contribution_page_title'] = CRM_Utils_Array::value(CRM_Utils_Array::value('contribution_page_id', $values), $contribPages);
     }
     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'] = CRM_Utils_Array::value(CRM_Utils_Array::value('honor_type_id', $values), $honor);
     }
     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) {
         $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($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);
     }
     $lineItems = array();
     if ($id) {
         $lineItem = CRM_Price_BAO_LineItem::getLineItems($id, 'contribution', 1);
         empty($lineItem) ? null : ($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);
     // 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");
     $displayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['contact_id'], 'display_name');
     $this->assign('displayName', $displayName);
     $title = $displayName . ' - (' . CRM_Utils_Money::format($values['total_amount']) . ' ' . ' - ' . $values['contribution_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);
 }
示例#14
0
文件: Note.php 项目: ksecor/civicrm
/**
 * Retrieve a specific note, given a set of input params
 *
 * @param  array   $params (reference ) input parameters
 *
 * @return array (reference ) array of properties, 
 * if error an array with an error id and error message
 * 
 * @static void
 * @access public
 */
function &civicrm_note_get(&$params)
{
    _civicrm_initialize();
    $values = array();
    if (empty($params)) {
        return civicrm_create_error(ts('No input parameters present'));
    }
    if (!is_array($params)) {
        return civicrm_create_error(ts('Input parameters is not an array'));
    }
    if (!is_numeric($params['entity_id'])) {
        return civicrm_create_error(ts("Invalid entity ID"));
    }
    if (!isset($params['entity_id']) && !isset($params['entity_table'])) {
        return civicrm_create_error('Required parameters missing.');
    }
    $note = CRM_Core_BAO_Note::getNote($params['entity_id'], $params['entity_table']);
    if (civicrm_error($note)) {
        return $note;
    }
    if (count($note) < 1) {
        return civicrm_create_error(ts('%1 notes matching the input parameters', array(1 => count($note))));
    }
    $note = array_values($note);
    $note['is_error'] = 0;
    return $note;
}
示例#15
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);
 }
示例#16
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);
 }
示例#17
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;
 }
 /**  
  * Function to set variables up before form is built  
  *                                                            
  * @return void  
  * @access public  
  */
 public function preProcess()
 {
     require_once 'CRM/Event/BAO/Participant.php';
     require_once 'CRM/Core/DAO.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'] = 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 (CRM_Utils_Array::value('participant_registered_by_id', $values[$participantID])) {
         $values[$participantID]['registered_by_contact_id'] = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Participant", $values[$participantID]['participant_registered_by_id'], 'contact_id', 'id');
         require_once 'CRM/Contact/BAO/Contact.php';
         $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);
     $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 (!CRM_Utils_Array::value('event', $values[$participantID])) {
         $values[$participantID]['event'] = $eventTitle;
     }
     $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");
     $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($contactID);
     $participantCount = array();
     foreach ($lineItem as $k => $v) {
         if (CRM_Utils_Array::value('participant_count', $lineItem[$k]) > 0) {
             $participantCount[] = $lineItem['participant_count'];
         }
     }
     if ($participantCount) {
         $this->assign('pricesetFieldsCount', $participantCount);
     }
     $this->assign('displayName', $displayName);
     $title = $displayName . ' (' . $participantRoles[$values[$participantID]['role_id']] . ' - ' . $eventTitle . ')';
     require_once 'CRM/Core/DAO.php';
     $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);
 }