\SyncController
How this works: 1. Client sends a list of new records (insert) and the ID and LastEdited timestamp of each existing record (check) 2. Server compares the "check" list with the db and generates 4 lists which it sends back to the client: a. send - records that appear to be newer on the client, so we're requesting the client hit us back with the full record b. insert - records that have been created on the server but weren't in the "check" list, so the client needs to add c. update - records that appear to be newer on the server, so the client needs to update d. delete - records that are in the "check" list with an ID but not present on the server. The ID means they have already been added to the server at one time, so odds are they've been deleted. Client should follow suit.
3. If the server's "send" list contained any ID's, the client sends another request, this time with only the update list
populated.
Cases this doesn't cover:
- deleting on the client (I can't think of a case this is needed on the kiosk)
- merging changes if a record were modified in both places (again, I don't think there's a use case on the kiosk)
NOTE: If PHP is on a different timezone to MySQL there will be problems with the way LastEdited is handled.
- Author: Mark Guinn <mark@adaircreative.com>
Synopsis
class SyncController
extends Controller
{
- // members
- public static string $url_segment = 'sync';
- public static boolean $allow_jsonp = true;
- public static boolean $allow_crossdomain = true;
- public static string $date_format = 'c';
- // methods
- public SS_HTTPResponse index()
- protected SS_HTTPResponse fail()
- protected string respond()
- public static array to_array()
- public static array filter_fields()
Hierarchy
Extends
- Controller
Members
public
- $allow_crossdomain
- $allow_jsonp
- $date_format
- $url_segment
Methods
protected
public
- filter_fields() — Takes an assoc array of data, removes any keys that are not on the fields list and returns the same array.
- index() — Handles all contexts !TODO - handle more than one model in one request
- to_array() — Given a dataobject, returns an array with the values of fields for that record. Optionally gives you the ability to limit which fields are returned and/or use dot notation or rename fields.