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 CiviContribute (Moderator: Donald Lobo) »
  • Maintain two variables calculated from civicrm DB throughout drupal
Pages: [1]

Author Topic: Maintain two variables calculated from civicrm DB throughout drupal  (Read 1395 times)

datagroove

  • I’m new here
  • *
  • Posts: 22
  • Karma: 0
  • CiviCRM version: 4
  • CMS version: drupal
  • MySQL version: 5
  • PHP version: 5.3
Maintain two variables calculated from civicrm DB throughout drupal
January 17, 2012, 07:08:32 am
Hi, and thanks for any help on this.

I am sure there are multiple ways of accomplishing the following request, but perhaps someone can suggest a best practice using drupal:

Throughout my drupal site i'd like retrieve from the civcirm DB:

- the total amount contributed
- the total number of contributors (unique)

I plan on using this data in two different ways:
As a block in the sidebar or scattered throughout text in a blog post or basic page (using php as the input filter). The intent of course is to ensure the data is always up to date.

Should I create a function in the template.php file that calls on the civi DB directly?
Use the civi API?
or perhaps there is already a feature that allows me to do this?

Thank you again for your help,

chris



Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Maintain two variables calculated from civicrm DB throughout drupal
January 17, 2012, 10:29:40 am
Quote
Use the civi API?

Yes, that's the best thing. I would create a small custom module with a function that returns one or both of these values. Then in that function you use the API to determine the correct values.
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.

datagroove

  • I’m new here
  • *
  • Posts: 22
  • Karma: 0
  • CiviCRM version: 4
  • CMS version: drupal
  • MySQL version: 5
  • PHP version: 5.3
Re: Maintain two variables calculated from civicrm DB throughout drupal
January 19, 2012, 07:19:58 am
Hi Hershel,

Thank you for your help, I will go that route. Another question related to this:

I noticed that the information I was after is already calculated at top of the "Find Contributions" page (after a search). Where can find the tpl and php pages that make this call? (so i can see how the civi team did it)

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Maintain two variables calculated from civicrm DB throughout drupal
January 19, 2012, 08:21:14 am
Look at the HTML source of the page and you will see in comments where the tpl is. But it should be around  CRM/Contribute/Form/SearchContribution.tpl
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.

datagroove

  • I’m new here
  • *
  • Posts: 22
  • Karma: 0
  • CiviCRM version: 4
  • CMS version: drupal
  • MySQL version: 5
  • PHP version: 5.3
Re: Maintain two variables calculated from civicrm DB throughout drupal
January 19, 2012, 08:56:13 am
Ok, after looking at the source and tracing all the smarty calls I get to a file located at:
Code: [Select]
CRM/Contribute/Page/ContributionTotals.tpl
that file called these three lines:
Code: [Select]
   
<th class="contriTotalLeft right">{ts}Total Amount{/ts} - {$contributionSummary.total.amount}</th>
<th class="right"> &nbsp; {ts}# Completed Contributions{/ts} - {$contributionSummary.total.count}</th>
<th class="right contriTotalRight"> &nbsp; {ts}Avg Amount{/ts} - {$contributionSummary.total.avg}</th>

so now I am stuck at trying to figure out where this $contributionSummary object is created. Again, the reason why, I want to see how the CIVI team generated these summary totals so I can use them else where in drupal.

Any idea where this $contributionSummary object was created?

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Maintain two variables calculated from civicrm DB throughout drupal
January 19, 2012, 08:59:50 am
Try CRM/Contribute/Page/ContributionTotals.php :)
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.

datagroove

  • I’m new here
  • *
  • Posts: 22
  • Karma: 0
  • CiviCRM version: 4
  • CMS version: drupal
  • MySQL version: 5
  • PHP version: 5.3
Re: Maintain two variables calculated from civicrm DB throughout drupal
January 19, 2012, 10:34:02 am
Logical, but I tried that, it's not 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: Maintain two variables calculated from civicrm DB throughout drupal
January 19, 2012, 01:52:59 pm

check:

CRM/Contribute/BAO/Contribution.php, function getTotalAmountAndCount
CRM/Contact/BAO/Query.php, function &summaryContribution -- though this relies on other aspects of the query framework

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

datagroove

  • I’m new here
  • *
  • Posts: 22
  • Karma: 0
  • CiviCRM version: 4
  • CMS version: drupal
  • MySQL version: 5
  • PHP version: 5.3
Re: Maintain two variables calculated from civicrm DB throughout drupal
January 19, 2012, 02:32:53 pm
Thank you. Hershel and Lobo.
« Last Edit: January 19, 2012, 02:35:00 pm by datagroove »

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviContribute (Moderator: Donald Lobo) »
  • Maintain two variables calculated from civicrm DB throughout drupal

This forum was archived on 2017-11-26.