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) »
  • Added PCP contribution info to the user dashboard if anyone finds this useful
Pages: [1]

Author Topic: Added PCP contribution info to the user dashboard if anyone finds this useful  (Read 1115 times)

RachelWright

  • I post occasionally
  • **
  • Posts: 78
  • Karma: 3
  • CiviCRM version: 4.2.7
  • CMS version: Joomla 2.5.17
  • MySQL version: 5.5.37
  • PHP version: 5.4.26
Added PCP contribution info to the user dashboard if anyone finds this useful
April 25, 2013, 03:38:55 pm
Just thought I'd share I wrote a little code to include information on the user dashboard for donations to their PCP. I found this very helpful as we would get a lot of calls requesting a list of people who donated on their page so they could thank them (in case the donor had not left a message on the honor roll). Thank you to lcdweb for a push in the right direction!!!

Code: [Select]
function joomla_civicrm_pageRun( &$page ) {
  if ( $page->getVar('_name') == 'CRM_Contact_Page_View_UserDashBoard' ) {
    require_once 'api/api.php';

    $config = CRM_Core_Config::singleton();

    //we only care about frontend display
    if ( !$config->userFrameworkFrontend ) {
      return;
    }

    //construct content for the user
    //can use $page->_contactId to filter api calls and queries on the user
$myid = $page->_contactId;

//functions to gather donation information for PCP page.

$myquery = mysql_query("
SELECT civicrm_contribution.id, civicrm_contribution.contact_id, civicrm_contribution.total_amount, civicrm_contribution.receive_date, civicrm_contact.id, civicrm_contact.display_name, civicrm_contribution_soft.contribution_id, civicrm_contribution_soft.contact_id, civicrm_contribution.contribution_status_id, civicrm_contribution_soft.pcp_anonymous_to_owner, civicrm_pcp.is_active
FROM civicrm_contribution
INNER JOIN civicrm_contribution_soft
ON civicrm_contribution.id = civicrm_contribution_soft.contribution_id
INNER JOIN civicrm_contact
ON civicrm_contribution.contact_id = civicrm_contact.id
INNER JOIN civicrm_pcp
ON civicrm_contribution_soft.pcp_id = civicrm_pcp.id
WHERE civicrm_contribution_soft.contact_id = $myid
AND civicrm_pcp.is_active = 1
ORDER BY civicrm_contribution.receive_date DESC
");   

$myStuff = '<table class="selector">';
$myStuff .='<tr class="columnheader"><th>Date Received</th><th>Status</th><th>Name</th><th>Amount</th></tr>';
$i = 0;
while ($row = mysql_fetch_array($myquery)){

if($i %2 == 0){
$myStuff .= '<tr class="even-row">';
}
else{
$myStuff .= '<tr class="odd-row">';
}
$myStuff .= '<td>'.date('F d, Y', strtotime($row['receive_date'])).'</td>';
$contStatus = $row['contribution_status_id'];
$anonymousStatus = $row['pcp_anonymous_to_owner'];
if ($contStatus == 1) {
$contStatusText = 'Completed';
}
else if ($contStatus == 2) {
$contStatusText = 'Pending (pay later)';
}
else if ($contStatus == 3) {
$contStatusText = 'Cancelled';
}
if ($anonymousStatus == 1) {
$donorName = 'Anonymous';
}
else if ($anonymousStatus == 0) {
$donorName = $row['display_name'];
}
$myStuff .= '<td>'.$contStatusText.'</td>';
$myStuff .= '<td>'.$donorName.'</td>';
$myStuff .= '<td>'.$row['total_amount'].'</td></tr>';
$i++;
}
$myStuff .= '</table>';
//contribution_status_id

    //now assign content to a smarty variable so I can iterate through in the tpl file
$page->assign('myStuff', $myStuff);
  }
}

A few caveats, it's definitely not perfect, it assumes that you only have one active PCP at a time (it does not show donations from inactive PCPs). I also have an additional variable (pcp_anonymous_to_owner) that I added so that a donor could indicate not to give their name to the pcp owner (we found the current radio options a little confusing so we added another checkbox to make things clearer.) Hopefully, you can use it as a jumping off point for your own needs for your users dashboards!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviContribute (Moderator: Donald Lobo) »
  • Added PCP contribution info to the user dashboard if anyone finds this useful

This forum was archived on 2017-11-26.