PDA

View Full Version : PM Users for Donation Alert


Abronsyth
02-18-2016, 02:51 PM
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?

Kyttias
02-18-2016, 03:29 PM
Try:

$pm = new PrivateMessage();
$pm->setsender('SYSTEM'); // Or... whatever? You can change this.
$pm->setrecipient(htmlentities(addslashes(trim($recipie nt->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?
$pm->setsender($mysidia->user->username);

Here's the whole donate.php with the addition:
<?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($recipie nt->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!

Abronsyth
02-18-2016, 03:56 PM
Sweet, it works perfectly!

Thank you very much <3

NobodysHero
04-06-2016, 12:19 PM
Awesome! That was a great idea, Abronsyth! Thanks for sharing. 8D

Micolai
07-04-2020, 01:14 AM
For some reason I keep getting an email that sends out to users after donations are made to them.