CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • membership api - id only
Pages: [1]

Author Topic: membership api - id only  (Read 973 times)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
membership api - id only
May 10, 2011, 11:26:37 pm
Hi,

I am finding the membership BAO create function is confounding our efforts to make the api accept 'id' only.

It looks like if we pass in $params['skipstatuscal'] it should work but that's a bit ergh.

We could set that param in the api if start_date & end_date aren't set ? What combo makes sense.

    static function &create( &$params, &$ids, $skipRedirect = false, $activityType = 'Membership Signup' )
    { 
        // always cal status if is_override/skipStatusCal is not true.
        // giving respect to is_override during import.  CRM-4012
       
        // To skip status cal we should use 'skipStatusCal'.
        // eg pay later membership, membership update cron CRM-3984
       
        if ( !CRM_Utils_Array::value( 'is_override', $params ) &&
             !CRM_Utils_Array::value( 'skipStatusCal', $params ) ) {
            require_once 'CRM/Utils/Date.php';
            $startDate = $endDate = $joinDate = null;
            if ( isset( $params['start_date'] ) ) {
                $startDate  = CRM_Utils_Date::customFormat($params['start_date'],'%Y%m%d');
            }
            if ( isset( $params['end_date'] ) ) {
                $endDate    = CRM_Utils_Date::customFormat($params['end_date'],'%Y%m%d');
            }
            if ( isset( $params['join_date'] ) ) {
                $joinDate   = CRM_Utils_Date::customFormat($params['join_date'],'%Y%m%d');
            }

            require_once 'CRM/Member/BAO/MembershipStatus.php';
            //fix for CRM-3570, during import exclude the statuses those having is_admin = 1
            $excludeIsAdmin = CRM_Utils_Array::value('exclude_is_admin', $params, false );
           
            //CRM-3724 always skip is_admin if is_override != true.
            if ( !$excludeIsAdmin &&
                 !CRM_Utils_Array::value( 'is_override', $params ) ) {
                $excludeIsAdmin = true;
            }
           
            $calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate( $startDate, $endDate, $joinDate,
                                                                                      'today', $excludeIsAdmin );           
            if ( empty( $calcStatus ) ) {
                if ( ! $skipRedirect ) {
                    // Redirect the form in case of error
                    CRM_Core_Session::setStatus( ts('The membership cannot be saved.') .
                                                 '<br/>' .
                                                 ts('No valid membership status for given dates.') );
                    return CRM_Utils_System::redirect( CRM_Utils_System::url( 'civicrm/contact/view',
                                                                              "reset=1&force=1&cid={$params['contact_id']}&selectedChild=member"));
                }
                // Return the error message to the api
                $error = array( );
                $error['is_error'] = ts( 'The membership cannot be saved. No valid membership status for given dates' );
                return $error;
            }
            $params['status_id'] = $calcStatus['id'];
        }

        }
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • membership api - id only

This forum was archived on 2017-11-26.