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) »
  • CiviContribute PCP listing on campaign pages
Pages: [1]

Author Topic: CiviContribute PCP listing on campaign pages  (Read 992 times)

cgd

  • I’m new here
  • *
  • Posts: 3
  • Karma: 2
  • CiviCRM version: 3.3
  • CMS version: Drupal 6.20
  • MySQL version: 5.1.54
  • PHP version: 5.3.4
CiviContribute PCP listing on campaign pages
June 01, 2011, 11:35:15 am
Hey all,

There was a topic discussing a feature like this a while back, I believe. I can't find it but I figured others might benefit from implementing this.

I created a simple function in a custom Drupal module to retrieve a list of active personal campaign pages -- along with some basic info like creator and introduction text -- and modified the main contribution form template to show the list. The PCP's are requested based on the campaign page id, so it'll work for any active campaign and show the corresponding PCP's.

Code: [Select]
/**
 * Retrieve PCP listing and relevant details.
 *
 * @param int $cid The id parameter in the query string, corresponding to the campaign id.
 * @return array Multidimensional array containing PCP details (if any) in the form of:
 * {
        id => PCP id,
        name => PCP author,
        title => PCP page title,
        intro => PCP introductory text,
        campaign => (unused) originally intended for campaign id or title
 * }
 */
function westfieldy_custom_pcp_listing_get_pcps($cid)
{
        $pcp_list = array();
        $_pcp_sql = "
SELECT  pcp.id, pcp.title, pcp.intro_text, conta.display_name
FROM    civicrm_pcp pcp INNER JOIN
civicrm_contact conta ON pcp.contact_id = conta.id INNER JOIN
civicrm_contribution_page contr_p ON pcp.contribution_page_id = contr_p.id
WHERE    contr_p.is_active = 1 AND
pcp.is_active = 1 AND
pcp.contribution_page_id = %d
ORDER BY conta.sort_name
";
        $_pcp_db = db_query($_pcp_sql, $cid);
        while($_pcp_page = db_fetch_array($_pcp_db))
        {
                $pcp_list[] = array(
                        'id' => $_pcp_page['id'],
                        'name' => $_pcp_page['display_name'],
                        'title' => $_pcp_page['title'],
                        'intro' => $_pcp_page['intro_text'],
                        'campaign' => $_pcp_page['campaign']
                );
}

        return($pcp_list);
}

As you can see, the code block above queries the database to get a list of PCP's (if any are available) and some basic details about each page. The unused campaign field was originally intended to hold the name or id of the campaign the PCP was associated with. I had planned to make a separate page that would show all of the active campaigns and the PCP's associated with them, but I dropped the idea for now since it seemed redundant.

To display the list, I modified templates/CRM/Contribute/Form/Contribution/Main.tpl:
Code: [Select]
56a57
>
64a66,96
> {if !$pcp}
>     <div id="pcp-list-content">
>       <h2 class="block-header">Personal Campaigners</h2>
>       {php}
>       if(is_numeric($_REQUEST['id']))
>       {
>               $pcp_list = westfieldy_custom_pcp_listing_get_pcps($_REQUEST['id']);
>               if(count($pcp_list) > 0)
>               {
> {/php}
> <p>
> Join the others to get the word out: <a href="http://www.westfieldynj.org/civicrm/contribute/campaign?action=add&reset=1&pageId={php} print($_REQUEST['id']); {/php} ">create your own personal campaign page</a> and help us in our fundraising efforts!</p>
> {php}
>                       foreach($pcp_list as $pcp_campaigner)
>                       {
>       {/php}
>       <div id="pcp-list-id-{php} print($pcp_campaigner['id']); {/php}"><span style="font-weight: bold; font-size: 1.1em; line-height: 1.3em;"><a href="http://www.westfieldynj.org/civicrm/contribute/pcp/info?reset=1&id={php} print($pcp_campaigner['id']); {/php}">{php} print($pcp_campaigner['title']); {/php}</a></span> ({php} print($pcp_campaigner['name']); {/php})
>       <p>{php} print('"' . $pcp_campaigner['intro'] . '"');{/php}</p></div>
>       {php}
>                       }
>               } else {
>       {/php}
>       <p>There are no personal campaign pages active right now. Get us started by <a href="http://www.westfieldynj.org/civicrm/contribute/campaign?action=add&reset=1&pageId={php} print($_REQUEST['id']); {/php}">creating your own fundraising page</a> today!</p>
>       {php}
>               }
>       }
>       {/php}
>     </div>
> {/if}
>
> <h2 class="block-header">Contribution Form</h2>

That takes care of displaying the PCP pages as links; if none are available, it politely suggests to the user that he/she should create one of their own to get things started. ;)

There's no special styling for the new layers; they're just there for easy identification. The h2 headers use JS to render the organisation's font with a horizontal rule underneath, so everything looks pretty in the end. However, I'll admit that I'm unsatisfied with putting the PHP code directly in the template, so I'll probably look to move the code elsewhere and rely on Smarty to iterate through the array, but this works fine for now.

If you go to one of my organisation's campaign pages you can see a demo of this feature in action.

Hope someone can get some use out of this! Let me know what you think.


- Charles D

Designed on:
  • CiviCRM 3.3.1
  • Drupal 6.20
  • PHP 5.3.4
  • MySQL 5.1.54
  • CentOS 5 (Linux 2.6.18-028stab070.14)
  • Apache/2.2.3

Eliet Henderson

  • I post occasionally
  • **
  • Posts: 49
  • Karma: 4
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 7
  • MySQL version: 5.0
  • PHP version: 5.2
Re: CiviContribute PCP listing on campaign pages
July 20, 2011, 02:31:37 pm
Hi Charles, thanks for posting this, it's very useful.

Eliet
« Last Edit: July 20, 2011, 04:29:19 pm by Eliet Henderson »

Kevin Field

  • I’m new here
  • *
  • Posts: 6
  • Karma: 0
  • CiviCRM version: 4.1.3
  • CMS version: Drupal 7.14
  • MySQL version: 5.1.63
  • PHP version: 5.3.10
Re: CiviContribute PCP listing on campaign pages
June 27, 2012, 10:38:37 am
I'm a Drupal and CiviCRM noob.  Does this code work on Drupal 7 / CiviCRM 4.1?  If so, could you give me some pointers on getting this up and running?

Thanks,
Kev

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviContribute (Moderator: Donald Lobo) »
  • CiviContribute PCP listing on campaign pages

This forum was archived on 2017-11-26.