Example #1
0
 public function actionCreate()
 {
     $model = new Room();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['detail', 'id' => $model->id]);
     }
     return $this->render('detail', compact('model'));
 }
 /**
  * Creates a new Room model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Room();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new Person model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $modelPerson = new Person();
     $modelsHouse = [new House()];
     $modelsRoom = [[new Room()]];
     if ($modelPerson->load(Yii::$app->request->post())) {
         $modelsHouse = Model::createMultiple(House::classname());
         Model::loadMultiple($modelsHouse, Yii::$app->request->post());
         // validate person and houses models
         $valid = $modelPerson->validate();
         $valid = Model::validateMultiple($modelsHouse) && $valid;
         if (isset($_POST['Room'][0][0])) {
             foreach ($_POST['Room'] as $indexHouse => $rooms) {
                 foreach ($rooms as $indexRoom => $room) {
                     $data['Room'] = $room;
                     $modelRoom = new Room();
                     $modelRoom->load($data);
                     $modelsRoom[$indexHouse][$indexRoom] = $modelRoom;
                     $valid = $modelRoom->validate();
                 }
             }
         }
         if ($valid) {
             $transaction = Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $modelPerson->save(false)) {
                     foreach ($modelsHouse as $indexHouse => $modelHouse) {
                         if ($flag === false) {
                             break;
                         }
                         $modelHouse->person_id = $modelPerson->id;
                         if (!($flag = $modelHouse->save(false))) {
                             break;
                         }
                         if (isset($modelsRoom[$indexHouse]) && is_array($modelsRoom[$indexHouse])) {
                             foreach ($modelsRoom[$indexHouse] as $indexRoom => $modelRoom) {
                                 $modelRoom->house_id = $modelHouse->id;
                                 if (!($flag = $modelRoom->save(false))) {
                                     break;
                                 }
                             }
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $modelPerson->id]);
                 } else {
                     $transaction->rollBack();
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     }
     return $this->render('create', ['modelPerson' => $modelPerson, 'modelsHouse' => empty($modelsHouse) ? [new House()] : $modelsHouse, 'modelsRoom' => empty($modelsRoom) ? [[new Room()]] : $modelsRoom]);
 }
Example #4
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $room = new Room();
     $room->event_id = Event::all()->first()->id;
     $room->length = 200;
     $room->width = 400;
     //need 25 tables of 6 people
     $room->save();
 }
Example #5
0
 public function saveRoom(Request $request)
 {
     $validator = $this->room_validator($request->all());
     if ($validator->fails()) {
         $this->throwValidationException($request, $validator);
     }
     $room = new Room();
     $room->nama_ruang = $request['nama_ruang'];
     $room->lokasi = $request['lokasi'];
     $room->daya_tampung = $request['daya_tampung'];
     $room->save();
     return redirect('/viewroom');
 }
Example #6
0
 public function actionCreate()
 {
     $model = new Room();
     $modelCanSave = false;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $modelCanSave = true;
         // $model->fileImage = UploadedFile::getInstance($model,'fileImage');
         // if($model->fileImage){
         //     $model->fileImage->saveAs(Yii::getAlias('@uploadedfiledir').'/'.$model->fileImage->baseName.'.'.$model->fileImage->extension);
         // }
     }
     return $this->render('create', ['model' => $model, 'modelSaved' => $modelCanSave]);
 }
 public function actionCreate()
 {
     $model = new Room();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['detail', 'id' => $model->id]);
     }
     // if (isset($POST['Room'])) {
     //     $model->attributes = $_POST['Room'];
     //
     //     if ($model->save()) {
     //         return $this->redirect(['view', 'id' => $model->id]);
     //     }
     // }
     return $this->render('create', ['model' => $model]);
 }
Example #8
0
 /**
  * Create a Room for an Accommodation.
  *
  * @param  RoomRequest  $request
  * @param  int  $aid
  * @return Response
  */
 public function store(RoomRequest $request, $aid)
 {
     try {
         $accommodation = Accommodation::find($aid);
         if (!$accommodation) {
             return response()->error(404, 'Accommodation Not Found');
         }
         $cid = $accommodation->conference()->first()->getKey();
         $user = $this->isConferenceManager($request, $cid);
         if (!$user) {
             return response()->error(403, 'You are not a manager of this conference!');
         }
         $room = new Room($request->all());
         $room->accommodation()->associate($accommodation);
         $room->save();
         return response()->success();
     } catch (Exception $e) {
         return response()->error();
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     // ---------------------------------------------------------------------
     // CONFERENCE 2
     // ---------------------------------------------------------------------
     $conference = Conference::find(2);
     $accommodation = ['name' => 'Shangri-La Hotel Vancouver', 'address' => '1128 West Georgia Street', 'city' => 'Vancouver', 'country' => 'Canada'];
     $accommodation = new Accommodation($accommodation);
     $accommodation->conference()->associate($conference);
     $accommodation->save();
     $room = ['room_no' => '100', 'guest_count' => 0, 'capacity' => 2];
     $room = new Room($room);
     $room->accommodation()->associate($accommodation);
     $room->save();
     $room = ['room_no' => '101', 'guest_count' => 0, 'capacity' => 3];
     $room = new Room($room);
     $room->accommodation()->associate($accommodation);
     $room->save();
     $room = ['room_no' => '102', 'guest_count' => 0, 'capacity' => 4];
     $room = new Room($room);
     $room->accommodation()->associate($accommodation);
     $room->save();
     $accommodation = ['name' => 'The Fairmont Hotel Vancouver', 'address' => '900 West Georgia Street', 'city' => 'Vancouver', 'country' => 'Canada'];
     $accommodation = new Accommodation($accommodation);
     $accommodation->conference()->associate($conference);
     $accommodation->save();
     $room = ['room_no' => '200', 'guest_count' => 0, 'capacity' => 2];
     $room = new Room($room);
     $room->accommodation()->associate($accommodation);
     $room->save();
     $room = ['room_no' => '201', 'guest_count' => 0, 'capacity' => 3];
     $room = new Room($room);
     $room->accommodation()->associate($accommodation);
     $room->save();
     $room = ['room_no' => '202', 'guest_count' => 0, 'capacity' => 4];
     $room = new Room($room);
     $room->accommodation()->associate($accommodation);
     $room->save();
 }