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) »
  • Using Hooks to modify Event Custom Data for contact / individual
Pages: [1]

Author Topic: Using Hooks to modify Event Custom Data for contact / individual  (Read 2161 times)

geeffland

  • I’m new here
  • *
  • Posts: 29
  • Karma: 0
Using Hooks to modify Event Custom Data for contact / individual
March 23, 2010, 09:55:32 am
I have some events in civiEvent where I have added a custom group and field for a contact (i.e. project leader).  By Default when the event info is shown it shows the contact's name only.  I would like this to also show their phone number and e-mail address along with their name but only have to enter the contact on the event (i.e. not duplicate phone and e-mail).

From what I have gleaned from the forums it sounds like this might be possible using civiCRM hooks...  Any insight or direction on how this might be accomplished?  (i.e. show extra contact info along with the Contact's name in event info).  I have no issue with adding the custom field for the contact... just want more data shown in the event info.

Thanks,
Greg

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: Using Hooks to modify Event Custom Data for contact / individual
March 23, 2010, 10:40:50 am

Hook documentation is here:

http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+hook+specification

To add more info on the event info page, u'll need to implement hook_civicrm_pageRun and based on the eventID find the custom field contact id and get the phone/email of the contact and expose to template

u'll need to custom the event info template here:

http://wiki.civicrm.org/confluence/display/CRMDOC/Customizing+CiviCRM+Screens

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: Using Hooks to modify Event Custom Data for contact / individual
March 23, 2010, 02:57:45 pm
Greg,
Did you consider using the built-in event contact Email and Phone fields (which are displayed on the Event Info pages). You configure those from Configure Event >> Event Location tab.
Protect your investment in CiviCRM by  becoming a Member!

geeffland

  • I’m new here
  • *
  • Posts: 29
  • Karma: 0
Re: Using Hooks to modify Event Custom Data for contact / individual
March 24, 2010, 06:24:23 am
I did consider the built in phone/e-mail fields but those are separate fields.  So to list a project leader I would define a custom field for the contact (i.e. his name) then enter the phone and e-mail also. 

The desired approach would be to assign a project leader then that contact's phone and e-mail come along with the contact (since it's already in their info).  Also if the project leader changes you just change the project leader and the contact info is updated for the event.

I can definitely see a use case for having a separate phone or e-mail for an event that is not tied directly to a contact "person" such as 800 numbers or generic e-mail addresses.  Even those could use a contact assuming it was not a person though.

geeffland

  • I’m new here
  • *
  • Posts: 29
  • Karma: 0
Re: Using Hooks to modify Event Custom Data for contact / individual
March 24, 2010, 12:35:43 pm
lobo,

Here is my status so far:
1) I have the custom hook implemented and can capture the Event Info Page. 
2) I also can get the eventID by using $page->get('id');
3) I have recognized that the EventInfo.tpl uses the CustomDataView.tpl to output the Contact Info

I know how to manually get the answers from the DB but was thinking a cleaner approach was to use the hooks, template overrides, etc. but not sure where exactly to go from here.

I know I need to learn up on Smarty Templates to better understand the .tpl files.  For instance on the CustomDataView.tpl file I need to dig into the $element item to find out what it knows... and what else I need to populate from the custom hooks for the template to know.  Then I also need to figure out if I change such a deep template what other areas am I affecting, possibly adversely.

To continue on and get the Custom Field ID and matching value for the desired fields should I load up the BAO Custom group File and proceed from there.

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: Using Hooks to modify Event Custom Data for contact / individual
March 24, 2010, 01:24:56 pm

here is what i would do to keep it simple, its a bit hardcoded, but gets you going without getting too deep into civi code:

1. from the hook u get the event ID. using this event ID find the contact ID in the custom value table (hard code the name for now). Using this contact ID get the phone/email either via a query or via the civicrm_contact_search api call. Expose the phone / email to the tpl

2. modify the tpl to display the phone / email if there is a value

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

ccowens

  • Guest
Re: Using Hooks to modify Event Custom Data for contact / individual
April 14, 2010, 08:18:13 am
I took a look at hook_custom.   The documentation is a little unclear about when the hook is called, but it seems there would be times when we would want it called as the custom field is retrieved, not just when it is edited or saved.

For example, you might have a custom field whose value depends upon a number of things that change dynamically, outside of the scope of the group to which the custom field belongs.

Here's a contrived example.  When we look at a member's contact info, we want to calculate, on the fly, how many trouble tickets he has open in our system.  It's easy enough to define a custom field labeled "Open Tickets"., and to write code that retrieves info from the database and makes a count.   But displaying an up-to-date value means we want that custom code to run every time the custom data group is retrieved, not when it is created, saved, or edited.

I understand that I could calculate the value in page_run, but localizing it to hook_custom seems like a better idea.

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: Using Hooks to modify Event Custom Data for contact / individual
April 14, 2010, 08:42:07 am

hooks currently dont support "view" operation (since it happens from quite a few places). I suspect this is not a easy change

if u'd like to work on a patch for this please contact us on irc and we can get you started

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

adixon

  • I post frequently
  • ***
  • Posts: 314
  • Karma: 19
    • Blackfly Solutions
Re: Using Hooks to modify Event Custom Data for contact / individual
July 13, 2010, 10:19:26 am
Just a quick note to say thanks for this posting. I just wrote my first custom civicrm hook and it's working delightfully.

Overall, i found the documentation of the hooks a little too technical - but probably just because I hadn't read any examples. The pageRun hook is a good one.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Using Hooks to modify Event Custom Data for contact / individual

This forum was archived on 2017-11-26.