[TYPO3-mvc] how to convert flag/type and bitmask values for output in the view
Martin Kutschker
masi-no at spam-typo3.org
Sun Dec 27 12:42:44 CET 2009
Steffen Ritter schrieb:
> 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 have thought about creating a class. But looks like a real overhead to create a class AND a custom
view helper just to get a localized string. Perhaps no problem once there is a code generator for
that, but now it looks to be tedious.
>> 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>
To much code in the template!!! An if-construct for each flag is nor practical.
Ein Minimum wäre sowas:
<f:translate key="{concat('subscribedToNewsletter.',$object.booleanInfo?'yes':'no')}" />
Aber selbst das conact ist a) zuviel Tipparbeit und b) schon wieder Logik, die nicht ins Template
gehört.
>
>> 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.
Could also be an array property.
> so for each you should create getter and setter comparing this specific
> option to the bitmask or setting the bit in int.
You will not be surprised that I hate classes that consist to 90% of setters and getters.
> 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" />
Again, I have to write custom code for a common task.
Steffen, thanx for detailed answers. I'll try to implement them. I hope that ExtBase and FLUID will
evolve to assist the coder in common tasks. Currently it seems that while I have not to worry about
persistence I have to write many repeating lines of code for simple stuff (question a).
Masi
More information about the TYPO3-project-typo3v4mvc
mailing list