Skip to content

Instantly share code, notes, and snippets.

@joshsmith
Created December 13, 2010 06:44
Show Gist options
  • Save joshsmith/738726 to your computer and use it in GitHub Desktop.
Save joshsmith/738726 to your computer and use it in GitHub Desktop.
public function notifyAdviceGiverOfComment($uid, $aid, $cid, $body)
{
$advice = new Advice();
$adviceArray = $advice->getAdvice($aid);
$usersArray = array(array("first_name" => $adviceArray['first_name'], "last_name" => $adviceArray['last_name'], "email" => $adviceArray['email']));
// Return true if the commenter and adviceer are the same
// ... we don't want to send an email
if($uid == $adviceArray['uid']) {
return true;
}
// Get the goal title
$goal = new Goal();
$goalArray = $goal->getGoal($adviceArray['goal_id']);
// Set the name of the commenter
$user = new User();
$userArray = $user->getUserArray($uid);
$info['commenter'] = $userArray[0]["first_name"] . " " . $userArray[0]["last_name"];
// Set the advice body
$info['advice'] = $adviceArray['body'];
if(strlen($info['advice']) > 97) {
$info['short_advice'] = substr(strip_tags($adviceArray['body']), 0, 97) . '...';
} else {
$info['short_advice'] = strip_tags($info['advice']);
}
// Set the comment body
$info['comment'] = $body;
// Set the question URL
$url = new URL();
$slug = $url->generateSlug($goalArray['title']);
$info['goal_url'] = "goals/".$goal_id."/".$slug;
// Set the BBC emails, sender, and subject
$info['emails'] = $usersArray;
$info['sender'] = "[email protected]";
$info['subject'] = $info['commenter'] . ' commented on your advice "' . $info['short_advice'] . '"';
// Send the email
$notification = new Notification();
if($notification->sendNotificationWithTemplate($info, 'newCommentOnYourAdviceTemplate')) {
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment