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) »
  • getfields ['format'] = simple
Pages: [1]

Author Topic: getfields ['format'] = simple  (Read 773 times)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
getfields ['format'] = simple
September 20, 2011, 05:10:16 pm
For the second time in 2 days I find myself writing a function that is a wrapper around getfields - with the requirement in both cases to have an array of keys being field names & values being field title.

I feel like it would be worth implementing

getfieldssimple or another format option (the second option has the problem that formats are not just for getfields)



 /**
   * Returns a list of fields available to be mapped for users
   *
   * @return array
   *  Keys: machine names of the fields (to be passed to addFieldMapping)
   *  Values: Human-friendly descriptions of the fields.
   */
  public function fields() {
  if(!civicrm_initialize()){
    return;
  }
  require_once 'CRM/Utils/Array.php';
   $fields = civicrm_api($this->entity,'getfields',array('version' => 3));
  $values = array();
  foreach ($fields['values'] as $field => $valueArray) {
    $values[$field] = CRM_Utils_Array::value('title',$valueArray,CRM_Utils_Array::value('label',$valueArray,$valueArray['name']));
  }
   return $values;
  }

NB - it might be that we should return a 'title' or other descriptive field if one doesn't exist as part of getfields - much like the above does.
« Last Edit: September 20, 2011, 05:31:37 pm by Eileen »
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

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • getfields ['format'] = simple

This forum was archived on 2017-11-26.