function sendMail($row, $feed) { // determine if we want to send mail for this feed // #1 - who is the target for this mail? // the guy who is the "owner", e.g when I create a post // and you LIKE it, I should get a notification. // so "owner of entity" is the target of our mails. // if X created a post and Y liked it then X gets a mail // if Z likes the same post then also only X gets a mail // Y will not receive a mail. $verb = $row["verb"]; $ownerId = $row["owner_id"]; if ($verb == AppConstants::FOLLOW_VERB) { //mail target is the guy you are following $ownerId = $row["object_id"]; } // #2 : I am not interested in receiving mails where // I am the subject or doer of deed! if (!empty($ownerId) && $ownerId != $row["subject_id"]) { // #3 - get my preference for this feed $preferenceDao = new \com\indigloo\sc\dao\Preference(); $preferenceObj = $preferenceDao->get($ownerId); $flag = $this->getMailflag($preferenceObj, $verb); if ($flag) { $activityHtml = new \com\indigloo\sc\html\Activity(); $emailData = $activityHtml->getEmailData($feed); if (empty($emailData)) { $message = sprintf("ACTIVITY_ERROR : getting email data :id %d ", $row["id"]); throw new \Exception($message); } $text = $emailData["text"]; $html = $emailData["html"]; $userDao = new \com\indigloo\sc\dao\User(); $row = $userDao->getOnLoginId($ownerId); $name = $row["name"]; $email = $row["email"]; if (!empty($email)) { $code = WebMail::sendActivityMail($name, $email, $text, $html); if ($code > 0) { $message = sprintf("ACTIVITY_ERROR : sending mail : id %d ", $row["id"]); throw new \Exception($message); } } } //condition:mail_flag } //condition:owner }