/** * Function to delete discount codes track * * @param int $trackID ID of the discount code track to be deleted. * * @access public * @static * @return true on success else false */ static function del($trackID) { if (!CRM_Utils_Rule::positiveInteger($trackID)) { return FALSE; } $item = new CRM_CiviDiscount_DAO_Track(); $item->id = $trackID; $item->delete(); return TRUE; }
/** * Implementation of hook_civicrm_postProcess() * * Record information about a discount use. */ function cividiscount_civicrm_postProcess($class, &$form) { if (!in_array($class, array('CRM_Contribute_Form_Contribution_Confirm', 'CRM_Event_Form_Participant', 'CRM_Event_Form_Registration_Confirm', 'CRM_Member_Form_Membership', 'CRM_Member_Form_MembershipRenewal', 'CRM_Event_Form_ParticipantFeeSelection'))) { return; } $discountInfo = $form->get('_discountInfo'); if (!$discountInfo) { return; } $ts = CRM_Utils_Time::getTime(); $discount = $discountInfo['discount']; $params = $form->getVar('_params'); $description = CRM_Utils_Array::value('amount_level', $params); // Online event registration. // Note that CRM_Event_Form_Registration_Register is an intermediate form. // CRM_Event_Form_Registration_Confirm completes the transaction. if ($class == 'CRM_Event_Form_Registration_Confirm') { $pids = $form->getVar('_participantIDS'); // if multiple participant discount is not enabled then only use primary participant info for discount // and ignore additional participants if (!_cividiscount_allow_multiple()) { $pids = array($pids[0]); } foreach ($pids as $pid) { $participant = _cividiscount_get_participant($pid); $contact_id = $participant['contact_id']; $participant_payment = _cividiscount_get_participant_payment($pid); $contribution_id = $participant_payment['contribution_id']; CRM_CiviDiscount_BAO_Item::incrementUsage($discount['id']); $track = new CRM_CiviDiscount_DAO_Track(); $track->item_id = $discount['id']; $track->contact_id = $contact_id; $track->contribution_id = $contribution_id; $track->entity_table = 'civicrm_participant'; $track->entity_id = $pid; $track->used_date = $ts; $track->description = $description; $track->save(); } // Online membership. // Note that CRM_Contribute_Form_Contribution_Main is an intermediate // form - CRM_Contribute_Form_Contribution_Confirm completes the // transaction. } else { if ($class == 'CRM_Contribute_Form_Contribution_Confirm') { $membership_type = $params['selectMembership']; $membershipId = $params['membershipID']; if (!is_array($membership_type)) { $membership_type = array($membership_type); } $discount_membership_matches = array_intersect($membership_type, $discount['memberships']); // check to make sure the discount actually applied to this membership. if (empty($discount_membership_matches) || !$membershipId) { return; } $description = CRM_Utils_Array::value('description', $params); $membership = _cividiscount_get_membership($membershipId); $contact_id = $membership['contact_id']; $membership_payment = _cividiscount_get_membership_payment($membershipId); $contribution_id = $membership_payment['contribution_id']; CRM_CiviDiscount_BAO_Item::incrementUsage($discount['id']); $track = new CRM_CiviDiscount_DAO_Track(); $track->item_id = $discount['id']; $track->contact_id = $contact_id; $track->contribution_id = $contribution_id; $track->entity_table = 'civicrm_membership'; $track->entity_id = $membershipId; $track->used_date = $ts; $track->description = $description; $track->save(); } else { $contribution_id = NULL; // Offline event registration. if (in_array($class, array('CRM_Event_Form_Participant', 'CRM_Event_Form_ParticipantFeeSelection'))) { if ($class == 'CRM_Event_Form_ParticipantFeeSelection') { $entity_id = $form->getVar('_participantId'); } else { $entity_id = $form->getVar('_id'); } $participant_payment = _cividiscount_get_participant_payment($entity_id); $contribution_id = $participant_payment['contribution_id']; $entity_table = 'civicrm_participant'; $participant = _cividiscount_get_participant($entity_id); $contact_id = $participant['contact_id']; } elseif (in_array($class, array('CRM_Member_Form_Membership', 'CRM_Member_Form_MembershipRenewal'))) { $membership_types = $form->getVar('_memTypeSelected'); $membership_type = isset($membership_types[0]) ? $membership_types[0] : NULL; if (!$membership_type) { $membership_type = $form->getVar('_memType'); } // Check to make sure the discount actually applied to this membership. if (!CRM_Utils_Array::value($membership_type, $discount['memberships'])) { return; } $entity_table = 'civicrm_membership'; $entity_id = $form->getVar('_id'); $membership_payment = _cividiscount_get_membership_payment($entity_id); $contribution_id = $membership_payment['contribution_id']; $description = CRM_Utils_Array::value('description', $params); $membership = _cividiscount_get_membership($entity_id); $contact_id = $membership['contact_id']; } else { $entity_table = 'civicrm_contribution'; $entity_id = $contribution_id; } CRM_CiviDiscount_BAO_Item::incrementUsage($discount['id']); $track = new CRM_CiviDiscount_DAO_Track(); $track->item_id = $discount['id']; $track->contact_id = $contact_id; $track->contribution_id = $contribution_id; $track->entity_table = $entity_table; $track->entity_id = $entity_id; $track->used_date = $ts; $track->description = $description; $track->save(); } } }
/** * returns the list of fields that can be exported * * @access public * return array */ function &export($prefix = FALSE) { if (!self::$_export) { self::$_export = array(); $fields = self::fields(); foreach ($fields as $name => $field) { if (CRM_Utils_Array::value('export', $field)) { if ($prefix) { self::$_export['ount_track'] =& $fields[$name]; } else { self::$_export[$name] =& $fields[$name]; } } } } return self::$_export; }
/** * Function to delete discount codes track * * @param int $trackID ID of the discount code track to be deleted. * * @access public * @static * @return true on success else false */ static function del($trackID) { if (!CRM_Utils_Rule::positiveInteger($trackID)) { return false; } require_once 'CRM/CiviDiscount/DAO/Track.php'; $item = new CRM_CiviDiscount_DAO_Track(); $item->id = $trackID; $item->delete(); return true; }