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 »
  • 5.0 Saloon »
  • 'Entities'
Pages: [1]

Author Topic: 'Entities'  (Read 741 times)

jcasharpe

  • I post occasionally
  • **
  • Posts: 57
  • Karma: 5
    • Woodlands Church
  • CiviCRM version: 4.4.6
  • CMS version: Drupal 7
  • MySQL version: MariaDB 10.0.13
  • PHP version: 5.5
'Entities'
April 30, 2014, 01:57:05 pm
One of the things that is quite arduous to do in the 4 series is to create my own 'entity'. Let me give an example:

I want to create an extension that records some activity but I want to record an extra notes field. I have two options; I can modify the activity entity schema to have the extra notes field or I can join on the activity id to another table. Either way I have to then propagate these modifications into BAO, DAO and API (and possibly Drupal views handlers) before I can then use it, either from an extension or some form of UI.

Drupal has the concept of entities and provides modules like eck to quickly build up this infrastructure. Until Civicrm provides something similar I have no motivation to write extensions that are cross CMS compatible because writing a Drupal specific extension is so much easier.

Thoughts?

jcasharpe

  • I post occasionally
  • **
  • Posts: 57
  • Karma: 5
    • Woodlands Church
  • CiviCRM version: 4.4.6
  • CMS version: Drupal 7
  • MySQL version: MariaDB 10.0.13
  • PHP version: 5.5
Re: 'Entities'
April 30, 2014, 02:00:18 pm
Taking this idea further we can actually remove a lot of code if we have the same sort of entity / bundle concepts that Drupal uses. For instance CiviMember then simply becomes additional metadata associated with membership of a group. The idea of membership of a household is equivalent to being a member of a group where the group has an address associated with it. This simplifies any logic dealing with merging by households because it is then simply a group membership query.

JonGold

  • Ask me questions
  • ****
  • Posts: 638
  • Karma: 81
    • Palante Technology
  • CiviCRM version: 4.1 to the latest
  • CMS version: Drupal 6-7, Wordpress 4.0+
  • PHP version: PHP 5.3-5.5
Re: 'Entities'
April 30, 2014, 02:05:30 pm
Hmm.  This is handled automatically in the API for custom fields - but you're right that the API doesn't provide a way to add a note to those entities* via the API.  I've also had to do extra work to work around that issue when using the API for imports.

That said - since adding custom fields to an entity DOES expose them via the API - is there another instance in which this is a problem?  If not, could it be solved by adding support at the API level for attaching a note to an entity that accepts notes?  That doesn't sound too hard to add, and would be a good feature.

*entities in this context meaning "CiviCRM entities", e.g. Contact, Membership, etc.
Sign up to StackExchange and get free expert CiviCRM advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

jcasharpe

  • I post occasionally
  • **
  • Posts: 57
  • Karma: 5
    • Woodlands Church
  • CiviCRM version: 4.4.6
  • CMS version: Drupal 7
  • MySQL version: MariaDB 10.0.13
  • PHP version: 5.5
Re: 'Entities'
April 30, 2014, 02:24:20 pm
The concept of custom fields needs to be extended to all of the entities i.e. Activities, Membership etc.. and all those code paths actually work; For instance the group custom field stuff doesn't always work in the same way it does for say Participants. We do get into an issue of bloat though in the number of Custom Fields; for instance take Event Participant custom fields. We have a number of different one off events that we collect some custom information in the participant record e.g. dietary requirements, whether someone can offer a lift etc.. These are all fields that are specific to only one instance of an Event; we currently have 21 different field groups on our participants for custom fields, each that was only required for a single event in most cases. I have a suspicion that at some point we will hit scalability issues due to the number of joins this generates in the queries. I guess that this highlights a subtly different use case where you want to be able to attach a set of fields to a single instance of an 'entity'.

Quote from: JonGold on April 30, 2014, 02:05:30 pm
  If not, could it be solved by adding support at the API level for attaching a note to an entity that accepts notes? 
You're making an assumption here that you know which entities you'd want to attach a note to; in general you should be able to attach anything to everything as thats the whole point of an extension, to provide functionality that hasn't been provided by core. If core places arbritrary restrictions like you can only attach notes to this set of entities then we're back to square one.

Quote from: JonGold on April 30, 2014, 02:05:30 pm
Hmm.  This is handled automatically in the API for custom fields - but you're right that the API doesn't provide a way to add a note to those entities* via the API.  I've also had to do extra work to work around that issue when using the API for imports.
This harks to the same point I was making in this thread (http://forum.civicrm.org/index.php/topic,32127.0.html); the API is missing simple things that you'd want to easily do. As a lot of these things are actually actions that the core does as well then by reimplementing those actions in terms of the API we do two things; we're constantly testing the API code as its the everyday code path used and we make sure that the API is broad enough to cover the useful things you'd want to do.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • 5.0 Saloon »
  • 'Entities'

This forum was archived on 2017-11-26.