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) »
  • New proposed action 'getvalues'
Pages: [1]

Author Topic: New proposed action 'getvalues'  (Read 973 times)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
New proposed action 'getvalues'
September 13, 2013, 01:25:22 pm
So, we have getvalue but for autocompletes 'getvalues' would be handy - e.g

Code: [Select]
CRM.api('state_province', 'getvalues', array(
  'country_id' => array('IN' => array(1228, 1229),
  'name' => array('LIKE' => 'M%'),
  'return' => 'name',
  'options' => array('limit' => 5)
);

to return an array like
Code: [Select]
{
'1018' : 'Maine',
'1019' : 'Maryland'
'1020' : 'Massachusetts'
}
Code: [Select]
CRM.api('state_province', 'getvalues', array(
  'country_id' => array('IN' => array(1228, 1229),
  'name' => array('LIKE' => 'M%'),
  'return' => 'name',
  'options' => array(
    'limit' => 5,
    'key' => 'abbreviation',
  )
);
to return an array like

Code: [Select]
{
'MD' : 'Maine',
'ME' : 'Maryland'
'MA' : 'Massachusetts'
}

Code: [Select]
CRM.api('state_province', 'getvalues', array(
  'country_id' => array('IN' => array(1228, 1229),
  'name' => array('LIKE' => 'M%'),
  'return' => 'name, abbreviation',
  'options' => array(
    'limit' => 5,
    'key' => 'id',
    'separator' => ': ',
  )
);
Code: [Select]
{
'1018' : 'MD: Maine',
'1019' : 'ME: Maryland',
'1020' : 'MA: Massachusetts',
}

The missing magic in the above (specific to state) is how to deal with the config var of limit to state. We could limit to configured if country is not specified & people can bypass using 'country_id' => array('LIKE' => '%',

Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: New proposed action 'getvalues'
September 16, 2013, 11:27:39 pm
Hi,

In jsland, I tend to find easier not to use keys, just an array that contains all the data, eg.

Code: [Select]
[
{id:'1018', abbreviation : 'MD',name: 'Maine'},
id:'1019', abbreviation: 'ME', name: 'Maryland'},
{id:'1020', abbeviation:'MA', name:'Massachusetts',}
]

if the other formats are needed, they can be trivially generated on the client side from this single one, so I'd rather not go the options.key options.separator
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

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: New proposed action 'getvalues'
September 16, 2013, 11:40:22 pm
I think we need to make the most of the js possibilities so +1 for X
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: New proposed action 'getvalues'
September 17, 2013, 12:18:58 am
hmm - so that is basically the same as doing a get & then using the values key. Maybe I'm still just too php in my thinking as the one I thought would be useful was

Code: [Select]
{
'1018' : 'Maine',
'1019' : 'Maryland'
'1020' : 'Massachusetts'
}

as it would mean the code doing the look up wouldn't need to know the field names involved - just $field => $key

Maybe I just need to re-look at my assumptions & use the existing get
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

nicolas

  • I post occasionally
  • **
  • Posts: 92
  • Karma: 6
    • cividesk
  • CiviCRM version: 4.4 LTS
  • CMS version: Standalone (yep)
  • MySQL version: 5.1
  • PHP version: 5.3
Re: New proposed action 'getvalues'
September 17, 2013, 10:36:15 am
Eileen - how would this fit with the new pseudoconstants functions that Tim worked on?
KISS: if this is already possible with a get, and massaging the output to the right format, then no need for 'getvalues'.
cividesk -- CiviCRM delivered ... your way!

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: New proposed action 'getvalues'
September 17, 2013, 01:55:34 pm
Yeah, my thinking was that getvalues would make js simpler (particularly in the context of jquery lookups) in the same way that 'getvalue' & getsingle' are handy wrappers & would not just apply to pseudoconstants.

However, I was specifically looking at existing autocomplete code as my starting point. X's reply has made me realise I would need to pass the 'return' values to my code anyway & so it makes sense to work with the existing get.

The problem with using a pseudoconstant (getoptions) here (for state & country)  is
1) I don't think you can specific country calling getoptions on state
2) in the context of an autocomplete the performance of calling getoptions is bad as it will render them all rather than those you want
3) the pseudoconstant is restricted by 'available states'. Turning on available states for all, or large numbers of, countries kills the site (out of memory errors) so I was hoping to be able to access states not deemed available
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: New proposed action 'getvalues'
September 17, 2013, 04:22:07 pm
@nicolas,Coleman was the main man behind the pseudo-constants changes. But thanks for thinking of me. ;)

nicolas

  • I post occasionally
  • **
  • Posts: 92
  • Karma: 6
    • cividesk
  • CiviCRM version: 4.4 LTS
  • CMS version: Standalone (yep)
  • MySQL version: 5.1
  • PHP version: 5.3
Re: New proposed action 'getvalues'
September 17, 2013, 09:41:27 pm
Ooops ... Coleman, next time we met f2f beer's on me  ;)
cividesk -- CiviCRM delivered ... your way!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • New proposed action 'getvalues'

This forum was archived on 2017-11-26.