Beispiel #1
0
 public function validaRangoHoras($attribute, $params)
 {
     if (empty($this->hora_desde) || empty($this->hora_hasta)) {
         if (empty($this->hora_desde)) {
             $this->addError('hora_desde', 'Debe ingresar un rango de horas');
             return;
         }
         if (empty($this->hora_hasta)) {
             $this->addError('hora_hasta', 'Debe ingresar un rango de horas');
             return;
         }
     }
     if (strtotime($this->hora_desde) > strtotime($this->hora_hasta)) {
         $this->addError('hora_hasta', 'Esta hora no puede ser anterior a la otra hora');
         return;
     }
     // controla que el rango de horas esté dentro del rango del corte de energia
     $ce = CortesEnergia::findOne($this->id_cortes_energia);
     if (strtotime($this->hora_desde) < strtotime($ce->hora_desde) || strtotime($this->hora_desde) > strtotime($ce->hora_hasta)) {
         $this->addError('hora_desde', 'Fuera de rango');
         return;
     }
     if (strtotime($this->hora_hasta) < strtotime($ce->hora_desde) || strtotime($this->hora_hasta) > strtotime($ce->hora_hasta)) {
         $this->addError('hora_hasta', 'Fuera de rango');
         return;
     }
     // controla que el rango de horas no se superponga con otra novedad del mismo generador
     $ceg = self::find()->where(['estado' => self::ESTADO_ACTIVO])->all();
     foreach ($ceg as $c) {
         // para el caso de una modificacion, evita que se controle a si misma
         if (!empty($this->id) && $this->id == $c->id) {
             continue;
         }
         if ($this->id_generador != $c->id_generador) {
             continue;
         }
         if (strtotime($this->hora_desde) >= strtotime($c->hora_desde) && strtotime($this->hora_desde) <= strtotime($c->hora_hasta)) {
             $this->addError('hora_desde', 'Se superpone con otra novedad');
             return;
         }
         if (strtotime($this->hora_hasta) >= strtotime($c->hora_desde) && strtotime($this->hora_hasta) <= strtotime($c->hora_hasta)) {
             $this->addError('hora_hasta', 'Se superpone con otra novedad');
             return;
         }
     }
 }
 /**
  * Deletes an existing CortesEnergiaGen model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $model = $this->findModel($id);
     $parent = CortesEnergia::findOne($model->id_cortes_energia);
     if ($model->load(Yii::$app->request->post())) {
         $model->estado = CortesEnergiaGen::ESTADO_BAJA;
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         return $this->render('delete', ['model' => $model, 'parent' => $parent]);
     }
 }
 /**
  * Finds the CortesEnergia model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return CortesEnergia the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = CortesEnergia::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }