Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Having a thermometer to track donation progress would be great. Perhaps a future release could include a built-in block?
To kick off, here is a snippet I wrote to make your own block:
<?php
$goal=50000; // your total fundraising goal
$width=170; //width of the thermometer in pixels
$sql = "SELECT d.uid, d.datepaid, d.mc_gross, d.mc_currency FROM {lm_paypal_donations} d";
$result = db_query_range($sql, $uid, 0, 9999);
$total=0;
$total=0;
while ($donation = db_fetch_object($result)) {
if ($donation->mc_currency == 'USD') {
$total += ($donation->mc_gross)/1.35; //preform inaccurate currency conversion to Euros
} else {
$total += $donation->mc_gross;
}
$count+=1;
}
$o="<table cellpadding=0 cellspacing=0 border=2px><tr>";
$o.='<td width='.round($total/$goal*$width,0).'px bgcolor=#00FF00 align="right">';
if ($total/$goal > 0.5) $o.=round($total/$goal*100,1)."% ";
$o.='</td><td width='.round((1-$total/$goal)*$width,0).'px bgcolor=#FFFFFF> ';
if ($total/$goal < 0.5) $o.=round($total/$goal*100,1)."%";
$o.="</td></tr></table><br>";
print $o;
print $count . ' donations, with <strong>'. round($total,2) . ' €</strong> raised towards our goal of '.$goal.' €';
?>
Comment | File | Size | Author |
---|---|---|---|
#16 | lm_paypal-donation_meter_contrib-2.patch | 4.37 KB | John Franklin |
#12 | lm_paypal-donation_meter_contrib.patch | 5.2 KB | toemaz |
#5 | lm_paypal_meter.zip | 1.88 KB | toemaz |
#4 | lm_paypal_meter.zip | 1.8 KB | toemaz |
Comments
Comment #1
goodluck4287 CreditAttribution: goodluck4287 commentedCan you please assist me with how to use this. I am relatively new to the Drupal scene, I know a little PHP, so I understand a lot of the code. As far as inputting it into a block, I have done that and created it, now what?
Can you please contact me through drupal or on aim at l i n k i n p a r k g t r g u y without the spaces of course. (A little less porn spam for me). Thank you so much, and I will of course give credit where it is due on the site.
Comment #2
goodluck4287 CreditAttribution: goodluck4287 commentedOk got that part up, now I need to hold true and try to get that currency changed to $, change the amount, and how do I link it to Paypal. I also need to set up the databases in sql. Do you have an sql config file set up that you can share?
Comment #3
toemaz CreditAttribution: toemaz commentedI started from a the original snippet and created a contrib module for D6: lm_paypal_meter
Find it attached.
Comment #4
toemaz CreditAttribution: toemaz commentedAttaching it again (perhaps a chrome issue)
Comment #5
toemaz CreditAttribution: toemaz commentedForgot to use hook_theme. Better now.
Comment #6
Cyberflyer CreditAttribution: Cyberflyer commentedDo I need to be running lm_PayPal 2.x to use this module?
Comment #7
toemaz CreditAttribution: toemaz commentedI run the 6.x-1.0 and it works perfect as you will see at http://musescore.org/donate
Comment #8
Junro CreditAttribution: Junro commentedCode is perfect :) Thanks
Comment #9
toemaz CreditAttribution: toemaz commented@Junro @Cyberflyer
Can you both confirm that you are running it successfully in production? Don't forget to add your lm_paypal release version.
Than I can add this as RTBC.
Comment #10
Junro CreditAttribution: Junro commentedI'm using 6.x-1.x-dev in production site.
Comment #11
toemaz CreditAttribution: toemaz commentedTo the lm_paypal module maintainers: should this be committed in the contrib directory or do you think this should get it's own project? Keep in mind it's pretty small module so not a lot of maintenance work.
Comment #12
toemaz CreditAttribution: toemaz commentedFind patch attached
Comment #13
lyricnz CreditAttribution: lyricnz commented(If you upload a new patch, please set status back to needs-review, rather than RTBC)
PS: The patch contains code unrelated to this feature-request (role/user_save)
Also, using round($total,2) results in output like
(as currently seen on http://musescore.org/donate - posted above). Suggest sprintf('%2d') or something like that? Also, HTML output should include quotes around attributes:
needs quotes.
Comment #14
greenpaisley CreditAttribution: greenpaisley commentedCan this be used for multiple PayPal donation buttons?
I have a website with several grants that need funding. All are listed with their own PayPal donation buttons. I would like a progress meter under each one.
Thanks for your time!
Comment #15
John Franklin CreditAttribution: John Franklin commentedThe
user_save()
bit is patched in #137494: Other Modules not notifed of role changes.In
theme_lm_paypal_meter_display()
,$goal
may be zero (0) if a target hasn't been set yet. This causes a handful of Warning: Division by zero errors.Any chance of a 6.x-1.x or 2.x release any time soon? It has been over 2 years since the last one.
Comment #16
John Franklin CreditAttribution: John Franklin commentedPatch re-rolled. Includes:
Comment #17
John Franklin CreditAttribution: John Franklin commentedThis submodule should depend on lm_paypal_donations, not lm_paypal.
Comment #18
John Franklin CreditAttribution: John Franklin commentedI'm going to add this to the 6.x-2.x branch. The 1.x branch is going to be bug-fixes only.
Comment #19
bloodyred CreditAttribution: bloodyred commentedFiles already patched or in a zip form would be nice for this that don't have shell access
Comment #20
John Franklin CreditAttribution: John Franklin commentedCommitted. Thanks for the patch.