wordpress custom fields: structured data table - wordpress

I know how to make custom fields for my custom post types. But I need a pretty complex custom field this time.
I'm making a website about agricultural machinery. There are a lot of types of machines. For every type of machine there are some products available with properties like size, mass, diameter, capacity, ....
Per type there is only one description, one title and one image needed. So my custom post-type machine contains posts (custom type = machines) with the basic information. For every machine I would like to sum up all the different size - mass - capacity - prize information in a table. I know I could just create a html table in the description, but I would really like the data to be structured so I can nicely style it, and eventually even do structured searches for price and stuff.
So ideally I would like to have a custom field that looks a bit like an excel sheet where I can create some columns and add rows per available product in the category. Any ideas how I can do this?
EDIT: I'm trying out the Types wordpress plugin http://wordpress.org/extend/plugins/types/. There's an option to group custom fields together and also an option to allow multiple instances of one field. Would be useful for me if there would be a possibility to allow multiple instances of a group. Does something like that exist?
EDIT: This looks promising. http://wp-types.com/documentation/user-guides/bulk-content-editing-with-fields-table/
I will look into it and maybe answer myself if it turns out to work :)

It seems like wp-types had the solution all along.
http://wp-types.com/documentation/user-guides/bulk-content-editing-with-fields-table/
This is what my custom data table looks like now:
Behind the scenes, all data is not actually saved in a single post. But wp-types allows you to create hierarchical relations between post types, and then provides a way to quickly create sub-posts straight from the parent. That's awesome enough for me.
In my case I created two post types. One called machine-type and another called machine.
machine-type holds all the basic information about the machine (title, description and image) while it's sub-type machine holds the specs for any of the different variants.

Related

Drupal 7 Views : How to reuse one view for multiple fields OR how to let user select which field view displays?

My Task: I have content type which have 100+ different mostly numeric fields (big questionnaire for NGO with yearly reports). For one field I can use Views module to let user select which reports include (for example one year) and display it as nice graph (using for example Views+Charts). I would have to define about 100+ nearly identical views, which differs only by what field data they use.
My Question: Is there any way how to reuse one view definition and just change data from which field id display?
Solutions so far: I found two not really good solutions:
Create one view, export it (using Features or similar way) and then clone this export, rewrite field it uses as source and than add. But this just speed up creating one view for each 100+ fields.
Use module Views Dynamic Fields - it allows user to select which fields to display. But I would still have separate definition how to display for each field, so not much better than add one view for each 100+ fields.
I suggest writing your own Views field display plugin! This is actually all documented within the Views module folder: views/docs/views.api.php. Depending on your fields I'm not sure how you would exactly connect the data to the view.
Another alternative would be to just use a PHP Code field, and figure out a way to programmatically display the data from the field you wanted. The downside to this is that you wont be able to use that field to sort/search on with any filters as far as I know.

Drupal data entry forms & db structure?

I'm trying to build a Drupal site in which users can input records containing data about "customers", "employees" and "sales".
I would like to be able to create a form(s) which takes data about a sale/customer/employee and can be associated with a record of a customer/employee(who made the sale)/sale.
I would also like to be able to display records showing a list of sales or customers or employees in which when clicking one record, it will open a page displaying all the relational data.
I'm new to development and am searching around like a headless chicken lol. I was thinking of using content types for sales/employees/customers and using individual nodes for each record then using something like views to displays filtered lists, but I am unsure if this is the best way to go about/structure it (maybe I should use separate custom tables or database and use a custom module to fetch the data?). It would also be nice if some of the fields can populate other fields based on it input and also if some fields can utilize a sort of auto-complete by garbing data from other records, or is that asking way too much?
Thank you for any suggestions you might be able to give me.
I, for one, would certainly prefer using a custom separate database and leave drupal databases to its own devices, if you would ever need to upgrade the site to a higher version of drupal it helps if you don't modify it, and also consider using webform (http://drupal.org/project/webform) as it makes development easier both in components and hooks.

Global data in drupal 7

I'm building one village's official site in Drupal 7. I need to create and store some information about village that will be accessible everywhere on the website (e.g. village's name, mayor's name, phone number, email, etc.). I want to define them in the admin site and access them in any node (e.g. all the data will be shown in the section about municipal office and some of them like phone number mentioned in the contact section. What is the best way to do that? Is there some module to handle that? Or should I write the own one? I have tried to search the answer there, but I found only topics about global variables (in PHP).
You can use the functions variable_get() and variable_set() to store arbitrary information that is available on all pages. It is easy to write a form that automatically saves all form fields with variable_set(), see http://drupal.org/node/222158.
Note:
- Saving variables with variable_set() will clear the cache of all variables, you should not use it for information that changes regularly.
- All variables are cached in a single, global cached and fetched on every single page request. You shouldn't store large amounts of data or data that is only used very seldomly.
The answer by Berdir is already very good in case you only want to store the raw data. However, if you always want to display the data in the same way like in some kind of widget format, you have other options, too.
For example, you could create a block with the contact details and you only show it on specific pages.
If you need more flexibility, you might consider to write a small module with different theming functions. You would either store the data directly in the module or in the variable table as outlined by Berdir.
In any case, if you want to allow the user to change this data on his own, you will probably need to write a small form in the backend. Otherwise, the user will need to manipulate the database directly to change the data.
You could also consider Creating advanced theme settings.
See how you can specify the site's logo path in your theme? You could do something similar with the info you would like to display on your site, practically setting up your theme as a template for a village website.
You get to add custom fields in your theme admin settings, field values can then be retrieved by using theme_get_setting()

Measurement sheets in Drupal 6

I'm doing a project for a surveying company in Drupal 6. Ultimately, employees will need to enter measurements into a new content type. Currently they do it in a big Excel spreadsheet that has a bunch of macros to do calculations between cells (Meters to Feet, m^2, some pricing stuff).
My question is:
How would one go about replicating the functionality of this spreadsheet best in Drupal 6, keeping in mind the amount of data the employees using this system gather varies between projects (I.e., 3-floor house versus 1-floor with basement; etc.).
I have two ideas so far:
Create a new content type and populate it with CCK fields. Use Sheetnode's CCK functionality to drop Sheetnode CCK fields to replicate the spreadsheet exactly. Use Views to display this data other ways.
Create a new content type and populate it with CCK fields. Use Views (and possibly something like Views Calc) to get varying measurement values.
That said, I'm completely open to suggestions outside of these two implementations.
Thank you!
I dont have an answer so much as a caution. I did a project where a number of pieces of content were rendered simultaneously on a page, each piece being in its own node. The down side to multiple nodes is the performance hit you will take having at least one (possibly complex) query per node.
So in this case, if there were many many lines in the sheet, and each line was a node, you might take a pretty heavy performance knock.
This might be acceptable - but I thought I'd give you the heads up.
This might be one of those times where its best to actually create a purpose-built mechanism on-top of the Drupal API instead of using nodes+CCK.
Like I said, I could be being over cautious. It depends on your exact usecase.
HTH!
This seems like the kind of question http://drupal.stackexchange.com was made for...
I ended up doing this with jQuery, Measured Value Field and Flexinode; see: Auto-updating width/length/area using jQuery and Drupal6

Drupal: module, cck or other

I have a legacy PHP form that I'm moving over to Drupal 6. I'm trying to make things easy for me as well as the future admins of the site. The below form is the heart of the old site data. So far in cck I have Locations, in taxonomy I have Countries, now I just need to allow these Species data to be added. I would do it in CCK, but I also want to be able to add N number of Species to each form with all 12 Quadrats of % Cover and Density. (For each species in that location there is % Cover, Density, Flower, Fruit, etc ie alot of data!)
Basically my question is, can this form be accomplished in 1) CCK where the whole form can be filled out on one page, 2) by creating a custom CCK field to enter in a Species (using FormAPI) or 3) bite the bullet and write a custom module with FormAPI fields and keep track of the data in tables myself?
Thanks for your insight.
It can be helpful to think of CCK the way you would an Object Oriented challenge: what are my Things, and how do they relate to each other.
If I'm reading you correctly, you're creating some kind of Botanical Entry type. I gather that Location is set up as a separate type, and that field could be a node reference in BE. (Or perhaps it's just a list in an text field with a drop down widget.) Same thing with Transect and Station. Researchers could be a user reference field.
Then you want to add your species data (the second form). I don't really know what all those fields are for, but I'll bet that interface could be simplified. Species might be a separate CCK type, which you'd connect via node reference, or you could create a custom CCK field type. Either way, you could allow adding more than one of those to a node to get the mulitple entries. If you do the node reference approach, you could probably use http://drupal.org/project/popups_reference to make the adding easier.
HTH

Resources