lost password?

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

rss
Tag this page
   

» Blogs that link here
last modified: Dec 14, 2006
(first posted: Aug 27, 2006)
(3494 Reads)
keywords: dynamic data
Permalink

Accessing dynamic data via hooks and tags

Although you can hook Dynamic Data to many modules, the way of access this data varies if the module has native support for this data.

 

Articles DD Display

In the display and summary templates, as well as the user API getall function, the dd fields come in to you directly.

For example, in the templates, just like you can access $body and $summary, you also have variables for $myfield1 and $myfield2 (if those are the dd field names).

This is the raw content of the field. If you want it processed for output, well, they already did that for you (thank you), its referenced as

#$myfield1_output#

Similarly, using the user API "getall" function ("get" doesnt support dd yet):

<xar:set name="stufflist">xarModAPIFunc('articles', 'user', 'getall', array('ptid'=>'12', 'extra'=>array('dynamicdata')))</xar:set>

<xarset name="stuff">current($stufflist)</xar:set>

#$stuff['myfield1']#

In this case, if you want it processed for output you dont get an "_output" field. For that you'll need to get the corresponding dd object directly for this pubtype like the general case (below), e.g. using

<xar:data-getitem name="$properties" module="articles" itemtype="$ptid" itemid="$aid />

and then access the properties by name, such as

<xar:data-output property="$properties['myfield1']" />

UPDATE:

articles get api now supports dd, so you can do:

<xar:set name="stuff">xarModAPIFunc('articles', 'user', 'get', array('ptid'=>'12', 'extra'=>array('dynamicdata')))</xar:set>
#$stuff['myfield1']#

 

Xarpages DD Display

In an Xarpages item template, dynamic data is contained in an subarray of the $current_page array, as follows:

#$current_page['dd']['myfield1']#

This is just the raw content, if you want it processed for output you'll need direct access to the Property objects array. You can make one for each dd object type (eh, that is, hook module item type). Go to Admin > Content > Dynamic Data > View DD Objects to determine the object name. , For example

mytheme/modules/dynamicdata/user-displayhook-xarpages_3.xt

To access dd properties directly, use the general case...

 

Roles DD

Dynamic Data hooked to Roles lets you define additional user profile variables. These are directly accessible via the Roles api functions

$value = xarUserGetVar( 'fieldname' );

xarUserSetVar( 'fieldname', $value );

These can take an optional 3rd arg, a $uid if other than the current logged in user.

To access all the dd fields in an array, use:

<xar:data-getitems value="$profiles" module="roles" itemids="$uid" />
<xar:set name="profile">$profiles[$uid]</xar:set>

The data-getitems tag returns an array of values per itemid. In this case it should return an array of one item. Then we take that item into the $profile variable array.

Similarly, for example, to find all users who have a specific dd value, you can do:

<xar:set name="wh">'myfield eq ' . $myvalue</xar:set>
<xar:data-getitems value="$users" module="roles" where="$wh" />

<xar:foreach in="$users" key="$uid" value="$dd">
<!-- do something -->
</xar:foreach>

This, of course, doesn't return the roles table data itself (such a uname, email, etc). If you need that you can call the roles getall, 

<xar:set name="rolesdata">xarModApiFunc('roles','user','getall',array('uidlist'=>$uids))</xar:set>

$rolesdata will be sorted by "name", or you can specify as 'order'=> field. But that doesnt let you sort by a dd field.

I tried using data-getitems with a join, and that works sort-of, as there are bugs. See http://bugs.xaraya.com/show_bug.cgi?id=6016 .

Here's an example where I have a list of articles, and I want to get the profiles of  all the authors who have a specific dd field value, and sort using my sortitems function (http://www.vaporbase.com/postings/74)

<xar:set name="authors">xarModApiFunc('articles','user','getauthors', array( 'ptid'=>'10' )</xar:set> 

<xar:set name="uids">array_keys($authors)</xar:set> 

<xar:set name="wh">"uid in (" . implode(",", $uids) . ")"</xar:set>

<xar:data-getitems value="$useritems" module="roles" join="xar_roles" where="$wh" />

<!-- sortitems only works in index arrays right now -->
<xar:set name="$useritems">array_values($useritems)</xar:set>

<xar:set name="$useritems">xarModApiFunc('misctools','user','sortitems', array('items'=>$useritems, 'field'=>'lastname'))</xar:set>

 

Other (General Case DD Display)

You can always retrieve a dynamic data item directly using the DD tags (or api). The general use is:

<xar:data-getitem name="$properties" module="123" itemtype="0" itemid="$id" fieldlist="$fieldlist" .../>

For example,

<xar:data-getitem name="$properties" module="xarpages" itemid="$pid" itemtype="$current_page['dd']['itemtype']" />

<xar:data-output property="$properties['myfield1']" />

You can override the value as follows:

<xar:data-output property="$properties['myfield1']" value="$newvalue" />

Outputting in a loop:

<xar:foreach in="$properties" key="$name">
<p>
<strong>
<xar:data-label property="$properties[$name]" />
</strong>
:
<xar:data-output property="$properties[$name]" />
</p>
</xar:foreach>

 

Input Forms

Sometimes you need to override the default property input tag.

  • You can do it by replacing the property's showinput template, but that will affect it everywhere on the site. That would be found, for example, in modules/base/xartemplates/properties/showinput-[propname].xd You can put an .xt version in your theme.
  • Make a newhook or modifyhook template for the specific item type. For example, for dd hooked to an Articles pubtype, the object might be called "articles_12", then you make a template named mytheme/modules/dynamicdata/admin-newhook-articles_12.xt or admin-modifyhook-articles_12.xt
  • Manage the dd object directly, such as

<xar:data-getitem name="$properties" module="xarpages" itemid="$ptid" />

then in your form,

<xar:data-input property="$properties['myfield']" />

or even

<xar:data-input name="myfield" type="dropdown" value="1" validation="$options" />

 

NOTE: for the Articles module built-in fields, there's a separate Fields definition and <xar:articles-field> tag you can use for input. See below (bottom of this article). For example,

<xar:articles-field definition="$fields['body']['definition']" />

 

What's in a Properties Data?

Example property array format and contents:

dynamic_tinymce_property Object
(
[id] => 113
[name] => narrative
[label] => Narrative
[type] => 205
[default] =>
[source] => dynamic_data
[status] => 1
[order] => 4
[validation] =>
[datastore] => _dynamic_data_
[value] => Asdf asdf
[invalid] =>
[_objectid] => 15
[_moduleid] => 27
[_itemtype] => 0
[_itemid] => 3
[_items] =>
[rows] => 10
[cols] => 50
[wrap] => soft
)

 

Dynamic Data Tags - Reference

Here's a synopsis of the DD tags (including usage both on hooked dd as well as dd objects)

* <xar:data-display ...> display tags
* Format : <xar:data-display module="123" itemtype="0" itemid="555" fieldlist="$fieldlist" static="yes" .../>
* or <xar:data-display fields="$fields" ... />
* or <xar:data-display object="$object" ... />
*
* @param array $args array containing the item that you want to display, or fields

 

* <xar:data-form ...> form tags
* Format : <xar:data-form module="123" itemtype="0" itemid="555" fieldlist="$fieldlist" static="yes" ... />
* or <xar:data-form fields="$fields" ... />
* or <xar:data-form object="$object" ... />
*
* @param $args array containing the item for which you want to show a form, or fields

<xar:data-form currently does everything between the between form tags except hidden fields and the buttons


* <xar:data-getitems ...> getitems tags
* Format : <xar:data-getitems name="$properties" value="$values" module="123" itemtype="0" itemids="$idlist" fieldlist="$fieldlist" .../>
* or <xar:data-getitems name="$properties" value="$values" object="$object" ... />
*
* @param $args array containing the items that you want to display, or fields

name= returns an array of properties ('propname' => property object)

value = returns an array of items values ('itemid' => array( 'fieldname' => value))

you dont need both name= and value=, just one or the other, or both

 

* <xar:data-getitem ...> getitem tags
* Format : <xar:data-getitem name="$properties" module="123" itemtype="0" itemid="$id" fieldlist="$fieldlist" .../>
* or <xar:data-getitem name="$properties" object="$object" ... />
*
* @param $args array containing the module and item that you want to display, or fields
* @returns string

N OTE: Use itemid=0 to get back the properties for an empty item, like for an input form to create new objects.

 

* <xar:data-input ...> form field tags
* Format : <xar:data-input name="thisname" type="thattype" value="$val" ... />
* or <xar:data-input field="$field" /> with $field an array containing the type, name, value, ...
* or <xar:data-input property="$property" /> with $property a Dynamic Property object
*
* Special attributes :
* hidden="yes" to show a hidden field regardless of the original property type
* preset="yes" this can typically be used in admin-new.xd templates for individual
* properties you'd like to automatically preset via GET or POST parameters
* Note: don't use this if you already check the input for the whole object or in the code
* See also preview="yes", which can be used on the object level to preview the whole object
*
* @param $args array containing the input field definition or the type, name, value, ...

 

* <xar:data-label ...> label tag
* Format : <xar:data-label object="$object" /> with $object some Dynamic Object
* or <xar:data-label property="$property" /> with $property some Dynamic Property
* <xar:data-label property="$property" label="id" /> will use <label for="dd_$property->id">...</label>
* <xar:data-label property="$property" label="name" /> will use <label for="$property->name">...</label>
* <xar:data-label property="$property" label="something" /> will use <label for="something">...</label>
*
* @param $args array containing the object or property

 

* <xar:data-list ...> list tags
* Format : <xar:data-list module="123" itemtype="0" itemids="$idlist" fieldlist="$fieldlist" static="yes" .../>
* or <xar:data-list items="$items" labels="$labels" ... />
* or <xar:data-list object="$object" ... />
*
* @param $args array containing the items that you want to list, or fields

 

* <xar:data-object ...> object tag
* Format : <xar:data-object object="$object" property="$property" /> with $object some object and $property some property of this object
* or <xar:data-object object="$object" method="$method" arguments="$args" /> with $object some object and $method some method of this object
*
* @param $args array containing the object and property/method

 

* <xar:data-output ...> form field tags
* Format : <xar:data-output name="thisname" type="thattype" value="$val" ... />
* or <xar:data-output field="$field" /> with $field an array containing the type, name, value, ...
* or <xar:data-output property="$property" /> with $property a Dynamic Property object
*
* @param $args array containing the input field definition or the type, name, value, ...

 

* <xar:data-view ...> view tags
* Format : <xar:data-view module="123" itemtype="0" itemids="$idlist" fieldlist="$fieldlist" static="yes" .../>
* or <xar:data-view items="$items" labels="$labels" ... />
* or <xar:data-view object="$object" ... />
*
* @param $args array containing the items that you want to display, or fields

Articles Fields

This is a bit off topic, but the Articles module has its own field definition and tag for the built in fields.

The field type is defined as follows (for example):

[myfield] => Array
(
[label] => School
[id] => body
[definition] => Array
(
[name] => body
[type] => dropdown
[id] => body
[value] => Harvard
[validation] => xarModApiFunc('articles','user','dropdownlist',array('ptid'=>'11','field'=>'summary','status'=>array(0,2,3)))
)
)

 

<xar:articles-field definition="$definition" />

with $definition an array containing the type, name, value, ...

or

<xar:articles-field name="thisname" type="thattype" value="$val" ... />

 

There are no comments attached to this item.

Post a new comment

How many days in a week?

Name :