예제 #1
0
 public function save()
 {
     $hasSpecifiedAvailability = false;
     if ($this->availability != null) {
         foreach ($this->availability as $day => $timeOfDay) {
             if ($timeOfDay == 0) {
                 continue;
             }
             $hasSpecifiedAvailability = true;
             $existing = RequestToUser::model()->find('User_ID=:User_ID AND Request_ID=:Request_ID AND Day=:Day', array(':User_ID' => $this->user_ID, ':Request_ID' => $this->request_ID, ':Day' => $day));
             if ($existing == null) {
                 $requestToUser = new RequestToUser();
                 $requestToUser->User_ID = $this->user_ID;
                 $requestToUser->Request_ID = $this->request_ID;
                 $requestToUser->Day = $day;
                 $requestToUser->Time_of_day = $timeOfDay;
                 $requestToUser->save();
             }
         }
     }
     if (!$hasSpecifiedAvailability) {
         $requestToUser = new RequestToUser();
         $requestToUser->User_ID = $this->user_ID;
         $requestToUser->Request_ID = $this->request_ID;
         $requestToUser->save();
     }
     $request = Request::model()->findByPk($this->request_ID);
     $user = User::model()->findByPk($this->user_ID);
     $userName = CHtml::link($user->fullName, array('user/view', 'id' => $user->User_ID));
     $requestName = CHtml::link($request->Name, array('request/view', 'id' => $request->Request_ID));
     Message::SendNotification($request->Create_User_ID, "{$userName} has joined your request \"{$requestName}\".");
 }
예제 #2
0
 public function actionLeave($id)
 {
     $model = $this->loadModel($id);
     $user_ID = Yii::app()->user->id;
     $existing = RequestToUser::model()->find('User_ID=:User_ID AND Request_ID=:Request_ID', array(':User_ID' => $user_ID, ':Request_ID' => $model->Request_ID));
     if ($existing != null) {
         RequestToUser::model()->deleteAll('User_ID=:User_ID AND Request_ID=:Request_ID', array(':User_ID' => $user_ID, ':Request_ID' => $model->Request_ID));
     }
     $leftOver = RequestToUser::model()->find('Request_ID=:Request_ID', array(':Request_ID' => $model->Request_ID));
     if ($leftOver == null) {
         // TODO: de-activate request
     }
     $this->redirect(array('view', 'id' => $id));
 }