コード例 #1
0
 /**
  * Function to list memberships for the UF user
  *
  * return null
  * @access public
  */
 function listMemberships()
 {
     $membership = array();
     $dao = new CRM_Member_DAO_Membership();
     $dao->contact_id = $this->_contactId;
     $dao->is_test = 0;
     $dao->find();
     while ($dao->fetch()) {
         $membership[$dao->id] = array();
         CRM_Core_DAO::storeValues($dao, $membership[$dao->id]);
         //get the membership status and type values.
         $statusANDType = CRM_Member_BAO_Membership::getStatusANDTypeValues($dao->id);
         foreach (array('status', 'membership_type') as $fld) {
             $membership[$dao->id][$fld] = CRM_Utils_Array::value($fld, $statusANDType[$dao->id]);
         }
         if (!empty($statusANDType[$dao->id]['is_current_member'])) {
             $membership[$dao->id]['active'] = TRUE;
         }
         $membership[$dao->id]['renewPageId'] = CRM_Member_BAO_Membership::getContributionPageId($dao->id);
         if (!$membership[$dao->id]['renewPageId']) {
             // Membership payment was not done via online contribution page or free membership. Check for default membership renewal page from CiviMember Settings
             $defaultRenewPageId = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MEMBER_PREFERENCES_NAME, 'default_renewal_contribution_page');
             if ($defaultRenewPageId) {
                 $membership[$dao->id]['renewPageId'] = $defaultRenewPageId;
             }
         }
     }
     $activeMembers = CRM_Member_BAO_Membership::activeMembers($membership);
     $inActiveMembers = CRM_Member_BAO_Membership::activeMembers($membership, 'inactive');
     $this->assign('activeMembers', $activeMembers);
     $this->assign('inActiveMembers', $inActiveMembers);
 }
コード例 #2
0
 /**
  * List memberships for the UF user.
  *
  */
 public function listMemberships()
 {
     $membership = array();
     $dao = new CRM_Member_DAO_Membership();
     $dao->contact_id = $this->_contactId;
     $dao->is_test = 0;
     $dao->find();
     while ($dao->fetch()) {
         $membership[$dao->id] = array();
         CRM_Core_DAO::storeValues($dao, $membership[$dao->id]);
         //get the membership status and type values.
         $statusANDType = CRM_Member_BAO_Membership::getStatusANDTypeValues($dao->id);
         foreach (array('status', 'membership_type') as $fld) {
             $membership[$dao->id][$fld] = CRM_Utils_Array::value($fld, $statusANDType[$dao->id]);
         }
         if (!empty($statusANDType[$dao->id]['is_current_member'])) {
             $membership[$dao->id]['active'] = TRUE;
         }
         $membership[$dao->id]['renewPageId'] = CRM_Member_BAO_Membership::getContributionPageId($dao->id);
         if (!$membership[$dao->id]['renewPageId']) {
             // Membership payment was not done via online contribution page or free membership. Check for default membership renewal page from CiviMember Settings
             $defaultRenewPageId = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MEMBER_PREFERENCES_NAME, 'default_renewal_contribution_page');
             if ($defaultRenewPageId) {
                 //CRM-14831 - check if membership type is present in contrib page
                 $memBlock = CRM_Member_BAO_Membership::getMembershipBlock($defaultRenewPageId);
                 if (!empty($memBlock['membership_types'])) {
                     $memTypes = explode(',', $memBlock['membership_types']);
                     if (in_array($dao->membership_type_id, $memTypes)) {
                         $membership[$dao->id]['renewPageId'] = $defaultRenewPageId;
                     }
                 }
             } else {
                 switch ($membership[$dao->id]['membership_type_id']) {
                     case "1":
                     default:
                         $membership[$dao->id]['renewPageId'] = 2;
                         break;
                     case "10":
                         $membership[$dao->id]['renewPageId'] = 19;
                         break;
                     case "11":
                         $membership[$dao->id]['renewPageId'] = 23;
                         break;
                     case "5":
                     case "9":
                         $membership[$dao->id]['renewPageId'] = 22;
                         break;
                 }
             }
         }
     }
     $activeMembers = CRM_Member_BAO_Membership::activeMembers($membership);
     $inActiveMembers = CRM_Member_BAO_Membership::activeMembers($membership, 'inactive');
     $this->assign('activeMembers', $activeMembers);
     $this->assign('inActiveMembers', $inActiveMembers);
 }
