Soma Posted July 18, 2013 Posted July 18, 2013 Dimension Fieldtype A new fieldtype to enter 3 integer values for width, height and depth. Output You can output the values from a page like this: echo $page->fieldname->width; echo $page->fieldname->height; echo $page->fieldname->depth; Volume There's also support for a "computed" value of the volume. W*H*D. This will get stored additionally to the database and updated every time a dimension value changed, so it can also be used in selectors for querying. echo $page->fieldname->volume; Selectors for searching The dimension can be used in selectors like this: $pages->find("dimension.width=120"); $pages->find("dimension.height>=100, dimension.depth<120"); $pages->find("dimension.volume>=1000"); Integers and Formatting The values are entered and stored using integer and not float, as this makes for easier headache free usage. Treat them as integer and format them on the output if you need to. echo (number_format(($p->dimension->width/100),2)); // 538 will be 5.38 Field Settings There's field settings for the width of the inputs in pixels. There's a input setting to add a suffix string to each input like "mm" or whatever you like. The module is already on the repository ready to use http://modules.processwire.com/modules/fieldtype-dimension/ 8
Pete Posted July 18, 2013 Posted July 18, 2013 Are you calculating volumes for shipping by any chance? Just one of the options that jumps out for me 1
ryan Posted July 18, 2013 Posted July 18, 2013 Looking great Soma. One quick suggestion would be to update your getDatabaseSchema method to have separate indexes on the width, height and depth. Currently, your index would only be used if one queried width and height and depth, or width and height, or just width, as the order matters in a combined index. If someone tried to query height independently of width, an index wouldn't be used. Whereas if width, height and depth each had their own index (either to replace, or in addition to the existing index) then they would all have the potential of having their indexes used in PW queries. This is assuming my understanding of MySQL combined indexes is correct: if you query just depth or height there would be no index to use since it is not the first named field in any combined index. 1
Soma Posted July 18, 2013 Author Posted July 18, 2013 Thanks Ryan! Haven't really thought about that, so thanks for the heads up! I changed the keys and also added support for a volume property that will get calculated everytime a dimension changes and stored to DB. So it can be used for convenience if needed to get the volume, and also use it in selectors. I updated the module and readme to reflect that change, along with some cleanup and coments. If you happen to already have the module installed, I recommend to reinstall the module for the updated index in db tables. 3
Soma Posted July 18, 2013 Author Posted July 18, 2013 Thanks kongondo, this idea was from mindplay.dk! Also wanted to add: - There's field settings for the width of the inputs in pixels. - There's a input setting to add a suffix string to each input like "mm" or whatever you like. 1
apeisa Posted July 18, 2013 Posted July 18, 2013 Great module Soma! Maybe also having shortcut and selector for area in addition to volume?
Soma Posted July 18, 2013 Author Posted July 18, 2013 Great module Soma! Maybe also having shortcut and selector for area in addition to volume? Do you mean area = W*H ?
pideluxe Posted July 18, 2013 Posted July 18, 2013 Do you mean area = W*H ? Shouldn't the area be: A = W * D? This is the space a cube occupies on a surface.
kongondo Posted July 19, 2013 Posted July 19, 2013 Shouldn't the area be: A = W * D? This is the space a cube occupies on a surface. Hmmm, I don't think so. Never heard of area of a cube . You can get surface area though using SA = 6 × a2. Here, I believe Anti is referring to a two dimensional surface, in this case a square/rectangle..
Ibn Saeed Posted July 19, 2013 Posted July 19, 2013 The first thing that popped in my mind was Shipping charges, any chance if it can be used for that ?
Soma Posted July 20, 2013 Author Posted July 20, 2013 Not sure what you mean by can it be used... it can be used for whatever you make out of it.
Martijn Geerts Posted March 5, 2014 Posted March 5, 2014 I have a hard time to understand the getDatabaseSchema(Field $field) methode. I Looked at the Fieldtype.php but that doensn't make me any wiser. In your Fieldtype you have in that methode: $schema['keys']['data_height'] = 'KEY data_height(data_height)'; $schema['keys']['data_depth'] = 'KEY data_depth(data_depth)'; $schema['keys']['data_volume'] = 'KEY data_volume(data_volume)'; What do they do ? If I leave them out the Fieldtype seems to function the same (sure I miss something here) If one of the columns in the field table is of type TEXT & those keys are set, the field throws an error while creating: (SQLSTATE[42000]: Syntax error or access violation: 1170 BLOB/TEXT column 'data_tralalala' used in key specification without a key length) So basicly what do they do & when do I need to set that array ?
Soma Posted March 5, 2014 Author Posted March 5, 2014 They set a index for the field in table. It's for optimizing when query database. Indexed field are faster to search. 3
NorbertH Posted July 20, 2019 Posted July 20, 2019 Using this field in conjunction with a lister , i can select its subfields like width or height for the lister, but there is no content shown. The button field i although used seems to have this functionality , its subfields appear in the lister. But to be true i cant figure out whats wrong.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now