# Welcome to DynamicSync PHP SDK! #

**Table of Contents**

-   [Installation][]
-   [Configuration][]
-   [Making your first call][]
    -   [Get a list of all events][]
-   [Working with Events][]
    -   [Getting Events][]
        -   [Get a list of dates for a specified Event ID][]
        -   [Get a list of events matching certain criteria][]
        -   [Get a list of event dates sorted by given field][]
        -   [Get a list of event dates, sorted by title and filtered by venue address for a specified Event ID][]
        -   [Get a specific event date by providing Event Date ID][]
        -   [Get a list of attendees for a specified Event ID][]
        -   [Get a list of attendees for a specified Event Date ID][]
    -   [CRUD][]
        -   [Creating a new event][]
        -   [Creating a new event date][]
        -   [Updating an event data][]
        -   [Updating an event date data][]
        -   [Registering an attendee][]
        -   [Updating an attendee data][]

  [Welcome to DynamicSync SDK!]: #welcome-to-dynamicsync-sdk
  [Installation]: #installation
  [Configuration]: #configuration
  [Making your first call]: #making-your-first-call
  [Get a list of all events]: #get-a-list-of-all-events
  [Working with Events]: #working-with-events
  [Getting Events]: #getting-events
  [Get a list of dates for a specified event id]: #get-a-list-of-dates-for-a-specified-event-id
  [Get a list of events matching certain criteria]: #get-a-list-of-events-matching-certain-criteria
  [Get a list of event dates sorted by given field]: #get-a-list-of-event-dates-sorted-by-given-field
  [Get a list of event dates, sorted by title and filtered by venue address for a specified event id]: #get-a-list-of-event-dates-sorted-by-title-and-filtered-by-venue-address-for-a-specified-event-id
  [Get a specific event date by providing event date id]: #get-a-specific-event-date-by-providing-event-date-id
  [Get a list of attendees for a specified Event ID]: #get-a-list-of-attendees-for-a-specified-event-id
  [Get a list of attendees for a specified Event Date ID]: #get-a-list-of-attendees-for-a-specified-event-date-id
  [CRUD]: #crud
  [Creating a new event]: #creating-a-new-event
  [Creating a new event date]: #creating-a-new-event-date
  [Updating an event data]: #updating-an-event-data
  [Updating an event date data]: #updating-an-event-date-data
  [Registering an attendee]: #registering-an-attendee
  [Updating an attendee data]: #updating-an-attendee-data

## Installation ##

The library can be installed via [composer](http://getcomposer.org/).
```php
{
    "require": {
        "designerlifetech/dynamicsync-php-sdk": "dev-master"
    }
}
```
## Configuration ##

You can get your API key by logging in to your [DynamicSync](http://app.dynamicsync.com) account, and then clicking on your **Profile Name**, found on the top menu.

**Initializing DynamicSync SDK:**
```php
use DynamicSync\DynamicSync;
$dynamicSync = new DynamicSync('your API key here');
```

## Making your first call ##

### Get a list of all events ###
```php
use DynamicSync\DynamicSync;
$dynamicSync = new DynamicSync('your API key here');

$events = $dynamicSync->getEvents();

echo '<p>Events:</p>';
echo '<ul>';

foreach( $events as $e => $event) {
	$event_data = $event->getEventData();
    echo '<li>' . $event_data['title'] . '</li>';
}

echo '</ul>';
```
**Result:**

> Events:

> - Live Event Demo
> - Online Webinar Demo
> - Online Meeting Demo

## Working with Events ##

### Getting Events ###
#### Get a list of dates for a specified event id ####
```php
use DynamicSync\DynamicSync;
$dynamicSync = new DynamicSync('your API key here');

$eventDates = $dynamicSync->getEventDates('the Event ID (guid) here');

echo '<p>Available Dates:</p>';
echo '<ul>';

foreach ($eventDates as $ed => $eventDate) {
    echo '<li>';

	$event_date_data = $eventDate->getEventDateData();
	
    //Get the event date's timezone
    if ( empty( $event_date_data['timezone'] ) )
        $timezone = 0;
    else
        $timezone = $event_date_data['timezone'] * 60 * 60;

    echo date("l, jS \of F Y h:i A", strtotime($event_date_data['start_date']) + $timezone);
    
    echo '</li>';
}

echo '</ul>';
```
**Result:**

>Available Dates:

> - Sunday, 12th of April 2015 02:00 AM
> - Sunday, 19th of April 2015 01:00 AM
> - Sunday, 26th of April 2015 06:00 AM

#### Get a list of events matching certain criteria ####
```php
use DynamicSync\DynamicSync;
$dynamicSync = new DynamicSync('your API key here');

//Get Event Dates, sort the start_date by descending order

//Create filter for this query. Get the event dates where the venue address has a word: 'Perth'
$filter = array(
    'key' => 'venue_address',
    'compare' => 'contains',
    'value' => 'Perth'
);

$eventDates = $dynamicSync->getEventDates('the Event ID (guid) here', $filter);

```
#### Get a list of event dates sorted by given field ####
```php
use DynamicSync\DynamicSync;
$dynamicSync = new DynamicSync('your API key here');

//Get Event Dates, sort the start_date by descending order
$eventDates = $dynamicSync->getEventDates('the Event ID (guid) here', null, 'start_date', SORT_DESC);
```
**Result**

> - Returns a list of event dates, sorted accordingly if sort parameters are specified.
> - Use **SORT_ASC** for ascending order and **SORT_DESC** for descending order

#### Get a list of event dates, sorted by title and filtered by venue address for a specified event id ####
```php
use DynamicSync\DynamicSync;
$dynamicSync = new DynamicSync('your API key here');

//Get Event Dates, sort the start_date by descending order

//Create filter for this query. Get the event dates where the venue address has a word: 'Perth'
$filter = array(
    'key' => 'venue_address',
    'compare' => 'contains',
    'value' => 'Perth'
);

$eventDates = $dynamicSync->getEventDates('the Event ID (guid) here', $filter, 'title', SORT_ASC);

```
**Result**

> - Returns a list of event dates, sorted accordingly as specified, and filtered according to the filter parameter

#### Get a specific event date by providing event date id ####
```php
use DynamicSync\DynamicSync;
$dynamicSync = new DynamicSync('your API key here');

$eventDate = $dynamicSync->getEventDate('the Event Date ID (guid) here');

$event_date_data = $eventDate->getEventDateData();

echo '<em>Event Date Details:</em>';
echo '<ul>';
echo '<li><strong>Title: </strong>' . $event_date_data['title'] . '</li>';

//Get the event date's timezone
if ( empty( $event_date_data['timezone'] ) )
    $timezone = 0;
else
    $timezone = $event_date_data['timezone'] * 60 * 60;

echo '<li><strong>Date &amp; Time: </strong>' . date("l, jS \of F Y h:i A", strtotime($event_date_data['start_date']) + $timezone) . '</li>';
echo '</ul>';
```
**Result:**

> *Event Date Details:*

> - **Title:** Live Event Test 1
> - **Date & Time:** Sunday, 19th of April 2015 01:00 AM

#### Get a list of attendees for a specified Event ID ####
```php
use DynamicSync\DynamicSync;
$dynamicSync = new DynamicSync('your API key here');

$attendeeList= $dynamicSync->getAttendees(null, 'the Event ID (guid) here');

/*
You can also specify the event id in an array:

	$args = array(
	    'eventId' => 'the Event ID (guid) here',
	);
	
	$attendeeList= $dynamicSync->getAttendees($args);

*/

echo '<ul>';
foreach( $attendeeList as $al => $attendee) {
	$attendeData = $attendee->getAttendeeData();
	echo '<li>' . $attendeData['contact_firstname']. ' ' . $attendeData['contact_lastname'] . '</li>';
}
echo '</ul>';
```

**Result:**

>  - Michael Balson
>  - Milla O'Flynn
>  - Georgia Hynes
>  - Samuel Gresswell

#### Get a list of attendees for a specified Event Date ID ####
```php
use DynamicSync\DynamicSync;
$dynamicSync = new DynamicSync('your API key here');

$attendeeList= $dynamicSync->getAttendees(null, null, 'the Event Date ID (guid) here');

/*
You can also specify the event date id in an array:

	$args = array(
	    'eventDateId' => 'the Event Date ID (guid) here',
	);
	
	$attendeeList= $dynamicSync->getAttendees($args);

*/

echo '<ul>';
foreach( $attendeeList as $al => $attendee) {
	$attendeData = $attendee->getAttendeeData();
	echo '<li>' . $attendeData['contact_firstname']. ' ' . $attendeData['contact_lastname'] . '</li>';
}
echo '</ul>';
```

**Result:**

>  - Milla O'Flynn
>  - Samuel Gresswell


### CRUD ###
#### Creating a new event ####
```php
use DynamicSync\DynamicSync;
$dynamicSync = new DynamicSync('your API key here');

//Date format must be: YYYY-MM-DD hh:mm:ss
$startDate = '2015-03-30 14:00:00';

$args = array(
    'title' => 'My Event',
    'start_date' => $startDate,
    'venue_name' => 'My Venue',
    'description' => 'My first event'
);

$result = $dynamicSync->createEvent($args);

echo '<pre>';
print_r( $result );
echo '</pre>';
```

**Result:**

Returns an array that includes the HTTP status code, message, and the data returned by the API. If the function succeeds, the data returned are the Tag IDs generated by Infusionsoft after the Event has been created.

```php
Array
(
    [http_status] => 200
    [http_message] => OK
    [data] => Array
        (
            [registered_tag] => 1329
            [attended_tag] => 1331
            [absent_tag] => 1333
        )

)
```
#### Creating a new event date ####
```php
use DynamicSync\DynamicSync;
$dynamicSync = new DynamicSync('your API key here');

$args = array(
    'eventId' => 'the Event ID here',
    'start_date' => '2015-04-25 15:00:00', //Date must be in YYYY-MM-DD hh:mm:ss format
    'end_date' => '', //if end_date is not specified, defaults to start_date + 1 hour
);

//Create a new event date for the specified Event ID
$result = $dynamicSync->createEventDate($args);

echo '<pre>';
print_r($result);
echo '</pre>';

```

**Result:**

Returns an array that includes the HTTP status code, message, and the data returned by the API.

```php
Array
(
    [http_status] => 200
    [http_message] => OK
    [data] => Array
        (
            [category] => Success
            [developerMessage] => OK
            [userMessage] => Request completed successfully
            [apiMessageNumber] => 20000
        )

)
```

#### Updating an event data ####
```php
use DynamicSync\DynamicSync;
$dynamicSync = new DynamicSync('your API key here');

//Update the event's venue name and description
$args = array(
    'venue_name' => 'New Venue',
    'description' => 'New Event'
);

$result = $dynamicSync->updateEvent($args, 'the Event Date ID (guid) here');

echo '<pre>';
print_r( $result );
echo '</pre>';
```

**Result:**

Returns an array that includes the HTTP status code, message, and the data returned by the API.

```php
Array
(
    [http_status] => 200
    [http_message] => OK
    [data] => Array
        (
            [category] => Success
            [developerMessage] => OK
            [userMessage] => Request completed successfully
            [apiMessageNumber] => 20000
        )

)
```
#### Updating an event date data ####
```php
use DynamicSync\DynamicSync;
$dynamicSync = new DynamicSync('your API key here');

$args = array(
    'start_date' => '2015-05-20 14:00:00',
    'title' => 'Updated Title',
    'venue_name' => 'Perth Arena 2',
    'description' => 'An updated event date'
);

$dynamicSync->updateEventDate( $args, 'the Event Date ID (guid) here' );
```
**Result:**

Returns an array that includes the HTTP status code, message, and the data returned by the API.
```php
Array
(
    [http_status] => 200
    [http_message] => OK
    [data] => Array
        (
            [category] => Success
            [developerMessage] => OK
            [userMessage] => Request completed successfully
            [apiMessageNumber] => 20000
        )

)
```
#### Registering an attendee ####
```php
use DynamicSync\DynamicSync;
$dynamicSync = new DynamicSync('your API key here');

$args = array(
    'eventId' => 'the Event ID (guid) here', //or...
    'eventDateId' => 'the Event Date ID (guid) here', //If both eventId and eventDateId is specified, eventDateId takes precedence and will be used.
    'contactFirstName' => 'John',
    'contactLastName' => 'Doe',
    'contactEmail' => 'john_doe@domain.com',
);

echo '<pre>';
print_r($dynamicSync->createAttendee( $args ));
echo '</pre>';
```
**Result**

Returns an array that includes the HTTP status code, message, and the data returned by the API.
```php
Array
(
    [http_status] => 200
    [http_message] => OK
    [data] => Array
        (
            [category] => Success
            [developerMessage] => OK
            [userMessage] => Request completed successfully
            [apiMessageNumber] => 20000
        )

)
```
#### Updating an attendee data ####
```php
use DynamicSync\DynamicSync;
$dynamicSync = new DynamicSync('your API key here');

$args = array(
    'attendeeId' => 'the Attendee ID (guid) here', //You can also specify the attendee Id by passing it as a second paramater of the updateAttendee() function
    'contactFirstName' => 'John',
    'contactLastName' => 'Doe',
    'contactEmail' => 'john_doe@domain.com',
    'contactMobile' => '+64123123123',
);

echo '<pre>';
print_r($dynamicSync->updateAttendee( $args, 'the Attendee ID (guid) here if not specified on the $args array' ));
echo '</pre>';
```
**Result**

Returns an array that includes the HTTP status code, message, and the data returned by the API.
```php
Array
(
    [http_status] => 200
    [http_message] => OK
    [data] => Array
        (
            [category] => Success
            [developerMessage] => OK
            [userMessage] => Request completed successfully
            [apiMessageNumber] => 20000
        )

)
```
