Exposing relationship data in CiviCRM profile view

2009-07-29 12:53
Written by
lobo - member of the CiviCRM community - view blog guidelines
I'm working on deploying CiviCRM for my kids school website. Part of the project requires us to expose the parent <-> child relationship information on the website and allow parents to edit their child information. I accomplished this using a combination of civicrm hooks, custom templates, permissioned relationships and custom code in a drupal module. You can access the module and template code here. The broad steps are:
  • Implement hook_civicrm_pageRun for the profile view page (CRM_Profile_Page_Dynamic). Only implement this hook for the specific profile id's you want relationship information. In this case we have two profiles, a Parent Profile (gid=3) and a Student Profile (gid=4)
  • The pageRun hook also adds the module's template directory to the smarty include path, so we dont have to set it globally. This also allow multiple modules to append different template directories to the template include path (check the function _sfschool_initialize)
  • The hook gets either the parent or the child information using a custom query. We ensure that only permissioned parents can see their child information (in case of some complicated family structures). The queries are relatively simple at this stage, i suspect they will increase in complexity over the next few weeks
  • The hook exposes the information gathered from the database to the smarty template
  • The custom template (templates/CRM/Profile/Page/3/Dynamic.tpl) uses that information to display the relationship data on the page. I also edited the View.tpl template to eliminate the "Back to Listings" link.
The school is currently exposing the data as read only (the primary database is a commercial SIS system). We will import the data from the SIS system and set the relationships via import. We will need to do a manual SQL query to give parents permission on all their children relationships. I suspect you can edit the profile edit/create forms via hooks to also gather relationship information via the form and create the appropriate permissioned relationships. I dont think that this will be a requirement for the school anytime soon, so i do hope someone from the community steps up and implements this. I did all the development on a local box and then migrate the custom data / profile information to the production server using the scripts in bin/migrate/{export,import}.php. They work quite nicely for the most part :) I'll be doing quite a few more things for the site via a combination of hooks and custom code. More blog entries on them as i figure things out ...
Filed under


Sarah Gladstone (not verified)
2009-07-30 - 12:27

Where can I see a demo website with this code in action?

as such there is no public demo available. You will need to download and install the modules to see it happen. at some point, we might decide to make a public demo available