コード例 #1
0
 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]);
 }
コード例 #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = PartnerRequest::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'sender_id' => $this->sender_id, 'created_at' => $this->created_at, 'moderation_status' => $this->moderation_status, 'moderated_by' => $this->moderated_by, 'moderated_at' => $this->moderated_at]);
     $query->andFilterWhere(['like', 'company_name', $this->company_name])->andFilterWhere(['like', 'website', $this->website])->andFilterWhere(['like', 'message', $this->message]);
     return $dataProvider;
 }
コード例 #3
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);
     }
 }
コード例 #4
0
 /**
  * Finds the PartnerRequest model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return PartnerRequest the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = PartnerRequest::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }