This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » support » symfony 1.3 and 1.4 » Key-Value Form Design
Key-Value Form Design [message #103148] Tue, 27 July 2010 19:25 Go to next message
briahn10  is currently offline briahn10
Messages: 8
Registered: December 2008
Junior Member
I have a users table, and a generic key-value user attributes table (one-many).

I don't know quite the best form design for this. The attributes would be locked--eg. weight, height, age. Should I extend a user-attribute form for each of these attributes (weight, height, age), and then create a generic User form that embeds each of these?

Anyone have any other ideas?
Re: Key-Value Form Design [message #103165 is a reply to message #103148 ] Wed, 28 July 2010 10:56 Go to previous messageGo to next message
tkoomzaaskz  is currently offline tkoomzaaskz
Messages: 101
Registered: February 2008
Location: Poland
Senior Member
Hi, so you want to create a base UserAttribute class to be extended by each attribute type subclass? Can you specify what do you need distinct UserAttribute form classes for? You mentioned only locking (which means that initial value can't be changed, I guess).


symfony-world blog
Re: Key-Value Form Design [message #103208 is a reply to message #103165 ] Wed, 28 July 2010 19:23 Go to previous messageGo to next message
briahn10  is currently offline briahn10
Messages: 8
Registered: December 2008
Junior Member
Sorry, it might have been helpful to include the schema.

UserAttribute:
tableName: sf_guard_user_attributes
columns:
user_id:
type: int(4)
notnull: true
primary: true
key1:
type: string(255)
notnull: true
primary: true
value1:
type: string
notnull: true
relations:
sfGuardUser:
local: user_id
foreignAlias: Attributes

So basically I want to "lock" key1 with a possible set of keys--height, weight, etc. Each key though, needs a specific validator associated with it.

if key1 is height, then value1 needs to be validated as a string
if key1 is weight, then value1 needs to be validated as a number/integer
etc.

I was thinking about making subforms that extend UserAttributeForm that have specific validators.

Eg. IntegerUserAttributeForm, StringUserAttributeForm, etc

With these specific UserAttributeForm's, I'd create a generic ProfileForm that would have embedded each of these specific subforms.

Eg. ProfileForm would have embedded:
an IntegerUserAttributeForm for the weight
a StringUserAttributeForm for the height

The only real dark spot is the best place to "automatically" set key1 for each of these embedded forms. I'm thinking I would set them in save() of the ProfileForm? Is there a better design in general?

Thanks in advance!
Re: Key-Value Form Design [message #103210 is a reply to message #103208 ] Wed, 28 July 2010 20:16 Go to previous messageGo to next message
tkoomzaaskz  is currently offline tkoomzaaskz
Messages: 101
Registered: February 2008
Location: Poland
Senior Member
Of course, you may use polimorphism and extending base form classes, but you should conider doing something easier:

configure()
{
  case($this->getObject()->getKey1())
  {
    case 'height':
      $this->validatorSchema->setValidator('value1', new StringValidator);
      break;
    case 'weight':
      $this->validatorSchema->setValidator('value1', new NumberOrIntegerValidator);
      break;
  }
}


As far as I understood your problem, this is the solution. When embedded, each UserAttributeForm has to call configure method and sets a proper validator. And it's automatic.


symfony-world blog
Re: Key-Value Form Design [message #103219 is a reply to message #103210 ] Thu, 29 July 2010 01:13 Go to previous message
briahn10  is currently offline briahn10
Messages: 8
Registered: December 2008
Junior Member
And I'd seed each UserAttributeForm with a UserAttribute model with key1 already filled in with the key (height, weight, age)?
Previous Topic:edit an object with a custom column in admin generator
Next Topic:Alternative path for Doctrine templates
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software