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) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Labels and descriptions in table civicrm_option_group
Pages: [1]

Author Topic: Labels and descriptions in table civicrm_option_group  (Read 1124 times)

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Labels and descriptions in table civicrm_option_group
September 15, 2010, 08:32:14 am
I am creating a specific API where I retrieve, on top of the standard contact_get and location_get, some custom values. I am writing a function to retrieve labels for option values, and whilst doing that I am stumbling of the fact that in the table civicrm_option_group sometimes the field 'label' holds values and sometimes not, and the same applies for the field 'description'. Is that on purpose? Can I just correct it with this SQL statement:
Code: [Select]
UPDATE civicrm_option_group SET label = description WHERE isnull(label) and not isnull(description)
Erik
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

demeritcowboy

  • Ask me questions
  • ****
  • Posts: 570
  • Karma: 42
  • CiviCRM version: Always the latest!
  • CMS version: Drupal 6 mostly, still evaluating 7.
  • MySQL version: Mix of 5.0 / 5.1 / 5.5
  • PHP version: 5.3, usually on Windows
Re: Labels and descriptions in table civicrm_option_group
September 15, 2010, 09:32:37 am
I'd use "name" instead of "description".

name is like key (never changes)
label is what the user sees
description is additional info dependent on context

example activity type:

name = my_activity
label = My Activity
description = Here is some text that appears at the top of the activity form.

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Labels and descriptions in table civicrm_option_group
September 15, 2010, 09:36:42 am
Thanks, I will. I was just hoping to avoid retrieving the required name for the custom data option_group, which will be something like 'burgerlijke_staat_20100708172613'
Erik
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

demeritcowboy

  • Ask me questions
  • ****
  • Posts: 570
  • Karma: 42
  • CiviCRM version: Always the latest!
  • CMS version: Drupal 6 mostly, still evaluating 7.
  • MySQL version: Mix of 5.0 / 5.1 / 5.5
  • PHP version: 5.3, usually on Windows
Re: Labels and descriptions in table civicrm_option_group
September 15, 2010, 09:39:57 am
I guess you could put some string manipulation in the update query, e.g. proper-case it, remove digits and replace underscores with space.

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Labels and descriptions in table civicrm_option_group
September 15, 2010, 09:48:43 am
I will have a nice play and let you know what I eventually came up with :-). Thanks!!!!
Erik
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Labels and descriptions in table civicrm_option_group
September 20, 2010, 02:21:31 am
OK, wrap up and workaround for my problem.

Situation
I have a custom data field that I use to store the marital status of a person. This is custom field 4, and the name of the custom field in the table civicrm_custom_field is
burgerlijke_staat_4 with label burgerlijke staat. This field has an option group attached, with all the possible values. This option group is created by the core functionality in table civicrm_option_group with the name 'burgerlijke_staat_20100708172613' and the label 'burgerlijke staat'

My problem
I am developing a specific API, based on the standard contact_get and location_get API's. I want to retrieve the labels for option values and return those in my API. So for example with phone_type_id 1, I also want to return the label of the phone_type Phone. I developed a function that retrieves that label, using CRM_Core_BAO_OptionGroup::retrieve to get the id of the option group and CRM_Core_BAO_OptionValue::retrieve to get the label for the specific option.
I can first retrieve the name of the required Option Group with the name 'phone_type'. However, I can not do this for my custom data option group as I can not retrieve the name 'burgerlijke_staat_20100708172613' anywhere. In that case I can use the label 'burgerlijke staat' to retrieve the id of the option group, but label is empty for phone_type. This is inconsistent and forces me in my function to make a distinction between a standard option value and an option value related to custom data.

Workaround
What I do in my function is pass either name or label as parameter, and retrieve in one or the other way. I hope we will have time to discuss this during the European code sprint and come up with a good solution  ;)
Erik
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

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: Labels and descriptions in table civicrm_option_group
September 20, 2010, 04:19:02 am

yes, we should fix this and make it more consistent. we can use the upgrade script to fix all the current places (we are doing this for custom/profile group/field)

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) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Labels and descriptions in table civicrm_option_group

This forum was archived on 2017-11-26.