implements feature request #46 to monitor other people's lists
http://sourceforge.net/p/phpgiftreg/feature-requests/46/
This commit is contained in:
parent
6513d8a14c
commit
a3bbdabbaa
6 changed files with 76 additions and 2 deletions
|
@ -92,6 +92,37 @@ function getExistingQuantity($itemid, $userid, $bought, $dbh, $opt) {
|
|||
}
|
||||
}
|
||||
|
||||
function processSubscriptions($publisher, $action, $dbh, $opt) {
|
||||
// join the users table as a cheap way to get the guy's name without having to pass it in.
|
||||
$stmt = $dbh->prepare("SELECT subscriber, fullname FROM subscriptions sub INNER JOIN users u ON u.userid = sub.publisher WHERE publisher = ? AND (last_notified IS NULL OR DATE_ADD(last_notified, INTERVAL {$opt["notify_threshold_minutes"]} MINUTE) < NOW())");
|
||||
$stmt->bindParam(1, $publisher, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
|
||||
$msg = "";
|
||||
while ($row = $stmt->fetch()) {
|
||||
if ($msg == "") {
|
||||
// same message for each user but we need the fullname from the first row before we can assemble it.
|
||||
if ($action == "insert") {
|
||||
$msg = $row["fullname"] . " has added an item to their list.";
|
||||
}
|
||||
else if ($action == "update") {
|
||||
$msg = $row["fullname"] . " has updated an item on their list.";
|
||||
}
|
||||
else if ($action == "delete") {
|
||||
$msg = $row["fullname"] . " has deleted an item from their list.";
|
||||
}
|
||||
$msg .= "\r\n\r\nYou are receiving this message because you are subscribed to their updates. You will not receive another message for their updates for the next " . $opt["notify_threshold_minutes"] . " minutes.";
|
||||
}
|
||||
sendMessage($publisher, $row["subscriber"], $msg, $dbh, $opt);
|
||||
|
||||
// stamp the subscription.
|
||||
$stmt2 = $dbh->prepare("UPDATE subscriptions SET last_notified = NOW() WHERE publisher = ? AND subscriber = ?");
|
||||
$stmt2->bindParam(1, $publisher, PDO::PARAM_INT);
|
||||
$stmt2->bindParam(2, $row["subscriber"], PDO::PARAM_INT);
|
||||
$stmt2->execute();
|
||||
}
|
||||
}
|
||||
|
||||
function sendMessage($sender, $recipient, $message, $dbh, $opt) {
|
||||
$stmt = $dbh->prepare("INSERT INTO {$opt["table_prefix"]}messages(sender,recipient,message,created) VALUES(?, ?, ?, ?)");
|
||||
$stmt->bindParam(1, $sender, PDO::PARAM_INT);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue