initial working module

master
Marek Isalski 7 years ago
parent 8378159630
commit 4c28bb2787

@ -0,0 +1,9 @@
name = fulcrm membership
description = fulcrm membership
core = 7.x
package = fulcrm
configure = admin/config/services/fulcrm/membership
dependencies[] = fulcrm_apiv2
dependencies[] = fulcrm_crypto

@ -0,0 +1,84 @@
<?php /* -*- php -*- */
function fulcrm_membership_menu() {
$items = array();
$items[ 'user/fulcrm/optin/%' ] = array( 'page callback' => 'fulcrm_membership_optin',
'page arguments' => array(3),
'title' => 'Subscription Opt-In',
'description' => 'Opt-In to a Membership.',
'access callback' => 'user_access',
'access arguments' => array('access content'),
);
return $items;
}
function fulcrm_membership_optin_form_submit( $form, &$form_state ) {
foreach ( $form_state[ 'values' ][ 'person2memberships' ] as $p2m_id ) {
$p2m_id = fulcrm_crypto_get_object_id_form_value( 'person2membership-optin', $p2m_id );
if ( $p2m_id ) {
$api_data = fulcrm_apiv2_PATCH( 'person2membership/' . $p2m_id . '/',
$data = array( 'archived' => NULL ),
$query = array( 'expand' => implode( ',', array( 'person', 'membership' ) ) ) );
if ( $api_data[ 'success' ] ) {
if ( $api_data[ 'data' ][ 'person' ][ 'archived' ] ) {
$api2_data = fulcrm_apiv2_PATCH( $api_data[ 'data' ][ 'person' ][ 'url' ],
$data = array( 'archived' => NULL ) );
if ( $api2_data[ 'success' ] ) {
drupal_set_message(t('Thank you! Your subscription to "%membership" has been confirmed.', array( '%membership' => $api_data[ 'data' ][ 'membership' ][ 'name' ] )), 'status', FALSE );
drupal_goto( '<front>' );
} else {
drupal_set_message(t('There was a problem confirming your subscription.'), 'error', FALSE);
}
} else {
drupal_set_message(t('Thank you! Your subscription to "%membership" has been confirmed.', array( '%membership' => $api_data[ 'data' ][ 'membership' ][ 'name' ] )), 'status', FALSE );
drupal_goto( '<front>' );
}
} else {
drupal_set_message(t('There was a problem confirming your subscription.'), 'error', FALSE);
}
}
}
}
function fulcrm_membership_optin_form( $form, &$form_state, $p2ms ) {
drupal_set_title( 'Confirm Your Subscriptions' );
$form[ 'title' ] = array( '#type' => 'markup',
'#markup' => '<h1>Confirm Your Subscriptions</h1>',
);
$options = array();
foreach ( $p2ms as $p2m ) {
$key = fulcrm_crypto_object_id_form_value( 'person2membership-optin', $p2m[ 'id' ] );
$options[ $key ] = $p2m[ 'membership' ][ 'name' ];
}
$form[ 'person2memberships' ] = array( '#type' => 'checkboxes',
'#title' => 'Please choose which subscriptions you would like to join below:',
'#options' => $options,
);
$form[ 'actions' ] = array( '#type' => 'actions' );
$form[ 'actions' ][ 'submit' ] = array( '#type' => 'submit',
'#value' => t('Confirm Subscriptions'),
'#submit' => array( 'fulcrm_membership_optin_form_submit' ),
);
return $form;
}
function fulcrm_membership_optin( $passport ) {
$url = $GLOBALS[ 'base_url' ];
$url = parse_url( $url, PHP_URL_HOST );
$api_data = fulcrm_apiv2_GET( 'person2membership/',
$query = array( 'passport__system' => $url,
'passport__passport' => $passport,
'expand' => implode( ',', array( 'person',
'membership',
) ) ) );
if ( $api_data[ 'success' ] ) {
return drupal_get_form( 'fulcrm_membership_optin_form', $api_data[ 'data' ][ 'results' ] );
}
}
Loading…
Cancel
Save