public function save(Doctrine_Connection $conn = null) { $send_message = false; if ($this->isNew()) { if (!$this->hasVerifiedSender()) { $this->deleteWithException("Cannot create Message " . "because sfGuardUser " . $this->getSenderId() . " has not been validated yet.", 406); } if (!$this->hasVerifiedRecipient()) { $this->deleteWithException("Cannot create Message " . "because sfGuardUser " . $this->getSenderId() . " has not been validated yet.", 406); } $send_message = true; } /* If the obejct is not new or has passed all rules for saving, we pass * it on to the parent save function. */ parent::save($conn); if ($send_message) { /* The following is for sending an email to the recipient to notify them that they've received a message. */ $recipient = sfGuardUserTable::getInstance()->find($this->getRecipientId()); if (!$recipient || !$recipient->getReceiveNotificationOfPrivateMessages()) { return parent::save($conn); } $parameters = array('user_id' => $this->getRecipientId(), 'message_id' => $this->getIncremented()); $prefer_html = $recipient->getPreferHtml(); $address = $recipient->getEmailAddress(); $name = $recipient->getPreferredName() ? $recipient->getPreferredName() : $recipient->getFullName(); $email = EmailTable::getInstance()->getFirstByEmailTypeAndLanguage('NewPrivateMessage', $recipient->getPreferredLanguage()); $subject = $email->generateSubject($parameters); $body = $email->generateBodyText($parameters, $prefer_html); $from = sfConfig::get('app_email_address', ProjectConfiguration::getApplicationName() . ' <' . ProjectConfiguration::getApplicationEmailAddress() . '>'); AppMail::sendMail($address, $from, $subject, $body, $prefer_html ? $body : null); } }
public function save(Doctrine_Connection $conn = null) { if (is_null($this->_get('username')) && is_null($this->_get('email_address'))) { return; //throw new sfException('Cannot save User with null username and email!'); } if ($this->isNew() && sfGuardUserTable::getIfValidatedUserHasUsername($this->_get('username'))) { throw new sfException('Cannot save user. This username has already been validated with another user.'); } if (!$this->isNew() && in_array('is_validated', $this->_modified) && !$this->_get('is_validated')) { /* The user has been un-validated, probably due to changing their * Reddit validation key by username or password. We need to send * them an email about it. */ $parameters = array('user_id' => $this->getIncremented()); $prefer_html = $this->getPreferHtml(); $address = $this->getEmailAddress(); $name = $this->getPreferredName() ? $this->getPreferredName() : $this->getFullName(); $email = EmailTable::getInstance()->getFirstByEmailTypeAndLanguage('ChangeRedditKey', $this->getPreferredLanguage()); $subject = $email->generateSubject($parameters); $body = $email->generateBodyText($parameters, $prefer_html); $from = sfConfig::get('app_email_address', ProjectConfiguration::getApplicationName() . ' <' . ProjectConfiguration::getApplicationEmailAddress() . '>'); AppMail::sendMail($address, $from, $subject, $body, $prefer_html ? $body : null); $this->addLoginMessage('You have changed information relating to your Reddit user and will need to validate your Reddit username again. Please see your email for more information.'); } parent::save($conn); }
public function sendMail($body_function, $additional_params = array()) { $user = $this->getGuardUser(); if (!$user) { return; } if (!$user->getReceiveNotificationOfEpisodeApprovalPending() && $body_function == "EpisodeApprovalPending") { return; } if (!$user->getReceiveNotificationOfNewlyOpenedEpisodes() && $body_function == "NewlyOpenedEpisode") { return; } if (!$user->getReceiveNotificationOfPrivateMessages() && $body_function == "NewPrivateMessage") { return; } $prefer_html = $user->getPreferHtml(); $address = $user->getEmailAddress(); $name = $user->getPreferredName() ? $user->getPreferredName() : $user->getFullName(); $user_id = $this->getApiUserId(); if (!array_key_exists('user_id', $additional_params)) { $additional_params['user_id'] = $user_id; } if (array_key_exists('language', $additional_params)) { $email = EmailTable::getInstance()->getFirstByEmailTypeAndLanguage($body_function, $additional_params['language']); } else { $email = EmailTable::getInstance()->getFirstByEmailTypeAndLanguage($body_function); } if (!$email) { throw new sfException("Cannot find email '{$body_function}' in language '{$language}'."); } $subject = $email->generateSubject($additional_params); $body = $email->generateBodyText($additional_params, $prefer_html); $from = sfConfig::get('app_email_address', ProjectConfiguration::getApplicationName() . ' <' . ProjectConfiguration::getApplicationEmailAddress() . '>'); return AppMail::sendMail($address, $from, $subject, $body, $prefer_html ? $body : null); }
public function sendEmailAboutPassedDeadline($user_id, $episode_id) { // Send an email to that user telling them their EpisodeAssignment is now valid $parameters = array('user_id' => $user_id, 'episode_id' => $episode_id); $user = sfGuardUserTable::getInstance()->find($user_id); $prefer_html = $user->getPreferHtml(); $address = $user->getEmailAddress(); $name = $user->getPreferredName() ? $user->getPreferredName() : $user->getFullName(); $email = EmailTable::getInstance()->getFirstByEmailTypeAndLanguage('PassedDeadlineOnEpisode', $user->getPreferredLanguage()); $subject = $email->generateSubject($parameters); $body = $email->generateBodyText($parameters, $prefer_html); $from = sfConfig::get('app_email_address', ProjectConfiguration::getApplicationName() . ' <' . ProjectConfiguration::getApplicationEmailAddress() . '>'); AppMail::sendMail($address, $from, $subject, $body, $prefer_html ? $body : null); $user->addLoginMessage('Your episode passed its release deadline and has been re-assigned.'); }
public function addEmail($address) { //make sure valid email address if (!EmailTable::isEmail($address)) { return false; } //make sure Entity doesn't already have phone foreach ($this->Email as $email) { if ($email->address == $address) { return false; } } //create new phone $email = new Email(); $email->address = $address; $this->Email[] = $email; return $email; }
public function save(Doctrine_Connection $conn = null) { if (!$this->isNew() && !$this->getSkipBackup() && in_array('graphic_file', $this->_modified) && $this->_get('graphic_file')) { $file_location = rtrim(ProjectConfiguration::getEpisodeGraphicFileLocalDirectory(), '/') . '/'; $filename = $this->_get('graphic_file'); if (file_exists($file_location . $filename)) { ProjectConfiguration::registerAws(); $response = $this->saveFileToApplicationBucket($file_location, $filename, 'upload', AmazonS3::ACL_PUBLIC); if ($response->isOK()) { unlink($file_location . $filename); } } } if (!$this->isNew() && !$this->getSkipBackup() && in_array('audio_file', $this->_modified) && $this->_get('audio_file')) { $file_location = rtrim(ProjectConfiguration::getEpisodeAudioFileLocalDirectory(), '/') . '/'; $filename = $this->_get('audio_file'); if (file_exists($file_location . $filename)) { ProjectConfiguration::registerAws(); $response = $this->saveFileToApplicationBucket($file_location, $filename, 'audio'); } } if (!$this->isNew() && in_array('is_submitted', $this->_modified) && $this->_get('is_submitted')) { /* The episode has been submitted. We need to send an email about * it to the subreddit moderators. */ $types = array('moderator'); $memberships = sfGuardUserSubredditMembershipTable::getInstance()->getAllBySubredditAndMemberships($this->getSubredditId(), $types); $initial_is_submitted = $this->_get('is_submitted'); $initial_submitted_at = $this->_get('submitted_at'); foreach ($memberships as $membership) { $user = $membership->getSfGuardUser(); $parameters = array('user_id' => $membership->getSfGuardUserId(), 'episode_id' => $this->getIncremented()); $prefer_html = $user->getPreferHtml(); $address = $user->getEmailAddress(); $name = $user->getPreferredName() ? $user->getPreferredName() : $user->getFullName(); $email = EmailTable::getInstance()->getFirstByEmailTypeAndLanguage('EpisodeApprovalPending', $user->getPreferredLanguage()); $subject = $email->generateSubject($parameters); $body = $email->generateBodyText($parameters, $prefer_html); $from = sfConfig::get('app_email_address', ProjectConfiguration::getApplicationName() . ' <' . ProjectConfiguration::getApplicationEmailAddress() . '>'); AppMail::sendMail($address, $from, $subject, $body, $prefer_html ? $body : null); $user->addLoginMessage('You have Episodes awaiting your approval.'); } // @todo: The previous foreach loop sets the 'is_submitted' and 'submitted_at' columns to null. I don't know why. $this->_set('is_submitted', $initial_is_submitted); $this->_set('submitted_at', $initial_submitted_at); } return parent::save($conn); }