コード例 #3
0
 /**
  * This function is called when action is browse
  *
  * return null
  * @access public
  */
 function browse()
 {
     $links = self::links('all', $this->_isPaymentProcessor, $this->_accessContribution);
     $membership = array();
     $dao = new CRM_Member_DAO_Membership();
     $dao->contact_id = $this->_contactId;
     $dao->is_test = 0;
     //$dao->orderBy('name');
     $dao->find();
     //CRM--4418, check for view, edit, delete
     $permissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('edit memberships')) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('delete in CiviMember')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     // get deceased status id
     $allStatus = CRM_Member_PseudoConstant::membershipStatus();
     $deceasedStatusId = array_search('Deceased', $allStatus);
     //get all campaigns.
     $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
     //checks membership of contact itself
     while ($dao->fetch()) {
         $membership[$dao->id] = array();
         CRM_Core_DAO::storeValues($dao, $membership[$dao->id]);
         //carry campaign.
         $membership[$dao->id]['campaign'] = CRM_Utils_Array::value($dao->campaign_id, $allCampaigns);
         //get the membership status and type values.
         $statusANDType = CRM_Member_BAO_Membership::getStatusANDTypeValues($dao->id);
         foreach (array('status', 'membership_type') as $fld) {
             $membership[$dao->id][$fld] = CRM_Utils_Array::value($fld, $statusANDType[$dao->id]);
         }
         if (CRM_Utils_Array::value('is_current_member', $statusANDType[$dao->id])) {
             $membership[$dao->id]['active'] = TRUE;
         }
         if (empty($dao->owner_membership_id)) {
             // unset renew and followup link for deceased membership
             $currentMask = $mask;
             if ($dao->status_id == $deceasedStatusId) {
                 $currentMask = $currentMask & ~CRM_Core_Action::RENEW & ~CRM_Core_Action::FOLLOWUP;
             }
             $isUpdateBilling = false;
             $paymentObject = CRM_Core_BAO_PaymentProcessor::getProcessorForEntity($membership[$dao->id]['membership_id'], 'membership', 'obj');
             if (!empty($paymentObject)) {
                 $isUpdateBilling = $paymentObject->isSupported('updateSubscriptionBillingInfo');
             }
             $isCancelSupported = CRM_Member_BAO_Membership::isCancelSubscriptionSupported($membership[$dao->id]['membership_id']);
             $membership[$dao->id]['action'] = CRM_Core_Action::formLink(self::links('all', NULL, NULL, $isCancelSupported, $isUpdateBilling), $currentMask, array('id' => $dao->id, 'cid' => $this->_contactId));
         } else {
             $membership[$dao->id]['action'] = CRM_Core_Action::formLink(self::links('view'), $mask, array('id' => $dao->id, 'cid' => $this->_contactId));
         }
         //does membership have auto renew CRM-7137.
         if (CRM_Utils_Array::value('contribution_recur_id', $membership[$dao->id]) && !CRM_Member_BAO_Membership::isSubscriptionCancelled($membership[$dao->id]['membership_id'])) {
             $membership[$dao->id]['auto_renew'] = 1;
         } else {
             $membership[$dao->id]['auto_renew'] = 0;
         }
     }
     //Below code gives list of all Membership Types associated
     //with an Organization(CRM-2016)
     $membershipTypes = CRM_Member_BAO_MembershipType::getMembershipTypesByOrg($this->_contactId);
     foreach ($membershipTypes as $key => $value) {
         $membershipTypes[$key]['action'] = CRM_Core_Action::formLink(self::membershipTypeslinks(), $mask, array('id' => $value['id'], 'cid' => $this->_contactId));
     }
     $activeMembers = CRM_Member_BAO_Membership::activeMembers($membership);
     $inActiveMembers = CRM_Member_BAO_Membership::activeMembers($membership, 'inactive');
     $this->assign('activeMembers', $activeMembers);
     $this->assign('inActiveMembers', $inActiveMembers);
     $this->assign('membershipTypes', $membershipTypes);
     if ($this->_contactId) {
         $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
         $this->assign('displayName', $displayName);
     }
 }
コード例 #4
0
ファイル: Tab.php プロジェクト: kidaa30/yes
 /**
  * called when action is browse.
  */
 public function browse()
 {
     $links = self::links('all', $this->_isPaymentProcessor, $this->_accessContribution);
     $membership = array();
     $dao = new CRM_Member_DAO_Membership();
     $dao->contact_id = $this->_contactId;
     $dao->is_test = 0;
     //$dao->orderBy('name');
     $dao->find();
     //CRM--4418, check for view, edit, delete
     $permissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('edit memberships')) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('delete in CiviMember')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     // get deceased status id
     $allStatus = CRM_Member_PseudoConstant::membershipStatus();
     $deceasedStatusId = array_search('Deceased', $allStatus);
     //get all campaigns.
     $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
     //checks membership of contact itself
     while ($dao->fetch()) {
         $membership[$dao->id] = array();
         CRM_Core_DAO::storeValues($dao, $membership[$dao->id]);
         //carry campaign.
         $membership[$dao->id]['campaign'] = CRM_Utils_Array::value($dao->campaign_id, $allCampaigns);
         //get the membership status and type values.
         $statusANDType = CRM_Member_BAO_Membership::getStatusANDTypeValues($dao->id);
         foreach (array('status', 'membership_type') as $fld) {
             $membership[$dao->id][$fld] = CRM_Utils_Array::value($fld, $statusANDType[$dao->id]);
         }
         if (!empty($statusANDType[$dao->id]['is_current_member'])) {
             $membership[$dao->id]['active'] = TRUE;
         }
         if (empty($dao->owner_membership_id)) {
             // unset renew and followup link for deceased membership
             $currentMask = $mask;
             if ($dao->status_id == $deceasedStatusId) {
                 $currentMask = $currentMask & ~CRM_Core_Action::RENEW & ~CRM_Core_Action::FOLLOWUP;
             }
             $isUpdateBilling = FALSE;
             $paymentObject = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($membership[$dao->id]['membership_id'], 'membership', 'obj');
             if (!empty($paymentObject)) {
                 $isUpdateBilling = $paymentObject->isSupported('updateSubscriptionBillingInfo');
             }
             $isCancelSupported = CRM_Member_BAO_Membership::isCancelSubscriptionSupported($membership[$dao->id]['membership_id']);
             $membership[$dao->id]['action'] = CRM_Core_Action::formLink(self::links('all', NULL, NULL, $isCancelSupported, $isUpdateBilling), $currentMask, array('id' => $dao->id, 'cid' => $this->_contactId), ts('more'), FALSE, 'membership.tab.row', 'Membership', $dao->id);
         } else {
             $membership[$dao->id]['action'] = CRM_Core_Action::formLink(self::links('view'), $mask, array('id' => $dao->id, 'cid' => $this->_contactId), ts('more'), FALSE, 'membership.tab.row', 'Membership', $dao->id);
         }
         //does membership have auto renew CRM-7137.
         if (!empty($membership[$dao->id]['contribution_recur_id']) && !CRM_Member_BAO_Membership::isSubscriptionCancelled($membership[$dao->id]['membership_id'])) {
             $membership[$dao->id]['auto_renew'] = 1;
         } else {
             $membership[$dao->id]['auto_renew'] = 0;
         }
         // if relevant, count related memberships
         if (CRM_Utils_Array::value('is_current_member', $statusANDType[$dao->id]) && CRM_Utils_Array::value('relationship_type_id', $statusANDType[$dao->id]) && empty($dao->owner_membership_id)) {
             // not an related membership
             $query = "\n SELECT COUNT(m.id)\n   FROM civicrm_membership m\n     LEFT JOIN civicrm_membership_status ms ON ms.id = m.status_id\n     LEFT JOIN civicrm_contact ct ON ct.id = m.contact_id\n  WHERE m.owner_membership_id = {$dao->id} AND m.is_test = 0 AND ms.is_current_member = 1 AND ct.is_deleted = 0";
             $num_related = CRM_Core_DAO::singleValueQuery($query);
             $max_related = CRM_Utils_Array::value('max_related', $membership[$dao->id]);
             $membership[$dao->id]['related_count'] = $max_related == '' ? ts('%1 created', array(1 => $num_related)) : ts('%1 out of %2', array(1 => $num_related, 2 => $max_related));
         } else {
             $membership[$dao->id]['related_count'] = ts('N/A');
         }
     }
     //Below code gives list of all Membership Types associated
     //with an Organization(CRM-2016)
     $membershipTypes = CRM_Member_BAO_MembershipType::getMembershipTypesByOrg($this->_contactId);
     foreach ($membershipTypes as $key => $value) {
         $membershipTypes[$key]['action'] = CRM_Core_Action::formLink(self::membershipTypeslinks(), $mask, array('id' => $value['id'], 'cid' => $this->_contactId), ts('more'), FALSE, 'membershipType.organization.action', 'MembershipType', $value['id']);
     }
     $activeMembers = CRM_Member_BAO_Membership::activeMembers($membership);
     $inActiveMembers = CRM_Member_BAO_Membership::activeMembers($membership, 'inactive');
     $this->assign('activeMembers', $activeMembers);
     $this->assign('inActiveMembers', $inActiveMembers);
     $this->assign('membershipTypes', $membershipTypes);
     if ($this->_contactId) {
         $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
         $this->assign('displayName', $displayName);
         $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('membership', $this->_contactId);
         // Refresh other tabs with related data
         $this->ajaxResponse['updateTabs'] = array('#tab_activity' => CRM_Contact_BAO_Contact::getCountComponent('activity', $this->_contactId), '#tab_rel' => CRM_Contact_BAO_Contact::getCountComponent('rel', $this->_contactId));
         if (CRM_Core_Permission::access('CiviContribute')) {
             $this->ajaxResponse['updateTabs']['#tab_contribute'] = CRM_Contact_BAO_Contact::getCountComponent('contribution', $this->_contactId);
         }
     }
 }
