Mys 1.3.4 Raffle Mod

Forum
Last Post
Threads / Messages

Dinocanid

Member
Member
Joined
Aug 30, 2016
Messages
520
Points
18
Age
23
Location
Maryland, USA
Mysidian Dollar
43,334
-Intro-
This mod creates a simple raffle where users can buy tickets and win currency. When a user buys a ticket, that amount of money goes into the pool (or jackpot if you will) and the winner gets the total amount of money in the pool. There is currently no adminCP support. The code it a bit messy and could probably be cleaned up somehow, but it works well. The code is full of comments too, so you know which part does what. It contains some unused code for stopping the raffle on a certain date that you can fix up and use if you know how, but I couldn't figure it out.

-Part 0-
If you've checked out my other mods, you know that part 0 is where I usually input the "under-the-hood" information like the database tables; so let's do that! In phpMyAdmin, we're going to create 3 new tables. First make a table called "raffle" with this information:
6084977341235200.png


Now create another table called raffle_tickets with this information:
5957993948774400.png


And now make a third table called raffle_winner with this information:
6014370201206784.png


-Part 1-
Now we're going to go to your root folder (presumably called public_html) and make a new file called raffle.php. Inside, paste this:
PHP:
<?php

use Resource\Native\String;
use Resource\Collection\LinkedList;

class RaffleController extends AppController{
	
	public function index(){
	    $mysidia = Registry::get("mysidia");
	    }             
}
?>

-Part 2-
Next, go to your view folder and make a new file called raffleview.php. Add this inside:
PHP:
<?php

use Resource\Native\String;
use Resource\Collection\LinkedList;

class RaffleView extends View{
	
	public function index(){
	    $mysidia = Registry::get("mysidia");
		$document = $this->document;		
	        $document->setTitle("Raffles");
                $pool = $mysidia->db->select("raffle", array("pool"))->fetchColumn();
                $ticketcheck = $mysidia->db->select("raffle_tickets")->rowCount();
                $rafflecheck = $mysidia->db->select("raffle")->rowCount();
                $moneyvalidate = $mysidia->user->getcash();
                
       		//This part picks a winner from the database
if($mysidia->input->post("win")){
//This checks if any tickets have been bought.
if($ticketcheck < 1){
$document->add(new Comment("<font color='red'>This raffle had no entries! A winner was not chosen.</font>"));
}
else{
$winner = $mysidia->db->select("raffle_tickets", array("owner"), "1 ORDER BY RAND() DESC LIMIT 1")->fetchColumn();
$winnermoneycheck = $mysidia->db->select("users", array("money"), "username = '$winner'")->fetchColumn();
$mysidia->db->update("users", array("money" => ($winnermoneycheck + $pool)), "username = '$winner'");
$document->add(new Comment( "<font color='green'>{$winner} won {$pool} CURRENCY from the raffle!</font>"));
$mysidia->db->query("TRUNCATE TABLE adopts_raffle_tickets");
$mysidia->db->query("TRUNCATE TABLE adopts_raffle");
$document->add(new Comment("<meta http-equiv='refresh' content='1;url=raffle' />"));
return TRUE;
}
}
//This starts a new raffle. For good measure, it deletes the previous raffle before making a new one.
if($mysidia->input->post("new")){
$mysidia->db->query("TRUNCATE TABLE adopts_raffle_tickets");
$mysidia->db->query("TRUNCATE TABLE adopts_raffle");
$mysidia->db->insert("raffle", array("pool" => 0));
$document->add(new Comment( "A new raffle has been started."));
$document->add(new Comment("<meta http-equiv='refresh' content='1;url=raffle' />"));
return TRUE;
}       
              
       //This part adds the number of tickets the user buys to the database
if($mysidia->input->post("buy")){
$chosenOption = $mysidia->input->post("myList");
	if($chosenOption == "5"){
		if($moneyvalidate < 25){
	           $document->add(new Comment("You cannot afford this!"));
	           $document->add(new Comment("<meta http-equiv='refresh' content='1;url=raffle' />"));
	           return TRUE;
	           }
	           else{
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->user->changecash(-25);
		$mysidia->db->update("raffle", array("pool" => ($pool + 25)));
		$document->add(new Comment( "You bought 5 tickets!"));
		$document->add(new Comment("<meta http-equiv='refresh' content='1;url=raffle' />"));
return TRUE;
}
		   }
	elseif($chosenOption == "10"){
	if($moneyvalidate < 50){
	           $document->add(new Comment("You cannot afford this!"));
	           $document->add(new Comment("<meta http-equiv='refresh' content='1;url=raffle' />"));
	           return TRUE;
	           }
	           else{
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->user->changecash(-50);
		$mysidia->db->update("raffle", array("pool" => ($pool + 50)));
		$document->add(new Comment( "You bought 10 tickets!"));
		$document->add(new Comment("<meta http-equiv='refresh' content='1;url=raffle' />"));
return TRUE;
}
		   }
	elseif($chosenOption == "15"){
	if($moneyvalidate < 75){
	           $document->add(new Comment("You cannot afford this!"));
	           $document->add(new Comment("<meta http-equiv='refresh' content='1;url=raffle' />"));
	           return TRUE;
	           }
	           else{
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->user->changecash(-75);
		$mysidia->db->update("raffle", array("pool" => ($pool + 75)));
		$document->add(new Comment( "You bought 15 tickets!"));
		$document->add(new Comment("<meta http-equiv='refresh' content='1;url=raffle' />"));
return TRUE;
}
		   }	   	
	elseif($chosenOption == "20"){
	if($moneyvalidate < 100){
	           $document->add(new Comment("You cannot afford this!"));
	           $document->add(new Comment("<meta http-equiv='refresh' content='1;url=raffle' />"));
	           return TRUE;
	           }
	           else{
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));
		$mysidia->user->changecash(-100);
		$mysidia->db->update("raffle", array("pool" => ($pool + 100)));
		$document->add(new Comment( "You bought 20 tickets!"));
		$document->add(new Comment("<meta http-equiv='refresh' content='1;url=raffle' />"));
return TRUE;
}
		   }  
		}
       
              
                
                //This section can only be seen by admins!
if($mysidia->user instanceof Admin){
$document->add(new Comment( "<h2>-Admin Section-</h2>"));
		 $document->add(new Comment( "Choosing a winner will end the current raffle. Starting a new raffle will end the current one, but will not pick a winner."));
		  $adminForm = new FormBuilder("adminForm", "", "post");
  $adminForm->buildButton("Choose a winner!", "win", "submit");
  $adminForm->buildButton("Start new raffle", "new", "submit");
        $document->add($adminForm);   
            		
		}
	
	//This checks if a raffle is going on.
	if($rafflecheck < 1){
$document->add(new Comment("<font color='red'><h2>There is no raffle going on right now. Come back later!</h2></font>"));
return TRUE;
}	
		
                if($pool < 1){
                $document->add(new Comment( "There is currently 0 CURRENCY in the pool!"));
$document->add(new Comment( "It costs 5 CURRENCY per ticket."));
$document->add(new Paragraph());
                }
                else{
$document->add(new Comment( "There is currently {$pool} CURRENCY in the pool!"));
$document->add(new Comment( "It costs 5 CURRENCY per ticket."));
$document->add(new Paragraph());
}


//This section checks the date! It's commented out since it isn't being used.
	  //$currenttime = time();
	 // $timerange = array(strtotime($this->stopdate));
		// if(!empty($timerange[1]) and $currenttime > $timerange[1]){
		     // The raffle has ended!
			// $winner = $mysidia->db->select("raffle_tickets", array("owner"), "1 ORDER BY RAND() DESC LIMIT 1")->fetchColumn();
                        // $document->add(new Comment( "{$winner} won {$pool} CURRENCY from the raffle! Congratulations!"));	
                        // $endraffle = TRUE;
		// }
		 //else{
  
//This is the ticket form!
$ticketForm = new FormBuilder("ticketForm", "", "post");
$exampleDropdown = new DropdownList("myList");
$exampleDropdown->add(new Option("5 tickets", "5")); 
$exampleDropdown->add(new Option("10 tickets", "10"));
$exampleDropdown->add(new Option("15 tickets", "15"));
$exampleDropdown->add(new Option("20 tickets", "20"));
$ticketForm->buildComment("Amount: ", FALSE);
$ticketForm->add($exampleDropdown);
$ticketForm->buildComment("<br></br>");
  $ticketForm->buildButton("Buy tickets", "buy", "submit");
        $document->add($ticketForm);
        

//}		
		
	}
}
?>
If you've never seen "TRUNCATE" before, it empties the whole table and resets the auto-increment number back to 1. You are free to change the amount it costs to buy tickets to whatever you like, I just chose 5.

Since I couldn't figure out adminCP support, there is a section right there on the raffle page that can only be seen by admins; so users won't be able to end the raffles on their own.

-Unused code-
This is the adminCP code that I couldn't figure out how to finish. If anyone can figure it out and fix it up, be my guest. Note that both files below are in the admincp and admindcp view folder, not the root folder.

raffle.php (Please disregard the shop information. I usually copy-paste from existing files to avoid typing from scratch and running into syntax errors, and it had nothing to do with the raffle script)
PHP:
<?php

use Resource\Native\String;
use Resource\Collection\LinkedHashMap;

class ACPRaffleController extends AppController{
	
	public function __construct(){
        parent::__construct();
		$mysidia = Registry::get("mysidia");
		if($mysidia->usergroup->getpermission("canmanagesettings") != "yes"){
		    throw new NoPermissionException("You do not have permission to manage raffles.");
		}		
    }
	
	public function index(){
	    parent::index();
	    $mysidia = Registry::get("mysidia");
	}
	
	public function start(){
	    $mysidia = Registry::get("mysidia");
	    $cost = $mysidia->input->post("cost");
	    $stopdate = $mysidia->input->post("stopdate");
	    
	    if($mysidia->input->post("submit")){
		$mysidia->db->insert("raffle", array("pool" => 0, "cost" => $cost, "stopdate" => $stopdate));	
		}	
	}
	
	public function end(){
	    $mysidia = Registry::get("mysidia");
	    if(!$mysidia->input->get("sid")){
		    $this->index();
			return;
		}
		elseif($mysidia->input->post("submit")){
		    $this->dataValidate();
            $imageurl = (!$mysidia->input->post("imageurl"))?$mysidia->input->post("existingimageurl"):$mysidia->input->post("imageurl");
			$salestax = (!$mysidia->input->post("salestax"))?0:$mysidia->input->post("salestax");
			$mysidia->db->update("shops", array("category" => $mysidia->input->post("category"), "shopname" => $mysidia->input->post("shopname"), "description" => $mysidia->input->post("description"), "imageurl" => $imageurl,
			                                    "status" => $mysidia->input->post("status"), "restriction" => $mysidia->input->post("restriction"), "salestax" => $salestax), "sid='{$mysidia->input->get("sid")}'");		
		    return;
		}
		else{
		    $shop = $mysidia->db->select("shops", array(), "sid='{$mysidia->input->get("sid")}'")->fetchObject();		
		    if(!is_object($shop)) throw new InvalidIDException("nonexist");
			$this->setField("shop", new DataObject($shop));	
	    }
	}
}
?>

raffleview.php
PHP:
<?php

use Resource\Native\String;
use Resource\Collection\LinkedHashMap;

class ACPRaffleView extends View{
  
	public function index(){
	    parent::index();		
		$stmt = $this->getField("stmt")->get();		
		$document = $this->document;			
	}
	
	public function start(){
	    $mysidia = Registry::get("mysidia");
		$document = $this->document;
	    if($mysidia->input->post("submit")){			
		    $document->setTitle("Successfully created raffle!");
			$document->add(new Comment("You will now be redirected to the index page."));
            header("Refresh:3; URL='../index'");
			return;
		}
		
		$document->setTitle("Create new raffle");
		$document->add(new Comment("Here you can start a new raffle. <em>You can only start a new one if there isn't one already!</em>", TRUE, "b"));	
			$document->add(new Paragraph);
		$raffleForm = new Form("addform", "add", "post");	
		$raffleForm->add(new Comment("<b>Ticket Cost:</b>", FALSE));
		$raffleForm->add(new TextField("cost"));
		$raffleForm->add(new Paragraph);
		$raffleForm->add(new Comment("<b>End Date:</b>", FALSE));
		$raffleForm->add(new TextField("stopdate"));
		$raffleForm->add(new Comment("<b>Note: <em>Date must follow the format (mm/dd/yyyy)!</em></b>"));
		$raffleForm->add(new Button("Create raffle", "submit", "submit"));
		$document->add($raffleForm);				
	}
	
	public function end(){
	    $mysidia = Registry::get("mysidia");
		$document = $this->document;
		if($mysidia->input->post("submit")){
		    $document->setTitle("Successfully ended raffle!");
			$document->addLangvar("A winner has been chosen. You will now be redirected to the index page. Be sure to check out your site's raffle page to see who won!");
            header("Refresh:3; URL='../index'");
		    return;
		}
		else{			
		    $document->setTitle("End current raffle");
			$document->add(new Comment("By clicking the button below, a winner will be chosen and the raffle will end!", TRUE, "b"));
			$raffleForm = new Form("endform", "end", "post");
		    $raffleForm->add(new Button("End raffle", "submit", "submit"));
		    $document->add($raffleForm);					 
		}
	}
}
?>

-Screenshots-
4883263208554496.png


6233853255745536.png
 
Last edited:
What in particular are you having issues with in the ACP portion?

I seem to be getting an error, when I visit the page I'm just getting a blank page with the title set as Raffle.
 
With the ACP I didn't know how to make it affect the raffle page itself. While attempting to make it time-based through the ACP (start and end on a certain date), I found myself breaking much of the code that already worked so I stopped and kept what I had.

As for the error, that's weird since I literally just copy-pasted the code I had and it works fine for me. Did you try it again? I'll put my code here again just in case there is a difference in it somewhere, but there shouldn't be any:

PHP:
<?php 

use Resource\Native\String; 
use Resource\Collection\LinkedList; 

class RaffleView extends View{ 
     
    public function index(){ 
        $mysidia = Registry::get("mysidia"); 
        $document = $this->document;         
            $document->setTitle("Raffles"); 
                $pool = $mysidia->db->select("raffle", array("pool"))->fetchColumn(); 
                $ticketcheck = $mysidia->db->select("raffle_tickets")->rowCount(); 
                $rafflecheck = $mysidia->db->select("raffle")->rowCount(); 
                $moneyvalidate = $mysidia->user->getcash(); 
                 
               //This part picks a winner from the database 
if($mysidia->input->post("win")){ 
//This checks if any tickets have been bought. 
if($ticketcheck < 1){ 
$document->add(new Comment("<font color='red'>This raffle had no entries! A winner was not chosen.</font>")); 
} 
else{ 
$winner = $mysidia->db->select("raffle_tickets", array("owner"), "1 ORDER BY RAND() DESC LIMIT 1")->fetchColumn(); 
$winnermoneycheck = $mysidia->db->select("users", array("money"), "username = '$winner'")->fetchColumn(); 
$mysidia->db->update("users", array("money" => ($winnermoneycheck + $pool)), "username = '$winner'"); 
$document->add(new Comment( "<font color='green'>{$winner} won {$pool} CURRENCY from the raffle!</font>")); 
$mysidia->db->query("TRUNCATE TABLE adopts_raffle_tickets"); 
$mysidia->db->query("TRUNCATE TABLE adopts_raffle"); 
$document->add(new Comment("<meta http-equiv='refresh' content='1;url=raffle' />")); 
return TRUE; 
} 
} 
//This starts a new raffle. For good measure, it deletes the previous raffle before making a new one. 
if($mysidia->input->post("new")){ 
$mysidia->db->query("TRUNCATE TABLE adopts_raffle_tickets"); 
$mysidia->db->query("TRUNCATE TABLE adopts_raffle"); 
$mysidia->db->insert("raffle", array("pool" => 0)); 
$document->add(new Comment( "A new raffle has been started.")); 
$document->add(new Comment("<meta http-equiv='refresh' content='1;url=raffle' />")); 
return TRUE; 
}        
               
       //This part adds the number of tickets the user buys to the database 
if($mysidia->input->post("buy")){ 
$chosenOption = $mysidia->input->post("myList"); 
    if($chosenOption == "5"){ 
        if($moneyvalidate < 25){ 
               $document->add(new Comment("You cannot afford this!")); 
               $document->add(new Comment("<meta http-equiv='refresh' content='1;url=raffle' />")); 
               return TRUE; 
               } 
               else{ 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->user->changecash(-25); 
        $mysidia->db->update("raffle", array("pool" => ($pool + 25))); 
        $document->add(new Comment( "You bought 5 tickets!")); 
        $document->add(new Comment("<meta http-equiv='refresh' content='1;url=raffle' />")); 
return TRUE; 
} 
           } 
    elseif($chosenOption == "10"){ 
    if($moneyvalidate < 50){ 
               $document->add(new Comment("You cannot afford this!")); 
               $document->add(new Comment("<meta http-equiv='refresh' content='1;url=raffle' />")); 
               return TRUE; 
               } 
               else{ 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->user->changecash(-50); 
        $mysidia->db->update("raffle", array("pool" => ($pool + 50))); 
        $document->add(new Comment( "You bought 10 tickets!")); 
        $document->add(new Comment("<meta http-equiv='refresh' content='1;url=raffle' />")); 
return TRUE; 
} 
           } 
    elseif($chosenOption == "15"){ 
    if($moneyvalidate < 75){ 
               $document->add(new Comment("You cannot afford this!")); 
               $document->add(new Comment("<meta http-equiv='refresh' content='1;url=raffle' />")); 
               return TRUE; 
               } 
               else{ 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->user->changecash(-75); 
        $mysidia->db->update("raffle", array("pool" => ($pool + 75))); 
        $document->add(new Comment( "You bought 15 tickets!")); 
        $document->add(new Comment("<meta http-equiv='refresh' content='1;url=raffle' />")); 
return TRUE; 
} 
           }            
    elseif($chosenOption == "20"){ 
    if($moneyvalidate < 100){ 
               $document->add(new Comment("You cannot afford this!")); 
               $document->add(new Comment("<meta http-equiv='refresh' content='1;url=raffle' />")); 
               return TRUE; 
               } 
               else{ 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username)); 
        $mysidia->user->changecash(-100); 
        $mysidia->db->update("raffle", array("pool" => ($pool + 100))); 
        $document->add(new Comment( "You bought 20 tickets!")); 
        $document->add(new Comment("<meta http-equiv='refresh' content='1;url=raffle' />")); 
return TRUE; 
} 
           }   
        } 
        
               
                 
                //This section can only be seen by admins! 
if($mysidia->user instanceof Admin){ 
$document->add(new Comment( "<h2>-Admin Section-</h2>")); 
         $document->add(new Comment( "Choosing a winner will end the current raffle. Starting a new raffle will end the current one, but will not pick a winner.")); 
          $adminForm = new FormBuilder("adminForm", "", "post"); 
  $adminForm->buildButton("Choose a winner!", "win", "submit"); 
  $adminForm->buildButton("Start new raffle", "new", "submit"); 
        $document->add($adminForm);    
                     
        } 
     
    //This checks if a raffle is going on. 
    if($rafflecheck < 1){ 
$document->add(new Comment("<font color='red'><h2>There is no raffle going on right now. Come back later!</h2></font>")); 
return TRUE; 
}     
         
                if($pool < 1){ 
                $document->add(new Comment( "There is currently 0 CURRENCY in the pool!")); 
$document->add(new Comment( "It costs 5 CURRENCY per ticket.")); 
$document->add(new Paragraph()); 
                } 
                else{ 
$document->add(new Comment( "There is currently {$pool} CURRENCY in the pool!")); 
$document->add(new Comment( "It costs 5 CURRENCY per ticket.")); 
$document->add(new Paragraph()); 
} 


//This section checks the date! It's commented out since it isn't being used. 
      //$currenttime = time(); 
     // $timerange = array(strtotime($this->stopdate)); 
        // if(!empty($timerange[1]) and $currenttime > $timerange[1]){ 
             // The raffle has ended! 
            // $winner = $mysidia->db->select("raffle_tickets", array("owner"), "1 ORDER BY RAND() DESC LIMIT 1")->fetchColumn(); 
                        // $document->add(new Comment( "{$winner} won {$pool} CURRENCY from the raffle! Congratulations!"));     
                        // $endraffle = TRUE; 
        // } 
         //else{ 
   
//This is the ticket form! 
$ticketForm = new FormBuilder("ticketForm", "", "post"); 
$exampleDropdown = new DropdownList("myList"); 
$exampleDropdown->add(new Option("5 tickets", "5"));  
$exampleDropdown->add(new Option("10 tickets", "10")); 
$exampleDropdown->add(new Option("15 tickets", "15")); 
$exampleDropdown->add(new Option("20 tickets", "20")); 
$ticketForm->buildComment("Amount: ", FALSE); 
$ticketForm->add($exampleDropdown); 
$ticketForm->buildComment("<br></br>"); 
  $ticketForm->buildButton("Buy tickets", "buy", "submit"); 
        $document->add($ticketForm); 
         

//}         
         
    } 
} 
?>
(^ raffleview.php)

PHP:
<?php

use Resource\Native\String;
use Resource\Collection\LinkedList;

class RaffleController extends AppController{
	
	public function index(){
	    $mysidia = Registry::get("mysidia");
	    }             
}
?>
(^ raffle.php)
 
Turns out I had put a bracket in the wrong place, whoops! It's working splendidly now :D

Excellent mod, thank you for sharing it with us!
 
This is awesome. Is there a way to set it up to automatically cycle through raffles and let the winner know they won?
-edit-
I've set up the stopdate to be one week in the future from the start
PHP:
//This section checks the date! It's commented out since it isn't being used. 
      $currenttime = time(); 
      $stoptime = $currenttime + 700000;
      $mysidia->db->update("raffle", array("stopdate" => $stoptime));
      $timerange = array(strtotime($this->stopdate));
With this
 
Last edited:
I don't know how to make it automatically cycle through, but you can let the winner know that they won by putting this with the part of the script that picks the winner:
PHP:
$pm = new PrivateMessage(); // Send the winner a pm
    $pm->setsender('AdminUsernameHere');
    $pm->setrecipient($winner);
    $pm->setmessage("You won the raffle! Congratulations! {$pool} CURRENCY has been added to your account.");
    $pm->post();
 
hmm I must have done something wrong

Warning: Missing argument 2 for PrivateMessage::setmessage(), called in /home/arconlin/public_html/view/raffleview.php on line 34 and defined in /home/arconlin/public_html/classes/class_privatemessage.php on line 91

Fatal error: Uncaught exception 'Exception' with message 'Cannot set an empty private message' in /home/arconlin/public_html/classes/class_privatemessage.php:92 Stack trace: #0 /home/arconlin/public_html/view/raffleview.php(34): PrivateMessage->setmessage('You won the raf...') #1 /home/arconlin/public_html/classes/class_frontcontroller.php(100): RaffleView->index() #2 /home/arconlin/public_html/index.php(74): FrontController->render() #3 /home/arconlin/public_html/index.php(78): IndexController::main() #4 {main} thrown in /home/arconlin/public_html/classes/class_privatemessage.php on line 92
 
My bad! You have to set a title for a message, so change this:
PHP:
$pm->setmessage("You won the raffle! Congratulations! {$pool} CURRENCY has been added to your account.");

To this:
PHP:
$pm->setmessage("Raffle prize", "You won the raffle! Congratulations! {$pool} CURRENCY has been added to your account.");

It should work now.
 
Haha I figured it out literally right when you posted the fix. Thanks bud. I'll play around with the code and see if I can make it cycle through automatically
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,274
Messages
33,114
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Latest Posts

Top