[TYPO3-mvc] how to convert flag/type and bitmask values for output in the view

Steffen Ritter info at rs-websystems.de
Sun Dec 27 12:19:46 CET 2009


Martin Kutschker schrieb:
> Hi!
> 
> I don't know if I am not yet in the right ExtBase/FLUID spirit or have missed the bits form the docs
> but I cannot solve the riddles on how tackle a few of the common tasks in plugin creation.
> 
> a) Assume I have a person object with a gender property which can have the internal values of 0
> (unknown), 1 (male, 2 (female), 9 (not appicable, eg company) on accordance to ISO 5218

> In the TCA I can set up a "select" field with a fixed list of items. What is the easiest way to get
> a localizable output in FLUID? In a "classic" TYPO3 I would turn the value (of the record array)
> into a locallang key and call the LL functions with it.


in "real OO" i think you would create a class "sex" as valueObject and 
deliver 4 static valueObjects with your extension.
ValueObject would have an property ISO-CODE and title. Translation would 
  be possible with the Translation-ViewHelper.

> 
> I think that I can do it on my own by adding a getSex() method to the view. But I was hoping to find
> some helpers in ExtBase or FLUID to assist me in the task. But where are they?
> 
> b) The same as a) but about booleans (yes/no checkboxes in the TCA). Eg the person could have a
> "subscribed to newsletter" property.
> 
the boolean property is the information to store, the "meaning" should 
be set by view.
<f:if condition="object.booleanInfo">
<f:then>
   <f:translate key="subscribedToNewsletter" />
</f:then>
<f:else>
   <f:tranlate key="notSubcribedToNewsletter" />
</f:else>
</f:if>

> c) Yet again the same as a) but about bitmasks (group of checkboxes). Perhaps the person object may
> have interests and we know that the list of possible interests our application wants to know about
> is fixed. Yes, I could use a relation but I cannot think of a better example now.

Since bitmask are just a way to store, it all are several "properties" 
of the object.
so for each you should create getter and setter comparing this specific 
option to the bitmask or setting the bit in int.

Than you are back on "single, booleans", If you create your locallang 
entries like propertyName0, propertyName1 or some scheme like this, you 
could make an own viewhelper rendering the above mentioned code for usage:
<own:booleanTranslated property="myProperty" />

> Masi

Steffen


More information about the TYPO3-project-typo3v4mvc mailing list