Reputation: 1309
I have TYPO3 version 7.6.18. I added 'interest' int field to fe_users table.
My TCA:
'interest' => [
'exclude' => 1,
'label' => 'Interest',
'config' => [
'type' => 'check',
'default' => '0',
'items' => [
['Mann', 0 ],
['Frau', 1],
['Paar', 2]
]
]
],
Help me please. What I must to model, that user can set interest checkbow in frontend in his profile ? How getters and setters method must be look like ? What object I must use, tell me please
Upvotes: 1
Views: 2095
Reputation: 6460
This is a bit tricky since TYPO3 stores multiple checkboxes as a single integer value bitmask. Thus at some point you'll need to split this combined value again if you want to use it. BTW, your checkbox values are unused since TYPO3 automatically stores all checkboxes as bit 1 or 0 depending on whether they are checked or not.
A simple solution would be mapping this value to an integer
in your model and then provide getters for each possible value:
/**
* @var integer
*/
protected $interests;
/**
* @return bool
*/
public function isInterestedInMen()
{
return $this->interests & 0b00000001;
}
/**
* @return bool
*/
public function isInterestedInWomen()
{
return $this->interests & 0b00000010;
}
/**
* @return bool
*/
public function isInterestedInPairs()
{
return $this->interests & 0b00000100;
}
You could then use $object->isInterestedInPairs()
in Extbase or {object.interestedInPairs}
in Fluid.
Here's an example how setters could be implemented:
/**
* @var integer
*/
protected $interests;
/**
* @param bool
*/
public function setInterestedInMen($interestedInMen)
{
if ($interestedInMen) {
$this->interests |= 0b00000001;
} else {
$this->interests &= ~0b00000001;
}
}
To write to these e.g. via Fluid forms you would simply use <f:form.checkbox property="interestedInMen" value="1" />
.
But as you can see this quickly becomes unwieldy and very hard to understand thus I'd suggest either creating a separate table and model for the interests which can then easily be maintained in the backend or at least switch to the select field and use string values which are then stored as CSV locally. This can then be mapped to string
in the model and passed through explode()
to get separate values. But again, I recommend looking at the separate table/model and relation approach.
Upvotes: 4
Reputation: 2685
Here you can find an example which is extending FileReference of TYPO3. The behavior is almost the same. In your case its just FrontendUser instead of FileReference: Extending sys_file_reference (FAL)
Upvotes: 1