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) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • Drupal Views Relationships - One for you Views gurus.
Pages: [1]

Author Topic: Drupal Views Relationships - One for you Views gurus.  (Read 2125 times)

SweetTooth

  • I post occasionally
  • **
  • Posts: 70
  • Karma: 1
  • CiviCRM version: 4.1
  • CMS version: Drupal 6.20
  • MySQL version: 5.1.54
  • PHP version: 5.2.17
Drupal Views Relationships - One for you Views gurus.
November 07, 2011, 10:11:50 am

At the moment, I believe that it only supports one level out of the box.

Contact A >> Contact B

I need

Contact A >> Contact B >> Contact C Details

I notice that it's possible to export the view. Is there anyway to hack it when it's exported, then re-import it?

If so, how?

I understand that I would need to populate such a hack with the internal relationship type IDs.

Thanks!

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Drupal Views Relationships - One for you Views gurus.
November 07, 2011, 10:52:05 am
Quote from: SweetTooth on November 07, 2011, 10:11:50 am
I notice that it's possible to export the view. Is there anyway to hack it when it's exported, then re-import it?

No. :)

Regarding your main question, yes, I don't think this can be done directly in a View, but you could certainly achieve it by customizing one of your view templates and fetching the data for Contact C using the CiviCRM API.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

SweetTooth

  • I post occasionally
  • **
  • Posts: 70
  • Karma: 1
  • CiviCRM version: 4.1
  • CMS version: Drupal 6.20
  • MySQL version: 5.1.54
  • PHP version: 5.2.17
Re: Drupal Views Relationships - One for you Views gurus.
November 08, 2011, 02:07:28 am
Quote from: Hershel on November 07, 2011, 10:52:05 am
Quote from: SweetTooth on November 07, 2011, 10:11:50 am
I notice that it's possible to export the view. Is there anyway to hack it when it's exported, then re-import it?

No. :)

Regarding your main question, yes, I don't think this can be done directly in a View, but you could certainly achieve it by customizing one of your view templates and fetching the data for Contact C using the CiviCRM API.

Hmmm...sounds a bit too complicated! I'll give it a go as a last resort.

Do you know of any way it can be done using panels? Something tells me that it can, but I can't seem to scrape together enough to do it!


Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Drupal Views Relationships - One for you Views gurus.
November 08, 2011, 03:15:32 am
I do not think you can do this with Panels. I think you will need to write a bit of code.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

SweetTooth

  • I post occasionally
  • **
  • Posts: 70
  • Karma: 1
  • CiviCRM version: 4.1
  • CMS version: Drupal 6.20
  • MySQL version: 5.1.54
  • PHP version: 5.2.17
Re: Drupal Views Relationships - One for you Views gurus.
November 09, 2011, 02:29:56 am
Quote from: Hershel on November 08, 2011, 03:15:32 am
I do not think you can do this with Panels. I think you will need to write a bit of code.

OK. Thanks for your help anyway.


ankles

  • I’m new here
  • *
  • Posts: 6
  • Karma: 0
  • MySQL version: ?
  • PHP version: ?
Re: Drupal Views Relationships - One for you Views gurus.
October 07, 2014, 05:55:13 am
(This is an old thread but seems to be the right place to finally answer this question for anyone else stuck on this problem. If I should have started a new topic for this please let me know and I will do that.)

I have been trying to set up a Drupal View of a multiple relationships in CiviCRM as the original poster was. The view I wanted was that showed a list of contacts that are provided services from the current user's employer, as below:

(current user) contact a => (is employed by) => organisation => (is a provider of) => contact c

I created a view of CiviCRM Contacts, and could not see a way of getting this relationship to display what I wanted without building a custom module. I solved this with a custom Drupal module and using the preprocess views hook to pass in the contextual filter. The filters are passed into the $args[] variable.

You also may need to enable multiple values in a contextual filter, if you have more than one relationship from Contact A to Contact B, in this case this is multiple employers of contact A. This is under Contextual Filters > Advanced > Allow multiple values. You do not add % to the path as you would normally do with a contextual filter as we are programmatically inserting it.

Create a custom Drupal module with the following code

/**
* @implements hook_views_pre_view().
*/
function my_module_views_pre_view(&$view, &$display_id, &$args){

if($view->name == "my_view") {
      // Check that we are altering the correct view based on and $view->name
      civicrm_initialize();
      require_once 'api/api.php';
      global $user;
      //get the matching civi id for the current user
      //This is using Civicrm version 4.4.6

      //first get the current user's Civicrm record
      $params = array(
         'version' => 3,
         'sequential' => 1,
         'uf_id' => $user->uid,
      );
      /*The contact ID is in $result['values'][0]['contact_id']*/
      $result = civicrm_api('UFMatch', 'get', $params);

      $params = array(
          'version' => 3,
          'sequential' => 1,
          'relationship_type_id' => 5, /*get your relationship ID from /civicrm/admin*/
          'contact_id_a' => $result['values'][0]['contact_id'],
      );
      $result = civicrm_api('Relationship', 'get', $params);

      //temp stores the string which will be passed to the $args[] array
      $temp = "";

      //loop through the a => b relationships, and append all the ids of contact b
      foreach ($result[values] as $key => $value ) {
         if ($key > 0)
            $temp .= "+";
         $temp .= $value['contact_id_b'];
      }
      // populate the $args contextual filters array with the ids.
      $args[] = $temp;
   }
}

« Last Edit: October 07, 2014, 06:42:15 am by ankles »

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: Drupal Views Relationships - One for you Views gurus.
October 07, 2014, 12:20:48 pm
We may be missing a large part of the picture here, but we have built many views that daisy-chain relationships, including from Contact-based Views and from CiviCRM-Activity-based Views

eg

- show Student
- link Student to School
- link School to School Contact

etc

Not suggesting what you required didn't involve custom modules - but just wanting to 'put it out there' that daisy-chaining (Views) Relationships can be done.
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

ankles

  • I’m new here
  • *
  • Posts: 6
  • Karma: 0
  • MySQL version: ?
  • PHP version: ?
Re: Drupal Views Relationships - One for you Views gurus.
October 14, 2014, 03:13:43 am
Sounds great - I have no idea how you would do this daisy chaining though. Can you explain a bit more how this would work?

Thanks
Alex

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: Drupal Views Relationships - One for you Views gurus.
October 14, 2014, 11:13:30 am
Sure I will try.
Add relationship 1 of type "Connects a contact (as contact A) to a relationship." (eg employer of)
Add relationship 2 of type "The contact B" use select 1 as the 'Relationship'

So you have now connected person X to Org Y

Add relationship 3 of type "Connects a contact (as contact A) to a relationship." (eg Primary Contact of) - use select 2 as the 'Relationship'
Add relationship 2 of type "The contact B" use select 3 as the 'Relationship'

So now you should have connected person X to Org Y and then Org Y to person Z.

etc

Hope that clarifies it somewhat.

Another example might be if you want to show grandchildren where you have multiple parent-child relationships including some 2 level situations.

so Person A is Parent of Person B, and Person B is Parent of Person C

Hence Person A is 'grandparent' of Person C
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • Drupal Views Relationships - One for you Views gurus.

This forum was archived on 2017-11-26.