PM Users for Donation Alert

Forum
Last Post
Threads / Messages

Abronsyth

A Headache Embodied
Member
Joined
Aug 25, 2011
Messages
1,012
Points
36
Location
NY
Mysidian Dollar
73,285
Resolved

I've looked at the functions that send a PM to a user when they receive a trade, but I couldn't figure this one out.

I'd like to make it so that when users receive a currency donation they also receive a PM that tells them;
"[Username] has sent you [amount] currency!"

Anyone have any ideas?
 
Last edited:
Try:
PHP:
$pm = new PrivateMessage(); 
$pm->setsender('SYSTEM'); // Or... whatever? You can change this.
$pm->setrecipient(htmlentities(addslashes(trim($recipient->username))));
$pm->setmessage("Donation For You!", "{$mysidia->user->username} has sent you {$amount} {$mysidia->settings->cost}!");
$pm->post();

You could probably also have the sender be the user?
PHP:
$pm->setsender($mysidia->user->username);

Here's the whole donate.php with the addition:
  Spoiler: donate.php 
PHP:
<?php

use Resource\Native\Integer;
use Resource\Native\String;

class DonateController extends AppController{

    public function __construct(){
        parent::__construct("member");
    }
	
	public function index(){
	    $mysidia = Registry::get("mysidia");		
	    if($mysidia->input->post("recipient") and $mysidia->input->post("amount")){
		    $recipient = preg_replace("/[^a-zA-Z0-9\\040]/", "", $mysidia->input->post("recipient"));
            $amount = $mysidia->input->post("amount");
	        $recipient = new Member($recipient);			
	 	    if($amount < 0) throw new DonationException("negative");
	        elseif($mysidia->user->money < $amount) throw new DonationException("funds");
            elseif($recipient->username == $mysidia->user->username) throw new DonationException("user");
			else{
			    $mysidia->user->donate($recipient, $amount);
				$this->setField("recipient", new String($recipient->username));
				$this->setField("amount", new Integer($amount));

				$pm = new PrivateMessage(); 
				$pm->setsender('SYSTEM'); // Or... whatever? You can change this.
				$pm->setrecipient(htmlentities(addslashes(trim($recipient->username))));
				$pm->setmessage("Donation Acquired", "{$mysidia->user->username} has sent you {$amount} {$mysidia->settings->cost}!");
				$pm->post();  
				
			}	
			return;
		}
	}
}
?>

Untested, of course. Luckily it appears to be super simple to implement notifications via PM!
 
Last edited:
For some reason I keep getting an email that sends out to users after donations are made to them.
 
Last edited:

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,277
Messages
33,122
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Latest Posts

Top