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) »
  • Unique names for v3
Pages: [1]

Author Topic: Unique names for v3  (Read 552 times)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Unique names for v3
January 27, 2011, 11:55:02 am
Hi all,

Current state of play is that many fields have unique names in the schema as well as their field names e.g

civicrm_contact.is_deleted has the unique name contact_is_deleted which distinguishes it from civicrm_activity.is_deleted.

We have established that:

1) the api currently supports and returns a mismash of field names & unique names
2) the desired direction is to support only unique names
3) we are unlikely to get this standardised in the v3 api release

However, I have noticed that one reason many requests don't return unique names is that the object_to_array function actively strips them:

Code: [Select]
/**
 * Converts an object to an array
 *
 * @param  object   $dao           (reference )object to convert
 * @param  array    $dao           (reference )array
 * @return array
 * @static void
 * @access public
 */
function _civicrm_object_to_array( &$dao, &$values )
{
    $tmpFields = $dao->fields();
    $fields = array();
    //rebuild $fields array to fix unique name of the fields
    foreach( $tmpFields as $key => $val ) {
        $fields[$val["name"]]  = $val;
    }
   
    foreach( $fields as $key => $value ) {
        if (array_key_exists($key, $dao)) {
            $values[$key] = $dao->$key;
        }
    }
}


I suggest we do one of the following

1) adjust this function to accept another variable $unique = 0 and if set then filter for unique names rather than field names in this function

OR

2) create another function (possibly a wrapper on the above) that converts to unique names rather than field names & call that function from any that we work on that we determine are 'unique name compliant'

AND POSSIBLY

mark functions in some way (e.g. defining a constant) that hopefully the @schema can pick up to say whether they are unique name compliant or not (not = either field compliant or a mismash!)

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) »
  • Unique names for v3

This forum was archived on 2017-11-26.