예제 #1
0
 /**
  * @param UserActivateEvent $event
  */
 public static function onUserActivate(UserActivateEvent $event)
 {
     $user = $event->getUser();
     if (null !== $user) {
         $notify = new NotifySettings();
         $notify->user_id = $user->id;
         $notify->save();
     }
 }
 public function safeUp()
 {
     $this->createTable('{{notify_settings}}', ['id' => 'pk', 'user_id' => 'integer NOT NULL', 'my_post' => 'BOOLEAN NOT NULL DEFAULT 1', 'my_comment' => 'BOOLEAN NOT NULL DEFAULT 1']);
     //ix
     $this->createIndex("ix_{{notify_settings}}_user_id", '{{notify_settings}}', "user_id", false);
     //fk
     $this->addForeignKey("fk_{{notify_settings}}_user_id", '{{notify_settings}}', 'user_id', '{{user_user}}', 'id', 'CASCADE', 'NO ACTION');
     $users = User::model()->findAll();
     foreach ($users as $user) {
         $model = new NotifySettings();
         $model->user_id = $user->id;
         $model->save();
     }
 }
예제 #3
0
 public static function onNewComment(CommentEvent $event)
 {
     $comment = $event->getComment();
     $module = $event->getModule();
     $parent = $comment->getParent();
     //ответ на комментарий
     if ($comment->hasParent()) {
         if (null !== $parent && $parent->user_id) {
             $notify = NotifySettings::model()->getForUser($parent->user_id);
             if (null !== $notify && $notify->isNeedSendForCommentAnswer()) {
                 Yii::app()->mail->send($module->email, $parent->email, Yii::t('NotifyModule.notify', 'Reply to your comment on the website "{app}"!', ['{app}' => CHtml::encode(Yii::app()->name)]), Yii::app()->getController()->renderPartial('comment-reply-notify-email', ['model' => $comment], true));
             }
         }
     }
     //нотификация автору поста
     if ('Post' === $comment->model) {
         $post = Post::model()->cache(Yii::app()->getModule('yupe')->coreCacheTime)->with(['createUser'])->get((int) $comment->model_id);
         if (null !== $post) {
             //пропускаем автора поста + если отвечают на комментарий автора поста - он уже получил уведомление выше
             if ($comment->user_id != $post->create_user_id) {
                 $notify = NotifySettings::model()->getForUser($post->create_user_id);
                 if (null != $notify && $notify->isNeedSendForNewPostComment()) {
                     Yii::app()->mail->send($module->email, $post->createUser->email, Yii::t('NotifyModule.notify', 'New comment to your post on website "{app}"!', ['{app}' => CHtml::encode(Yii::app()->name)]), Yii::app()->getController()->renderPartial('comment-new-notify-email', ['model' => $comment], true));
                 }
             }
         }
     }
 }
예제 #4
0
 public function actionSettings()
 {
     $profile = Yii::app()->getUser()->getProfile();
     $model = NotifySettings::model()->getForUser($profile->id);
     if (null === $model) {
         $model = new NotifySettings();
         $model->create($profile->id);
         if (null === $model) {
             throw new CHttpException(404);
         }
     }
     if (Yii::app()->getRequest()->getIsPostRequest() && !empty($_POST['NotifySettings'])) {
         $model->setAttributes(Yii::app()->getRequest()->getPost('NotifySettings'));
         if ($model->save()) {
             Yii::app()->getUser()->setFlash(\yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('NotifyModule.notify', 'Settings changed!'));
             $this->redirect(['/notify/notify/settings']);
         }
     }
     $this->render('settings', ['model' => $model]);
 }
예제 #5
0
 /**
  * Возвращает модель по указанному идентификатору
  * Если модель не будет найдена - возникнет HTTP-исключение.
  *
  * @param integer идентификатор нужной модели
  *
  * @return void
  */
 public function loadModel($id)
 {
     $model = NotifySettings::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, Yii::t('NotifyModule.notify', 'Page not found!'));
     }
     return $model;
 }