Jump to content

Grouping attributes with addFieldSet: Difference between revisions

From NusaATK
New page: 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...
 
No edit summary
Line 5: Line 5:
Assumming we had the following node:
Assumming we had the following node:


{{{
<syntaxhighlight lang="php">
     function employee()
     function employee()
     {
     {
Line 23: Line 23:
       $this->setTable("lesson3_employee");
       $this->setTable("lesson3_employee");
     }
     }
}}}
</syntaxhighlight>


Now let's group the following attributes so they appear on the same row:
Now let's group the following attributes so they appear on the same row:
Line 32: Line 32:
Below is the revised version of our node to accommodate for these enhancements using the addFieldSet() function:
Below is the revised version of our node to accommodate for these enhancements using the addFieldSet() function:


{{{
<syntaxhighlight lang="php">
     function employee()
     function employee()
     {
     {
Line 53: Line 53:
       $this->setTable("lesson3_employee");
       $this->setTable("lesson3_employee");
     }
     }
}}}
</syntaxhighlight>


The addFieldSet() function is defined as follows on '''class.atknode.inc''':
The addFieldSet() function is defined as follows on '''class.atknode.inc''':


{{{
<syntaxhighlight lang="php">
addFieldSet($name, $template, $flags=0, $sections=NULL, $order=0)
addFieldSet($name, $template, $flags=0, $sections=NULL, $order=0)


}}}
</syntaxhighlight>


Until next time,
Until next time,

Revision as of 22:41, 11 June 2008

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)

Until next time,

Jorge Garifuna [1]