コード例 #1
0
 /**
  * @param User $model
  * Add new email alerts and delete older
  */
 private function saveEmailAlerts(User $model)
 {
     if (isset($_POST['User'])) {
         UserConfig::model()->deleteAll("userId=" . $model->use_id . " AND configType ='" . UserConfig::TYPE_EMAIL_ALERT . "' AND configKey='" . UserConfig::KEY_EMAIL_ALERT_DEAL_STATUS . "'");
         if (isset($_POST['User']['emailAlertForDealStatus'])) {
             $emailAlerts = $_POST['User']['emailAlertForDealStatus'];
             foreach ($emailAlerts as $k => $v) {
                 if ($v == 1) {
                     $userConfig = new UserConfig();
                     $userConfig->unsetAttributes();
                     $userConfig->userId = $model->use_id;
                     $userConfig->configType = UserConfig::TYPE_EMAIL_ALERT;
                     $userConfig->configKey = UserConfig::KEY_EMAIL_ALERT_DEAL_STATUS;
                     $userConfig->configValue = $k;
                     $userConfig->save();
                 }
             }
         }
     }
 }
コード例 #2
0
 /**
  * @param $instruction
  */
 private function sendEmailOnStatusChange(Deal $instruction)
 {
     if ($instruction) {
         /** @var  $instruction Deal [ ] */
         $status = $instruction->dea_status;
         $address = $instruction->property->address->getFullAddressString(', ');
         $userConfigs = UserConfig::model()->findAll("configType =:configType AND configKey=:configKey AND configValue = :configValue", array('configType' => UserConfig::TYPE_EMAIL_ALERT, 'configKey' => UserConfig::KEY_EMAIL_ALERT_DEAL_STATUS, 'configValue' => $status));
         $userIds = [];
         foreach ($userConfigs as $userConfig) {
             $userIds[] = $userConfig->userId;
         }
         $criteria = new CDbCriteria();
         $criteria->scopes = ["emailAlertsForDealStatus"];
         $criteria->addInCondition('use_id', $userIds);
         $users = User::model()->findAll($criteria);
         foreach ($users as $user) {
             /** @var $user User[ ] */
             if ($user->use_email) {
                 $fromEmail = "*****@*****.**";
                 $recipient = $user->use_email;
                 $emailMessage = "From:\t" . $fromEmail . "\n\n";
                 $emailMessage .= "Dear " . ($user->fullName ? $user->fullName : $user->use_fname) . ",\n\n";
                 $emailMessage .= "Following property status has changed to " . $status . " \n\n";
                 $emailMessage .= $address;
                 $emailMessage .= "\n\nSent:\t" . date("d/m/Y H:i");
                 try {
                     include_once "Zend/Mail.php";
                     $mailToUser = new Zend_Mail("UTF-8");
                     $mailToUser->addTo($recipient);
                     $mailToUser->setFrom($fromEmail);
                     $mailToUser->setSubject("Property status changed");
                     $mailToUser->setBodyText($emailMessage);
                     $mailToUser->send();
                 } catch (Exception $e) {
                 }
             }
         }
     }
 }