public function UejEntidad($id_uej, $entidad) { /* Vaciar Si viene null */ if ($id_uej == null) { $id_uej = ''; } /* Query para buscar si quitaron una unidad si trae algo hay q borrarlas */ $ace = UePartidaEntidad::find()->select('ue_partida_entidad.id')->where(['cuenta' => $this->cuenta, 'partida' => $this->partida, 'id_tipo_entidad' => $entidad])->andWhere(['not in', 'id_ue', $id_uej])->asArray()->all(); /* Si encontró algo, son las unidades que deben ser eliminadas */ if ($ace != null) { foreach ($ace as $key => $value) { $model_cambiar = UePartidaEntidad::findOne($value); $model_cambiar->delete(); } } /* Ya se borraron ahora query para buscar si agregaron una unidad nueva, si es asi almacenar y guardar */ $ace = UePartidaEntidad::find()->select('id_ue')->where(['cuenta' => $this->cuenta, 'partida' => $this->partida, 'id_tipo_entidad' => $entidad])->andWhere(['in', 'id_ue', $id_uej])->asArray()->all(); /* Declaro arreglo donde se guardará los nuevos elementos agregados */ foreach ($ace as $key => $value) { if (isset($value['id_ue'])) { $tabla[] = $value['id_ue']; } } //si viene null, lo coloco vacio if ($id_uej == null) { $id_uej = []; } if (!isset($tabla)) { $tabla = []; } /* Guardo en $nuevo los elementos nuevos que se han agregado. */ $nuevo = array_diff($id_uej, $tabla); foreach ($nuevo as $key => $value) { $model_uej = new UePartidaEntidad(); $model_uej->id_ue = $value; $model_uej->cuenta = $this->cuenta; $model_uej->partida = $this->partida; $model_uej->id_tipo_entidad = $entidad; $model_uej->save(); } }
/** * Finds the UePartidaEntidad model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return UePartidaEntidad the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = UePartidaEntidad::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }