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 CiviReport (Moderator: Dave Greenberg) »
  • CiviReport - Nested Queries? Need to find relationship+fields of related contact
Pages: [1]

Author Topic: CiviReport - Nested Queries? Need to find relationship+fields of related contact  (Read 2070 times)

DerekL

  • I post frequently
  • ***
  • Posts: 132
  • Karma: 1
  • CiviCRM version: 4.5.5
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.54
  • PHP version: 5.2.17
CiviReport - Nested Queries? Need to find relationship+fields of related contact
November 11, 2012, 12:00:03 pm
Hi,

I've been asked to put together a report that lists member organizations, their membership status info, and the address info of their "primary contact" (a custom relationship).

I have created a custom report to get the member info, the membership status, and the primary contact's contact_id. 
(Via query to civicrm_membership, then joining to civicrm_contact, civicrm_status, and civicrm_relationship)

I now need to run a query to get the contact_id's phone/address information for every row returned.

Is there a way to nest queries like this via civicrm custom report? Is there some other way to go about this?

Any help would be much appreciated!

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: CiviReport - Nested Queries? Need to find relationship+fields of related contact
November 21, 2012, 01:29:10 pm
Hi, It won't last the next refresh but you can see on demo @ the moment an example of more than one phone per person

http://drupal.demo.civicrm.org/civicrm/report/instance/35?reset=1?force=1

That's from the extended report extension (basic contact report) & it creates a temp table for phone numbers. This is a report we use for phone banking (although the printed report isn't working on demo right at the moment)
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

DerekL

  • I post frequently
  • ***
  • Posts: 132
  • Karma: 1
  • CiviCRM version: 4.5.5
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.54
  • PHP version: 5.2.17
Re: CiviReport - Nested Queries? Need to find relationship+fields of related contact
December 10, 2012, 01:02:02 pm
Hi Eileen,

I tried this one two of my sites and on both I am getting :

  Unable to extract the extension. Extension has been installed.

Log Says:

Warning: curl_setopt(): CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in CRM_Core_Extensions_Extension->download() (line 365 of /var/www/vhosts/site.com/httpdocs/sites/all/modules/civicrm/CRM/Core/Extensions/Extension.php).

Though php_safe mode is off. I'm not sure about the open_basedir part though.

Any way to debug this further? I'd really like to take a look at these extended reports.

Perhaps some instructions on how to manually install?

Thanks!
« Last Edit: December 10, 2012, 01:41:57 pm by DerekL »

DerekL

  • I post frequently
  • ***
  • Posts: 132
  • Karma: 1
  • CiviCRM version: 4.5.5
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.54
  • PHP version: 5.2.17
Re: CiviReport - Nested Queries? Need to find relationship+fields of related contact
December 10, 2012, 02:14:07 pm
Is there any way to use straight SQL with CiviCRM reporting?

I have 3-4 queries already done using nested selects, and porting them over to CiviCRM report-style php would be a major pain, if even possible?

Either going straight SQL would work, or some idea of how to nest selects using the report php method?

Thank You!

demeritcowboy

  • Ask me questions
  • ****
  • Posts: 570
  • Karma: 42
  • CiviCRM version: Always the latest!
  • CMS version: Drupal 6 mostly, still evaluating 7.
  • MySQL version: Mix of 5.0 / 5.1 / 5.5
  • PHP version: 5.3, usually on Windows
Re: CiviReport - Nested Queries? Need to find relationship+fields of related contact
December 10, 2012, 05:50:14 pm
If you don't need it to respect ACL's or have the fancier filtering widgets then you could just do it as a custom search instead. But then you lose all the surrounding framework. Depends on your needs.

http://wiki.civicrm.org/confluence/display/CRMDOC42/Create+a+Module+Extension#CreateaModuleExtension-Addacustomsearch

DerekL

  • I post frequently
  • ***
  • Posts: 132
  • Karma: 1
  • CiviCRM version: 4.5.5
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.54
  • PHP version: 5.2.17
Re: CiviReport - Nested Queries? Need to find relationship+fields of related contact
December 11, 2012, 01:25:30 pm
Thanks for the lead, I'll follow it tonight!

DerekL

  • I post frequently
  • ***
  • Posts: 132
  • Karma: 1
  • CiviCRM version: 4.5.5
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.54
  • PHP version: 5.2.17
Re: CiviReport - Nested Queries? Need to find relationship+fields of related contact
December 13, 2012, 08:31:41 am
So after banging my head against this while annoying the devs on IRC, this is what I came up with, just in case anyone has a use case like mine where a large amount of flat data is requested for export to feed other more antiquated processes.

Nutshell: When you need to translate an existing SQL query into an on-demand csv export using the existing CiviCRM GUI.

Handy Link: http://wiki.civicrm.org/confluence/display/CRMDOC41/CiviReport+structure+and+customization


Code: [Select]
<?php

//Member Breakdown - Hail Mary.

require_once 'CRM/Report/Form.php';

class 
CRM_Report_Form_Member_Breakdown extends CRM_Report_Form 
{
  protected 
$_customGroupExtends = array( 'Membership' );

 
function 
__construct( ) {
        
$this->_columns = array( );
        
parent::__construct( );
    }
 

  function 
postProcess( ) 
  {
    
$this->beginPostProcess( );

    
// get the acl clauses built before we assemble the query
   // $this->buildACLClause( $this->_aliases['civicrm_membership'] );

    
$sql  = "(SELECT ANYTHING, NEST AS DEEP AS YOUR SCRIPT TIMEOUT WILL ALLOW)";

   
$this->_columnHeaders =
                array(
                 
'a_column_name' => array( 'title' => 'Rewritten Column Name'),
 'another_column_name' => array( 'title' => 'Another Rewritten Column Name'),
                       );



    
$rows = $graphRows = array();
    
$this->buildRows ( $sql, $rows );

    
$this->formatDisplay( $rows );
    
$this->doTemplateAssignment( $rows );
    
$this->endPostProcess( $rows ); 
  }
  

} 

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: CiviReport - Nested Queries? Need to find relationship+fields of related contact
December 13, 2012, 09:44:06 am

derek:

1. thanx for the recipe. Much appreciated. this question has come up a bit recently, and i think would be great if you can convert the below to a simple sample and post it on the blog / wiki

2. Note that any questions are not annoying :) We do super appreciate it when people do what you just did :) i.e. report back and provide a solution. So THANK YOU :)

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

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: CiviReport - Nested Queries? Need to find relationship+fields of related contact
December 13, 2012, 12:22:59 pm
Derek - just saw I didn't reply back earlier - the reports I did have had a few problems ironed out & should install properly now.

However, looks like you sorted it (although the site is down at the moment so I can't follow the link)
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

DerekL

  • I post frequently
  • ***
  • Posts: 132
  • Karma: 1
  • CiviCRM version: 4.5.5
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.54
  • PHP version: 5.2.17
Re: CiviReport - Nested Queries? Need to find relationship+fields of related contact
December 13, 2012, 02:18:03 pm
Hi Eileen, it was a CURLOPT_FOLLOWLOCATION vs. open_basedir thing on my side, the extension came online without a hitch after.

Freaking incredible work on the extended reports btw, and I still owe you big time for CiviMigrate!

Lobo, thanks for the support, I'll try pitch in as best I can.

ltaliano

  • I’m new here
  • *
  • Posts: 2
  • Karma: 0
  • CiviCRM version: 4.3
  • CMS version: Drupal 7.14
  • MySQL version: 5.5.30-log
  • PHP version: 5.3.15
Re: CiviReport - Nested Queries? Need to find relationship+fields of related contact
December 05, 2013, 02:56:12 pm
Hi. I created a report with nested queries as Derek did, and everything works great.  now i would like my users to be able to filter results in the where clause of a nested query.
is that possible using __construct()?

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviReport (Moderator: Dave Greenberg) »
  • CiviReport - Nested Queries? Need to find relationship+fields of related contact

This forum was archived on 2017-11-26.