function create_from_supporter($dia_supporter_key) { $dia = new DemocracyInAction_API(DIA_API_NODE, DIA_API_USERNAME, DIA_API_PASSWORD); $dia->authenticate(); $supporter = $dia->get('supporter', $dia_supporter_key); if (empty($supporter)) { WinMember::dia_supporter_not_found(); } $member = WinMember::find_by_email($supporter['Email']); if (!$member) { $member = new WinMember($supporter['uid']); } $member->dia =& $dia; if (empty($supporter['uid'])) { trigger_error('no supporter UID'); $member->data->mergeData(array(WIN_USERNAME => $supporter['Email'], WIN_DIA_SUPPORTER_KEY => $supporter['supporter_KEY'], 'Email' => $supporter['Email'], 'First_Name' => $supporter['First_Name'], 'Last_Name' => $supporter['Last_Name'], 'Street' => $supporter['Street'], 'City' => $supporter['City'], 'State' => $supporter['State'], 'Zip' => $supporter['Zip'], 'modin' => 20)); $member->data->save(); trigger_error(var_export($member->data->id, true)); trigger_error(var_export($member->data->getData('Email'), true)); $member->dia->save('supporter', array('Email' => $member->data->getData('Email'), 'email_trigger_KEYS' => '0,' . WIN_SET_PASSWORD_EMAIL_KEY, 'USERNAME' => $member->data->getData('Email'))); $message = 'You must set your password before you can log in. <a href="http://www.winonline.org/forgot_password.php?login_type=content">Click here to set your password now </a>'; AMP_flashMessage($message, $error = 'true'); } return $member; }
function dia_connection( $dia_config ) { static $dia; if( $dia ) return $dia; $dia = new DemocracyInAction_API( $dia_config['node'], $dia_config['login'], $dia_config['password'] ); $dia->authenticate( ); $dia_groups = $dia->get( 'groups', array( 'limit' => 1) ); if( !$dia_groups ) { print "auth failed"; exit; } return $dia; }
// DemocracyInAction API: EXAMPLE USAGE // // THE FOLLOWING ACTIONS ARE SUPPORTED: get, save, delete, report // // more details about the external API can be found at http://dev.salsacommons.org/o/8001/p/salsa/commons/dev/docs/api/ // require dirname(__FILE__) . '/api.php'; // LOGIN INFO: Make sure you are using the correct node $node = 'salsa.democracyinaction.org'; $user = '******'; $password = '******'; // CREATE THE API $api = new DemocracyInAction_API($node, $user, $password); // GET A SINGLE SUPPORTER RECORD WITH ID 1234567 AS AN ARRAY OF DATA $data = $api->get('supporter', 1234567); // ALL OF THIS WORKS WITH ANY DIA TABLE $data = $api->get('donation', 1234567); // GETTING AN ARRAY OF MULTIPLE SUPPORTERS // YOU CAN PASS IN MULTIPLE CONDITIONS AS AN ARRAY, ALL OTHER OPTIONS TAKE A SINGLE VALUE OR A COMMA SEPERATED LIST $options = array('condition' => array('State=CA', 'Last_Name=McTest'), 'orderBy' => 'Last_Name,First_Name', 'limit' => 5, 'include' => 'First_Name,Last_Name,State'); $supporters = $api->get('supporter', $options); print "DATA RECIEVED FROM DIA: \n"; print var_dump($supporters); // SAVING DATA: MAKE AN ARRAY OF FIELDS WITH DIA FIELD NAMES // THE NEW SUPPORTER KEY IS RETURNED IF SUCCESSFUL $record = array('First_Name' => 'Testy', 'Last_Name' => 'McTest', 'Email' => '*****@*****.**', 'State' => 'CA'); $supporter_key = $api->save('supporter', $record); // UPDATING RECORDS: SAME AS SAVING, BUT INCLUDE A KEY $update = array('key' => $supporter_key, 'First_Name' => 'Testofolus', 'State' => 'OR'); $supporter_key = $api->save('supporter', $update);
} #get supporter key from url $supporter_KEY = $_GET['$u']; if ($_REQUEST['u']) { $supporter_KEY = $_REQUEST['u']; } else { #$supporter_KEY ='42703842'; } #get supporter action key from url if ($_REQUEST['p']) { $supporter_action_KEY = $_REQUEST['p']; } elseif ($_REQUEST['u']) { #$supporter_action_KEY ='8979243'; # look up in supporter_action where supporter_KEY = $U and personal_petition =1 $options = array('condition' => array('action_KEY=' . $action_KEY, 'supporter_KEY=' . $_REQUEST['u'])); $pet = $DIA->get('supporter_action', $options); $supporter_action_KEY = $pet[0]['supporter_action_KEY']; } # get action data #$options = array('condition' => array('campign_slug='.$campaign_slug)); $options = array('condition' => array('action_KEY=' . $action_KEY)); $action = $DIA->get('action', $options); $a = $action[0]; #$action_KEY = $a['action_KEY'] #get tell a firend data $options = array('condition' => array('tell_a_friend_KEY=' . $a['tell_a_friend_KEY'])); $tell = $DIA->get('tell_a_friend', $options); $taf = $tell[0]; #get user data if ($supporter_KEY) { $options = array('condition' => array('supporter_KEY=' . $supporter_KEY));
$d['gift_string__avg__low'] = $avg * 1; $d['gift_string__avg__medium'] = $avg * 1.5; $d['gift_string__avg__high'] = $avg * 2; $d['gift_string__last__low'] = $last * 1; $d['gift_string__last__medium'] = $last * 1.5; $d['gift_string__last__high'] = $last * 2; $d['key'] = $supporter_KEY; #$DIA->save('supporter',$data) echo '<pre>'; print_r($d); echo '</pre>'; } function get_last_donation($supporter_KEY) { global $db; $sql = 'select amount, Transaction_Date from donations where supporter_KEY = ' . $supporter_KEY . ' and recurring_donation_KEY = 0 order by Transaction_Date desc limit 1'; if ($r['amount'] = 0) { $sql = 'select amount, Transaction_Date from donations where supporter_KEY = ' . $supporter_KEY . ' and recurring_donation_KEY = 0 order by Transaction_Date desc limit 1'; } return $r['amount']; } $options = array('condition' => array('Email=david@riseup.net')); $supporters = $DIA->get('supporter', $options); echo '<h1>Calculate</h1>'; #echo '<pre>'; print_r($supporters); #echo '</pre>'; foreach ($supporters as $i) { echo $i['Email'] . '<br>'; caclulate_score($i['supporter_KEY'], $i['donation_history__max'], $i['donation_history__average'], $i['donation_history__last']); }
# encode share codes in twitter bitly url # paste button copying to buffer require_once 'dia/api.php'; require_once 'settings.php'; $DIA = new DemocracyInAction_API($node, $user, $password); #get the action info #to do, populate the action key by the url slug if ($_REQUEST['a']) { $action_KEY = $_REQUEST['a']; } else { ##GET THE ACTION KEY FROM THE URL SLUG $action_KEY = '5917'; } #$options = array('condition' => array('campaign_slug='.$campaign_slug)); $options = array('condition' => array('action_KEY=' . $action_KEY)); $action = $DIA->get('action', $options); $a = $action[0]; #get the action content $options = array('condition' => array('action_KEY=' . $a['action_KEY'])); $con = $DIA->get('action_content', $options); $options = array('condition' => array('action_content_KEY=' . $con[0]['action_content_KEY'])); $detail = $DIA->get('action_content_detail', $options); $c = $detail[0]; #get the action targets $options = array('condition' => array('action_KEY=' . $a['action_KEY'])); $tar = $DIA->get('action_target', $options); $target = $tar[0]; # if there is a user go get em if ($_GET['u']) { $options = array('condition' => array('supporter_KEY=' . $_GET['u'])); $sup = $DIA->get('supporter', $options);
<?php require_once 'start.php'; // initialize DIA library require_once APP_ROOT . '/lib/democracyinaction-php/api.php'; $dia_config = $app_config['democracy_in_action']; $dia = new DemocracyInAction_API($dia_config['node'], $dia_config['login'], $dia_config['password']); $dia->authenticate(); $dia_groups = $dia->get(Group::dia_object); if (!$dia_groups) { print "auth failed"; exit; } foreach ($dia_groups as $dia_group) { $group = GroupPeer::find_or_create_by_dia_key($dia_group); $group->save(); } $groups = GroupPeer::doSelect(new Criteria()); $groups_to_geocode = GroupPeer::geocodable(); foreach ($groups_to_geocode as $group) { $group->geocode(); $group->save(); }