Jump to content

Recommended Posts

Posted

Dimension Fieldtype

A new fieldtype to enter 3 integer values for width, height and depth.

post-100-0-61302300-1374175340_thumb.png

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/

  • Like 8
Posted

Are you calculating volumes for shipping by any chance? Just one of the options that jumps out for me :)

  • Like 1
Posted

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. 

  • Like 1
Posted

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.

  • Like 3
Posted

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.

  • Like 1
Posted

Great module Soma! Maybe also having shortcut and selector for area in addition to volume?

Do you mean area = W*H ?

Posted

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..

Posted

Not sure what you mean by can it be used... it can be used for whatever you make out of it.

  • 7 months later...
Posted

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 ?

Posted

They set a index for the field in table. It's for optimizing when query database. Indexed field are faster to search.

  • Like 3
  • 5 years later...
Posted

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.

screenshot-futuresteam.de-2019-07-21-01-07-35.png

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...