Exemplo n.º 1
0
 public function __construct($config)
 {
     $this->_plan = Plan::findOne($config['plan_id']);
     $this->scenario = $config['action'];
     $this->modelClass = Usage::className();
     array_shift($config);
     parent::__construct($config);
 }
Exemplo n.º 2
0
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;']);
                        }
                        echo '</td>';
                        echo '</tr>';
                    } else {
                        echo '<tr><td colspan="3" style="text-align: center;"><span class="glyphicon glyphicon-minus btn" aria-hidden="true" style="padding: 0; cursor: default;"></span></td></tr>';
                    }
Exemplo n.º 3
0
 public function validateAttribute($model, $attribute)
 {
     if (empty($this->limitsAttributes) || count($this->limitsAttributes) != 2) {
         throw new InvalidParamException(Module::t('res', 'No time limits parameters!'));
     } else {
         $error = false;
         $conflictUsages = [];
         $requestedUsages = [];
         /** @noinspection PhpUndefinedFieldInspection */
         if ($model->item_id) {
             /** @noinspection PhpUndefinedFieldInspection */
             /** @noinspection PhpUndefinedMethodInspection */
             $usages = Usage::find()->where(['device_id' => $model->plan->device_id])->andWhere(['!=', 'id', $model->item_id])->all();
         } else {
             /** @noinspection PhpUndefinedFieldInspection */
             /** @noinspection PhpUndefinedMethodInspection */
             $usages = Usage::findAll(['device_id' => $model->plan->device_id]);
         }
         /** @var UsageForm $model */
         $dayTimeValue = 86400;
         switch ($model->{$attribute}) {
             case UsageForm::DAY_REPEAT:
                 $additionalTime = $dayTimeValue;
                 break;
             case UsageForm::WEEK_REPEAT:
                 $additionalTime = 7 * $dayTimeValue;
                 break;
             case UsageForm::TWO_WEEK_REPEAT:
                 $additionalTime = 14 * $dayTimeValue;
                 break;
             case UsageForm::THREE_WEEK_REPEAT:
                 $additionalTime = 21 * $dayTimeValue;
                 break;
             case UsageForm::FOUR_WEEK_REPEAT:
                 $additionalTime = 28 * $dayTimeValue;
                 break;
             default:
                 $model->repetition_end_date = $model->date;
                 $additionalTime = $dayTimeValue;
                 break;
         }
         /** @noinspection PhpUndefinedFieldInspection */
         for ($i = \Yii::$app->formatter->asTimestamp($model->date); $i <= \Yii::$app->formatter->asTimestamp($model->repetition_end_date); $i += $additionalTime) {
             for ($j = $model->{$this->limitsAttributes[0]}; $j < $model->{$this->limitsAttributes[1]}; ++$j) {
                 $requestedUsages[] = ['date' => \Yii::$app->formatter->asDate($i, 'y-MM-dd'), 'hour_nr' => $j];
             }
         }
         /** @var Usage $usage */
         foreach ($usages as $usage) {
             $searchedArray = ['date' => $usage->date, 'hour_nr' => $usage->hour_nr];
             if (array_search($searchedArray, $requestedUsages)) {
                 /** @noinspection PhpUndefinedFieldInspection */
                 $conflictUsages[] = \Yii::$app->formatter->asDate($usage->date, 'dd.MM.y') . ' ' . $model->dayTimes[$usage->hour_nr] . ': ' . $usage->subject->name;
                 $error = true;
             }
         }
         if ($error === true) {
             $this->message = Module::t('res', 'This usage is in conflict with one or more other usages') . ': ' . implode(', ', $conflictUsages);
             $model->addError($attribute, $this->message);
         }
     }
 }
Exemplo n.º 4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUsages()
 {
     return $this->hasMany(Usage::className(), ['device_id' => 'id']);
 }
Exemplo n.º 5
0
/* @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>';
            echo '</table>';
        }
    }
}
Exemplo n.º 6
0
 /**
  * Finds the model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Usage the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Usage::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }