当前位置: 首页>>代码示例>>PHP>>正文


PHP CRM_Member_BAO_MembershipType::getMembershipTypeDetails方法代码示例

本文整理汇总了PHP中CRM_Member_BAO_MembershipType::getMembershipTypeDetails方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Member_BAO_MembershipType::getMembershipTypeDetails方法的具体用法?PHP CRM_Member_BAO_MembershipType::getMembershipTypeDetails怎么用?PHP CRM_Member_BAO_MembershipType::getMembershipTypeDetails使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CRM_Member_BAO_MembershipType的用法示例。


在下文中一共展示了CRM_Member_BAO_MembershipType::getMembershipTypeDetails方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: preProcess

 /**  
  * Function to set variables up before form is built  
  *                                                            
  * @return void  
  * @access public  
  */
 public function preProcess()
 {
     require_once 'CRM/Member/BAO/Membership.php';
     require_once 'CRM/Member/BAO/MembershipType.php';
     require_once 'CRM/Core/BAO/CustomGroup.php';
     $values = array();
     $id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     // Make sure context is assigned to template for condition where we come here view civicrm/membership/view
     $context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('context', $context);
     if ($id) {
         $params = array('id' => $id);
         CRM_Member_BAO_Membership::retrieve($params, $values);
         // build associated contributions
         require_once 'CRM/Member/Page/Tab.php';
         CRM_Member_Page_Tab::associatedContribution($values['contact_id'], $id);
         //Provide information about membership source when it is the result of a relationship (CRM-1901)
         $values['owner_membership_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $id, 'owner_membership_id');
         if (isset($values['owner_membership_id'])) {
             $values['owner_contact_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $values['owner_membership_id'], 'contact_id', 'id');
             $values['owner_display_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['owner_contact_id'], 'display_name', 'id');
             $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($values['membership_type_id']);
             $direction = strrev($membershipType['relationship_direction']);
             $values['relationship'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $membershipType['relationship_type_id'], "name_{$direction}", 'id');
         }
         $displayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['contact_id'], 'display_name');
         $this->assign('displayName', $displayName);
         // add viewed membership to recent items list
         require_once 'CRM/Utils/Recent.php';
         $url = CRM_Utils_System::url('civicrm/contact/view/membership', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}");
         $title = $displayName . ' - ' . ts('Membership Type:') . ' ' . $values['membership_type'];
         CRM_Utils_Recent::add($title, $url, $values['id'], 'Membership', $values['contact_id'], null);
         CRM_Member_Page_Tab::setContext($values['contact_id']);
         $memType = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $id, "membership_type_id");
         $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Membership', $this, $id, 0, $memType);
         CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
     }
     if ($values['is_test']) {
         $values['membership_type'] .= ' (test) ';
     }
     $this->assign($values);
 }
开发者ID:ksecor,项目名称:civicrm,代码行数:48,代码来源:MembershipView.php

示例2: formRule

 /**
  * Function for validation
  *
  * @param array $params (ref.) an assoc array of name/value pairs
  *
  * @return mixed true or array of errors
  * @access public
  * @static
  */
 public function formRule($params, $files, $self)
 {
     $errors = array();
     $priceSetId = CRM_Utils_Array::value('price_set_id', $params);
     if ($priceSetId) {
         CRM_Price_BAO_Field::priceSetValidation($priceSetId, $params, $errors);
         $priceFieldIDS = array();
         foreach ($self->_priceSet['fields'] as $priceIds => $dontCare) {
             if (!empty($params['price_' . $priceIds])) {
                 if (is_array($params['price_' . $priceIds])) {
                     foreach ($params['price_' . $priceIds] as $priceFldVal => $isSet) {
                         if ($isSet) {
                             $priceFieldIDS[] = $priceFldVal;
                         }
                     }
                 } else {
                     $priceFieldIDS[] = $params['price_' . $priceIds];
                 }
             }
         }
         if (!empty($priceFieldIDS)) {
             $ids = implode(',', $priceFieldIDS);
             $count = CRM_Price_BAO_Set::getMembershipCount($ids);
             foreach ($count as $id => $occurance) {
                 if ($occurance > 1) {
                     $errors['_qf_default'] = ts('Select at most one option associated with the same membership type.');
                 }
             }
             foreach ($priceFieldIDS as $priceFieldId) {
                 if ($id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_FieldValue', $priceFieldId, 'membership_type_id')) {
                     $self->_memTypeSelected[$id] = $id;
                 }
             }
         }
     } elseif (!CRM_Utils_Array::value(1, $params['membership_type_id'])) {
         $errors['membership_type_id'] = ts('Please select a membership type.');
     } else {
         $self->_memTypeSelected[] = $params['membership_type_id'][1];
     }
     // Return error if empty $self->_memTypeSelected
     if ($priceSetId && empty($errors) && empty($self->_memTypeSelected)) {
         $errors['_qf_default'] = ts('Select at least one membership option.');
     }
     if (!empty($errors) && count($self->_memTypeSelected) > 1) {
         $memberOfContacts = CRM_Member_BAO_MembershipType::getMemberOfContactByMemTypes($self->_memTypeSelected);
         $duplicateMemberOfContacts = array_count_values($memberOfContacts);
         foreach ($duplicateMemberOfContacts as $countDuplicate) {
             if ($countDuplicate > 1) {
                 $errors['_qf_default'] = ts('Please do not select more than one membership associated with the same organization.');
             }
         }
     }
     //check if contact is selected in standalone mode
     if (isset($params['contact_select_id'][1]) && !$params['contact_select_id'][1]) {
         $errors['contact[1]'] = ts('Please select a contact or create new contact');
     }
     if (!empty($errors)) {
         return $errors;
     }
     if ($priceSetId && !$self->_mode && !CRM_Utils_Array::value('record_contribution', $params)) {
         $errors['record_contribution'] = ts('Record Membership Payment is required when you using price set.');
     }
     if (CRM_Utils_Array::value('payment_processor_id', $params)) {
         // make sure that credit card number and cvv are valid
         if (CRM_Utils_Array::value('credit_card_type', $params)) {
             if (CRM_Utils_Array::value('credit_card_number', $params) && !CRM_Utils_Rule::creditCardNumber($params['credit_card_number'], $params['credit_card_type'])) {
                 $errors['credit_card_number'] = ts("Please enter a valid Credit Card Number");
             }
             if (CRM_Utils_Array::value('cvv2', $params) && !CRM_Utils_Rule::cvv($params['cvv2'], $params['credit_card_type'])) {
                 $errors['cvv2'] = ts("Please enter a valid Credit Card Verification Number");
             }
         }
     }
     $joinDate = NULL;
     if (CRM_Utils_Array::value('join_date', $params)) {
         $joinDate = CRM_Utils_Date::processDate($params['join_date']);
         foreach ($self->_memTypeSelected as $memType) {
             $startDate = NULL;
             if (CRM_Utils_Array::value('start_date', $params)) {
                 $startDate = CRM_Utils_Date::processDate($params['start_date']);
             }
             // if end date is set, ensure that start date is also set
             // and that end date is later than start date
             // If selected membership type has duration unit as 'lifetime'
             // and end date is set, then give error
             $endDate = NULL;
             if (CRM_Utils_Array::value('end_date', $params)) {
                 $endDate = CRM_Utils_Date::processDate($params['end_date']);
             }
             $membershipDetails = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($memType);
             if ($startDate && CRM_Utils_Array::value('period_type', $membershipDetails) == 'rolling') {
//.........这里部分代码省略.........
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:101,代码来源:Membership.php

示例3: relatedMemberships


//.........这里部分代码省略.........
         $memParams = array('contact_id' => $cid);
         $memberships = array();
         CRM_Member_BAO_Membership::getValues($memParams, $memberships, $active);
         if (empty($memberships)) {
             continue;
         }
         $values[$cid]['memberships'] = $memberships;
     }
     $deceasedStatusId = array_search('Deceased', CRM_Member_PseudoConstant::membershipStatus());
     // done with 'values' array.
     // Finally add / edit / delete memberships for the related contacts
     foreach ($values as $cid => $details) {
         if (!array_key_exists('memberships', $details)) {
             continue;
         }
         $mainRelatedContactId = key(CRM_Utils_Array::value('relatedContacts', $details, array()));
         foreach ($details['memberships'] as $membershipId => $membershipValues) {
             $relTypeIds = array();
             if ($action & CRM_Core_Action::DELETE) {
                 // Delete memberships of the related contacts only if relationship type exists for membership type
                 $query = "\nSELECT relationship_type_id, relationship_direction\n  FROM civicrm_membership_type\n WHERE id = {$membershipValues['membership_type_id']}";
                 $dao = CRM_Core_DAO::executeQuery($query);
                 $relTypeDirs = array();
                 while ($dao->fetch()) {
                     $relTypeId = $dao->relationship_type_id;
                     $relDirection = $dao->relationship_direction;
                 }
                 $relTypeIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $relTypeId);
                 if (in_array($values[$cid]['relationshipTypeId'], $relTypeIds)) {
                     CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipId, $mainRelatedContactId);
                 }
                 continue;
             }
             if ($action & CRM_Core_Action::UPDATE && $status & self::PAST && $membershipValues['owner_membership_id']) {
                 // If relationship is PAST and action is UPDATE
                 // then delete the RELATED membership
                 CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipValues['owner_membership_id'], $membershipValues['membership_contact_id']);
                 continue;
             }
             // add / edit the memberships for related
             // contacts.
             // Get the Membership Type Details.
             $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($membershipValues['membership_type_id']);
             // Check if contact's relationship type exists in membership type
             $relTypeDirs = array();
             if (CRM_Utils_Array::value('relationship_type_id', $membershipType)) {
                 $relTypeIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $membershipType['relationship_type_id']);
             }
             if (CRM_Utils_Array::value('relationship_direction', $membershipType)) {
                 $relDirections = explode(CRM_Core_DAO::VALUE_SEPARATOR, $membershipType['relationship_direction']);
             }
             foreach ($relTypeIds as $key => $value) {
                 $relTypeDirs[] = $value . '_' . $relDirections[$key];
             }
             $relTypeDir = $details['relationshipTypeId'] . $details['relationshipTypeDirection'];
             if (in_array($relTypeDir, $relTypeDirs)) {
                 // Check if relationship being created/updated is
                 // similar to that of membership type's
                 // relationship.
                 $membershipValues['owner_membership_id'] = $membershipId;
                 unset($membershipValues['id']);
                 unset($membershipValues['membership_contact_id']);
                 unset($membershipValues['contact_id']);
                 unset($membershipValues['membership_id']);
                 foreach ($details['relatedContacts'] as $relatedContactId => $donCare) {
                     $membershipValues['contact_id'] = $relatedContactId;
                     if ($deceasedStatusId && CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $relatedContactId, 'is_deceased')) {
                         $membershipValues['status_id'] = $deceasedStatusId;
                         $membershipValues['skipStatusCal'] = TRUE;
                     }
                     foreach (array('join_date', 'start_date', 'end_date') as $dateField) {
                         if (CRM_Utils_Array::value($dateField, $membershipValues)) {
                             $membershipValues[$dateField] = CRM_Utils_Date::processDate($membershipValues[$dateField]);
                         }
                     }
                     if ($action & CRM_Core_Action::UPDATE) {
                         //delete the membership record for related
                         //contact before creating new membership record.
                         CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipId, $relatedContactId);
                     }
                     // check whether we have some related memberships still available
                     $query = "\nSELECT count(*)\n  FROM civicrm_membership\n    LEFT JOIN civicrm_membership_status ON (civicrm_membership_status.id = civicrm_membership.status_id)\n WHERE membership_type_id = {$membershipValues['membership_type_id']} AND owner_membership_id = {$membershipValues['owner_membership_id']}\n    AND is_current_member = 1";
                     $result = CRM_Core_DAO::singleValueQuery($query);
                     if ($result < CRM_Utils_Array::value('max_related', $membershipValues, PHP_INT_MAX)) {
                         CRM_Member_BAO_Membership::create($membershipValues, CRM_Core_DAO::$_nullArray);
                     }
                 }
             } elseif ($action & CRM_Core_Action::UPDATE) {
                 // if action is update and updated relationship do
                 // not match with the existing
                 // membership=>relationship then we need to
                 // delete the membership record created for
                 // previous relationship.
                 if (self::isDeleteRelatedMembership($relTypeIds, $contactId, $mainRelatedContactId, $relTypeId, CRM_Utils_Array::value('relationship_ids', $params))) {
                     CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipId, $mainRelatedContactId);
                 }
             }
         }
     }
 }
开发者ID:hguru,项目名称:224Civi,代码行数:101,代码来源:Relationship.php

示例4: formRule

 /** 
  * global form rule 
  * 
  * @param array $fields  the input form values 
  * @param array $files   the uploaded files if any 
  * @param array $options additional user data 
  * 
  * @return true if no errors, else array of errors 
  * @access public 
  * @static 
  */
 static function formRule($fields, $files, $self)
 {
     $errors = array();
     $amount = self::computeAmount($fields, $self);
     //check for atleast one pricefields should be selected
     if (CRM_Utils_Array::value('priceSetId', $fields)) {
         $priceField = new CRM_Price_DAO_Field();
         $priceField->price_set_id = $fields['priceSetId'];
         $priceField->find();
         $check = array();
         while ($priceField->fetch()) {
             if (!empty($fields["price_{$priceField->id}"])) {
                 $check[] = $priceField->id;
             }
         }
         if (empty($check)) {
             $errors['_qf_default'] = ts("Select at least one option from Contribution(s).");
         }
         require_once 'CRM/Price/BAO/Set.php';
         CRM_Price_BAO_Set::processAmount($self->_values['fee'], $fields, $lineItem);
         if ($fields['amount'] < 0) {
             $errors['_qf_default'] = ts("Contribution can not be less than zero. Please select the options accordingly");
         }
         $amount = $fields['amount'];
     }
     if (isset($fields['selectProduct']) && $fields['selectProduct'] != 'no_thanks' && $self->_values['amount_block_is_active']) {
         require_once 'CRM/Contribute/DAO/Product.php';
         require_once 'CRM/Utils/Money.php';
         $productDAO = new CRM_Contribute_DAO_Product();
         $productDAO->id = $fields['selectProduct'];
         $productDAO->find(true);
         $min_amount = $productDAO->min_contribution;
         if ($amount < $min_amount) {
             $errors['selectProduct'] = ts('The premium you have selected requires a minimum contribution of %1', array(1 => CRM_Utils_Money::format($min_amount)));
         }
     }
     if ($self->_values["honor_block_is_active"] && CRM_Utils_Array::value('honor_type_id', $fields)) {
         // make sure there is a first name and last name if email is not there
         if (!CRM_Utils_Array::value('honor_email', $fields)) {
             if (!CRM_Utils_Array::value('honor_first_name', $fields) || !CRM_Utils_Array::value('honor_last_name', $fields)) {
                 $errors['honor_last_name'] = ts('In Honor Of - First Name and Last Name, OR an Email Address is required.');
             }
         }
     }
     if (isset($fields['is_recur']) && $fields['is_recur']) {
         if ($fields['frequency_interval'] <= 0) {
             $errors['frequency_interval'] = ts('Please enter a number for how often you want to make this recurring contribution (EXAMPLE: Every 3 months).');
         }
         if ($fields['frequency_unit'] == '0') {
             $errors['frequency_unit'] = ts('Please select a period (e.g. months, years ...) for how often you want to make this recurring contribution (EXAMPLE: Every 3 MONTHS).');
         }
     }
     if (CRM_Utils_Array::value('is_recur', $fields) && $fields['is_pay_later']) {
         $errors['is_pay_later'] = ' ';
         $errors['_qf_default'] = ts('You cannot set up a recurring contribution if you are not paying online by credit card.');
     }
     if (CRM_Utils_Array::value('is_for_organization', $fields)) {
         if (CRM_Utils_Array::value('org_option', $fields) && !$fields['onbehalfof_id']) {
             $errors['organization_id'] = ts('Please select an organization or enter a new one.');
         }
         if (!CRM_Utils_Array::value('org_option', $fields) && !$fields['organization_name']) {
             $errors['organization_name'] = ts('Please enter the organization name.');
         }
         if (!$fields['email'][1]['email']) {
             $errors["email[1][email]"] = ts('Organization email is required.');
         }
     }
     if (CRM_Utils_Array::value('selectMembership', $fields) && $fields['selectMembership'] != 'no_thanks') {
         require_once 'CRM/Member/BAO/Membership.php';
         require_once 'CRM/Member/BAO/MembershipType.php';
         $memTypeDetails = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($fields['selectMembership']);
         if ($self->_values['amount_block_is_active'] && !CRM_Utils_Array::value('is_separate_payment', $self->_membershipBlock)) {
             require_once 'CRM/Utils/Money.php';
             if ($amount < CRM_Utils_Array::value('minimum_fee', $memTypeDetails)) {
                 $errors['selectMembership'] = ts('The Membership you have selected requires a minimum contribution of %1', array(1 => CRM_Utils_Money::format($memTypeDetails['minimum_fee'])));
             }
         } else {
             if (CRM_Utils_Array::value('minimum_fee', $memTypeDetails)) {
                 // we dont have an amount, so lets get an amount for cc checks
                 $amount = $memTypeDetails['minimum_fee'];
             }
         }
     }
     if ($self->_values['is_monetary']) {
         //validate other amount.
         $checkOtherAmount = false;
         if (CRM_Utils_Array::value('amount', $fields) == 'amount_other_radio' || CRM_Utils_Array::value('amount_other', $fields)) {
             $checkOtherAmount = true;
         }
//.........这里部分代码省略.........
开发者ID:hampelm,项目名称:Ginsberg-CiviDemo,代码行数:101,代码来源:Main.php

示例5: formRule


//.........这里部分代码省略.........
     }
     if (!$priceSetId && $self->_mode && empty($params['financial_type_id'])) {
         $errors['financial_type_id'] = ts('Please enter the financial Type.');
     }
     if (!empty($params['record_contribution']) && empty($params['payment_instrument_id'])) {
         $errors['payment_instrument_id'] = ts('Paid By is a required field.');
     }
     if (!empty($params['is_different_contribution_contact'])) {
         if (empty($params['soft_credit_type_id'])) {
             $errors['soft_credit_type_id'] = ts('Please Select a Soft Credit Type');
         }
         if (empty($params['soft_credit_contact_id'])) {
             $errors['soft_credit_contact_id'] = ts('Please select a contact');
         }
     }
     if (!empty($params['payment_processor_id'])) {
         // validate payment instrument (e.g. credit card number)
         CRM_Core_Payment_Form::validatePaymentInstrument($params['payment_processor_id'], $params, $errors, $self);
     }
     $joinDate = NULL;
     if (!empty($params['join_date'])) {
         $joinDate = CRM_Utils_Date::processDate($params['join_date']);
         foreach ($self->_memTypeSelected as $memType) {
             $startDate = NULL;
             if (!empty($params['start_date'])) {
                 $startDate = CRM_Utils_Date::processDate($params['start_date']);
             }
             // if end date is set, ensure that start date is also set
             // and that end date is later than start date
             $endDate = NULL;
             if (!empty($params['end_date'])) {
                 $endDate = CRM_Utils_Date::processDate($params['end_date']);
             }
             $membershipDetails = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($memType);
             if ($startDate && CRM_Utils_Array::value('period_type', $membershipDetails) == 'rolling') {
                 if ($startDate < $joinDate) {
                     $errors['start_date'] = ts('Start date must be the same or later than Member since.');
                 }
             }
             if ($endDate) {
                 if ($membershipDetails['duration_unit'] == 'lifetime') {
                     // Check if status is NOT cancelled or similar. For lifetime memberships, there is no automated
                     // process to update status based on end-date. The user must change the status now.
                     $result = civicrm_api3('MembershipStatus', 'get', array('sequential' => 1, 'is_current_member' => 0));
                     $tmp_statuses = $result['values'];
                     $status_ids = array();
                     foreach ($tmp_statuses as $cur_stat) {
                         $status_ids[] = $cur_stat['id'];
                     }
                     if (empty($params['status_id']) || in_array($params['status_id'], $status_ids) == FALSE) {
                         $errors['status_id'] = ts('Please enter a status that does NOT represent a current membership status.');
                         $errors['is_override'] = ts('This must be checked because you set an End Date for a lifetime membership');
                     }
                 } else {
                     if (!$startDate) {
                         $errors['start_date'] = ts('Start date must be set if end date is set.');
                     }
                     if ($endDate < $startDate) {
                         $errors['end_date'] = ts('End date must be the same or later than start date.');
                     }
                 }
             }
             //  Default values for start and end dates if not supplied
             //  on the form
             $defaultDates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($memType, $joinDate, $startDate, $endDate);
             if (!$startDate) {
开发者ID:indydas,项目名称:civi-demo,代码行数:67,代码来源:Membership.php

示例6: postProcess

 /**
  * Process the form.
  *
  * @return void
  */
 public function postProcess()
 {
     // get the submitted form values.
     $params = $this->controller->exportValues($this->_name);
     $deletePriceSet = 0;
     if ($params['membership_type']) {
         // we do this in case the user has hit the forward/back button
         $dao = new CRM_Member_DAO_MembershipBlock();
         $dao->entity_table = 'civicrm_contribution_page';
         $dao->entity_id = $this->_id;
         $dao->find(TRUE);
         $membershipID = $dao->id;
         if ($membershipID) {
             $params['id'] = $membershipID;
         }
         $membershipTypes = array();
         if (is_array($params['membership_type'])) {
             foreach ($params['membership_type'] as $k => $v) {
                 if ($v) {
                     $membershipTypes[$k] = CRM_Utils_Array::value("auto_renew_{$k}", $params);
                 }
             }
         }
         if ($this->_id && !empty($params['member_price_set_id'])) {
             CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'amount_block_is_active', 0);
         }
         // check for price set.
         $priceSetID = CRM_Utils_Array::value('member_price_set_id', $params);
         if (!empty($params['member_is_active']) && is_array($membershipTypes) && !$priceSetID) {
             $usedPriceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, 2);
             if (empty($params['mem_price_field_id']) && !$usedPriceSetId) {
                 $pageTitle = strtolower(CRM_Utils_String::munge($this->_values['title'], '_', 245));
                 $setParams['title'] = $this->_values['title'];
                 if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $pageTitle, 'id', 'name')) {
                     $setParams['name'] = $pageTitle;
                 } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $pageTitle . '_' . $this->_id, 'id', 'name')) {
                     $setParams['name'] = $pageTitle . '_' . $this->_id;
                 } else {
                     $timeSec = explode(".", microtime(TRUE));
                     $setParams['name'] = $pageTitle . '_' . date('is', $timeSec[0]) . $timeSec[1];
                 }
                 $setParams['is_quick_config'] = 1;
                 $setParams['extends'] = CRM_Core_Component::getComponentID('CiviMember');
                 $setParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_values);
                 $priceSet = CRM_Price_BAO_PriceSet::create($setParams);
                 $priceSetID = $priceSet->id;
                 $fieldParams['price_set_id'] = $priceSet->id;
             } elseif ($usedPriceSetId) {
                 $setParams['extends'] = CRM_Core_Component::getComponentID('CiviMember');
                 $setParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_values);
                 $setParams['id'] = $usedPriceSetId;
                 $priceSet = CRM_Price_BAO_PriceSet::create($setParams);
                 $priceSetID = $priceSet->id;
                 $fieldParams['price_set_id'] = $priceSet->id;
             } else {
                 $fieldParams['id'] = CRM_Utils_Array::value('mem_price_field_id', $params);
                 $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', CRM_Utils_Array::value('mem_price_field_id', $params), 'price_set_id');
             }
             $editedFieldParams = array('price_set_id' => $priceSetID, 'name' => 'membership_amount');
             $editedResults = array();
             CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults);
             if (empty($editedResults['id'])) {
                 $fieldParams['name'] = strtolower(CRM_Utils_String::munge('Membership Amount', '_', 245));
                 if (empty($params['mem_price_field_id'])) {
                     CRM_Utils_Weight::updateOtherWeights('CRM_Price_DAO_PriceField', 0, 1, array('price_set_id' => $priceSetID));
                 }
                 $fieldParams['weight'] = 1;
             } else {
                 $fieldParams['id'] = CRM_Utils_Array::value('id', $editedResults);
             }
             $fieldParams['label'] = !empty($params['membership_type_label']) ? $params['membership_type_label'] : ts('Membership');
             $fieldParams['is_active'] = 1;
             $fieldParams['html_type'] = 'Radio';
             $fieldParams['is_required'] = !empty($params['is_required']) ? 1 : 0;
             $fieldParams['is_display_amounts'] = !empty($params['display_min_fee']) ? 1 : 0;
             $rowCount = 1;
             $options = array();
             if (!empty($fieldParams['id'])) {
                 CRM_Core_PseudoConstant::populate($options, 'CRM_Price_DAO_PriceFieldValue', TRUE, 'membership_type_id', NULL, " price_field_id = {$fieldParams['id']} ");
             }
             foreach ($membershipTypes as $memType => $memAutoRenew) {
                 if ($priceFieldID = CRM_Utils_Array::key($memType, $options)) {
                     $fieldParams['option_id'][$rowCount] = $priceFieldID;
                     unset($options[$priceFieldID]);
                 }
                 $membetype = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($memType);
                 $fieldParams['option_label'][$rowCount] = CRM_Utils_Array::value('name', $membetype);
                 $fieldParams['option_amount'][$rowCount] = CRM_Utils_Array::value('minimum_fee', $membetype, 0);
                 $fieldParams['option_weight'][$rowCount] = CRM_Utils_Array::value('weight', $membetype);
                 $fieldParams['option_description'][$rowCount] = CRM_Utils_Array::value('description', $membetype);
                 $fieldParams['default_option'] = CRM_Utils_Array::value('membership_type_default', $params);
                 $fieldParams['option_financial_type_id'][$rowCount] = CRM_Utils_Array::value('financial_type_id', $membetype);
                 $fieldParams['membership_type_id'][$rowCount] = $memType;
                 // [$rowCount] = $membetype[''];
                 $rowCount++;
//.........这里部分代码省略.........
开发者ID:kcristiano,项目名称:civicrm-core,代码行数:101,代码来源:MembershipBlock.php

示例7: preProcess

 /**
  * Set variables up before form is built.
  *
  * @return void
  */
 public function preProcess()
 {
     $values = array();
     $id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     // Make sure context is assigned to template for condition where we come here view civicrm/membership/view
     $context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('context', $context);
     if ($id) {
         $params = array('id' => $id);
         CRM_Member_BAO_Membership::retrieve($params, $values);
         $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($values['membership_type_id']);
         // Do the action on related Membership if needed
         $relAction = CRM_Utils_Request::retrieve('relAction', 'String', $this);
         if ($relAction) {
             $this->relAction($relAction, $values);
         }
         // build associated contributions
         $this->assign('accessContribution', FALSE);
         if (CRM_Core_Permission::access('CiviContribute')) {
             $this->assign('accessContribution', TRUE);
             CRM_Member_Page_Tab::associatedContribution($values['contact_id'], $id);
         }
         //Provide information about membership source when it is the result of a relationship (CRM-1901)
         $values['owner_membership_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $id, 'owner_membership_id');
         if (isset($values['owner_membership_id'])) {
             $values['owner_contact_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $values['owner_membership_id'], 'contact_id', 'id');
             $values['owner_display_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['owner_contact_id'], 'display_name', 'id');
             $direction = strrev($membershipType['relationship_direction']);
             // To display relationship type in view membership page
             $relTypeIds = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ",", $membershipType['relationship_type_id']);
             $sql = "\nSELECT relationship_type_id,\n  CASE\n  WHEN  contact_id_a = {$values['owner_contact_id']} AND contact_id_b = {$values['contact_id']} THEN 'b_a'\n  WHEN  contact_id_b = {$values['owner_contact_id']} AND contact_id_a = {$values['contact_id']} THEN 'a_b'\nEND AS 'relType'\n  FROM civicrm_relationship\n WHERE relationship_type_id IN ({$relTypeIds})";
             $dao = CRM_Core_DAO::executeQuery($sql);
             $values['relationship'] = NULL;
             while ($dao->fetch()) {
                 $typeId = $dao->relationship_type_id;
                 $direction = $dao->relType;
                 if ($direction && $typeId) {
                     if ($values['relationship']) {
                         $values['relationship'] .= ',';
                     }
                     $values['relationship'] .= CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $typeId, "name_{$direction}", 'id');
                 }
             }
         }
         $this->assign('has_related', FALSE);
         // if membership can be granted, and we are the owner of the membership
         if (!empty($membershipType['relationship_type_id']) && empty($values['owner_membership_id'])) {
             // display related contacts/membership block
             $this->assign('has_related', TRUE);
             $this->assign('max_related', CRM_Utils_Array::value('max_related', $values, ts('Unlimited')));
             // split the relations in 2 arrays based on direction
             $relTypeId = explode(CRM_Core_DAO::VALUE_SEPARATOR, $membershipType['relationship_type_id']);
             $relDirection = explode(CRM_Core_DAO::VALUE_SEPARATOR, $membershipType['relationship_direction']);
             foreach ($relTypeId as $rid) {
                 $dir = each($relDirection);
                 $relTypeDir[substr($dir['value'], 0, 1)][] = $rid;
             }
             // build query in 2 parts with a UNION if necessary
             // _x and _y are replaced with _a and _b first, then vice-versa
             // comment is a qualifier for the relationship - now just job_title
             $select = "\nSELECT r.id, c.id as cid, c.display_name as name, c.job_title as comment,\n       rt.name_x_y as relation, r.start_date, r.end_date,\n       m.id as mid, ms.is_current_member, ms.label as status\n  FROM civicrm_relationship r\n  LEFT JOIN civicrm_relationship_type rt ON rt.id = r.relationship_type_id\n  LEFT JOIN civicrm_contact c ON c.id = r.contact_id_x\n  LEFT JOIN civicrm_membership m ON (m.owner_membership_id = {$values['id']}\n  AND m.contact_id = r.contact_id_x AND m.is_test = 0)\n  LEFT JOIN civicrm_membership_status ms ON ms.id = m.status_id\n WHERE r.contact_id_y = {$values['contact_id']} AND r.is_active = 1  AND c.is_deleted = 0";
             $query = '';
             foreach (array('a', 'b') as $dir) {
                 if (isset($relTypeDir[$dir])) {
                     $query .= ($query ? ' UNION ' : '') . str_replace('_y', '_' . $dir, str_replace('_x', '_' . ($dir == 'a' ? 'b' : 'a'), $select)) . ' AND r.relationship_type_id IN (' . implode(',', $relTypeDir[$dir]) . ')';
                 }
             }
             $query .= " ORDER BY is_current_member DESC";
             $dao = CRM_Core_DAO::executeQuery($query);
             $related = array();
             $relatedRemaining = CRM_Utils_Array::value('max_related', $values, PHP_INT_MAX);
             $rowElememts = array('id', 'cid', 'name', 'comment', 'relation', 'mid', 'start_date', 'end_date', 'is_current_member', 'status');
             while ($dao->fetch()) {
                 $row = array();
                 foreach ($rowElememts as $field) {
                     $row[$field] = $dao->{$field};
                 }
                 if ($row['mid'] && $row['is_current_member'] == 1) {
                     $relatedRemaining--;
                     $row['action'] = CRM_Core_Action::formLink(self::links(), CRM_Core_Action::DELETE, array('id' => CRM_Utils_Request::retrieve('id', 'Positive', $this), 'cid' => $row['cid'], 'mid' => $row['mid']), ts('more'), FALSE, 'membership.relationship.action', 'Relationship', CRM_Utils_Request::retrieve('id', 'Positive', $this));
                 } else {
                     if ($relatedRemaining > 0) {
                         $row['action'] = CRM_Core_Action::formLink(self::links(), CRM_Core_Action::ADD, array('id' => CRM_Utils_Request::retrieve('id', 'Positive', $this), 'cid' => $row['cid'], 'rid' => $row['cid']), ts('more'), FALSE, 'membership.relationship.action', 'Relationship', CRM_Utils_Request::retrieve('id', 'Positive', $this));
                     }
                 }
                 $related[] = $row;
             }
             $this->assign('related', $related);
             if ($relatedRemaining <= 0) {
                 $this->assign('related_text', ts('None available'));
             } else {
                 if ($relatedRemaining < 100000) {
                     $this->assign('related_text', ts('%1 available', array(1 => $relatedRemaining)));
                 } else {
                     $this->assign('related_text', ts('Unlimited', array(1 => $relatedRemaining)));
//.........这里部分代码省略.........
开发者ID:kidaa30,项目名称:yes,代码行数:101,代码来源:MembershipView.php

示例8: testGetMembershipTypeDetails

 /**
  * check function getMembershipTypeDetails( )
  *
  */
 public function testGetMembershipTypeDetails()
 {
     $ids = array();
     $params = array('name' => 'General', 'description' => NULL, 'minimum_fee' => 100, 'domain_id' => 1, 'duration_unit' => 'year', 'period_type' => 'fixed', 'member_of_contact_id' => $this->_orgContactID, 'duration_interval' => 1, 'financial_type_id' => $this->_financialTypeId, 'relationship_type_id' => $this->_relationshipTypeId, 'visibility' => 'Public', 'is_active' => 1);
     $membership = CRM_Member_BAO_MembershipType::add($params, $ids);
     $result = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($membership->id);
     $this->assertEquals($result['name'], 'General', 'Verify membership type details.');
     $this->assertEquals($result['duration_unit'], 'year', 'Verify membership types details.');
     $this->membershipTypeDelete(array('id' => $membership->id));
 }
开发者ID:hyebahi,项目名称:civicrm-core,代码行数:14,代码来源:MembershipTypeTest.php

示例9: preProcess

 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 public function preProcess()
 {
     $values = array();
     $id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     // Make sure context is assigned to template for condition where we come here view civicrm/membership/view
     $context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('context', $context);
     if ($id) {
         $params = array('id' => $id);
         CRM_Member_BAO_Membership::retrieve($params, $values);
         // build associated contributions
         CRM_Member_Page_Tab::associatedContribution($values['contact_id'], $id);
         //Provide information about membership source when it is the result of a relationship (CRM-1901)
         $values['owner_membership_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $id, 'owner_membership_id');
         if (isset($values['owner_membership_id'])) {
             $values['owner_contact_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $values['owner_membership_id'], 'contact_id', 'id');
             $values['owner_display_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['owner_contact_id'], 'display_name', 'id');
             $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($values['membership_type_id']);
             $direction = strrev($membershipType['relationship_direction']);
             // To display relationship type in view membership page
             $relTypeIds = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ",", $membershipType['relationship_type_id']);
             $sql = "\nSELECT relationship_type_id,\n  CASE    \n  WHEN  contact_id_a = {$values['owner_contact_id']} AND contact_id_b = {$values['contact_id']} THEN 'b_a'\n  WHEN  contact_id_b = {$values['owner_contact_id']} AND contact_id_a = {$values['contact_id']} THEN 'a_b'\nEND AS 'relType'\n  FROM civicrm_relationship \n WHERE relationship_type_id IN ({$relTypeIds})";
             $dao = CRM_Core_DAO::executeQuery($sql);
             $values['relationship'] = NULL;
             while ($dao->fetch()) {
                 $membershipType['relationship_type_id'] = $dao->relationship_type_id;
                 $direction = $dao->relType;
                 if ($direction && $membershipType['relationship_type_id']) {
                     if ($values['relationship']) {
                         $values['relationship'] .= ',';
                     }
                     $values['relationship'] .= CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $membershipType['relationship_type_id'], "name_{$direction}", 'id');
                 }
             }
         }
         $displayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['contact_id'], 'display_name');
         $this->assign('displayName', $displayName);
         // add viewed membership to recent items list
         $url = CRM_Utils_System::url('civicrm/contact/view/membership', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
         $title = $displayName . ' - ' . ts('Membership Type:') . ' ' . $values['membership_type'];
         $recentOther = array();
         if (CRM_Core_Permission::checkActionPermission('CiviMember', CRM_Core_Action::UPDATE)) {
             $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/membership', "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
         }
         if (CRM_Core_Permission::checkActionPermission('CiviMember', CRM_Core_Action::DELETE)) {
             $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/membership', "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
         }
         CRM_Utils_Recent::add($title, $url, $values['id'], 'Membership', $values['contact_id'], NULL, $recentOther);
         CRM_Member_Page_Tab::setContext($values['contact_id']);
         $memType = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $id, "membership_type_id");
         $groupTree = CRM_Core_BAO_CustomGroup::getTree('Membership', $this, $id, 0, $memType);
         CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
         $isRecur = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $id, 'contribution_recur_id');
         $autoRenew = $isRecur ? TRUE : FALSE;
     }
     if (CRM_Utils_Array::value('is_test', $values)) {
         $values['membership_type'] .= ' (test) ';
     }
     $subscriptionCancelled = CRM_Member_BAO_Membership::isSubscriptionCancelled($id);
     $values['auto_renew'] = $autoRenew && !$subscriptionCancelled ? 'Yes' : 'No';
     //do check for campaigns
     if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) {
         $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
         $values['campaign'] = $campaigns[$campaignId];
     }
     $this->assign($values);
 }
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:73,代码来源:MembershipView.php

示例10: relatedMemberships


//.........这里部分代码省略.........
     $targetContact = array();
     if ($action & CRM_Core_Action::ADD || $action & CRM_Core_Action::DELETE) {
         $contact = $contactId;
         $targetContact = CRM_Utils_Array::value('contact_check', $params);
     } else {
         if ($action & CRM_Core_Action::UPDATE) {
             $contact = $ids['contact'];
             $targetContact = array($ids['contactTarget'] => 1);
         }
     }
     // Build the 'values' array for
     // 1. ContactA
     // 2. ContactB
     // This will allow us to check if either of the contacts in
     // relationship have active memberships.
     $values = array();
     // 1. ContactA
     $values[$contact] = array('relatedContacts' => $targetContact, 'relationshipTypeId' => $relTypeId, 'relationshipTypeDirection' => $relDirection);
     // 2. ContactB
     if (!empty($targetContact)) {
         foreach ($targetContact as $cid => $donCare) {
             $values[$cid] = array('relatedContacts' => array($contact => 1), 'relationshipTypeId' => $relTypeId);
             $relTypeParams = array('id' => $relTypeId);
             $relTypeValues = array();
             require_once 'CRM/Contact/BAO/RelationshipType.php';
             CRM_Contact_BAO_RelationshipType::retrieve($relTypeParams, $relTypeValues);
             if (CRM_Utils_Array::value('name_a_b', $relTypeValues) == CRM_Utils_Array::value('name_b_a', $relTypeValues)) {
                 $values[$cid]['relationshipTypeDirection'] = '_a_b';
             } else {
                 $values[$cid]['relationshipTypeDirection'] = $relDirection == '_a_b' ? '_b_a' : '_a_b';
             }
         }
     }
     // Now get the active memberships for all the contacts.
     // If contact have any valid membership(s), then add it to
     // 'values' array.
     foreach ($values as $cid => $subValues) {
         $memParams = array('contact_id' => $cid);
         $memberships = array();
         require_once 'CRM/Member/BAO/Membership.php';
         CRM_Member_BAO_Membership::getValues($memParams, $memberships, $active);
         if (empty($memberships)) {
             continue;
         }
         $values[$cid]['memberships'] = $memberships;
     }
     // done with 'values' array.
     // Finally add / edit / delete memberships for the related contacts
     foreach ($values as $cid => $details) {
         if (!array_key_exists('memberships', $details)) {
             continue;
         }
         require_once 'CRM/Member/BAO/MembershipType.php';
         foreach ($details['memberships'] as $membershipId => $membershipValues) {
             if ($action & CRM_Core_Action::DELETE) {
                 // delete memberships of the related contacts.
                 CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipId);
                 continue;
             }
             if ($action & CRM_Core_Action::UPDATE && $status & self::PAST && $membershipValues['owner_membership_id']) {
                 // If relationship is PAST and action is UPDATE
                 // then delete the RELATED membership
                 CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipValues['owner_membership_id'], $membershipValues['membership_contact_id']);
                 continue;
             }
             // add / edit the memberships for related
             // contacts.
             // Get the Membership Type Details.
             $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($membershipValues['membership_type_id']);
             if ("{$details['relationshipTypeId']}{$details['relationshipTypeDirection']}" == CRM_Utils_Array::value('relationship_type_id', $membershipType) . "_" . CRM_Utils_Array::value('relationship_direction', $membershipType)) {
                 // Check if relationship being created/updated is
                 // similar to that of membership type's
                 // relationship.
                 $membershipValues['owner_membership_id'] = $membershipId;
                 unset($membershipValues['id']);
                 unset($membershipValues['membership_contact_id']);
                 unset($membershipValues['contact_id']);
                 unset($membershipValues['membership_id']);
                 foreach ($details['relatedContacts'] as $relatedContactId => $donCare) {
                     $membershipValues['contact_id'] = $relatedContactId;
                     if ($action & CRM_Core_Action::UPDATE) {
                         //delete the membership record for related
                         //contact before creating new membership record.
                         CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipId, $relatedContactId);
                     }
                     CRM_Member_BAO_Membership::create($membershipValues, CRM_Core_DAO::$_nullArray);
                 }
             } else {
                 if ($action & CRM_Core_Action::UPDATE) {
                     // if action is update and updated relationship do
                     // not match with the existing
                     // membership=>relationship then we need to
                     // delete the membership record created for
                     // previous relationship.
                     CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipId, $ids['contactTarget']);
                 }
             }
         }
     }
 }
开发者ID:bhirsch,项目名称:voipdev,代码行数:101,代码来源:Relationship.php

示例11: formRule

 /**
  * Function for validation
  *
  * @param array $params (ref.) an assoc array of name/value pairs
  *
  * @return mixed true or array of errors
  * @access public
  * @static
  */
 public function formRule(&$params, &$files, $self)
 {
     $errors = array();
     //check if contact is selected in standalone mode
     if (isset($params['contact_select_id']) && !$params['contact_select_id']) {
         $errors['contact'] = ts('Please select a contact or create new contact');
     }
     if (!$params['membership_type_id'][1]) {
         $errors['membership_type_id'] = ts('Please select a membership type.');
     }
     if ($params['membership_type_id'][1] && CRM_Utils_Array::value('payment_processor_id', $params)) {
         // make sure that credit card number and cvv are valid
         require_once 'CRM/Utils/Rule.php';
         if (CRM_Utils_Array::value('credit_card_type', $params)) {
             if (CRM_Utils_Array::value('credit_card_number', $params) && !CRM_Utils_Rule::creditCardNumber($params['credit_card_number'], $params['credit_card_type'])) {
                 $errors['credit_card_number'] = ts("Please enter a valid Credit Card Number");
             }
             if (CRM_Utils_Array::value('cvv2', $params) && !CRM_Utils_Rule::cvv($params['cvv2'], $params['credit_card_type'])) {
                 $errors['cvv2'] = ts("Please enter a valid Credit Card Verification Number");
             }
         }
     }
     $joinDate = CRM_Utils_Date::processDate($params['join_date']);
     if ($joinDate) {
         require_once 'CRM/Member/BAO/MembershipType.php';
         $membershipDetails = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($params['membership_type_id'][1]);
         $startDate = CRM_Utils_Date::processDate($params['start_date']);
         if ($startDate && $membershipDetails['period_type'] == 'rolling') {
             if ($startDate < $joinDate) {
                 $errors['start_date'] = ts('Start date must be the same or later than join date.');
             }
         }
         // if end date is set, ensure that start date is also set
         // and that end date is later than start date
         // If selected membership type has duration unit as 'lifetime'
         // and end date is set, then give error
         $endDate = CRM_Utils_Date::processDate($params['end_date']);
         if ($endDate) {
             if ($membershipDetails['duration_unit'] == 'lifetime') {
                 $errors['end_date'] = ts('The selected Membership Type has a lifetime duration. You cannot specify an End Date for lifetime memberships. Please clear the End Date OR select a different Membership Type.');
             } else {
                 if (!$startDate) {
                     $errors['start_date'] = ts('Start date must be set if end date is set.');
                 }
                 if ($endDate < $startDate) {
                     $errors['end_date'] = ts('End date must be the same or later than start date.');
                 }
             }
         }
         //CRM-3724, check for availability of valid membership status.
         if (!CRM_Utils_Array::value('is_override', $params)) {
             require_once 'CRM/Member/BAO/MembershipStatus.php';
             $calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($startDate, $endDate, $joinDate, 'today', true);
             if (empty($calcStatus)) {
                 $url = CRM_Utils_System::url('civicrm/admin/member/membershipStatus', 'reset=1&action=browse');
                 $errors['_qf_default'] = ts('There is no valid Membership Status available for selected membership dates.');
                 $status = ts('Oops, it looks like there is no valid membership status available for the given membership dates. You can <a href="%1">Configure Membership Status Rules</a>.', array(1 => $url));
                 if (!$self->_mode) {
                     $status .= ' ' . ts('OR You can sign up by setting Status Override? to true.');
                 }
                 CRM_Core_Session::setStatus($status);
             }
         }
     } else {
         $errors['join_date'] = ts('Please enter the join date.');
     }
     if (isset($params['is_override']) && $params['is_override'] && !$params['status_id']) {
         $errors['status_id'] = ts('Please enter the status.');
     }
     //total amount condition arise when membership type having no
     //minimum fee
     if (isset($params['record_contribution'])) {
         if (!$params['contribution_type_id']) {
             $errors['contribution_type_id'] = ts('Please enter the contribution Type.');
         }
         if (!$params['total_amount']) {
             $errors['total_amount'] = ts('Please enter the contribution.');
         }
     }
     // validate contribution status for 'Failed'.
     if ($self->_onlinePendingContributionId && CRM_Utils_Array::value('record_contribution', $params) && CRM_Utils_Array::value('contribution_status_id', $params) == array_search('Failed', CRM_Contribute_PseudoConstant::contributionStatus(null, 'name'))) {
         $errors['contribution_status_id'] = ts("Please select a valid payment status before updating.");
     }
     return empty($errors) ? true : $errors;
 }
开发者ID:ksecor,项目名称:civicrm,代码行数:94,代码来源:Membership.php

示例12: testGetMembershipTypeDetails

 function testGetMembershipTypeDetails()
 {
     $ids = array('memberOfContact' => $this->_orgContactID);
     $params = array('name' => 'General', 'description' => null, 'minimum_fee' => 100, 'duration_unit' => 'year', 'period_type' => 'fixed', 'duration_interval' => 1, 'contribution_type_id' => $this->_contributionTypeId, 'relationship_type_id' => $this->_relationshipTypeId, 'visibility' => 'Public', 'is_active' => 1);
     $membership = CRM_Member_BAO_MembershipType::add($params, $ids);
     $result = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($membership->id);
     $this->assertEquals($result['name'], 'General', 'Verify membership type details.');
     $this->assertEquals($result['duration_unit'], 'year', 'Verify membership types details.');
 }
开发者ID:ksecor,项目名称:civicrm,代码行数:9,代码来源:MembershipTypeTest.php

示例13: civicrm_api3_membership_get

/**
 * Get contact membership record.
 *
 * This api will return the membership records for the contacts
 * having membership based on the relationship with the direct members.
 *
 * @param  Array $params key/value pairs for contact_id and some
 *          options affecting the desired results; has legacy support
 *          for just passing the contact_id itself as the argument
 *
 * @return  Array of all found membership property values.
 * @access public
 * @todo needs some love - basically only a get for a given contact right now
 * {@getfields membership_get}
 */
function civicrm_api3_membership_get($params)
{
    $contactID = $activeOnly = $membershipTypeId = $membershipType = NULL;
    $contactID = CRM_Utils_Array::value('contact_id', $params);
    if (is_array(CRM_Utils_Array::value('filters', $params)) && !empty($params['filters'])) {
        $activeOnly = CRM_Utils_Array::value('is_current', $params['filters'], FALSE);
    }
    $activeOnly = CRM_Utils_Array::value('active_only', $params, $activeOnly);
    //@todo replace this by handling in API layer - we should have enough info to do this
    // between pseudoconstant & fk - see comments in format_params
    $membershipTypeId = CRM_Utils_Array::value('membership_type_id', $params);
    if (!$membershipTypeId) {
        $membershipType = CRM_Utils_Array::value('membership_type', $params);
        if ($membershipType) {
            $membershipTypeId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $membershipType, 'id', 'name');
        }
    }
    if (CRM_Utils_Array::value('contact_id', $params)) {
        $membershipValues = _civicrm_api3_membership_get_customv2behaviour($params, $contactID, $membershipTypeId, $activeOnly);
    } else {
        //legacy behaviour only ever worked when contact_id passed in - use standard api function otherwise
        $membershipValues = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE);
    }
    if (empty($membershipValues)) {
        # No results is NOT an error!
        return civicrm_api3_create_success($membershipValues, $params);
    }
    $relationships = array();
    foreach ($membershipValues as $membershipId => $values) {
        // populate the membership type name for the membership type id
        $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($values['membership_type_id']);
        $membershipValues[$membershipId]['membership_name'] = $membershipType['name'];
        if (CRM_Utils_Array::value('relationship_type_id', $membershipType)) {
            $relationships[$membershipType['relationship_type_id']] = $membershipId;
        }
        // populating relationship type name.
        $relationshipType = new CRM_Contact_BAO_RelationshipType();
        $relationshipType->id = CRM_Utils_Array::value('relationship_type_id', $membershipType);
        if ($relationshipType->find(TRUE)) {
            $membershipValues[$membershipId]['relationship_name'] = $relationshipType->name_a_b;
        }
        _civicrm_api3_custom_data_get($membershipValues[$membershipId], 'Membership', $membershipId, NULL, $values['membership_type_id']);
    }
    $members = $membershipValues;
    // populating contacts in members array based on their relationship with direct members.
    if (!empty($relationships)) {
        foreach ($relationships as $relTypeId => $membershipId) {
            // As members are not direct members, there should not be
            // membership id in the result array.
            unset($membershipValues[$membershipId]['id']);
            $relationship = new CRM_Contact_BAO_Relationship();
            $relationship->contact_id_b = $contactID;
            $relationship->relationship_type_id = $relTypeId;
            if ($relationship->find()) {
                while ($relationship->fetch()) {
                    clone $relationship;
                    $membershipValues[$membershipId]['contact_id'] = $relationship->contact_id_a;
                    $members[$membershipId]['related_contact_id'] = $relationship->contact_id_a;
                }
            }
        }
    }
    return civicrm_api3_create_success($members, $params, 'membership', 'get');
}
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:79,代码来源:Membership.php

示例14: renewMembershipFormWrapper

 /**
  * @deprecated
  * A wrapper for renewing memberships from a form - including the form in the membership processing adds complexity
  * as the forms are being forced to pretend similarity
  * Try to call the renewMembership directly
  * @todo - this form method needs to have the interaction with the form layer removed from it
  * as a BAO function. Note that the api now supports membership renewals & it is not clear this function does anything
  * not done by the membership.create api (with a lot less unit tests)
  *
  * This method will renew / create the membership depending on
  * whether the given contact has a membership or not. And will add
  * the modified dates for membership and in the log table.
  *
  * @param int $contactID
  *   Id of the contact.
  * @param int $membershipTypeID
  *   Id of the new membership type.
  * @param bool $is_test
  *   If this is test contribution or live contribution.
  * @param CRM_Core_Form $form
  *   Form object.
  * @param null $changeToday
  * @param int $modifiedID
  *   Individual contact id in case of On Behalf signup (CRM-4027 ).
  * @param null $customFieldsFormatted
  * @param int $numRenewTerms
  *   How many membership terms are being added to end date (default is 1).
  * @param int $membershipID
  *   Membership ID, this should always be passed in & optionality should be removed.
  *
  * @throws CRM_Core_Exception
  *
  */
 public static function renewMembershipFormWrapper($contactID, $membershipTypeID, $is_test, &$form, $changeToday = NULL, $modifiedID = NULL, $customFieldsFormatted = NULL, $numRenewTerms = 1, $membershipID = NULL, $pending = FALSE)
 {
     $statusFormat = '%Y-%m-%d';
     $format = '%Y%m%d';
     $ids = array();
     //@todo would be better to make $membershipID a compulsory function param & make form layer responsible for extracting it
     if (!$membershipID && isset($form->_membershipId)) {
         $membershipID = $form->_membershipId;
     }
     //get all active statuses of membership.
     $allStatus = CRM_Member_PseudoConstant::membershipStatus();
     $membershipTypeDetails = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($membershipTypeID);
     // check is it pending. - CRM-4555
     list($pending, $contributionRecurID, $changeToday, $membershipSource, $isPayLater, $campaignId) = self::extractFormValues($form, $changeToday, $membershipTypeDetails, $pending);
     list($membership, $renewalMode, $dates) = self::renewMembership($contactID, $membershipTypeID, $is_test, $changeToday, $modifiedID, $customFieldsFormatted, $numRenewTerms, $membershipID, $pending, $allStatus, $membershipTypeDetails, $contributionRecurID, $format, $membershipSource, $ids, $statusFormat, $isPayLater, $campaignId);
     $form->set('renewal_mode', $renewalMode);
     if (!empty($dates)) {
         $form->assign('mem_start_date', CRM_Utils_Date::customFormat($dates['start_date'], $format));
         $form->assign('mem_end_date', CRM_Utils_Date::customFormat($dates['end_date'], $format));
     }
     return $membership;
 }
开发者ID:kidaa30,项目名称:yes,代码行数:55,代码来源:Membership.php

示例15: crm_get_contact_memberships

/**
 * Get conatct membership record.
 * 
 * This api is used for finding an existing membership record.
 * This api will also return the mebership records for the contacts
 * having mebership based on the relationship with the direct members.
 * 
 * @param  Int  $contactID  ID of a contact
 *
 * @return  Array of all found membership property values.
 * @access public
 */
function crm_get_contact_memberships($contactID)
{
    _crm_initialize();
    if (empty($contactID)) {
        return _crm_error('Invalid value for ContactID.');
    }
    // get the membership for the given contact ID
    require_once 'CRM/Member/BAO/Membership.php';
    $membership = array('contact_id' => $contactID);
    $membershipValues = array();
    CRM_Member_BAO_Membership::getValues($membership, $membershipValues);
    if (empty($membershipValues)) {
        return _crm_error('No memberships for this contact.');
    }
    foreach ($membershipValues as $membershipId => $values) {
        // populate the membership type name for the membership type id
        require_once 'CRM/Member/BAO/MembershipType.php';
        $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($values['membership_type_id']);
        $membershipValues[$membershipId]['membership_name'] = $membershipType['name'];
        $relationships[$membershipType['relationship_type_id']] = $membershipId;
        // populating relationship type name.
        require_once 'CRM/Contact/BAO/RelationshipType.php';
        $relationshipType = new CRM_Contact_BAO_RelationshipType();
        $relationshipType->id = $membershipType['relationship_type_id'];
        if ($relationshipType->find(true)) {
            $membershipValues[$membershipId]['relationship_name'] = $relationshipType->name_a_b;
        }
    }
    $members[$contactID] = $membershipValues;
    // populating contacts in members array based on their relationship with direct members.
    require_once 'CRM/Contact/BAO/Relationship.php';
    foreach ($relationships as $relTypeId => $membershipId) {
        // As members are not direct members, there should not be
        // membership id in the result array.
        unset($membershipValues[$membershipId]['id']);
        $relationship = new CRM_Contact_BAO_Relationship();
        $relationship->contact_id_b = $contactID;
        $relationship->relationship_type_id = $relTypeId;
        if ($relationship->find()) {
            while ($relationship->fetch()) {
                clone $relationship;
                $membershipValues[$membershipId]['contact_id'] = $relationship->contact_id_a;
                $members[$contactID][$relationship->contact_id_a] = $membershipValues[$membershipId];
            }
        }
    }
    return $members;
}
开发者ID:bhirsch,项目名称:voipdev,代码行数:60,代码来源:Membership.php


注:本文中的CRM_Member_BAO_MembershipType::getMembershipTypeDetails方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。