コード例 #5
0
 static function getUsage($id = NULL, $cid = NULL, $orgid = NULL)
 {
     require_once 'CRM/CiviDiscount/Utils.php';
     require_once 'CRM/Member/BAO/Membership.php';
     require_once 'CRM/Contact/BAO/Contact.php';
     $where = '';
     $sql = "\nSELECT    t.item_id as item_id,\n      t.contact_id as contact_id,\n      t.used_date as used_date,\n      t.contribution_id as contribution_id,\n      t.entity_table as entity_table,\n      t.entity_id as entity_id,\n      t.description as description ";
     $from = " FROM cividiscount_track AS t ";
     if ($orgid) {
         $sql .= ", i.code ";
         $where = " LEFT JOIN cividiscount_item AS i ON (i.id = t.item_id) ";
         $where .= " WHERE i.organization_id = " . CRM_Utils_Type::escape($orgid, 'Integer');
     } else {
         if ($cid) {
             $where = " WHERE t.contact_id = " . CRM_Utils_Type::escape($cid, 'Integer');
         } else {
             $where = " WHERE t.item_id = " . CRM_Utils_Type::escape($id, 'Integer');
         }
     }
     $orderby = " ORDER BY t.item_id, t.used_date ";
     $sql = $sql . $from . $where . $orderby;
     $dao = new CRM_Core_DAO();
     $dao->query($sql);
     $rows = array();
     while ($dao->fetch()) {
         $row = array();
         $row['contact_id'] = $dao->contact_id;
         $row['display_name'] = CRM_Contact_BAO_Contact::displayName($dao->contact_id);
         $row['used_date'] = $dao->used_date;
         $row['contribution_id'] = $dao->contribution_id;
         $row['entity_table'] = $dao->entity_table;
         $row['entity_id'] = $dao->entity_id;
         $row['description'] = $dao->description;
         if (isset($dao->code)) {
             $row['code'] = $dao->code;
         }
         if ($row['entity_table'] == 'civicrm_participant') {
             $event_id = self::_get_participant_event($dao->entity_id);
             $events = CRM_CiviDiscount_Utils::getEvents();
             if (array_key_exists($event_id, $events)) {
                 $row['event_title'] = $events[$event_id];
             }
         } else {
             if ($row['entity_table'] == 'civicrm_membership') {
                 $result = CRM_Member_BAO_Membership::getStatusANDTypeValues($dao->entity_id);
                 if (array_key_exists($dao->entity_id, $result)) {
                     if (array_key_exists('membership_type', $result[$dao->entity_id])) {
                         $row['membership_title'] = $result[$dao->entity_id]['membership_type'];
                     }
                 }
             }
         }
         $rows[] = $row;
     }
     return $rows;
 }
 /**
  * Build the form
  *
  * @access public
  * @return void
  */
 public function buildQuickForm()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         // Check if any contributions created for the recurring record
         $recurringIds = array($this->_id);
         $contributionCount = CRM_Contribute_BAO_ContributionRecur::getCount($recurringIds);
         if (isset($contributionCount[$this->_id]) && $contributionCount[$this->_id] > 0) {
             $this->assign('contributionCount', $contributionCount[$this->_id]);
         }
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => '         ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     //need to assign custom data type to the template
     $this->assign('customDataType', 'ContributionRecur');
     $this->assign('entityID', $this->_id);
     $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionRecur');
     $cid = CRM_Utils_Request::retrieve('cid', 'Integer', $this);
     $id = CRM_Utils_Request::retrieve('crid', 'Integer', $this);
     $this->_paymentProcessors = $this->getValidProcessors();
     $offlineRecurPaymentProcessors = array();
     foreach ($this->_paymentProcessors as $processor) {
         if (!empty($processor['is_recur']) && !empty($processor['object']) && $processor['object']->supports('EditRecurringContribution') && $processor['is_test'] == 0) {
             $offlineRecurPaymentProcessors[$processor['id']] = $processor['name'];
         }
     }
     $paymentProcessor = $this->add('select', 'payment_processor_id', ts('Payment Processor'), array('' => ts('- select -')) + $offlineRecurPaymentProcessors, TRUE, NULL);
     $trxnId = $this->add('text', 'trxn_id', ts('Transaction ID'), array('class' => 'twelve'));
     $processorid = $this->add('text', 'processor_id', ts('Processor ID'), array('class' => 'twelve'));
     $financialType = $this->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType(), TRUE, NULL);
     $contributionStatus = $this->add('select', 'contribution_status_id', ts('Status'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionStatus(), TRUE, NULL);
     // Get contact memberships
     $contactMembershipsList = $contactMemberships = array();
     $memParams = array('contact_id' => $this->_contactID);
     CRM_Member_BAO_Membership::getValues($memParams, $contactMembershipsList, TRUE);
     if (count($contactMembershipsList) > 0) {
         foreach ($contactMembershipsList as $memid => $mem) {
             $statusANDType = CRM_Member_BAO_Membership::getStatusANDTypeValues($memid);
             $contactMemberships[$memid] = $statusANDType[$memid]['membership_type'] . ' / ' . $statusANDType[$memid]['status'] . ' / ' . $mem['start_date'] . ' / ' . $mem['end_date'];
         }
     }
     if ($this->_action == 1) {
         $memberships = $this->add('select', 'membership_id', ts('Membership'), array('' => ts('- select -')) + $contactMemberships, FALSE, NULL);
     }
     $totalAmount = $this->addMoney('amount', ts('Amount'), TRUE, NULL, TRUE, 'currency', NULL, FALSE);
     $paymentInstrument = $this->add('select', 'payment_instrument_id', ts('Paid By'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), TRUE, NULL);
     $frequencyUnit = $this->add('select', 'frequency_unit', NULL, array('' => ts('- select -')) + CRM_Core_OptionGroup::values('recur_frequency_units', FALSE, FALSE, FALSE, NULL, 'name'), TRUE, NULL);
     $frequencyInterval = $this->add('text', 'frequency_interval', ts('Every'), array('maxlength' => 2, 'size' => 2), TRUE);
     // add dates
     $this->addDateTime('start_date', ts('Start Date'), TRUE, array('formatType' => 'activityDateTime'));
     $this->addDateTime('end_date', ts('End Date'), FALSE, array('formatType' => 'activityDateTime'));
     $this->addDateTime('cancel_date', ts('Cancel Date'), FALSE, array('formatType' => 'activityDateTime'));
     $this->addDateTime('next_sched_contribution_date', ts('Next Scheduled Contribution Date'), FALSE, array('formatType' => 'activityDateTime'));
     $cycleDay = $this->add('text', 'cycle_day', ts('Cycle day'), array('maxlength' => 2, 'size' => 2), TRUE);
     // Move recurring record to another contact/membership
     // Field for moving contribution to another contact/membership
     if (!empty($this->_id)) {
         $this->addEntityRef('contact_id', ts('Contact'), array('create' => TRUE, 'api' => array('extra' => array('email'))), TRUE);
         $this->addElement('text', 'contact_name', 'Contact', array('size' => 50, 'maxlength' => 255));
         $this->addElement('hidden', 'selected_cid', 'selected_cid');
         $this->addElement('checkbox', 'move_recurring_record', ts('Move Recurring Record?'));
         $this->addElement('checkbox', 'move_existing_contributions', ts('Move Existing Contributions?'));
         // Get memberships of the contact
         // This will allow the recur record to be attached to a different membership of the same contact
         $existingMemberships = array('' => ts('- select -')) + $contactMemberships;
         // Remove current membership during move
         if ($existingMemberships[$this->_membershipID]) {
             unset($existingMemberships[$this->_membershipID]);
         }
         $this->add('select', 'membership_record', ts('Membership'), $existingMemberships, FALSE);
         $this->assign('show_move_membership_field', 1);
     }
     // build associated contributions
     $associatedContributions = array();
     $contributions = new CRM_Contribute_DAO_Contribution();
     $contributions->contribution_recur_id = $this->_id;
     while ($contributions->find(TRUE)) {
         $associatedContributions[$contributions->id]['total_amount'] = $contributions->total_amount;
         $associatedContributions[$contributions->id]['financial_type'] = CRM_Contribute_PseudoConstant::financialType($contributions->financial_type_id);
         $associatedContributions[$contributions->id]['contribution_source'] = $contributions->source;
         $associatedContributions[$contributions->id]['receive_date'] = $contributions->receive_date;
         $associatedContributions[$contributions->id]['contribution_status'] = CRM_Contribute_PseudoConstant::contributionStatus($contributions->contribution_status_id);
     }
     $this->assign('associatedContributions', $associatedContributions);
     $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
 }