コード例 #1
0
ファイル: grid.php プロジェクト: QiLiuXianSheng/yii2
<?php

use yii\grid\GridView;
use yii\helpers\Html;
use app\components\GridViewReservation;
$roomsFilterData = yii\helpers\ArrayHelper::map(app\models\Room::find()->all(), 'id', function ($model, $defaultValue) {
    return sprintf('Floor: %d - Number: %d', $model->floor, $model->room_number);
});
$sumPc = 0;
$avgPc = 0;
if (sizeof($dataProvider->getModels()) > 0) {
    foreach ($dataProvider->getModels() as $m) {
        $sumPc += $m->price_per_day;
    }
    $avgPc = $sumPc / sizeof($dataProvider->getModels());
}
?>
<h2>Reservations</h2>
<?php 
echo GridViewReservation::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'showFooter' => true, 'columns' => ['id', ['header' => 'Room', 'filter' => Html::activeDropDownList($searchModel, 'room_id', $roomsFilterData, ['prompt' => '--- all']), 'content' => function ($model) {
    return $model->room->floor;
}], ['header' => 'Customer', 'attribute' => 'customer.surname'], ['attribute' => 'price_per_day', 'footer' => Yii::$app->formatter->asCurrency($allAvgPc, 'CNY')], 'date_from', 'date_to']]);
コード例 #2
0
ファイル: grid.php プロジェクト: soanni/yii2news
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
use yii\helpers\Url;
use app\models\Room;
use app\models\Customer;
use app\components\GridViewReservation;
$filterRoom = ArrayHelper::map(Room::find()->all(), 'id', function ($model) {
    return sprintf('Floor: %d - Number: %d', $model->floor, $model->room_number);
});
//    $sum = 0;
//    $avg = 0;
//    if(count($data->getModels()) > 0){
//        foreach($data->getModels() as $m){
//            $sum += $m->price_per_day;
//        }
//        $avg = $sum/sizeof($data->getModels());
//    }
//    $filterCustomer = ArrayHelper::map(Customer::find()->all(),'id',function($model){
//        $name = $model->name;
//        $surname = $model->surname;
//        return "$name $surname";
//    });
echo Html::a('Detail dependent dropdown(AJAX)', Url::to(['reservations/detail-dependent-dropdown']), ['class' => 'btn btn-primary']);
?>
<h2>Reservations</h2>
<?php 
echo GridViewReservation::widget(['dataProvider' => $dataReservation, 'filterModel' => $searchReservation, 'showFooter' => true, 'columns' => [['header' => 'Room', 'filter' => Html::activeDropDownList($searchReservation, 'room_id', $filterRoom, ['prompt' => '--All--']), 'attribute' => 'room.room_number'], ['header' => 'Customer', 'attribute' => 'customer.surname'], 'price_per_day' => ['attribute' => 'price_per_day', 'header' => 'Daily price', 'footer' => sprintf('Average: %0.1f', $averagePrice)], 'date_from', 'date_to', 'reservation_date']]);
?>
<h2>Rooms</h2>
<?php 
echo GridView::widget(['dataProvider' => $dataRoom, 'filterModel' => $searchRoom, 'columns' => ['id', 'floor', 'room_number', 'has_conditioner:boolean', 'has_tv:boolean', 'has_phone:boolean', 'available_from', 'price_per_day', 'description']]);
コード例 #3
0
<?php

use app\models\Room;
use yii\grid\GridView;
use app\components\GridViewReservation;
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
$roomsFilterData = ArrayHelper::map(Room::find()->all(), 'id', function ($model, $defaultValue) {
    return sprintf('Floor: %d - Number: %d', $model->floor, $model->room_number);
});
$sumOfPricesPerDay = 0;
$averagePricePerDay = 0;
$numberOfRows = count($reservationsDataProvider->getModels());
if ($numberOfRows > 0) {
    foreach ($reservationsDataProvider->getModels() as $m) {
        $sumOfPricesPerDay += $m->price_per_day;
    }
    $averagePricePerDay = $sumOfPricesPerDay / $numberOfRows;
}
echo "<h2>Reservations</h2>" . GridViewReservation::widget(['showFooter' => true, 'dataProvider' => $reservationsDataProvider, 'filterModel' => $reservationsSearchModel, 'columns' => ['id', ['header' => 'Room', 'filter' => Html::activeDropDownList($reservationsSearchModel, 'room_id', $roomsFilterData, ['prompt' => '--- all']), 'content' => function ($model) {
    return $model->room->floor;
}], ['header' => 'Customer', 'attribute' => 'customer.nameAndSurname'], ['header' => 'Customer (name)', 'attribute' => 'customer.name'], ['header' => 'Customer (surname)', 'attribute' => 'customer.surname'], 'room_id', ['attribute' => 'price_per_day', 'footer' => sprintf('Average: %0.2f', $resultQueryAveragePricePerDay)], 'date_from', 'date_to', 'reservation_date', ['class' => 'yii\\grid\\ActionColumn', 'template' => '{delete}', 'header' => 'Actions']]]);
echo "<h2>Rooms</h2>" . GridViewReservation::widget(['dataProvider' => $roomsDataProvider, 'filterModel' => $roomsSearchModel, 'columns' => ['id', 'floor', 'room_number', 'has_conditioner:boolean', 'has_phone:boolean', 'has_tv:boolean', 'available_from']]);
コード例 #4
0
ファイル: grid.php プロジェクト: AntoninSlejska/yii-test
<?php

use app\models\Room;
use yii\grid\GridView;
use app\components\GridViewReservation;
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
$roomsFilterData = ArrayHelper::map(Room::find()->all(), 'id', function ($model, $defaultValue) {
    return sprintf('Floor: %d - Number: %d', $model->floor, $model->room_number);
});
$sumOfPricesPerDay = 0;
$averagePricePerDay = 0;
$numberOfRows = count($dataProvider->getModels());
if ($numberOfRows > 0) {
    foreach ($dataProvider->getModels() as $m) {
        $sumOfPricesPerDay += $m->price_per_day;
    }
    $averagePricePerDay = $sumOfPricesPerDay / $numberOfRows;
}
echo "<h2>Reservations</h2>" . GridViewReservation::widget(['showFooter' => true, 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => ['id', ['header' => 'Room', 'filter' => Html::activeDropDownList($searchModel, 'room_id', $roomsFilterData, ['prompt' => '--- all']), 'content' => function ($model) {
    return $model->room->floor;
}], ['header' => 'Customer', 'attribute' => 'customer.nameAndSurname'], ['header' => 'Customer (name)', 'attribute' => 'customer.name'], ['header' => 'Customer (surname)', 'attribute' => 'customer.surname'], 'room_id', ['attribute' => 'price_per_day', 'footer' => sprintf('Average: %0.2f', $resultQueryAveragePricePerDay)], 'date_from', 'date_to', 'reservation_date', ['class' => 'yii\\grid\\ActionColumn', 'template' => '{delete}', 'header' => 'Actions']]]);