lost password?

home
•  xaraya +
•  rails
•  django
•  webdev
•  xamp
•  musings

rss
Tag this page
   

ยป Blogs that link here
last modified: Oct 30, 2006
(first posted: Oct 09, 2006)
(1528 Reads)
keywords: dynamic data
Permalink

Intro to Dynamic Data Objects API

How to create and use dd objects natively. (Article under construction). This is Xar 1.x only.

 

Create Dynamic Object

Define New Object

Admin > Content > Dynamic Data > View Objects,

click New Dynamic Object Item

Name: name of the dd object type
Label: descriptive name
Module: Dynamic Data
Item Type: 0 (will get assigned (?)
URL Param: itemid (?)
Max Id: 0 (?)
Config: (?)
Alias in short URLs: checked

Create

Create Properties

Admin > Content > Dynamic Data > View Objects,

click Edit for the item type, then Modify Dynamic Properties

First one should always be "Item ID" (even if you dont think you'll need it, its better to be safe than sorry)

Label: itemid
Property type: Item ID

then add additional properties as needed

 

Object API

Get an empty object of itemtype $itype

$object = xarModApiFunc('dynamicdata', 'user', 'getobject', array('module'=>'dynamicdata', 'itemtype' => $itype));

 

Get a saved object, by item id

$object = xarModApiFunc('dynamicdata', 'user', 'getitem', array('module'=>'dynamicdata', 'itemtype' => $itype, 'itemid' => $iid, 'getobject'=>true ));

 

Populate fields from POST or GET vars, and check validation

$isvalid = $object->checkInput();

 

Set the value of property

$object2->properties['propname']->setValue( $value );

 

Save object in database and get item id

$iid = $object->createItem();

 

Dump object contents to page

echo "<pre>"; var_dump($object); echo "</pre>";


 

Referencing Other Objects

When defining an object that refences another object, there are Properties available.

Item Type

My first use-case of this is where I have extended Xarpages with hooked DD, and I'm adding fields. One field to reference an object type associated with that page.

Property: Object Reference

Validation:
Which object contains the property to reference: objects
Which property should be use as the value to DISPLAY? name
Which property should be used as the value to STORE? itemtype

The funky thing here is while this property is mostly intended to reference specific object instances, I'm using it here against "objects", so its presenting a list of item types.

 

API Method Reference

Complete list of object api methods (objects.php)

Produced using get_class_methods($object)

Array
(
[0] => dynamic_object_master
[1] => getdatastores
[2] => property2datastore
[3] => adddatastore
[4] => getproperties
[5] => addproperty
[6] => getobjects
[7] => getobjectinfo
[8] => getobject
[9] => getobjectlist
[10] => getobjectinterface
[11] => createobject
[12] => updateobject
[13] => deleteobject
[14] => jointable
[15] => dynamic_object
[16] => getitem
[17] => checkinput
[18] => showform
[19] => showdisplay
[20] => getfieldvalues
[21] => getdisplayvalues
[22] => createitem
[23] => updateitem
[24] => deleteitem
[25] => getnextitemtype
)

 

function Dynamic_Object_Master($args)

* Default constructor to set the object variables, retrieve the dynamic properties
* and get the corresponding data stores for those properties
*
* @param $args['objectid'] id of the object you're looking for, or
* @param $args['moduleid'] module id of the object to retrieve +
* @param $args['itemtype'] item type of the object to retrieve, or
* @param $args['table'] database table to turn into an object
* @param $args['catid'] categories we're selecting in (if hooked)
*
* @param $args['fieldlist'] optional list of properties to use, or
* @param $args['status'] optional status of the properties to use
* @param $args['allprops'] skip disabled properties by default

function &getDataStores($reset = false)

* Get the data stores where the dynamic properties of this object are kept

function property2datastore(&$property)

* Find the datastore name and type corresponding to the data source of a property

function addDataStore($name = '_dynamic_data_', $type='data')

* Add a data store for this object
*
* @param $name the name for the data store
* @param $type the type of data store

function &getProperties($args = array())

* Get the selected dynamic properties for this object

function addProperty($args)

* Add a property for this object
*
* @param $args['name'] the name for the dynamic property (required)
* @param $args['type'] the type of dynamic property (required)
* @param $args['label'] the label for the dynamic property
* @param $args['id'] the id for the dynamic property
* ...

function &getObjects()

* Class method to retrieve information about all Dynamic Objects
*
* @returns array
* @return array of object definitions

 

function getObjectInfo($args)

* Class method to retrieve information about a Dynamic Object
*
* @param $args['objectid'] id of the object you're looking for, or
* @param $args['name'] name of the object you're looking for, or
* @param $args['moduleid'] module id of the object you're looking for +
* @param $args['itemtype'] item type of the object you're looking for
* @returns array
* @return array containing the name => value pairs for the object

function &getObject($args)

* Class method to retrieve a particular object definition, with sub-classing
* (= the same as creating a new Dynamic Object with itemid = null)
*
* @param $args['objectid'] id of the object you're looking for, or
* @param $args['moduleid'] module id of the object to retrieve +
* @param $args['itemtype'] item type of the object to retrieve
* @param $args['classname'] optional classname (e.g. <module>_Dynamic_Object)
* @returns object
* @return the requested object definition

 

function &getObjectList($args)

* Class method to retrieve a particular object list definition, with sub-classing
* (= the same as creating a new Dynamic Object List)
*
* @param $args['objectid'] id of the object you're looking for, or
* @param $args['moduleid'] module id of the object to retrieve +
* @param $args['itemtype'] item type of the object to retrieve
* @param $args['classname'] optional classname (e.g. <module>_Dynamic_Object[_List])
* @returns object
* @return the requested object definition

 

function &getObjectInterface($args)

* Class method to retrieve a particular object interface definition, with sub-classing
* (= the same as creating a new Dynamic Object Interface)
*
* @param $args['objectid'] id of the object you're looking for, or
* @param $args['moduleid'] module id of the object to retrieve +
* @param $args['itemtype'] item type of the object to retrieve
* @param $args['classname'] optional classname (e.g. <module>_Dynamic_Object[_Interface])
* @returns object
* @return the requested object definition


function createObject($args)
function updateObject($args)

* Class method to create a new type of Dynamic Object
*
* @param $args['objectid'] id of the object you want to create (optional)
* @param $args['name'] name of the object to create
* @param $args['label'] label of the object to create
* @param $args['moduleid'] module id of the object to create
* @param $args['itemtype'] item type of the object to create
* @param $args['urlparam'] URL parameter to use for the object items (itemid, exid, aid, ...)
* @param $args['maxid'] for purely dynamic objects, the current max. itemid (for import only)
* @param $args['config'] some configuration for the object (free to define and use)
* @param $args['isalias'] flag to indicate whether the object name is used as alias for short URLs
* @param $args['classname'] optional classname (e.g. <module>_Dynamic_Object)
* @returns integer
* @return the object id of the created item

 

function deleteObject($args)

* @param $args['objectid'] id of the object you want to create (optional)
* @param $args['moduleid'] module id of the object to create
* @param $args['itemtype'] item type of the object to create
* @param $args['classname'] optional classname (e.g. <module>_Dynamic_Object)
* @returns integer

function joinTable($args)

* Join another database table to this object (unfinished)
* The difference with the 'join' argument above is that we don't create a new datastore for it here,
* and the join is handled directly in the original datastore, i.e. more efficient querying...
*
* @param $args['table'] the table to join with
* @param $args['key'] the join key for this table
* @param $args['fields'] the fields you want from this table
* @param $args['where'] optional where clauses for those table fields
* @param $args['andor'] optional combination of those clauses with the ones from the object
* @param $args['sort'] optional sort order in that table (TODO)
* ...

 

class Dynamic_Object extends Dynamic_Object_Master

function Dynamic_Object($args)

* Inherits from Dynamic_Object_Master and sets the requested item id
*
* @param $args['itemid'] item id of the object to get

 

function getItem($args = array())

* Retrieve the values for this item



function checkInput($args = array())

* Check the different input values for this item

function showForm($args = array())

* Show an input form for this item

 

function showDisplay($args = array())

* Show an output display for this item

 

function getFieldValues($args = array())

* Get the names and values of

 

function getDisplayValues($args = array())

* Get the labels and values to include in some output display for this item

 

function createItem($args = array())

 

function updateItem($args = array())

 

function deleteItem($args = array())

 

function getNextItemtype($args = array())

* Get the next available item type (for objects that are assigned to the dynamicdata module)
*
* @param $args['moduleid'] module id for the object
* @returns integer
* @return value of the next item type

 

class Dynamic_Object_List extends Dynamic_Object_Master

function Dynamic_Object_List($args)

* Inherits from Dynamic_Object_Master and sets the requested item ids, sort, where, ...
*
* @param $args['itemids'] array of item ids to return
* @param $args['sort'] sort field(s)
* @param $args['where'] WHERE clause to be used as part of the selection
* @param $args['numitems'] number of items to retrieve
* @param $args['startnum'] start number


function setArguments($args)

 

function setSort($sort)

 

function setWhere($where)

 

function setGroupBy($groupby)

 

function setCategories($catid)

 

function &getItems($args = array())

 

function countItems($args = array())

* Count the number of items that match the selection criteria
* Note : this must be called *before* getItems() if you're using numitems !


function showList($args = array())

 

function showView($args = array())

 

function &getViewValues($args = array())

* Get the labels and values to include in some output view for these items

 

function getPager($currenturl = '')

 

function getNext($args = array())

* Get items one at a time, instead of storing everything in $this->items

 

Sample Object Dump

Here's a dump of a simple object, before and after validation (checkInput):

Before Validation (using print_r)

pageform.xt object: dynamic_object Object
(
[objectid] => 22
[name] => testdata1
[label] =>
[moduleid] => 182
[itemtype] => 7
[urlparam] => itemid
[maxid] => 0
[config] =>
[isalias] => 1
[properties] => Array
(
[itemid] => dynamic_itemid_property Object
(
[size] => 10
[maxlength] => 30
[id] => 119
[name] => itemid
[label] => itemid
[type] => 21
[default] =>
[source] => dynamic_data
[status] => 1
[order] => 1
[validation] =>
[datastore] => _dynamic_data_
[value] =>
[invalid] =>
[_objectid] => 22
[_moduleid] => 182
[_itemtype] => 7
[_itemid] =>
[_items] =>
[min] =>
[max] =>
[regex] =>
)

[firstname] => dynamic_textbox_property Object
(
[id] => 120
[name] => firstname
[label] => firstname
[type] => 2
[default] =>
[source] => dynamic_data
[status] => 1
[order] => 2
[validation] => 1:
[datastore] => _dynamic_data_
[value] =>
[invalid] =>
[_objectid] => 22
[_moduleid] => 182
[_itemtype] => 7
[_itemid] =>
[_items] =>
[size] => 50
[maxlength] => 254
[min] => 1
[max] =>
[regex] =>
)

[lastname] => dynamic_textbox_property Object
(
[id] => 121
[name] => lastname
[label] => lastname
[type] => 2
[default] =>
[source] => dynamic_data
[status] => 1
[order] => 3
[validation] =>
[datastore] => _dynamic_data_
[value] =>
[invalid] =>
[_objectid] => 22
[_moduleid] => 182
[_itemtype] => 7
[_itemid] =>
[_items] =>
[size] => 50
[maxlength] => 254
[min] =>
[max] =>
[regex] =>
)

[emall] => dynamic_email_property Object
(
[id] => 122
[name] => email
[label] => email
[type] => 26
[default] =>
[source] => dynamic_data
[status] => 1
[order] => 4
[validation] => 1:
[datastore] => _dynamic_data_
[value] =>
[invalid] =>
[_objectid] => 22
[_moduleid] => 182
[_itemtype] => 7
[_itemid] =>
[_items] =>
[size] => 50
[maxlength] => 254
[min] => 1
[max] =>
[regex] =>
)

)

[datastores] => Array
(
[_dynamic_data_] => dynamic_variabletable_datastore Object
(
[name] => _dynamic_data_
[type] =>
[fields] => Array
(
[119] => dynamic_itemid_property Object
(
[size] => 10
[maxlength] => 30
[id] => 119
[name] => itemid
[label] => itemid
[type] => 21
[default] =>
[source] => dynamic_data
[status] => 1
[order] => 1
[validation] =>
[datastore] => _dynamic_data_
[value] =>
[invalid] =>
[_objectid] => 22
[_moduleid] => 182
[_itemtype] => 7
[_itemid] =>
[_items] =>
[min] =>
[max] =>
[regex] =>
)

[120] => dynamic_textbox_property Object
(
[id] => 120
[name] => firstname
[label] => firstname
[type] => 2
[default] =>
[source] => dynamic_data
[status] => 1
[order] => 2
[validation] => 1:
[datastore] => _dynamic_data_
[value] =>
[invalid] =>
[_objectid] => 22
[_moduleid] => 182
[_itemtype] => 7
[_itemid] =>
[_items] =>
[size] => 50
[maxlength] => 254
[min] => 1
[max] =>
[regex] =>
)

[121] => dynamic_textbox_property Object
(
[id] => 121
[name] => lastname
[label] => lastname
[type] => 2
[default] =>
[source] => dynamic_data
[status] => 1
[order] => 3
[validation] =>
[datastore] => _dynamic_data_
[value] =>
[invalid] =>
[_objectid] => 22
[_moduleid] => 182
[_itemtype] => 7
[_itemid] =>
[_items] =>
[size] => 50
[maxlength] => 254
[min] =>
[max] =>
[regex] =>
)

[122] => dynamic_email_property Object
(
[id] => 122
[name] => email
[label] => email
[type] => 26
[default] =>
[source] => dynamic_data
[status] => 1
[order] => 4
[validation] => 1:
[datastore] => _dynamic_data_
[value] =>
[invalid] =>
[_objectid] => 22
[_moduleid] => 182
[_itemtype] => 7
[_itemid] =>
[_items] =>
[size] => 50
[maxlength] => 254
[min] => 1
[max] =>
[regex] =>
)

)

[primary] => 119
[sort] => Array
(
)

[where] => Array
(
)

[groupby] => Array
(
)

[join] => Array
(
)

[_itemids] =>
[cache] => 0
)

)

[fieldlist] => Array
(
)

[status] =>
[layout] => default
[template] => testdata1
[tplmodule] => dynamicdata
[urlmodule] =>
[viewfunc] => view
[primary] => itemid
[secondary] =>
[filter] =>
[upload] =>
[fieldprefix] =>
[itemid] =>
[module] => dynamicdata
)

 

After Validation: (using var_dump)

object(dynamic_object)(25) {
["objectid"]=>
string(2) "22"
["name"]=>
string(9) "testdata1"
["label"]=>
string(0) ""
["moduleid"]=>
string(3) "182"
["itemtype"]=>
string(1) "7"
["urlparam"]=>
string(6) "itemid"
["maxid"]=>
string(1) "0"
["config"]=>
string(0) ""
["isalias"]=>
string(1) "1"
["properties"]=>
array(4) {
["itemid"]=>
&object(dynamic_itemid_property)(23) {
["size"]=>
int(10)
["maxlength"]=>
int(30)
["id"]=>
string(3) "119"
["name"]=>
string(6) "itemid"
["label"]=>
string(6) "itemid"
["type"]=>
string(2) "21"
["default"]=>
string(0) ""
["source"]=>
string(12) "dynamic_data"
["status"]=>
string(1) "1"
["order"]=>
string(1) "1"
["validation"]=>
string(0) ""
["datastore"]=>
string(14) "_dynamic_data_"
["value"]=>
int(0)
["invalid"]=>
string(0) ""
["_objectid"]=>
string(2) "22"
["_moduleid"]=>
string(3) "182"
["_itemtype"]=>
string(1) "7"
["_itemid"]=>
&NULL
["_items"]=>
NULL
["min"]=>
NULL
["max"]=>
NULL
["regex"]=>
NULL
["fieldname"]=>
string(6) "dd_119"
}
["firstname"]=>
&object(dynamic_textbox_property)(23) {
["id"]=>
string(3) "120"
["name"]=>
string(9) "firstname"
["label"]=>
string(9) "firstname"
["type"]=>
string(1) "2"
["default"]=>
string(0) ""
["source"]=>
string(12) "dynamic_data"
["status"]=>
string(1) "1"
["order"]=>
string(1) "2"
["validation"]=>
string(2) "1:"
["datastore"]=>
string(14) "_dynamic_data_"
["value"]=>
NULL
["invalid"]=>
string(41) "text : must be at least 1 characters long"
["_objectid"]=>
string(2) "22"
["_moduleid"]=>
string(3) "182"
["_itemtype"]=>
string(1) "7"
["_itemid"]=>
&NULL
["_items"]=>
NULL
["size"]=>
int(50)
["maxlength"]=>
int(254)
["min"]=>
string(1) "1"
["max"]=>
NULL
["regex"]=>
NULL
["fieldname"]=>
string(6) "dd_120"
}
["lastname"]=>
&object(dynamic_textbox_property)(23) {
["id"]=>
string(3) "121"
["name"]=>
string(8) "lastname"
["label"]=>
string(8) "lastname"
["type"]=>
string(1) "2"
["default"]=>
string(0) ""
["source"]=>
string(12) "dynamic_data"
["status"]=>
string(1) "1"
["order"]=>
string(1) "3"
["validation"]=>
string(0) ""
["datastore"]=>
string(14) "_dynamic_data_"
["value"]=>
string(0) ""
["invalid"]=>
string(0) ""
["_objectid"]=>
string(2) "22"
["_moduleid"]=>
string(3) "182"
["_itemtype"]=>
string(1) "7"
["_itemid"]=>
&NULL
["_items"]=>
NULL
["size"]=>
int(50)
["maxlength"]=>
int(254)
["min"]=>
NULL
["max"]=>
NULL
["regex"]=>
NULL
["fieldname"]=>
string(6) "dd_121"
}
["email"]=>
&object(dynamic_email_property)(23) {
["id"]=>
string(3) "122"
["name"]=>
string(5) "email"
["label"]=>
string(5) "email"
["type"]=>
string(2) "26"
["default"]=>
string(0) ""
["source"]=>
string(12) "dynamic_data"
["status"]=>
string(1) "1"
["order"]=>
string(1) "4"
["validation"]=>
string(2) "1:"
["datastore"]=>
string(14) "_dynamic_data_"
["value"]=>
string(0) ""
["invalid"]=>
string(43) "E-Mail : must be at least 1 characters long"
["_objectid"]=>
string(2) "22"
["_moduleid"]=>
string(3) "182"
["_itemtype"]=>
string(1) "7"
["_itemid"]=>
&NULL
["_items"]=>
NULL
["size"]=>
int(50)
["maxlength"]=>
int(254)
["min"]=>
string(1) "1"
["max"]=>
NULL
["regex"]=>
NULL
["fieldname"]=>
string(6) "dd_122"
}
}
["datastores"]=>
array(1) {
["_dynamic_data_"]=>
&object(dynamic_variabletable_datastore)(10) {
["name"]=>
string(14) "_dynamic_data_"
["type"]=>
NULL
["fields"]=>
array(4) {
[119]=>
&object(dynamic_itemid_property)(23) {
["size"]=>
int(10)
["maxlength"]=>
int(30)
["id"]=>
string(3) "119"
["name"]=>
string(6) "itemid"
["label"]=>
string(6) "itemid"
["type"]=>
string(2) "21"
["default"]=>
string(0) ""
["source"]=>
string(12) "dynamic_data"
["status"]=>
string(1) "1"
["order"]=>
string(1) "1"
["validation"]=>
string(0) ""
["datastore"]=>
string(14) "_dynamic_data_"
["value"]=>
int(0)
["invalid"]=>
string(0) ""
["_objectid"]=>
string(2) "22"
["_moduleid"]=>
string(3) "182"
["_itemtype"]=>
string(1) "7"
["_itemid"]=>
&NULL
["_items"]=>
NULL
["min"]=>
NULL
["max"]=>
NULL
["regex"]=>
NULL
["fieldname"]=>
string(6) "dd_119"
}
[120]=>
&object(dynamic_textbox_property)(23) {
["id"]=>
string(3) "120"
["name"]=>
string(9) "firstname"
["label"]=>
string(9) "firstname"
["type"]=>
string(1) "2"
["default"]=>
string(0) ""
["source"]=>
string(12) "dynamic_data"
["status"]=>
string(1) "1"
["order"]=>
string(1) "2"
["validation"]=>
string(2) "1:"
["datastore"]=>
string(14) "_dynamic_data_"
["value"]=>
NULL
["invalid"]=>
string(41) "text : must be at least 1 characters long"
["_objectid"]=>
string(2) "22"
["_moduleid"]=>
string(3) "182"
["_itemtype"]=>
string(1) "7"
["_itemid"]=>
&NULL
["_items"]=>
NULL
["size"]=>
int(50)
["maxlength"]=>
int(254)
["min"]=>
string(1) "1"
["max"]=>
NULL
["regex"]=>
NULL
["fieldname"]=>
string(6) "dd_120"
}
[121]=>
&object(dynamic_textbox_property)(23) {
["id"]=>
string(3) "121"
["name"]=>
string(8) "lastname"
["label"]=>
string(8) "lastname"
["type"]=>
string(1) "2"
["default"]=>
string(0) ""
["source"]=>
string(12) "dynamic_data"
["status"]=>
string(1) "1"
["order"]=>
string(1) "3"
["validation"]=>
string(0) ""
["datastore"]=>
string(14) "_dynamic_data_"
["value"]=>
string(0) ""
["invalid"]=>
string(0) ""
["_objectid"]=>
string(2) "22"
["_moduleid"]=>
string(3) "182"
["_itemtype"]=>
string(1) "7"
["_itemid"]=>
&NULL
["_items"]=>
NULL
["size"]=>
int(50)
["maxlength"]=>
int(254)
["min"]=>
NULL
["max"]=>
NULL
["regex"]=>
NULL
["fieldname"]=>
string(6) "dd_121"
}
[122]=>
&object(dynamic_email_property)(23) {
["id"]=>
string(3) "122"
["name"]=>
string(5) "email"
["label"]=>
string(5) "email"
["type"]=>
string(2) "26"
["default"]=>
string(0) ""
["source"]=>
string(12) "dynamic_data"
["status"]=>
string(1) "1"
["order"]=>
string(1) "4"
["validation"]=>
string(2) "1:"
["datastore"]=>
string(14) "_dynamic_data_"
["value"]=>
string(0) ""
["invalid"]=>
string(43) "E-Mail : must be at least 1 characters long"
["_objectid"]=>
string(2) "22"
["_moduleid"]=>
string(3) "182"
["_itemtype"]=>
string(1) "7"
["_itemid"]=>
&NULL
["_items"]=>
NULL
["size"]=>
int(50)
["maxlength"]=>
int(254)
["min"]=>
string(1) "1"
["max"]=>
NULL
["regex"]=>
NULL
["fieldname"]=>
string(6) "dd_122"
}
}
["primary"]=>
int(119)
["sort"]=>
array(0) {
}
["where"]=>
array(0) {
}
["groupby"]=>
array(0) {
}
["join"]=>
array(0) {
}
["_itemids"]=>
NULL
["cache"]=>
int(0)
}
}
["fieldlist"]=>
array(0) {
}
["status"]=>
NULL
["layout"]=>
string(7) "default"
["template"]=>
string(9) "testdata1"
["tplmodule"]=>
string(11) "dynamicdata"
["urlmodule"]=>
string(0) ""
["viewfunc"]=>
string(4) "view"
["primary"]=>
string(6) "itemid"
["secondary"]=>
NULL
["filter"]=>
NULL
["upload"]=>
bool(false)
["fieldprefix"]=>
string(0) ""
["itemid"]=>
&NULL
["module"]=>
string(11) "dynamicdata"
}

 

 

There are no comments attached to this item.

Post a new comment

How many days in a week?

Name :