示例#1
0
// 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);
// SAVING TO MULTIPLE TABLES: ADD 'link' and 'linkKey' for each related table.  For multiple related tables, include an array of links and linkKeys.  Becareful here, and test to make sure data is actually being save the way you are expecting.
$update = array('key' => $supporter_key, 'Last_Name' => 'McTest-Smith', 'link' => array('custom', 'groups'), 'linkKey' => array(0, 12345), 'VARCHAR3' => 'Setting a custom field');
$supporter_key = $api->save('supporter', $update);
// You can also save to related tables via seperate interactions
$new_supporter = array('First_Name' => 'Joe', 'Last_Name' => 'Boy', 'Email' => '*****@*****.**');
$supporter_key = $api->save('supporter', $new_supporter);
$group_key = $api->save('groups', array('Group_Name' => 'Left Coast Supporters'));
$supporter_key = $api->save('supporter', array('key' => $supporter_key, 'link' => 'groups', 'linkKey' => $group_key));
<?php

require_once 'dia/api.php';
require_once 'settings.php';
$DIA = new DemocracyInAction_API($node, $user, $password);
$d = $_REQUEST;
$s_a = array('key' => $d['key'], 'personal_petition' => '1', 'personal_message' => $d['personal_message'], 'signature_goal' => $d['signature_goal'], 'email_message' => $d['email_message'], 'facebook_message' => $d['facebook_message'], 'twitter_message' => $d['twitter_message']);
$DIA->save('supporter_action', $s_a);
if ($d['email_trigger_KEYS'] && $d['Email']) {
    $s['email_trigger_KEYS'] = $d['email_trigger_KEYS'];
    $s['Email'] = $d['Email'];
}
if ($d['image']) {
    $s['image'] = $d['image'];
}
$s['key'] = $d['linkKey'];
$DIA->save('supporter', $s);
header('Location: ' . $d['redirect']);