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 (Moderator: Dave Greenberg) »
  • how to set up a raffle with CiviCRM, allowing user to choose quantity of tickes
Pages: [1] 2

Author Topic: how to set up a raffle with CiviCRM, allowing user to choose quantity of tickes  (Read 4260 times)

Sean Madsen

  • I post occasionally
  • **
  • Posts: 98
  • Karma: 5
  • CiviCRM implementer/developer
    • Bikes Not Bombs
  • CiviCRM version: 4.6
  • CMS version: Drupal 7
how to set up a raffle with CiviCRM, allowing user to choose quantity of tickes
April 06, 2009, 09:33:24 am
I'd like to set up a way for users to buy raffle tickets through CiviCRM. Users should be able to pay more so that they can have higher chances of winning the raffle. The best way I can think of doing it is to have a contribution page with multiple options like "1 ticket", "5 tickets", "15 tickets", "30 tickets" and so on.

Ideally however, the user would be presented with a text box where they can enter any number, the Civi would show them a total based on how many tickets they chose to buy. Anyone know of a way to do that? Thanks.

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: how to set up a raffle with CiviCRM, allowing user to choose quantity of tickes
April 06, 2009, 10:26:59 pm
The Price Set feature in CiviEvent works this way. If your raffle is part of an event - then it's a great "match". You can experiment with this by creating a Price Set 'group' - and adding a single field to it where the unit price is the 'per ticket' raffle price. Then create a new event, and under Event Fees - select your Price Set.
Protect your investment in CiviCRM by  becoming a Member!

nycschool

  • I’m new here
  • *
  • Posts: 16
  • Karma: 1
Re: how to set up a raffle with CiviCRM, allowing user to choose quantity of tickes
July 16, 2010, 09:31:11 am
Would there be a way to have a raffle ticket number generated for each ticket the user buys?

After the contribution, the buyer would get a receipt that would automatically generate raffle ticket numbers, so they'd know their numbers.  Then we could put a the "stub(s)" for the purchaser in the raffle.

I know this would be easily do this using the transaction number, but if the person purchases more than one ticket, we'd like to a number for each.  

Just checking if someone has done this. (of course, we're open to other solutions, too) Thanks!
« Last Edit: July 16, 2010, 09:39:08 am by nycschool »

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: how to set up a raffle with CiviCRM, allowing user to choose quantity of tickes
July 19, 2010, 03:05:04 pm
I haven't heard of anyone implementing something like this yet.

One approach would be to create "view-only" custom field extending Participant to hold a list of 1 to N raffle ticket "numbers". Then use the post hook on Participant to auto-generate a list of unique values and write that to the Participant record - the hook code would need to query the associated price set field to get the ticket count. Finally, the custom field could be included in the Event Confirmation message template (so it is included in the email to the purchaser).

If you need a structured data-store for the raffle tickets - you could create a separate additional table in your DB to store them (foreign keyed to the participant id). Then the hook code could query for max value a transaction and assign / insert the next N tickets).
Protect your investment in CiviCRM by  becoming a Member!

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: how to set up a raffle with CiviCRM, allowing user to choose quantity of tickes
July 20, 2010, 09:19:07 am
Do you need to ticket number with specific format? If not you can just use some prefix + participant id

Kurund
« Last Edit: July 20, 2010, 10:45:55 am by Kurund Jalmi »
Found this reply helpful? Support CiviCRM

nycschool

  • I’m new here
  • *
  • Posts: 16
  • Karma: 1
Re: how to set up a raffle with CiviCRM, allowing user to choose quantity of tickes
July 20, 2010, 12:23:38 pm
Su
Quote from: Kurund Jalmi on July 20, 2010, 09:19:07 am
Do you need to ticket number with specific format? If not you can just use some prefix + participant id

No, it doesn't need to be in any specific format.  However, would this approach be able to issue more than one ticket number (should the person choose to buy more than one ticket)?

Thank you!

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: how to set up a raffle with CiviCRM, allowing user to choose quantity of tickes
July 21, 2010, 05:43:45 am
So are you using price sets? If not that then each participant id will be unique for each purchase.

Kurund
Found this reply helpful? Support CiviCRM

nycschool

  • I’m new here
  • *
  • Posts: 16
  • Karma: 1
Re: how to set up a raffle with CiviCRM, allowing user to choose quantity of tickes
July 21, 2010, 05:52:46 am
Yes, we were considering using a price set like:

1 raffle ticket - $5
5 raffle tickets - $22
10 raffle tickets - $40

We would like to sell one or more tickets in each transaction, with each ticket getting a unique number.  So if someone were to buy 5 raffle tickets for $22, the would get a confirmation something like:

Thank you for buying raffle tickets.  Your ticket numbers are #122442, #122443, #122444, #122445, #122446.  Good luck!

The ticket numbers, and how they are generated, are not important, but must be unique. 

I'm wondering about additional participants...  It would be a bonus if additional participants are allowed but I don't anticipate it being used very much so probably not necessary.  Maybe they could buy tickets for other people?  I don't think people would use that very much.
« Last Edit: July 21, 2010, 05:56:14 am by nycschool »

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: how to set up a raffle with CiviCRM, allowing user to choose quantity of tickes
July 21, 2010, 06:48:48 am

i suspect you will need to:

1. Implement a hook to generate the ticket numbers and expose them to the email template. You can potentially use ticket numbers based on participant id (which is guaranteed to be unique), so participantID.1, participantID.2 etc. Doing this in the postProcess hook is probably a bit too late (since the mail is already sent), so maybe in the mail alter hook?

2. customize the email template to print the ticket number string.

you will require a fair amount of php/smarty/debugging skills to get this working. if you are not an experienced developer consider hiring someone from http://civicrm.org/professional/

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

nycschool

  • I’m new here
  • *
  • Posts: 16
  • Karma: 1
Re: how to set up a raffle with CiviCRM, allowing user to choose quantity of tickes
July 22, 2010, 07:51:09 am
Do we know if any others would find this feature useful?

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: how to set up a raffle with CiviCRM, allowing user to choose quantity of tickes
July 22, 2010, 09:48:15 am

if i had to guess, yes :)

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

nycschool

  • I’m new here
  • *
  • Posts: 16
  • Karma: 1
Re: how to set up a raffle with CiviCRM, allowing user to choose quantity of tickes
July 22, 2010, 01:45:26 pm
We might consider co-sponsoring this if we could get two or more co-sponsors.  Pls get in touch if you're interested.  Thank you for all the ideas on how to implement.

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: how to set up a raffle with CiviCRM, allowing user to choose quantity of tickes
July 22, 2010, 03:24:11 pm
you might want to tweet or blog about it to get more visibility for the idea / attract co-sponsors :-)
Protect your investment in CiviCRM by  becoming a Member!

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: how to set up a raffle with CiviCRM, allowing user to choose quantity of tickes
July 26, 2010, 05:53:09 pm

hey philip:

advantages of being offline :) here's a sample hook implementation for generating raffle ticket numbers. Please test and complete it etc before deploying in production. Its a bit hackish, but seemed the easiest way

Code: [Select]
/**                                                                                                                                                       
 * use the mail alter hook to inject raffle ticket numbers for participants                                                                               
 * this is not complete, IMO and i'd also store the raffle ticket numbers in a                                                                           
 * DB table to be on the safe side                                                                                                                       
 */
function civitest_civicrm_alterMailParams( &$params ) {

    if ( $params['groupName'] == 'msg_tpl_workflow_event' &&
         $params['valueName'] == 'event_online_receipt' ) {

        $smarty =  CRM_Core_Smarty::singleton( );
        $values =& $smarty->get_template_vars( );
        $vars = array( 'lineItem', 'participantID', 'contactID' );
        foreach ( $vars as $varName ) {
            $$varName = CRM_Utils_Array::value( $varName, $values, null );
        }

        // return if no lineitems in event registration                                                                                                   
        if ( ! $lineItem ||
             ! is_array( $lineItem ) ) {
            return;
        }

        // check for price field. the raffle id is 1 (in my test case)                                                                                   
        define( 'RAFFLE_PRICE_FIELD_ID', 1 );
        foreach ( $lineItem as $priceSet => $itemValues ) {
            foreach ( $itemValues as $itemID => $itemValue ) {
                if ( $itemValue['price_field_id'] != RAFFLE_PRICE_FIELD_ID ) {
                    continue;
                }

                $rafflePrefix = "{$contactID}_{$participantID}_";
                $raffleCount  = 0;
                switch ( $itemValue['label'] ) {
                case 'One':
                    $raffleCount = 1;
                    break;

                case 'Five':
                    $raffleCount = 5;
                    break;

                case 'Ten':
                    $raffleCount = 10;
                    break;

                }
                for ( $i = 1 ; $i <= $raffleCount; $i++ ) {
                    $raffleString[] = $rafflePrefix . $i;
                }
                if ( ! empty( $raffleString ) ) {
                    $raffleString = implode( ', ', $raffleString );
                    $params['text'] .= "                                                                                                                 
                                                                                                                                                         
===========================================================                                                                                               
Event Raffle Ticket Numbers                                                                                                                               
===========================================================                                                                                               
                                                                                                                                                         
Thank you for buying raffle tickets.  Your ticket numbers are:$raffleString. Good luck!                                                                   
                                                                                                                                                         
";
                    $htmlSnippet = "                                                                                                                     
<center>                                                                                                                                                 
 <table width=\"620\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" id=\"crm-event_receipt\" style=\"font-family: Arial, Verdana, sans-serif; text-align: left;\">                                                                                                                                             
                                                                                                                                                         
  <tr>                                                                                                                                                   
   <td>                                                                                                                                                   
    <table style=\"border: 1px solid #999; margin: 1em 0em 1em; border-collapse: collapse; width:100%;\">
     <tr>                                                                                                                                                 
      <th colspan=\"2\" style=\"text-align: left; padding: 4px; border-bottom: 1px solid #999; background-color: #eee;\">                                 
       Event Raffle Ticket Numbers      </th>                                                                                                             
     </tr>                                                                                                                                               
     <tr>                                                                                                                                                 
      <td colspan=\"2\" style=\"padding: 4px; border-bottom: 1px solid #999;\">                                                                           
       Thank you for buying raffle tickets.  Your ticket numbers are:$raffleString. Good luck!                                                           
      </td>                                                                                                                                               
     </tr>                                                                                                                                               
    </table>                                                                                                                                             
   </td>                                                                                                                                                 
  </tr>                                                                                                                                                   
 </table>                                                                                                                                                 
</center>                                                                                                                                                 
                                                                                                                                                         
</body>                                                                                                                                                   
";

                    $params['html'] = str_replace( "</body>",
                                                   $htmlSnippet,
                                                   $params['html'] );
                }
            }
        }
    }
}

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

nycschool

  • I’m new here
  • *
  • Posts: 16
  • Karma: 1
Re: how to set up a raffle with CiviCRM, allowing user to choose quantity of tickes
July 27, 2010, 08:29:33 am
This is great, Lobo!  thanks so much!  I'm going to be on vacation soon but I'd like to work with this more when I get back.

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM (Moderator: Dave Greenberg) »
  • how to set up a raffle with CiviCRM, allowing user to choose quantity of tickes

This forum was archived on 2017-11-26.