Grouping attributes with addFieldSet: Difference between revisions
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
{{howto|intermediate|Jorge Garifuna <http://www.garidigital.com>}} | |||
The addFieldSet() function was introduced to ATK on June 11, 2008. Prior to this the addGroup() function was used, but subsequently dropped from the core of ATK due to compatibility issues. | The addFieldSet() function was introduced to ATK on June 11, 2008. Prior to this the addGroup() function was used, but subsequently dropped from the core of ATK due to compatibility issues. | ||
| Line 61: | Line 63: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 22:48, 28 August 2008
|
ATK Howto: Grouping attributes with addFieldSet
|
The addFieldSet() function was introduced to ATK on June 11, 2008. Prior to this the addGroup() function was used, but subsequently dropped from the core of ATK due to compatibility issues.
To make use of the addFieldSet() function, you need to have an ATK build created after June 11, 2008.
Assumming we had the following node:
function employee()
{
$this->atkNode("employee", NF_ADD_LINK);
$this->add(new atkAttribute("id", AF_AUTOKEY));
$this->add(new atkAttribute("name", AF_OBLIGATORY|AF_UNIQUE|AF_SEARCHABLE));
$this->add(new atkManyToOneRelation("department_id","lesson3.department", AF_SEARCHABLE));
$this->add(new atkManyToOneRelation("manager_id","lesson3.employee", AF_SEARCHABLE|AF_RELATION_AUTOCOMPLETE));
$this->add(new atkDateAttribute("hiredate"));
$this->add(new atkNumberAttribute("salary", AF_TOTAL));
$this->add(new atkTextAttribute("notes", 0, AF_HIDE_LIST));
$this->setOrder("name");
$this->setIndex("name");
$this->setTable("lesson3_employee");
}
Now let's group the following attributes so they appear on the same row:
Group0 will contain: department and manager Group1 will contain: name salary and the notes will have the label displayed on top of the attribute as opposed to the left
Below is the revised version of our node to accommodate for these enhancements using the addFieldSet() function:
function employee()
{
$this->atkNode("employee", NF_ADD_LINK);
$this->add(new atkAttribute("id", AF_AUTOKEY));
$this->add(new atkAttribute("name", AF_OBLIGATORY|AF_UNIQUE|AF_SEARCHABLE));
$this->add(new atkManyToOneRelation("department_id","lesson3.department", AF_SEARCHABLE));
$this->add(new atkManyToOneRelation("manager_id","lesson3.employee", AF_SEARCHABLE|AF_RELATION_AUTOCOMPLETE));
$this->add(new atkDateAttribute("hiredate"));
$this->add(new atkNumberAttribute("salary", AF_TOTAL));
$this->add(new atkTextAttribute("notes", 0, AF_HIDE_LIST));
$this->addFieldSet("group0","[department_id.label] [department_id.field] [manager_id.label] [manager_id.field] ",AF_SEARCHABLE|AF_BLANK_LABEL,NULL,300 );
$this->addFieldSet("group1","[name.field] [salary.field] <hr>[notes.label]:<br>[notes.field]",AF_SEARCHABLE|AF_BLANK_LABEL,NULL,600 );
$this->setOrder("name");
$this->setIndex("name");
$this->setTable("lesson3_employee");
}
The addFieldSet() function is defined as follows on class.atknode.inc:
addFieldSet($name, $template, $flags=0, $sections=NULL, $order=0)