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 (Moderator: Donald Lobo) »
  • How to show custom field value in overview relationships?
Pages: [1]

Author Topic: How to show custom field value in overview relationships?  (Read 980 times)

alainb

  • I’m new here
  • *
  • Posts: 24
  • Karma: 0
  • CiviCRM version: 4.4.x
  • CMS version: Drupal
  • MySQL version: 5.x
  • PHP version: 5.x
How to show custom field value in overview relationships?
May 29, 2013, 07:21:16 am
Most of our contacts have multiple jobs, and for each job we want to keep the job title. So we created a custom field 'Job title', and linked it to the relatiohsip of type 'Employee of/Employer of'.

Now, when you open the contact form and you click on the tab 'Relationships', we want to show the value of the field 'job title' in the overview.
So for a person with two jobs, it could look like:
Employee of | IBM | Marketing manager
Employee of | Cisco | Member of the board

How can you do this?

What did I do so far, you might ask? :-)
- I was able to add a column header 'job title', by copying the file CRM/Contact/Page/View/Relationship.tpl to my own template folder and making the necessary changes, thus overwriting the standard functionality without modifying core files.
- But I noticed that when I copy CRM/Contact/BAO/Relationship.php to my corresponding template folder, the changes I make are ignored. Is this by design?

« Last Edit: May 30, 2013, 07:36:18 am by alainb »

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: How to show custom field value in overview relationships?
May 29, 2013, 11:18:52 am

did u set the php include path?

ideally u should keep your template path and php path separate and not intermix the two (at least thats what we do)

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

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: How to show custom field value in overview relationships?
May 30, 2013, 12:13:45 am
As Lobo pointed out, CiviCRM expects php scripts in another folder, and you can specify which folder in the settings. But what where you planning to do with the php file? I would not recommend you to change core php-files, but use hooks to customize behaviour? Are you familiar with CiviCRM hooks?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

alainb

  • I’m new here
  • *
  • Posts: 24
  • Karma: 0
  • CiviCRM version: 4.4.x
  • CMS version: Drupal
  • MySQL version: 5.x
  • PHP version: 5.x
Re: How to show custom field value in overview relationships? [SOLVED]
May 30, 2013, 07:35:17 am
Thank you Donald and Erik for the help!

I solved the problem as follows:


In Administer > System Settings > Directories, I entered a path for Custom PHP Path
Then I copied the file CRM\Contact\BAO\Relationship.php from the civi folder to that path (including the sub folders).

Then I changed the query on line 791:
-   I added a Left join with the table that contains my custom field
-   I replaced the existing field job_title on line 794 by my custom field

Then I copied the file CRM\Contact\Page\View\Relationship.tpl to my custom templates folder.
I added a <th>Job title</th> in the table (line 54), and a few lines below, where the data is filled in, I added <td>{$rel.job_title}</td>

I hope this is an acceptable way of customizing civi.

Kind regards,
Alain

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: How to show custom field value in overview relationships?
May 30, 2013, 07:59:18 am
Well, it works, at least that is achieved  ;)
Obiously it is not standard or promoted practise to change core php files. Ideally you should achieve the same either by:
  • customizing the template end then call the API from Smarty and retrieve your custom field for each row
  • using a buildForm (if the form is a form) or a pageRun hook (if it is a page) to change the object before it is displayed
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • How to show custom field value in overview relationships?

This forum was archived on 2017-11-26.