Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2008-09-30 17:21:43
- azw
- Member
- Registered: 2007-01-29
- Posts: 279
[request] A plug-in to provide calculated custom fields
I’d be interested in a plug-in that allows us to create calculated custom fields.
The plug-in would calculate the value for the calculated custom field whenever one of the source fields is changed.
For example, let’s say I have a section called “reports” which I use for articles about a number of reports. I’d have a custom field called “type of document” with four options (four different types). I’d also want to associate a color to each type of document. The plug-in would automatically assign a color value to the associated calculated field when the new article is submitted.
Type of document – Color
annual report > blue
monthly report > green
daily report > yellow
hourly report > red
I’ve used a similar setup with Google maps so that different types of articles have different pin markers. A plug-in would eliminate a lot of server and client (javascript) overhead.
There would have to be a way for the site developer to insert the PHP to be used to calculate each calculated custom field.
Last edited by azw (2008-09-30 17:24:50)
Offline
Re: [request] A plug-in to provide calculated custom fields
I’m not sure if I entirely follow why you need a second custom field for colour if the document type and colour will always correspond. Surely then one would be sufficient and you could use if_custom_field with document_type to detect which type of document it is and set your output colour correspondingly for your particular purpose (I’m assuming using straight css is not enough).
(If there is a reason I haven’t followed, then maybe this is something for the new txp:variable
tag in the forthcoming 4.07 version, in which you can store and use a value without it having to be a custom_field).
TXP Builders – finely-crafted code, design and txp
Offline
#3 2008-09-30 21:47:56
- azw
- Member
- Registered: 2007-01-29
- Posts: 279
Re: [request] A plug-in to provide calculated custom fields
Hi, Jakob. Thanks for the reply!
The example is simplified, so you can’t judge the need from that. There are a series of conditions which are evaluated to give the ending value.
The original code for Google Maps on Textpattern uses JavaScript to do a lot of the work preparing the data for the map. Unfortunately, the JavaScript recalculates these values each time the page is redrawn. I’m looking for ways to increase the efficiency and speed. Server-side processing done once, would be a lot more efficient than client-side processing done for every page draw.
Yes, txp:variable sounds useful in general, but would only be helpful in this case if the variable was related to a specific article, like the custom field is.
Last edited by azw (2008-09-30 21:48:36)
Offline
Re: [request] A plug-in to provide calculated custom fields
I’ll put a couple of my students to make a first attempt at this.
It won’t have optimizations or caching, but will leave the calculation in the server side.
You’ll be able to put up to 250 chars of php in a custom field and get whatever your code “return“s
Mariano Absatz – El Baby
I don’t suffer from insanity. I enjoy every minute of it.
Offline
#5 2008-11-14 03:34:13
- azw
- Member
- Registered: 2007-01-29
- Posts: 279
Re: [request] A plug-in to provide calculated custom fields
¡Qué bomba! That’d be fantastic, Mariano! Let me know if you need testing or feedback.
By the way, if you’re looking for a fairly easy projects, here’s another:
http://forum.textpattern.com/viewtopic.php?id=28818
I’ll update it tonight with a more complete description.
Last edited by azw (2008-11-15 06:24:31)
Offline
#6 2008-11-15 06:26:02
- azw
- Member
- Registered: 2007-01-29
- Posts: 279
Re: [request] A plug-in to provide calculated custom fields
A propósito, si sus alumnos quieren comunicar conmigo, podemos hablar en castellano.
Offline
Re: [request] A plug-in to provide calculated custom fields
How about doing this with an article form and css selectors.
Set up a custom field called “my_article_type”
You can use glz_custom_fields to make it a select if you like and populate it with values
Your article-form
<div class="article <txp:custom_field name="my_article_type" />">
<txp:title/>
<txp:body/>
Whatever else you want
</div>
your css
.annual {color:red}
.monthly {color:orange}
.weekly {color:blue}
.daily {color:green}
Or did I miss the point?
Offline
#8 2008-11-15 19:11:53
- azw
- Member
- Registered: 2007-01-29
- Posts: 279
Re: [request] A plug-in to provide calculated custom fields
MrDale, when you and other people suggest these things I’m always stunned by the range of alternatives and the creative thinking. Thanks for giving this some thought!
In this case, the color is actually related to a color of an image of a “map pin” or marker to be displayed in a Google Map. There are different image files with different color pins. I don’t think a CSS approach would work because you have to specify which images to show in the JavaScript that requests a map. I now have to run a JavaScript routine to determine the marker color every time the map is displayed. If it could be done just once, when the article page is saved, that would save a lot of processing.
In another example, someone has a catalog of products, each item has a specific price. They wanted to be able to calculate a range of prices automatically for sorting purposes (0-10.00, 10.01-20.00, etc.). Instead, they had to enter two custom fields, one for the price and another for the price range.
Offline