classy-org / classy-org-wp

Classy.org Wordpress plugin and integration.
MIT License
22 stars 10 forks source link

Organisation-wide fundraiser-leaders? #16

Open parkersweb opened 7 years ago

parkersweb commented 7 years ago

Hey guys,

On our public website we used to have a nice "top fundraisers" wall that showcased people from across all events & campaigns that were near to target and had raised over a nominal amount. That broke since API1 went away - so we're obviously looking to revive it in a shiny new API2 suit :)

Trouble is [classy-campaign-fundraiser-leaders id="12345" title="Top Fundraisers"] doesn't quite seem to fit the bill because I don't think we don't have a campaign id? Is that right?

Is there any way of achieving what we need?

Thanks!

Andrew

dpfavand commented 7 years ago

@parkersweb as the plugin currently stands, no. However the API does allow you to pull all of an organization's fundraisers. I believe you could write a shortcode that would pull the following (as a starting point).

so the request params would look like:

$params = array(
                'aggregates' => 'true',
                'sort'       => 'total_raised:desc',
                'per_page'   => $count,
                'with'       => 'supporter',
                'filter'     => 'status=active,created_at>=${TWELVE_MONTHS_AGO},percent_to_goal>=70'
            );

Does that sound like it would achieve your goal?

parkersweb commented 6 years ago

@dpfavand that sounds perfect - I'm guessing it'll take some digging through the current shortcodes to work out how to build on the API from the plugin to do that - unless there's some documentation available somewhere?

dpfavand commented 6 years ago

@parkersweb it shouldn't be too difficult from the API perspective. There is documentation at https://developers.classy.org/api-docs/v2/index.html but I think the filter param above should work, provided the variable TWELVE_MONTHS_AGO is defined properly as an ISO date string without milliseconds. (Classy's API breaks if you supply ISO 8601-compliant milliseconds.)

However, the ClassyContent class would probably have to be reworked to provide caching for these options to ensure that multiple uses of the shortcode with different parameters don't clash.

@mjalkio and @cj-beck would adding this shortcode be acceptable for the plugin? I suspect we don't want a shortcode for every possible use case, but showing top organization fundraisers seems like a fairly general need and we can provide reasonable options for configuration.

I'd suggest a shortcode with these options to meet @parkersweb's needs:

Perhaps the options should also be added to the campaign fundraisers and teams leaderboards? Again if we do this the caching mechanisms would have to be reworked.

mjalkio commented 6 years ago

Unfortunately, the issue you're referring to with filtering on total_raised is actually an issue with filtering by any aggregate. So a percent_to_goal filter would also not work.

Everything else seems very reasonable. I don't see the need to update the caching mechanism (although it's all on the WP side, so it's doable). It's caching whatever resource you ask for, regardless of the options you provide. Unless you have a use-case where the same resource would be requested with different settings in a single use of the plugin, the current caching should still be fine.

dpfavand commented 6 years ago

Ah good point re percent_to_goal. @parkersweb for now would a the option to show the top 5 fundraisers from the past year across all your campaigns work for you? Once the API is fixed we can look at adding a minimum threshold.

@mjalkio for caching, I'm thinking of exactly those use cases - for instance if your home page shows the top five fundraisers this year but on an inside page you show the top 50 fundraisers of all time. If the cache key is simply the org or campaign ID, they will conflict. Maybe the cache key could just be built out of the supplied shortcode/widget options?