public static function write($to, $from, $subject, $body, $mail = true) { $message = new YumMessage(); if(!$mail) $message->omit_mail = true; if(is_object($from)) $message->from_user_id = (int) $from->id; else if(is_numeric($from)) $message->from_user_id = $from; else if(is_string($from) && $user = YumUser::model()->find("username = '******'")) $message->from_user_id = $user->id; else return false; if(is_object($to)) $message->to_user_id = (int) $to->id; else if(is_numeric($to)) $message->to_user_id = $to; else if(is_string($to) && $user = YumUser::model()->find("username = '******'")) $message->to_user_id = $user->id; else return false; $message->title = $subject; $message->message = $body; return $message->save(); }
protected function renderContent() { if (Yum::module('message')->messageSystem === false) { return false; } if (!Yii::app()->user->isGuest) { $messages = YumMessage::model()->unread()->limit(10)->findAll(); $this->render('messages', array('messages' => $messages)); } }
public function afterSave() { // If the user has activated email receiving, send a email if ($user = $this->profile->user) { if (Yum::hasModule('messages') && $user->privacy && $user->privacy->message_new_profilecomment) { Yii::import('application.modules.messages.models.YumMessage'); YumMessage::write($user, $this->user_id, Yum::t('New profile comment from {username}', array('{username}' => $this->user->username)), YumTextSettings::getText('text_profilecomment_new', array('{username}' => $this->user->username, '{message}' => $this->comment, '{link_profile}' => Yii::app()->controller->createUrl('//profile/profile/view')))); } } return parent::afterSave(); }
public function afterSave() { // If the user has activated email receiving, send a email if ($user = $this->profile->user) { if (Yum::hasModule('messages') && $user->privacy && $user->privacy->message_new_profilecomment) { Yii::import('application.modules.messages.models.YumMessage'); YumMessage::write($user, $this->user_id, Yum::t('New profile comment from {username}', array('{username}' => $this->user->username)), strtr('A new profile comment has been made from {username}: {message} <br /> <a href="{link_profile}">to my profile</a>', array('{username}' => $this->user->username, '{message}' => $this->comment, '{link_profile}' => Yii::app()->controller->createUrl('//profile/profile/view')))); } } return parent::afterSave(); }
<?php $messages = YumMessage::model()->findAll('to_user_id = :to and message_read = 0', array(':to' => Yii::app()->user->id)); if (count($messages) > 0) { if (Yum::module('message')->messageSystem == YumMessage::MSG_PLAIN) { $this->renderPartial('user.message.views.message.new_messages_plain', array('message' => $message)); } else { if (Yum::module('message')->messageSystem == YumMessage::MSG_DIALOG) { $this->renderPartial('user.message.views.message.new_messages_dialog', array('message' => $message)); } } }
public function actionSendDigest() { $message = ''; $recipients = array(); if (isset($_POST['sendDigest'])) { foreach (YumMessage::model()->with('to_user')->findAll('not message_read') as $message) { if (is_object($message->to_user) && $message->to_user->notifyType == 'Digest' || Yum::module('message')->notifyType == 'Digest') { $this->mailMessage($message); $recipients[] = $message->to_user->profile->email; } } if (count($recipients) == 0) { $message = Yum::t('No messages are pending. No message has been sent.'); } else { $message = Yum::t('Digest has been sent to {users} users:', array('{users}' => count($recipients))); $message .= '<ul>'; foreach ($recipients as $recipient) { $message .= sprintf('<li> %s </li>', $recipient); } $message .= '</ul>'; } } $this->render('send_digest', array('message' => $message)); }
/** * Activation of an user account. * If everything is set properly, and the emails exists in the database, * and is associated with a correct user, and this user has the status * NOTACTIVE and the given activationKey is identical to the one in the * database then generate a new Activation key to avoid double activation, * set the status to ACTIVATED and save the data * Error Codes: * -1 : User is not inactive, it can not be activated * -2 : Wrong activation key * -3 : Profile found, but no user - database inconsistency? */ public static function activate($email, $key) { Yii::import('application.modules.profile.models.*'); if ($profile = YumProfile::model()->find("email = :email", array(':email' => $email))) { if ($user = $profile->user) { if ($user->status != self::STATUS_INACTIVE) { return -1; } if ($user->activationKey == $key) { $user->activationKey = $user->generateActivationKey(true); $user->status = self::STATUS_ACTIVE; if ($user->save(false, array('activationKey', 'status'))) { Yum::log(Yum::t('User {username} has been activated', array('{username}' => $user->username))); if (Yum::hasModule('messages') && Yum::module('registration')->enableActivationConfirmation) { Yii::import('application.modules.messages.models.YumMessage'); YumMessage::write($user, 1, Yum::t('Your activation succeeded'), strtr('The activation of the account {username} succeeded. Please use <a href="{link_login}">this link</a> to go to the login page', array('{username}' => $user->username, '{link_login}' => Yii::app()->controller->createUrl('//user/user/login')))); } return $user; } } else { return -2; } } else { return -3; } } return false; }
public function beforeSave() { $this->updatetime = time(); // If the user has activated email receiving, send a email if ($this->isNewRecord) { if ($user = YumUser::model()->findByPk($this->friend_id)) { if (Yum::hasModule('messages') && $user->privacy && $user->privacy->message_new_friendship) { Yii::import('application.modules.messages.models.YumMessage'); YumMessage::write($user, $this->inviter, Yum::t('New friendship request from {username}', array('{username}' => $this->inviter->username)), YumTextSettings::getText('text_friendship_new', array('{username}' => $this->inviter->username, '{link_friends}' => Yii::app()->controller->createUrl('//friendship/friendship/index'), '{link_profile}' => Yii::app()->controller->createUrl('//profile/profile/view'), '{message}' => $this->message))); } } } return parent::beforeSave(); }
/** * Activation of an user account. * If everything is set properly, and the emails exists in the database, * and is associated with a correct user, and this user has the status * NOTACTIVE and the given activationKey is identical to the one in the * database then generate a new Activation key to avoid double activation, * set the status to ACTIVATED and save the data * Error Codes: * -1 : User is not inactive, it can not be activated * -2 : Wrong activation key * -3 : Profile found, but no user - database inconsistency? */ public static function activate($email, $key) { Yii::import('application.modules.profile.models.*'); if ($profile = YumProfile::model()->find("email = :email", array( ':email' => $email)) ) { if ($user = $profile->user) { if ($user->status != self::STATUS_INACTIVE) return -1; if ($user->activationKey == $key) { $user->activationKey = $user->generateActivationKey(true); $user->status = self::STATUS_ACTIVE; if ($user->save(false, array('activationKey', 'status'))) { Yum::log(Yum::t('User {username} has been activated', array( '{username}' => $user->username))); if (Yum::hasModule('messages') && Yum::module('registration')->enableActivationConfirmation ) { Yii::import('application.modules.messages.models.YumMessage'); YumMessage::write($user, 1, Yum::t('Your activation succeeded'), YumTextSettings::getText('text_email_activation', array( '{username}' => $user->username, '{link_login}' => Yii::app()->controller->createUrl('//user/user/login')))); } return $user; } } else return -2; } else return -3; } return false; }
public function sendPaymentConfirmation() { Yii::import('application.modules.message.models.*'); return YumMessage::write($this->user, 1, Yum::t('Payment arrived'), YumTextSettings::getText('text_payment_arrived', array('{payment_date}' => date(Yum::module()->dateTimeFormat, $this->payment_date), '{id}' => $this->id))); }
public function beforeSave() { $this->updatetime = time(); // If the user has activated email receiving, send a email if ($this->isNewRecord) { if ($user = YumUser::model()->findByPk($this->friend_id)) { if (Yum::hasModule('message') && $user->privacy && $user->privacy->message_new_friendship) { Yii::import('user.message.models.YumMessage'); YumMessage::write($user, $this->inviter, Yum::t('New friendship request from {username}', array('{username}' => $this->inviter->username)), strtr('A new friendship request from {username} has been made: {message} <a href="{link_friends}">Manage my friends</a><br /><a href="{link_profile}">To the profile</a>', array('{username}' => $this->inviter->username, '{link_friends}' => Yii::app()->controller->createUrl('//friendship/friendship/index'), '{link_profile}' => Yii::app()->controller->createUrl('//profile/profile/view'), '{message}' => $this->message))); } } } return parent::beforeSave(); }
public function sendPaymentConfirmation () { if(Yum::hasModule('message')) { Yii::import('application.modules.message.models.*'); return YumMessage::write($this->user, 1, Yum::t('Payment arrived'), strtr( 'The payment of order {id} has been arrived at {payment_date}', array( '{payment_date}' => date(Yum::module()->dateTimeFormat, $this->payment_date), '{id}' => $this->id, ))); } }