Пример #1
0
 public function send($event)
 {
     if (Yii::$app->user->isGuest) {
         $profile = Yii::$app->request->post('Profile');
         $partnerRequest = Yii::$app->request->post('PartnerRequest');
         $partnerEmail = Yii::$app->request->post('register-form')['email'];
     } else {
         $profile = Profile::find()->where(['user_id' => Yii::$app->user->id])->one();
         $partnerRequest = PartnerRequest::find()->where(['sender_id' => $profile->user_id])->one();
         $partnerEmail = $profile->user->email;
     }
     try {
         Yii::$app->partnerMailer->compose('partner-request-manager', ['partnerRequest' => $partnerRequest, 'profile' => $profile])->setFrom($event->sender->module->senderEmail)->setTo($event->sender->module->partnerManagerEmail)->setSubject(Yii::t('shop', 'New partner request'))->send();
     } catch (Exception $ex) {
         throw new Exception($ex);
     }
     try {
         Yii::$app->partnerMailer->compose('partner-request-partner', ['partnerRequest' => $partnerRequest, 'profile' => $profile])->setFrom($event->sender->module->senderEmail)->setTo($partnerEmail)->setSubject(Yii::t('shop', 'Partner request'))->send();
     } catch (Exception $ex) {
         throw new Exception($ex);
     }
 }
 public function actionSend()
 {
     $partner = new PartnerRequest();
     if (Yii::$app->user->isGuest) {
         $user = \Yii::createObject(RegistrationForm::className());
         $profile = \Yii::createObject(Profile::className());
     } else {
         $user = User::findOne(Yii::$app->user->id);
         $profile = Profile::findOne($user->id);
     }
     if (Yii::$app->request->isPost) {
         if (Yii::$app->user->isGuest) {
             if ($user->load(\Yii::$app->request->post())) {
                 $profile->user_id = $user->register();
                 if ($profile->load(Yii::$app->request->post())) {
                     if ($profile->validate()) {
                         $profile->save();
                     }
                 }
             } else {
                 throw new Exception('Registration is failed.');
             }
         }
         $partner->load(Yii::$app->request->post());
         if ($partner->validate()) {
             $partner->sender_id = $profile->user_id;
             $partner->moderation_status = PartnerRequest::STATUS_ON_MODERATION;
             $partner->save();
             $this->trigger(self::EVENT_SEND, new PartnersEvents());
             Yii::$app->getSession()->setFlash('success', \Yii::t('shop', 'Your partner request was successfully sent.'));
             return $this->redirect(Yii::$app->request->referrer);
         }
     }
     $this->registerStaticSeoData();
     return $this->render('send', ['partner' => $partner, 'user' => $user, 'profile' => $profile]);
 }
Пример #3
0
 public function getOwnerProfile()
 {
     return $this->hasOne(Profile::className(), ['user_id' => 'owner']);
 }