Пример #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Assignation::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'client_id' => $this->client_id, 'equipment_id' => $this->equipment_id, 'room_id' => $this->room_id, 'start_date' => $this->start_date, 'end_date' => $this->end_date, 'duration' => $this->duration]);
     $query->andFilterWhere(['like', 'location', $this->location]);
     return $dataProvider;
 }
Пример #2
0
 public function actionCreateFromAssignation($id)
 {
     $model = new Incident();
     $model->solved = false;
     $model->user_id = Yii::$app->user->id;
     $assignationmodel = new Assignation();
     $assignationmodel = Assignation::findOne($id);
     $model->date = $assignationmodel->date;
     $model->equipment_id = $assignationmodel->equipment_id;
     $model->room_id = $assignationmodel->room_id;
     $model->location_id = $assignationmodel->location_id;
     $model->client_id = $assignationmodel->client_id;
     $this->layout = '/main2';
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view2', 'id' => $model->id]);
     } else {
         return $this->render('create2', ['model' => $model]);
     }
 }
Пример #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Assignation::find();
     $query->joinWith(['client', 'room', 'location', 'equipment']);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['date' => SORT_DESC]], 'pagination' => ['pageSize' => 1000]]);
     $dataProvider->sort->attributes['client'] = ['asc' => ['client.client_id' => SORT_ASC], 'desc' => ['client.client_id' => SORT_DESC]];
     $dataProvider->sort->attributes['full_name'] = ['asc' => ['client.full_name' => SORT_ASC], 'desc' => ['client.full_name' => SORT_DESC]];
     $dataProvider->sort->attributes['room'] = ['asc' => ['room.name' => SORT_ASC], 'desc' => ['room.name' => SORT_DESC]];
     $dataProvider->sort->attributes['location'] = ['asc' => ['location.location' => SORT_ASC], 'desc' => ['location.location' => SORT_DESC]];
     $dataProvider->sort->attributes['equipment'] = ['asc' => ['equipment.inventory' => SORT_ASC], 'desc' => ['equipment.inventory' => SORT_DESC]];
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'duration' => $this->duration, 'start_time' => $this->start_time, 'end_time' => $this->end_time]);
     $query->andFilterWhere(['like', 'purpose', $this->purpose])->andFilterWhere(['like', 'date', $this->date])->andFilterWhere(['like', 'client.client_id', $this->client])->andFilterWhere(['like', 'client.full_name', $this->full_name])->andFilterWhere(['like', 'room.id', $this->room])->andFilterWhere(['like', 'location.id', $this->location])->andFilterWhere(['like', 'equipment.inventory', $this->equipment]);
     return $dataProvider;
 }
Пример #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAssignations()
 {
     return $this->hasMany(Assignation::className(), ['room_id' => 'id']);
 }
 public function actionCreate3($id)
 {
     $model = new Assignation();
     $model->client_id = $id;
     $this->layout = '/main2';
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect('index');
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #6
0
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         if ($this->isNewRecord) {
             //registra la fecha en que se genera una asignación
             //$this->date = new \yii\db\Expression('NOW()');
             date_default_timezone_set(Yii::$app->formatter->timeZone);
             $assignationDate = new \DateTime();
             // $this->date = date('Y-m-d H:i:s');
             $this->date = $assignationDate->format('Y-m-d H:i:s');
             $start_time = $this->start_time;
             $end_time = $this->end_time;
             //Calcula y asigna la hora en que terminará una asignación en base a la duración seleccionada
             if ($start_time == "00:00:00") {
                 //$this->start_time = new \yii\db\Expression('NOW()');
                 $start_time = $assignationDate->format('H:i:s');
                 switch ($this->duration) {
                     case 15:
                         $end_time = date("H:i:s", strtotime('+15 min'));
                         break;
                     case 30:
                         $end_time = date("H:i:s", strtotime('+30 min'));
                         break;
                     case 45:
                         $end_time = date("H:i:s", strtotime('+45 min'));
                         break;
                     case 60:
                         $end_time = date("H:i:s", strtotime('+60 min'));
                         break;
                     case 90:
                         $end_time = date("H:i:s", strtotime('+90 min'));
                         break;
                     case 120:
                         $end_time = date("H:i:s", strtotime('+120 min'));
                         break;
                 }
             } else {
                 //Permite reservar equipos tomando como hora inicical la de la reservación y calcula la hora final en base a esta.
                 switch ($this->duration) {
                     case 15:
                         $end_time = date('H:i:s', strtotime('+15 min', strtotime($start_time)));
                         break;
                     case 30:
                         $end_time = date('H:i:s', strtotime('+30 min', strtotime($start_time)));
                         break;
                     case 45:
                         $end_time = date('H:i:s', strtotime('+45 min', strtotime($start_time)));
                         break;
                     case 60:
                         $end_time = date('H:i:s', strtotime('+60 min', strtotime($start_time)));
                         break;
                     case 90:
                         $end_time = date('H:i:s', strtotime('+90 min', strtotime($start_time)));
                         break;
                     case 120:
                         $end_time = date('H:i:s', strtotime('+120 min', strtotime($start_time)));
                         break;
                 }
             }
             $colision = Assignation::find()->where(['and', ['=', 'location_id', $this->location_id], ['like', 'date', $assignationDate->format('Y-m-d')], ['or', ['and', ['<=', 'start_time', $start_time], ['>=', 'end_time', $start_time]], ['and', ['<=', 'start_time', $end_time], ['>=', 'end_time', $end_time]]]])->one();
             if ($colision) {
                 Yii::$app->session->setFlash("error2", "La ubicación se encuentra en uso.");
                 return false;
             }
             $this->start_time = $start_time;
             $this->end_time = $end_time;
             return true;
         } else {
             //Actualiza la hora final y la duracion de la asignación
             switch ($this->duration) {
                 case 15:
                     $this->end_time = date('H:i:s', strtotime('+15 min', strtotime($this->start_time)));
                     break;
                 case 30:
                     $this->end_time = date('H:i:s', strtotime('+30 min', strtotime($this->start_time)));
                     break;
                 case 45:
                     $this->end_time = date('H:i:s', strtotime('+45 min', strtotime($this->start_time)));
                     break;
                 case 60:
                     $this->end_time = date('H:i:s', strtotime('+60 min', strtotime($this->start_time)));
                     break;
                 case 90:
                     $this->end_time = date('H:i:s', strtotime('+90 min', strtotime($this->start_time)));
                     break;
                 case 120:
                     $this->end_time = date('H:i:s', strtotime('+120 min', strtotime($this->start_time)));
                     break;
             }
             return true;
         }
     }
 }
 /**
  * Finds the Assignation model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Assignation the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Assignation::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }