Ejemplo n.º 1
0
 public function actionLeave($id)
 {
     $model = $this->loadModel($id);
     $user_ID = Yii::app()->user->id;
     UserToExperience::model()->deleteAll('User_ID=:User_ID AND Experience_ID=:Experience_ID', array(':User_ID' => $user_ID, ':Experience_ID' => $model->Experience_ID));
     $this->redirect(array('view', 'id' => $model->Experience_ID));
 }
Ejemplo n.º 2
0
 public function SignUp($session = null, $quantity = 1, $creditCard = null)
 {
     $transaction = $this->dbConnection->beginTransaction();
     try {
         $user = User::model()->findByPk(Yii::app()->user->id);
         if ($this->Create_User_ID == $user->User_ID) {
             throw new Exception("Can't sign up for own experience.");
         }
         $userToExperience = new UserToExperience();
         $userToExperience->User_ID = $user->User_ID;
         $userToExperience->Experience_ID = $this->Experience_ID;
         if ($session == null) {
             $existing = UserToExperience::model()->find('User_ID=:User_ID AND Experience_ID=:Experience_ID', array(':User_ID' => $user->User_ID, ':Experience_ID' => $this->Experience_ID));
         } else {
             $existing = UserToExperience::model()->find('User_ID=:User_ID AND Session_ID=:Session_ID AND Experience_ID=:Experience_ID', array(':User_ID' => $user->User_ID, ':Session_ID' => $session, ':Experience_ID' => $this->Experience_ID));
             $userToExperience->Session_ID = $session;
         }
         if ($this->MaxPerPerson != null) {
             if ($quantity > $this->MaxPerPerson) {
                 throw new Exception("Quantity exceeds limit.");
             }
         }
         $userToExperience->Quantity = $quantity;
         if ($existing != null && !$this->MultipleAllowed) {
             throw new Exception("Can't sign up multiple times.");
         }
         $confirmationCode = $this->code;
         if (isset($this->Price) && $this->Price != null && $this->Price > 0) {
             $amount = $quantity * $this->Price;
             $scheduledFor = strtotime('+' . Yii::app()->params["PaymentDelay"] . ' days');
             if ($session != null) {
                 $sessionModel = Session::model()->findByPk($session);
                 $start = strtotime($sessionModel->Start);
                 if ($start < time()) {
                     throw new Exception("Session starts in the past.");
                 }
                 if ($start < $scheduledFor) {
                     $scheduledFor = $start;
                 }
             }
             $payment = new Payment();
             $payment->Experience_ID = $this->Experience_ID;
             $payment->CreditCard_ID = $creditCard;
             $payment->BankAccount_ID = $this->createUser->bankAccount->BankAccount_ID;
             $payment->Amount = $amount;
             $payment->Batch_ID = uniqid();
             $payment->ScheduledFor = date('Y-m-d H:i:s', $scheduledFor);
             $payment->Status = PaymentStatus::Scheduled;
             $payment->save();
             $confirmationCode = $payment->code;
         }
         $userToExperience->save();
         $userName = CHtml::link($user->fullName, array('user/view', 'id' => $user->User_ID));
         $experienceName = CHtml::link($this->Name, array('experience/view', 'id' => $this->Experience_ID));
         Message::SendNotification($this->Create_User_ID, "{$userName} has joined your experience \"{$experienceName}\".");
         // Notify the enrollees
         foreach ($this->enrolled as $enrollee) {
             if ($enrollee->User_ID != $user->User_ID) {
                 $userName = CHtml::link($user->fullName, array('user/view', 'id' => $user->User_ID));
                 $experienceName = CHtml::link($this->Name, array('experience/view', 'id' => $this->Experience_ID));
                 Message::SendNotification($enrollee->User_ID, "{$userName} has also joined the experience \"{$experienceName}\".");
             }
         }
         if (!is_numeric($quantity)) {
             $quantity = 1;
         }
         $models = array('model' => $this, 'confirmationCode' => $confirmationCode, 'quantity' => $quantity);
         Mail::Instance()->SendTemplate($user->Email, 'Signup Confirmation', '/experience/_emailConfirmation', $models);
         $transaction->commit();
     } catch (Exception $e) {
         $transaction->rollback();
         return false;
     }
     return true;
 }