Exemple #1
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->plan_id) {
         $query = Day::find()->where(['plan_id' => $this->plan_id])->orderBy(['day_nr' => SORT_ASC]);
         $this->_dataProvider = new ActiveDataProvider(['query' => $query]);
     } else {
         throw new InvalidParamException(Module::t('res', 'No plan ID given!'));
     }
 }
Exemple #2
0
/* @var $periodModel \backend\modules\reservation\models\PeriodForm */
/* @var $device \backend\modules\reservation\models\Device */
use backend\modules\reservation\Module;
use backend\modules\reservation\models\Day;
use backend\modules\reservation\models\Plan;
use backend\modules\reservation\models\Usage;
use yii\helpers\Html;
use yii\helpers\StringHelper;
?>

<div class="row">
	<?php 
$device = $periodModel->device;
for ($i = Yii::$app->formatter->asTimestamp($periodModel->firstDate); $i <= Yii::$app->formatter->asTimestamp($periodModel->lastDate); $i += 86400) {
    if ($plan = Plan::find()->where(['device_id' => $device->id])->andWhere(['<=', 'date_from', date('Y-m-d', $i)])->andWhere(['>=', 'date_to', date('Y-m-d', $i)])->one()) {
        if ($day = Day::find()->where(['plan_id' => $plan->id])->andWhere(['day_nr' => date('N', $i)])->one()) {
            if ($day->is_open == 1) {
                echo '<div class="col-xs-6 col-md-4 col-lg-3"><table class="table table-bordered table-striped table-condensed">';
                echo '<tr><th colspan="3">' . $day->getDayName() . ' ' . date('d.m.Y', $i) . '</th></tr>';
                for ($j = strtotime(date('Y-m-d', $i) . ' ' . $plan->time_from), $k = 1; $j < strtotime(date('Y-m-d', $i) . ' ' . $plan->time_to); $j += $plan->hour_length * 60) {
                    if (date('H:i', $j) >= date('H:i', strtotime($day->time_from)) && date('H:i', $j) < date('H:i', strtotime($day->time_to))) {
                        $usage = Usage::find()->where(['device_id' => $device->id])->andWhere(['date' => date('Y-m-d', $i)])->andWhere(['hour_nr' => $k])->one();
                        echo '<tr' . ($usage ? ' class="used"' : '') . '>';
                        echo '<td style="width: 3em;">' . date('H:i', $j) . '</td>';
                        echo '<td>' . ($usage ? Html::tag('span', StringHelper::truncate($usage->subject->name, 12), ['data' => ['toggle' => 'tooltip', 'placement' => 'top', 'html' => true, 'title' => $usage->subject->name . '<br />' . $usage->subject->email . '<br />' . $usage->subject->phone]]) : '&nbsp;') . '</td>';
                        echo '<td style="text-align: center; width: 4em;">';
                        if ($usage) {
                            echo Html::a('<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>', ['/reservation/usage/update', 'plan_id' => $plan->id, 'id' => $usage->id], ['title' => Module::t('res', 'Update usage'), 'class' => 'btn btn-link', 'style' => 'padding: 0;']);
                            echo Html::a('<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>', ['/reservation/usage/delete', 'plan_id' => $plan->id, 'id' => $usage->id], ['title' => Module::t('res', 'Delete usage'), 'class' => 'btn btn-link', 'style' => 'padding: 0;', 'data-confirm' => Module::t('res', 'Are you sure you want to delete this item?'), 'data-method' => 'post', 'data-pjax' => '0']);
                        } else {
                            echo Html::a('<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>', ['/reservation/usage/create', 'plan_id' => $plan->id, 'date' => date('Y-m-d', $i), 'hour_nr' => $k], ['title' => Module::t('res', 'Add usage'), 'class' => 'btn btn-link', 'style' => 'padding: 0;']);
Exemple #3
0
<?php

/* @var $this yii\web\View */
/* @var $deviceId integer */
/* @var $requestedDate string */
use backend\modules\reservation\models\Day;
use backend\modules\reservation\models\Plan;
use backend\modules\reservation\models\Usage;
$this->title = Yii::t('front', 'Information');
if ($plan = Plan::find()->where(['device_id' => $deviceId])->andWhere(['<=', 'date_from', $requestedDate])->andWhere(['>=', 'date_to', $requestedDate])->one()) {
    $dayNr = Yii::$app->formatter->asDate($requestedDate, 'php:N');
    if ($day = Day::find()->where(['plan_id' => $plan->id])->andWhere(['day_nr' => $dayNr])->one()) {
        if ($day->is_open == 1) {
            echo '<table class="usage-table bordered">';
            echo '<thead>';
            echo '<tr><th colspan="2">' . $day->getDayName() . ' ' . Yii::$app->formatter->asDate($requestedDate, 'dd.MM.y') . '</th></tr>';
            echo '</thead>';
            echo '<tbody>';
            for ($j = strtotime($requestedDate . ' ' . $plan->time_from), $k = 1; $j < strtotime($requestedDate . ' ' . $plan->time_to); $j += $plan->hour_length * 60) {
                if (date('H:i', $j) >= date('H:i', strtotime($day->time_from)) && date('H:i', $j) < date('H:i', strtotime($day->time_to))) {
                    $usage = Usage::find()->where(['device_id' => $deviceId])->andWhere(['date' => $requestedDate])->andWhere(['hour_nr' => $k])->one();
                    echo '<tr class=' . ($usage ? 'used' : 'free') . '>';
                    echo '<td style="width: 3em;">' . date('H:i', $j) . '</td>';
                    echo '<td>' . ($usage ? $usage->subject->name : Yii::t('front', 'available')) . '</td>';
                    echo '</tr>';
                } else {
                    echo '<tr><td colspan="2" style="text-align: center;"><i class="material-icons">remove</i></td></tr>';
                }
                ++$k;
            }
            echo '</tbody>';
Exemple #4
0
 /**
  * Sets day times array
  */
 private function setDayTimes()
 {
     if ($this->date == null) {
         throw new InvalidArgumentException(Module::t('res', 'Date not set!'));
     }
     $dayWeekNr = date('N', Yii::$app->formatter->asTimestamp($this->date));
     $day = Day::find()->where(['plan_id' => $this->_plan->id])->andWhere(['day_nr' => $dayWeekNr])->one();
     $dayTimes = [];
     for ($i = strtotime($this->_plan->time_from), $j = 1; $i <= strtotime($this->_plan->time_to); $i += 60 * $this->_plan->hour_length) {
         if ($i >= strtotime($day->time_from) && $i <= strtotime($day->time_to)) {
             $dayTimes[strval($j)] = date('H:i', $i);
         }
         ++$j;
     }
     $this->_dayTimes = $dayTimes;
 }