Ejemplo n.º 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();
     }
 }
Ejemplo n.º 3
0
 /**
  * Создает новую модель уведомления.
  * Если создание прошло успешно - перенаправляет на просмотр.
  *
  * @return void
  */
 public function actionCreate()
 {
     $model = new NotifySettings();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['NotifySettings'])) {
         $model->attributes = $_POST['NotifySettings'];
         if ($model->save()) {
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('NotifyModule.notify', 'Record created!'));
             if (!isset($_POST['submit-type'])) {
                 $this->redirect(['update', 'id' => $model->id]);
             } else {
                 $this->redirect([$_POST['submit-type']]);
             }
         }
     }
     $this->render('create', ['model' => $model]);
 }
Ejemplo n.º 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]);
 }