Data plugins
From Project Auriga
Data Plugins extend the abstract fl_data class. The abstract class provides methods that should be able to load data from any MySQL or Postgres database, if it has been registered. For these to work, the extended class needs to provide certain properties:
- valid_obj_types - array of object types it accepts: account, contact, invoice, project, etc.
- typeMap - array of maps to convert between native object properties and remote system properties for an object. The key of this array is the object type, and its value is an array with keys of native parameter names and values of the foreign names. All foreign names must be declared to be loaded/saved by the base classes.
- where_{$type}_sql - any additional where clause to be added to queries
- orderby_{$type}_sql - default ORDER BY clause, padded with spaces
- map_col - default column name for key in map table
- key_name - name of key column in foreign database
- name_field - name of default display column for get_list
* prefix - prefix for ids to designate a foreign key
[edit] Methods in base class
- ->__construct($args) - takes an associative array of args, including 'type', 'spec', and 'url'.
- ->provides('type'); -- returns whether or not a plugin supports a class
- ->query($qry,$args); -- does a PEAR::DB query on the plugin's data object
- ->load($srch, &$object, $object_type='account', $multiple=false, $case_sensitive = false); $srch is either a specific foreign key to load, or an array of search values. $object, if an object, will get called with loadResult() with the result of the search. $object_type determines which map to use. If multiple, gets all results, otherwise only the first. Returns an array of results of all the columns in the map.
- ->get_list($type, $foreign = false, $col, $srch, $order) - returns an id=>$col array of results matching $srch, ordered by $order.
- ->get_map_col($type) -- returns the key column name in the map table (pass in type)
- ->get_key_name($type) -- returns the key column name in foreign database
- ->search_field($type, $field, $value="", $start=true) -- Searches a specific column and returns an array of id=>value of matches.
- ->get_table($type) -- returns the table name corresponding to $type
- ->get_field($type,$field) -- Looks up the foreign column name in the appropriate map
- ->default_field($type) -- returns the default display value for get_list()
- ->get_prefix($type) -- get the prefix for the type
[edit] Methods to implement in plugin
- __construct($args) -- set up properties as appropriate
- lookup_authz($userid) -- return false if unauthorized, single (native) account id, or array of native account_ids.
- get_{$type} -- use ->load instead...
- ->save($native_id, $object, $object_type);

