Пример #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = RoomType::find()->notDeleted();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by, 'deleted' => $this->deleted]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Пример #2
0
<?php

use yii\helpers\Html;
use common\components\GridView;
use common\models\Hotel;
use common\models\RoomType;
use common\models\Registration;
/* @var $this yii\web\View */
/* @var $searchModel backend\models\RoomSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('app', 'Rooms');
?>
<div class="room-index">
    <?php 
$gridColumns = [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'hotel_id', 'value' => function ($data) {
    return $data->hotel->name;
}, 'filter' => Hotel::getMap()], ['attribute' => 'room_type_id', 'value' => function ($data) {
    return $data->roomType->name;
}, 'filter' => RoomType::getMap()], ['attribute' => 'date', 'format' => ['date', 'php:d-m-Y'], 'filterType' => GridView::FILTER_DATE, 'filterWidgetOptions' => ['pluginOptions' => ['autoclose' => true, 'format' => 'dd-mm-yyyy']], 'width' => '180px'], 'allotment', ['attribute' => 'booked', 'value' => function ($data) {
    $data->booked = $data->getBooked();
    return $data->booked;
}], ['attribute' => 'free', 'value' => function ($data) {
    return $data->allotment - $data->booked;
}], ['attribute' => 'price', 'value' => function ($data) {
    return Registration::generateRoomRate($data->price);
}, 'format' => 'raw']];
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => $gridColumns, 'responsive' => true, 'hover' => true, 'pjax' => true, 'resizableColumns' => false, 'toolbar' => [Html::a('<i class="glyphicon glyphicon-repeat"></i>', ['index'], ['data-pjax' => 0, 'class' => 'btn btn-default', 'title' => Yii::t('kvgrid', 'Reset Grid')]), '{export}', '{toggleData}'], 'toggleDataOptions' => ['default' => 'all'], 'panelBeforeTemplate' => '<div class="pull-right"><div class="btn-toolbar kv-grid-toolbar" role="toolbar"><span class="pager-mini">{pager}</span>{toolbar}</div></div>{before}<div class="clearfix"></div>', 'panelAfterTemplate' => '{after}<span class="pager-mini clearfix">{pager}</span>', 'panel' => ['type' => GridView::TYPE_PRIMARY, 'heading' => '<h3 class="panel-title"><i class="glyphicon glyphicon-user"></i>' . Html::encode($this->title) . '</h3>', 'footer' => false], 'exportConfig' => [GridView::EXCEL => [], GridView::CSV => ['config' => ['colDelimiter' => ';', 'rowDelimiter' => "\r\n"]], GridView::PDF => []]]);
?>

</div>
Пример #3
0
<?php

use yii\helpers\Html;
use common\components\GridView;
use common\models\Registration;
use common\models\Hotel;
/* @var $this yii\web\View */
/* @var $searchModel backend\models\RegistrationSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('app', 'Registrations');
?>
<div class="registration-index">
    <?php 
$gridColumns = [['attribute' => 'status', 'value' => function ($data) {
    return isset($data->status) && array_key_exists($data->status, Registration::$reverseStatus) ? Registration::$reverseStatus[$data->status] : null;
}, 'filterType' => GridView::FILTER_SELECT2, 'filterWidgetOptions' => ['data' => Registration::$statusNames + ['' => 'All']], 'headerOptions' => ['style' => 'min-width:115px;']], 'first_name', 'last_name', 'company', 'department', ['attribute' => 'hotel_id', 'value' => function ($data) {
    return isset($data->hotel) && $data->hotel ? $data->hotel->name : null;
}, 'filterType' => GridView::FILTER_SELECT2, 'filterWidgetOptions' => ['data' => Hotel::getMap(), 'options' => ['prompt' => Yii::t('general', 'All')]], 'headerOptions' => ['style' => 'min-width:155px;']], ['attribute' => 'check_in', 'format' => ['date', 'php:d/m/Y'], 'filterType' => GridView::FILTER_SELECT2, 'filterWidgetOptions' => ['data' => Registration::getCheckIn(), 'options' => ['prompt' => Yii::t('general', 'All')]], 'headerOptions' => ['style' => 'min-width:115px;']], ['attribute' => 'check_out', 'format' => ['date', 'php:d/m/Y'], 'filterType' => GridView::FILTER_SELECT2, 'filterWidgetOptions' => ['data' => Registration::getCheckOut(), 'options' => ['prompt' => Yii::t('general', 'All')]], 'headerOptions' => ['style' => 'min-width:115px;']], ['attribute' => 'room_type_id', 'value' => function ($data) {
    return isset($data->roomType) && $data->roomType ? $data->roomType->name : null;
}, 'filterType' => GridView::FILTER_SELECT2, 'filterWidgetOptions' => ['data' => \common\models\RoomType::getMap(), 'options' => ['prompt' => Yii::t('general', 'All')]]], ['attribute' => 'room_rate', 'value' => function ($data) {
    return isset($data->room_rate) ? Registration::generateRoomRate($data->room_rate) : null;
}, 'format' => 'raw'], ['attribute' => 'updated_at', 'format' => ['date', 'php:h:i:s A d-m-Y']], 'd12', 'd13', 'd14', 'd15', 'd16'];
// Generate a bootstrap responsive striped table with row highlighted on hover
echo GridView::widget(['dataProvider' => $dataProvider, 'responsive' => true, 'hover' => true, 'columns' => $gridColumns, 'pjax' => true, 'resizableColumns' => false, 'toolbar' => [Html::a('<i class="glyphicon glyphicon-repeat"></i>', ['index'], ['data-pjax' => 0, 'class' => 'btn btn-default', 'title' => Yii::t('kvgrid', 'Reset Grid')]), '{export}', '{toggleData}'], 'toggleDataOptions' => ['default' => 'all'], 'panelBeforeTemplate' => '<div class="pull-right"><div class="btn-toolbar kv-grid-toolbar" role="toolbar"><span class="pager-mini">{pager}</span>{toolbar}</div></div>{before}<div class="clearfix"></div>', 'panelAfterTemplate' => '{after}<span class="pager-mini clearfix">{pager}</span>', 'panel' => ['type' => GridView::TYPE_PRIMARY, 'heading' => '<h3 class="panel-title"><i class="glyphicon glyphicon-list-alt"></i> Hotel Rooming List</h3>', 'footer' => false], 'exportConfig' => [GridView::EXCEL => [], GridView::CSV => ['config' => ['colDelimiter' => ';', 'rowDelimiter' => "\r\n"]], GridView::PDF => []]]);
?>

</div>
Пример #4
0
 /**
  * Updates an existing Hotel model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     //$this->allowAccess(Hotel::checkAccess($id));
     $model = $this->findModel($id);
     $languages = Lang::getAll();
     $roomTypes = RoomType::getRoomTypes();
     $department = Department::getAll();
     $modelHotelDepartmentMapping = new HotelDepartmentMapping();
     $modelHotelData = HotelData::getByHotelId($id);
     if (!$modelHotelData) {
         $modelHotelData = new HotelData();
     }
     $availableRooms = HotelRoomTypeMapping::getRoomTypesIdByHotelId($id);
     $hotelDepartments = HotelDepartmentMapping::getByHotelId($id);
     $modelHotelRoomTypeMapping = new HotelRoomTypeMapping();
     $countries = Country::getAllCountries();
     $savePath = Yii::getAlias($model::FILE_PATH);
     $imageDataProvider = new ArrayDataProvider(['models' => Image::getImagesByHotelId($id)]);
     if ($model->load(Yii::$app->request->post())) {
         //            $modelCity = City::getOrCreateByNameAndCountryId($_POST['Hotel']['cityName'], $model->country_id);
         //            $model->city_id = $modelCity->id;
         if ($model->save()) {
             foreach ($_POST['HotelRoomTypeMapping']['room_type_id'] as $roomTypeId) {
                 $hotelRoomTypeMappings = HotelRoomTypeMapping::getRoomTypeByHotelIdAndRoomTypeId($id, $roomTypeId);
                 if (!$hotelRoomTypeMappings) {
                     $modelHotelRoomTypeMapping = new HotelRoomTypeMapping();
                     $modelHotelRoomTypeMapping->setAttribute('hotel_id', $model->getAttribute('id'));
                     $modelHotelRoomTypeMapping->setAttribute('room_type_id', $roomTypeId);
                     $modelHotelRoomTypeMapping->save();
                 } elseif ($hotelRoomTypeMappings->getAttribute('deleted') === ActiveRecord::STATUS_DELETED) {
                     $hotelRoomTypeMappings->setAttribute('deleted', ActiveRecord::STATUS_NOT_DELETED);
                     $hotelRoomTypeMappings->save();
                 }
             }
             foreach ($languages as $key => $language) {
                 $modelHotelData = HotelData::getByLanguageIdAndHotelId($language->local, $id);
                 if ($modelHotelData) {
                     $modelHotelData->setAttribute('lang_id', Yii::$app->request->post('HotelData')['lang_id'][$key]);
                     $modelHotelData->setAttribute('description', Yii::$app->request->post('HotelData')['description'][$key]);
                     $modelHotelData->setAttribute('location', Yii::$app->request->post('HotelData')['location'][$key]);
                     $modelHotelData->setAttribute('price_information', Yii::$app->request->post('HotelData')['price_information'][$key]);
                     $modelHotelData->setAttribute('other', Yii::$app->request->post('HotelData')['other'][$key]);
                     $modelHotelData->save();
                 } else {
                     $modelHotelData = new HotelData();
                     $modelHotelData->setAttribute('hotel_id', $id);
                     $modelHotelData->setAttribute('lang_id', Yii::$app->request->post('HotelData')['lang_id'][$key]);
                     $modelHotelData->setAttribute('description', Yii::$app->request->post('HotelData')['description'][$key]);
                     $modelHotelData->setAttribute('location', Yii::$app->request->post('HotelData')['location'][$key]);
                     $modelHotelData->setAttribute('price_information', Yii::$app->request->post('HotelData')['price_information'][$key]);
                     $modelHotelData->setAttribute('other', Yii::$app->request->post('HotelData')['other'][$key]);
                     $modelHotelData->save();
                 }
             }
             foreach ($availableRooms as $room) {
                 if (!in_array($room, $_POST['HotelRoomTypeMapping']['room_type_id'])) {
                     $hotelRoomTypeMapping = HotelRoomTypeMapping::getRoomTypeByHotelIdAndRoomTypeId($id, $room);
                     $hotelRoomTypeMapping->setAttribute('deleted', ActiveRecord::STATUS_DELETED);
                     $hotelRoomTypeMapping->save();
                 }
             }
             foreach ($_POST['HotelDepartmentMapping']['department_id'] as $departmentId) {
                 $hotelDepartmentMapping = HotelDepartmentMapping::getByHotelIdAndDepartmentId($id, $departmentId);
                 if (!$hotelDepartmentMapping) {
                     $modelHotelDepartmentMapping = new HotelDepartmentMapping();
                     $modelHotelDepartmentMapping->setAttribute('hotel_id', $model->getAttribute('id'));
                     $modelHotelDepartmentMapping->setAttribute('department_id', $departmentId);
                     $modelHotelDepartmentMapping->save();
                 } elseif ($hotelDepartmentMapping->getAttribute('deleted') === ActiveRecord::STATUS_DELETED) {
                     $hotelDepartmentMapping->setAttribute('deleted', ActiveRecord::STATUS_NOT_DELETED);
                     $hotelDepartmentMapping->save();
                 }
             }
             foreach ($hotelDepartments as $department) {
                 if (!in_array($department, $_POST['HotelDepartmentMapping']['department_id'])) {
                     $modelHotelDepartmentMapping = HotelDepartmentMapping::getByHotelIdAndDepartmentId($id, $department);
                     $modelHotelDepartmentMapping->setAttribute('deleted', ActiveRecord::STATUS_DELETED);
                     $modelHotelDepartmentMapping->save();
                 }
             }
             $files = $model->loadFiles($model->fileAttribute);
             if ($files !== false) {
                 foreach ($files as $file) {
                     if ($file->saveAs($savePath . $file->name)) {
                         $image = new Image();
                         $image->setAttribute('name', $file->name);
                         $image->setAttribute('hotel_id', $id);
                         $image->setAttribute('path', $model::FILE_PATH . $file->name);
                         $image->save();
                     }
                 }
             }
             if ($model->preview_image_id === 0 || $model->preview_image_id === null) {
                 $model->setAttribute('preview_image_id', !empty($image) ? $image->id : $model::IMAGE_NOT_SET);
                 $model->save();
             }
             return $this->redirect(['view', 'id' => $model->id]);
         }
     }
     return $this->render('update', ['model' => $model, 'modelHotelData' => $modelHotelData, 'modelHotelRoomTypeMapping' => $modelHotelRoomTypeMapping, 'roomTypes' => $roomTypes, 'countries' => $countries, 'availableRooms' => $availableRooms, 'hotelDepartments' => $hotelDepartments, 'imageDataProvider' => $imageDataProvider, 'department' => $department, 'modelHotelDepartmentMapping' => $modelHotelDepartmentMapping, 'languages' => $languages]);
 }
Пример #5
0
 /**
  * Finds the RoomType model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return RoomType the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = RoomType::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }