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) »
  • Activities Mod: Update One Custom Data Field with Data From Another Custom Field
Pages: [1]

Author Topic: Activities Mod: Update One Custom Data Field with Data From Another Custom Field  (Read 3273 times)

cmcallister

  • Guest
Activities Mod: Update One Custom Data Field with Data From Another Custom Field
March 25, 2009, 06:45:56 am
This is my first venture into hooking some new functionality into CiviCRM, so please feel free to redirect me where I need to go. :)

BACKGROUND:
I'm using the Activities core component as a way of tracking student extra-curricular involvement. Teachers will track their students by five categories (Activity Types). The students are awarded 'points' for their participation in a particular activity. Points are captured using a Custom Data field related to each Activity Type.

In order for students to win an award in a particular category. They need to have achieved a certain total number of points within a particular category. Example: Billy won an Academic Award because his total number of points in Academic activities is equal to 170 points.

TASK:
- Add up the POINTS (custom data) for each Activity Type, and post the total to an ACTIVITY TYPE TOTAL (custom data) field that is searchable.

I have all of the fields created that are needed to capture individual points per activity, as well as the place-holder custom data fields for storing the TOTALS for each Activity Type (which are searchable of course) - I just need to know what the best method is to add up and shuttle the data from one point to the other.

I appreciate any help or light that can be shed on the subject. Thank you very much. :)

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: Activities Mod: Update One Custom Data Field with Data From Another Custom Field
March 25, 2009, 06:57:09 am

a couple of options and some ideas

1. Create a custom search that basically computes and displays activity total based on some search criteria. In this case activity total is a virtual field and not in the DB, so folks cant see it

2. Add a custom group / field for a contact with an activity total field. Make this field a "view only field" (i.e. set by php code). Implement hook_civicrm_custom (http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+hook+specification#CiviCRMhookspecification-hookcivicrmcustom) to update this field whenever you notice a write on a activity point custom field. u'll need to be relatively good at sql and php to do so :)

3. if you have mysql super user privileges on your DB, you can potentially use a trigger / stored procedure to update the activity total custom field (since its a relatively simple calculation). This might be faster and easier (and also more scalable)

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

cmcallister

  • Guest
Re: Activities Mod: Update One Custom Data Field with Data From Another Custom Field
March 25, 2009, 07:19:31 am
Some great ideas here! There's also a need for students to be able to login and see their activity category totals. Its also preferable that teachers can easily search by range- a custom profile field that captures their category totals seemed like the best way to go.

2.  Option #2 seemed like the best route to take before I posted here. Issuing a hook that performed the calculation and modified the appropriate TOTALS field upon write seemed like the way to go - especially considering there's maybe only 1400 students total. It doesn't seem like it would cause any serious performance problems if a teacher entered 15 people for one activity (say, a sports team).

3. Option #3 interested me quite a bit. Would this be similar to a cron job that would execute based on time? Or would this be a procedure that executed as part of an action within CiviCRM.

There's also a concern that I don't wish to modify the core too much, so it doesn't create any issues for me when upgrading them to later versions of Drupal/CiviCRM. Based on these requirements, would you lean more towards option 2 or 3?

Thank you so much. :)

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: Activities Mod: Update One Custom Data Field with Data From Another Custom Field
March 25, 2009, 09:30:15 am

does not seem a large performance hit for your case

triggers are part of mysql. So your trigger will be fired whenever that custom field is created/updated. You'll need SUPER privileges with mysql to add triggers etc

neither 2 nor 3 modifies core. However since it is custom code, you will need to maintain it going forward

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

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Activities Mod: Update One Custom Data Field with Data From Another Custom Field
March 25, 2009, 10:25:37 am
Separately - we are interested in hearing more about CiviCRM implementations in school settings. Please take a few minutes to add a brief description of your project on the CiviCRM Showcase board:

http://forum.civicrm.org/index.php/board,4.0.html

thx!
Protect your investment in CiviCRM by  becoming a Member!

cmcallister

  • Guest
Re: Activities Mod: Update One Custom Data Field with Data From Another Custom Field
March 28, 2009, 12:16:20 am
Hi Dave,
Certainly - I can do a full writeup on the use at the highschool level. I'm also looking into using CiviCRM as a solution for higher ed (where I work). In order to get this off the ground, can you make a recommendation (amongst your recommendations) of developers you've worked with to write this bit of code that Lobo and I are speaking about?

Thank you.

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: Activities Mod: Update One Custom Data Field with Data From Another Custom Field
March 28, 2009, 06:55:58 am

you might want to contact web access india ltd to help you out. they are on http://civicrm.org/professional/

note that the civicrm dev team in india is based at web access, so as a disclaimer we do have a professional and financial relationship with them. please do your due diligence :)

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) »
  • Activities Mod: Update One Custom Data Field with Data From Another Custom Field

This forum was archived on 2017-11-26.