CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Hierarchical Custom Data
Pages: [1]

Author Topic: Hierarchical Custom Data  (Read 2921 times)

pbarmak

  • I post occasionally
  • **
  • Posts: 111
  • Karma: 3
  • CiviCRM version: 3.3.5
  • CMS version: Pressflow 6.19
  • MySQL version: 5.1
  • PHP version: 5.2.10
Hierarchical Custom Data
July 27, 2010, 03:59:25 pm
Apologies if this has been answered, I couldn't find a similar post.

We're looking to have some custom fields that are currently set up as a lookup table in our legacy system.  Something like:
Group     Item
A           Car
A           Van
B           Apple
...

where multiple Items belong to one Group.  And, of course, Items have other characteristics that we would want to include and show up on reports as well.

We'd like to set up custom fields which keep the hierarchy/relationship between Group and Item.  So a user would pick the Group, and the Item dropdown list would refresh to show only those Items in that Group.  Same is true the other way (pick an Item without first picking a Group, the system automatically selects the Group).

The idea would be to then set up custom searches or reports, reporting at the Group level (summarizing data at the higher level) or at the Group/Item level.

How would we set something like this up in Civi?

If it helps, we're typically looking at this type of hierarchy in our Events and Contributions.

Thanks!

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Hierarchical Custom Data
July 27, 2010, 05:55:48 pm

no support for hierarchical custom fields as yet. u'll have to do this via hooks

there has been some demand for this, so coming up with a generic custom field(s) that does this would be awesome

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

pbarmak

  • I post occasionally
  • **
  • Posts: 111
  • Karma: 3
  • CiviCRM version: 3.3.5
  • CMS version: Pressflow 6.19
  • MySQL version: 5.1
  • PHP version: 5.2.10
Re: Hierarchical Custom Data
July 28, 2010, 07:42:51 am
Thanks for the quick reply.  What hooks would allow us to refresh a second custom field based on the first field's value change?  Can this be done with just hooks or do we need to figure out a refresh mechanism on the form itself (via javascript or something)?

I'd love to hear what you all have been doing as a workaround.  I might be over-thinking the complexity here.  I'm not exactly sure what the easiest method may be as an interim solution.

Thanks

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Hierarchical Custom Data
July 28, 2010, 03:36:36 pm
You might be able to put together an interim solution strictly with a customized template. I'm thinking a combination of jQuery magic to dynamically build the select options for custom field 2 based on custom field 1 selection, combined with using crmAPI in the template to set default filtered set of options when editing existing record.

http://civicrm.org/node/599

Maybe using the grouping column in civicrm_option_value table for to link the child (custom 2) rows to the parent row...

CAVEAT: More of a brainstorm - might not be do-able once u try and put the pieces together.  ???
Protect your investment in CiviCRM by  becoming a Member!

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Hierarchical Custom Data
July 28, 2010, 07:17:28 pm

might want to check the chainSelect jQuery widget that we use for our state/country hierarchical selector

would be good to have a recipe for folks to implement hier select via hooks/customized templates etc

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

pbarmak

  • I post occasionally
  • **
  • Posts: 111
  • Karma: 3
  • CiviCRM version: 3.3.5
  • CMS version: Pressflow 6.19
  • MySQL version: 5.1
  • PHP version: 5.2.10
Re: Hierarchical Custom Data
July 29, 2010, 08:57:41 am
You know, the more I look into this, the more I'm realizing single-column Custom Fields, even ones that work with hierarchies, might not be cutting it for us.  Our need for custom fields is really building a table; an entity that has a key plus other descriptive fields for that key, just as any normal transactional db table would have.

It seems like what we really need are Custom Schemas and Custom Tables.  I'm sure the concept makes sense ... here are some ideas (sorry if they are all over the place, just thinking out loud)

A Custom Schema would have one or more Custom Tables, with some characteristics:
  • Every table has an id field - auto increment, pk
  • Table names have rules, but in general, are user driven
  • Each Table has one or more Custom Fields similar to the current Custom Fields (same rules, etc)
  • Each Table has a Unique Key and users pick the Fields belonging to that Key

A Custom Schema would also have Relationships between Custom Tables.  This sets up our joins and FKs.

Users would then be able to include Custom Fields in profiles by picking the Custom Table first, then the Field from that table.  Maybe the form logic would create a "View" of all the tables, pre-joined so the user picks fields from that view.

Custom Searches and Reports would be able to pull in these Schemas and allows report builders to choose Fields from different Tables (and either manually or automatically include Relationships as JOINs in the query).

Of course, we'd need an Admin interface to manage the data in the Tables once the Schema is built - to start, maybe something simple like a hook into phpMyAdmin that just provides the tables and allows users to edit the data from there?

It seems to me like a bunch of the logic needed for this might already be in place as schema creation exists today with custom fields (MySQL tables are created based on those groups and fields).  I wonder how much incremental work it would be to expand on that and make Custom Tables instead.

Is this something that might interest others or is it something specific to our team?  How have others handled this type of thing so far?

For now, I'm actually thinking of providing my Admin users (or maybe a new set of "super admins") a phpMyAdmin login that has permissions to a new database which has our custom tables and then link/mimic those tables to current Custom Fields in some way (have the Custom Field Value be the id of the table so they join) - I'd have to then build DB triggers to populate/modify those linked Custom Fields with whatever has changed on the back-end, but I can't think of a better work-around for what we need.  I'd love to get some opinions on this.

Thanks!

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Hierarchical Custom Data
July 29, 2010, 07:09:06 pm

while we do have a fair amount of the code for the below in place, building support for "independent" tables is still a fairly big feature (and will probably be a point release in its own right). if you are interested in sponsoring / developing this feature check:

http://wiki.civicrm.org/confluence/display/CRM/Recommended+Steps+for+Developing+and+Contributing+to+CiviCRM+Core+Codebase

A easy workaround for now, is to develop and manage this table on your own via PMA and custom scripts. I've done this in the past for the school project

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Hierarchical Custom Data

This forum was archived on 2017-11-26.