示例#1
0
 public function __construct($config)
 {
     $this->device_id = $config['device_id'];
     $this->modelClass = Plan::className();
     array_shift($config);
     parent::__construct($config);
 }
示例#2
0
 public function validateAttribute($model, $attribute)
 {
     $error = false;
     $conflictPlans = [];
     $value1 = \Yii::$app->formatter->asTimestamp($model->{$this->firstAttribute});
     $value2 = \Yii::$app->formatter->asTimestamp($model->{$attribute});
     /** @var $plans Plan */
     /** @noinspection PhpUndefinedFieldInspection */
     if ($model->item_id) {
         /** @noinspection PhpUndefinedFieldInspection */
         $plans = Plan::find()->where(['device_id' => $model->device_id])->andWhere(['!=', 'id', $model->item_id])->all();
     } else {
         /** @noinspection PhpUndefinedFieldInspection */
         $plans = Plan::findAll(['device_id' => $model->device_id]);
     }
     foreach ($plans as $plan) {
         $timestamp1 = \Yii::$app->formatter->asTimestamp($plan->date_from);
         $timestamp2 = \Yii::$app->formatter->asTimestamp($plan->date_to);
         if ($value1 < $timestamp1 && $value2 >= $timestamp1 || $value1 <= $timestamp2 && $value2 > $timestamp2) {
             $conflictPlans[] = \Yii::$app->formatter->asDate($plan->date_from, 'php:d.m.Y') . ' - ' . \Yii::$app->formatter->asDate($plan->date_to, 'php:d.m.Y');
             $error = true;
         }
     }
     if ($error === true) {
         $this->message = Module::t('res', 'This plan is in conflict with one or more other plans') . ': ' . implode(', ', $conflictPlans);
         $model->addError($attribute, $this->message);
     }
 }
示例#3
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);
 }
示例#4
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->device_id) {
         $query = Plan::find()->where(['device_id' => $this->device_id])->orderBy(['date_from' => SORT_ASC]);
         $this->_dataProvider = new ActiveDataProvider(['query' => $query]);
     } else {
         throw new InvalidParamException(Module::t('res', 'No device ID given!'));
     }
 }
示例#5
0
 /**
  * @param \yii\base\Action $action
  *
  * @return bool
  */
 public function beforeAction($action)
 {
     $request = \Yii::$app->request;
     if (!$request->get('plan_id')) {
         return false;
     }
     /** @noinspection PhpUndefinedFieldInspection */
     $action->controller->plan = Plan::findOne($request->get('plan_id'));
     return parent::beforeAction($action);
 }
示例#6
0
 public function validateAttribute($model, $attribute)
 {
     $error = true;
     $todayTime = strtotime(date('Y-m-d', time()));
     $testDate = \Yii::$app->formatter->asDate($todayTime, 'y-MM-dd');
     $plans = Plan::find()->where(['device_id' => $this->device_id])->andWhere(['>=', 'date_to', $testDate])->all();
     foreach ($plans as $plan) {
         if ($model->{$attribute} >= $plan->date_from && $model->{$attribute} <= $plan->date_to) {
             $error = false;
             break;
         }
     }
     if ($error === true) {
         $model->addError($attribute, $model->getAttributeLabel($attribute) . ' ' . $this->message);
     }
 }
示例#7
0
/* @var $this yii\web\View */
/* @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 {
示例#8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPlans()
 {
     return $this->hasMany(Plan::className(), ['device_id' => 'id']);
 }
示例#9
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 Plan the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Plan::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#10
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>';
示例#11
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPlan()
 {
     return $this->hasOne(Plan::className(), ['id' => 'plan_id']);
 }
示例#12
0
 /**
  * Checking for actual plans
  *
  * @return bool
  */
 public function existsActualPlans()
 {
     $actualPlans = Plan::find()->where(['device_id' => $this->device->id])->andWhere(['>', 'date_to', date('Y-m-d', time())])->all();
     return empty($actualPlans) ? false : true;
 }