public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if (!Yii::$app->user->can('admin')) {
         if ($model->user_id != Yii::$app->user->id) {
             $this->redirect(['index']);
         }
     }
     if (!Yii::$app->user->can('admin')) {
         if ($model->status == 1) {
             $this->redirect(['index']);
         }
     }
     $months = Month::find()->all();
     $years = Year::find()->all();
     if ($model->load(Yii::$app->request->post())) {
         $model->date = date('Y-m-d', strtotime($model->date));
         if (!Monitoring2::find()->where(['date' => $model->date, 'user_id' => Yii::$app->user->id])->one()) {
             if ($model->save()) {
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         }
     }
     return $this->render('update', ['model' => $model, 'months' => $months, 'years' => $years]);
 }
 public function putDetailedNotasYear()
 {
     $user = User::fromToken();
     $grupo_id = Request::input('grupo_id');
     $periodo_a_calcular = Request::input('periodo_a_calcular', 10);
     $alumnos_response = [];
     $grupo = Grupo::datos($grupo_id);
     $year = Year::datos($user->year_id);
     $alumnos = Grupo::alumnos($grupo_id);
     foreach ($alumnos as $keyAlum => $alumno) {
         $alumno->notas_asig = $this->definitivas_year_alumno($alumno->alumno_id, $user->year_id, $periodo_a_calcular);
         $sumatoria_asignaturas_year = 0;
         $perdidos_year = 0;
         foreach ($alumno->notas_asig as $keyAsig => $asignatura) {
             $sumatoria_asignaturas_year += $asignatura->nota_asignatura_year;
             $perdidos_year += $asignatura->perdidos;
         }
         try {
             $cant = count($alumno->notas_asig);
             if ($cant == 0) {
                 $alumno->promedio_year = 0;
             } else {
                 $alumno->promedio_year = $sumatoria_asignaturas_year / $cant;
                 $alumno->perdidos_year = $perdidos_year;
             }
         } catch (Exception $e) {
             $alumno->promedio_year = 0;
         }
         array_push($alumnos_response, $alumno);
     }
     return ['grupo' => $grupo, 'year' => $year, 'alumnos' => $alumnos_response];
 }
 public function putActual()
 {
     $user = User::fromToken();
     $year = Year::find(Request::input('year_id'));
     $year->config_certificado_estudio_id = Request::input('config_certificado_estudio_id');
     $year->save();
     return 'Cambiado';
 }
 /**
  * Updates an existing Monitoring1 model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $months = Month::find()->all();
     $years = Year::find()->all();
     $model->user_id = Yii::$app->user->id;
     //      добавление даты  http://www.yiiframework.com/doc-2.0/guide-output-formatting.html
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'months' => $months, 'years' => $years]);
     }
 }
示例#5
0
    public static function matricularUno($alumno_id, $grupo_id)
    {
        $year = Year::where('actual', '=', true)->first();
        $consulta = 'SELECT m.id, m.alumno_id, m.grupo_id, m.matriculado, g.year_id 
			FROM matriculas m 
			inner join grupos g 
				on m.alumno_id = :alumno_id and g.year_id = :year_id and m.grupo_id=g.id';
        $matriculas = DB::select(DB::raw($consulta), array('alumno_id' => $alumno_id, 'year_id' => $year->id));
        $matricula = false;
        for ($i = 0; $i < count($matriculas); $i++) {
            $matri = Matricula::onlyTrashed()->where('id', $matriculas[$i]->id)->first();
            /*
            $queries = DB::getQueryLog();
            $last_query = end($queries);
            return $last_query;
            */
            if ($matri) {
                if ($matri->grupo_id == $grupo_id) {
                    if ($matricula) {
                        // Si ya he encontrado en un elemento anterior una matrícula identica, es por que ya la he activado, no debo activar más. Por el contrario, debo borrarlas
                        ${$matri}->delete();
                    } else {
                        $matri->matriculado = true;
                        $matri->fecha_retiro = null;
                        $matri->save();
                        $matri->restore();
                        $matricula = $matri;
                    }
                } else {
                    $matri->delete();
                }
            }
        }
        try {
            if (!$matricula) {
                $matricula = new Matricula();
                $matricula->alumno_id = $alumno_id;
                $matricula->grupo_id = $grupo_id;
                $matricula->matriculado = true;
                $matricula->save();
            }
        } catch (Exception $e) {
            // se supone que esto nunca va a ocurrir, ya que eliminé todas las matrículas
            // excepto la que concordara con el grupo, poniéndola en matriculado=true
            $matricula = Matricula::where('alumno_id', '=', $alumno_id)->where('grupo_id', '=', $grupo_id)->first();
            $matricula->matriculado = true;
            $matricula->save();
        }
        return $matricula;
    }
示例#6
0
 public function getShowProfesor($profesor_id)
 {
     $user = User::fromToken();
     $year = Year::datos_basicos($user->year_id);
     $asignaturas = Profesor::asignaturas($user->year_id, $profesor_id);
     $periodos = Periodo::where('year_id', '=', $user->year_id)->get();
     $year->periodos = $periodos;
     $profesor = Profesor::detallado($profesor_id);
     foreach ($asignaturas as $keyAsig => $asignatura) {
         $alumnos = Grupo::alumnos($asignatura->grupo_id);
         $asignatura->nombres_profesor = $profesor->nombres_profesor;
         $asignatura->apellidos_profesor = $profesor->apellidos_profesor;
         $asignatura->foto_nombre = $profesor->foto_nombre;
         $asignatura->foto_id = $profesor->foto_id;
         $asignatura->sexo = $profesor->sexo;
         $asignatura->periodosProm = Periodo::where('year_id', '=', $user->year_id)->get();
         // A cada alumno le daremos los periodos y la definitiva de cada periodo
         foreach ($alumnos as $keyAl => $alumno) {
             $periodosTemp = Periodo::where('year_id', '=', $user->year_id)->get();
             foreach ($periodosTemp as $keyPer => $periodo) {
                 // Unidades y subunidades de la asignatura en el periodo
                 $asignaturaTemp = Asignatura::find($asignatura->asignatura_id);
                 $asignaturaTemp->unidades = Unidad::deAsignatura($asignaturaTemp->id, $periodo->id);
                 foreach ($asignaturaTemp->unidades as $unidad) {
                     $unidad->subunidades = Subunidad::deUnidad($unidad->unidad_id);
                 }
                 // Traemos las notas de esta asignatura segun las unidades y subunidades calculadas arriba
                 Asignatura::calculoAlumnoNotas($asignaturaTemp, $alumno->alumno_id);
                 $periodo->nota_asignatura = $asignaturaTemp->nota_asignatura;
                 unset($asignaturaTemp);
             }
             $alumno->periodos = $periodosTemp;
             unset($periodosTemp);
             foreach ($asignatura->periodosProm as $keyPer => $periodo) {
                 if (!$periodo->sumatoria) {
                     $periodo->sumatoria = 0;
                 }
                 foreach ($alumno->periodos as $keyPerAl => $periodo_alum) {
                     if ($periodo_alum->id == $periodo->id) {
                         $periodo->sumatoria += $periodo_alum->nota_asignatura;
                     }
                 }
             }
         }
         $asignatura->alumnos = $alumnos;
     }
     return array($year, $asignaturas);
 }
示例#7
0
 public function detailedNotasGrupo($grupo_id, $user, $requested_alumnos = '')
 {
     $grupo = Grupo::datos($grupo_id);
     $year = Year::datos($user->year_id);
     $alumnos = Grupo::alumnos($grupo_id, $requested_alumnos);
     $year->periodos = Periodo::where('year_id', $user->year_id)->get();
     $grupo->cantidad_alumnos = count($alumnos);
     $response_alumnos = [];
     foreach ($alumnos as $alumno) {
         // Todas las materias con sus unidades y subunides
         $this->definitivasMateriasXPeriodo($alumno, $grupo_id, $user->year_id, $year->periodos);
         $asignaturas_perdidas = $this->asignaturasPerdidasDeAlumno($alumno, $grupo_id, $user->year_id);
         if (count($asignaturas_perdidas) > 0) {
             $alumno->asignaturas_perdidas = $asignaturas_perdidas;
             $alumno->notas_perdidas_year = 0;
             $alumno->periodos_con_perdidas = Periodo::where('year_id', $user->year_id)->get();
             foreach ($alumno->periodos_con_perdidas as $keyPerA => $periodoAlone) {
                 $periodoAlone->cant_perdidas = 0;
                 foreach ($alumno->asignaturas_perdidas as $keyAsig => $asignatura_perdida) {
                     foreach ($asignatura_perdida->periodos as $keyPer => $periodo) {
                         if ($periodoAlone->periodo_id == $periodo->periodo_id) {
                             if ($periodo->id == $periodoAlone->id) {
                                 $periodoAlone->cant_perdidas += $periodo->cantNotasPerdidas;
                             }
                         }
                     }
                 }
                 $alumno->notas_perdidas_year += $periodoAlone->cant_perdidas;
             }
         }
     }
     foreach ($alumnos as $alumno) {
         $alumno->puesto = Nota::puestoAlumno($alumno->promedio, $alumnos);
         if ($requested_alumnos == '') {
             array_push($response_alumnos, $alumno);
         } else {
             foreach ($requested_alumnos as $req_alumno) {
                 if ($req_alumno['alumno_id'] == $alumno->alumno_id) {
                     array_push($response_alumnos, $alumno);
                 }
             }
         }
     }
     return array($grupo, $year, $response_alumnos);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Mon1str::find()->joinWith('monitoring1.user.profile.region');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->sort->attributes['region'] = ['asc' => [Region::tableName() . '.name' => SORT_ASC], 'desc' => [Region::tableName() . '.name' => SORT_DESC]];
     $dataProvider->sort->attributes['month'] = ['asc' => [Month::tableName() . '.month' => SORT_ASC], 'desc' => [Month::tableName() . '.month' => SORT_DESC]];
     $dataProvider->sort->attributes['year'] = ['asc' => [Year::tableName() . '.year' => SORT_ASC], 'desc' => [Year::tableName() . '.year' => 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([Monitoring1::tableName() . '.date' => $this->date, Region::tableName() . '.id' => $this->region]);
     //        $query->andFilterWhere(['like', 'status', $this->status]);
     return $dataProvider;
 }
示例#9
0
文件: Year.php 项目: bluesky777/5myvc
 public static function de_un_periodo($periodo_id)
 {
     $periodo = Periodo::find($periodo_id);
     $year = Year::find($periodo->year_id);
     return $year;
 }
示例#10
0
    public function detailedNotasGrupo($grupo_id, $user, $requested_alumnos = '')
    {
        $this->escalas_val = EscalaDeValoracion::where('year_id', $user->year_id)->get();
        $grupo = Grupo::datos($grupo_id);
        $year = Year::datos($user->year_id);
        $alumnos = Grupo::alumnos($grupo_id, $requested_alumnos);
        $year->periodos = Periodo::where('year_id', $user->year_id)->get();
        $cons = 'SELECT c.*, i.nombre as encabezado_nombre, i2.nombre as pie_nombre 
				FROM config_certificados c 
				left join images i on i.id=c.encabezado_img_id and i.deleted_at is null
				left join images i2 on i2.id=c.piepagina_img_id and i2.deleted_at is null
					where c.id=?';
        $config_certificado = DB::select($cons, [$year->config_certificado_estudio_id]);
        if (count($config_certificado) > 0) {
            $year->config_certificado = $config_certificado[0];
        }
        $cons = 'SELECT n.nombre as nivel_educativo FROM niveles_educativos n
				inner join grados gra on gra.nivel_educativo_id=n.id and gra.deleted_at is null
				inner join grupos gru on gru.grado_id=gra.id and gru.id=? and gru.deleted_at is null
				where n.deleted_at is null';
        $niveles = DB::select($cons, [$grupo_id]);
        if (count($niveles) > 0) {
            $grupo->nivel_educativo = $niveles[0]->nivel_educativo;
        }
        $grupo->cantidad_alumnos = count($alumnos);
        $response_alumnos = [];
        foreach ($alumnos as $alumno) {
            // Todas las materias con sus unidades y subunides
            $this->definitivasMateriasXPeriodo($alumno, $grupo_id, $user->year_id, $year->periodos);
            $asignaturas_perdidas = $this->asignaturasPerdidasDeAlumno($alumno, $grupo_id, $user->year_id);
            if (count($asignaturas_perdidas) > 0) {
                $alumno->asignaturas_perdidas = $asignaturas_perdidas;
                $alumno->notas_perdidas_year = 0;
                $alumno->periodos_con_perdidas = Periodo::where('year_id', $user->year_id)->get();
                foreach ($alumno->periodos_con_perdidas as $keyPerA => $periodoAlone) {
                    $periodoAlone->cant_perdidas = 0;
                    foreach ($alumno->asignaturas_perdidas as $keyAsig => $asignatura_perdida) {
                        foreach ($asignatura_perdida->periodos as $keyPer => $periodo) {
                            if ($periodoAlone->periodo_id == $periodo->periodo_id) {
                                if ($periodo->id == $periodoAlone->id) {
                                    $periodoAlone->cant_perdidas += $periodo->cantNotasPerdidas;
                                }
                            }
                        }
                    }
                    $alumno->notas_perdidas_year += $periodoAlone->cant_perdidas;
                }
            }
        }
        foreach ($alumnos as $alumno) {
            $alumno->puesto = Nota::puestoAlumno($alumno->promedio, $alumnos);
            if ($requested_alumnos == '') {
                array_push($response_alumnos, $alumno);
            } else {
                foreach ($requested_alumnos as $req_alumno) {
                    if ($req_alumno['alumno_id'] == $alumno->alumno_id) {
                        array_push($response_alumnos, $alumno);
                    }
                }
            }
        }
        return array($grupo, $year, $response_alumnos);
    }
示例#11
0
 public function deleteDestroy($id)
 {
     $img = ImageModel::findOrFail($id);
     $filename = 'images/perfil/' . $img->nombre;
     // Debería crear un código que impida borrar si la imagen es usada.
     if (File::exists($filename)) {
         File::delete($filename);
         $img->delete();
     } else {
         return 'No se encuentra la imagen a eliminar. ' . $img->nombre;
     }
     // Elimino cualquier referencia que otros tengan a esa imagen borrada.
     $alumnos = Alumno::where('foto_id', $id)->get();
     foreach ($alumnos as $alum) {
         $alum->foto_id = null;
         $alum->save();
     }
     $profesores = Profesor::where('foto_id', $id)->get();
     foreach ($profesores as $prof) {
         $prof->foto_id = null;
         $prof->save();
     }
     $acudientes = Acudiente::where('foto_id', $id)->get();
     foreach ($acudientes as $acud) {
         $acud->foto_id = null;
         $acud->save();
     }
     $users = User::where('imagen_id', $id)->get();
     foreach ($users as $user) {
         $user->imagen_id = null;
         $user->save();
     }
     $years = Year::where('logo_id', $id)->get();
     foreach ($years as $year) {
         $year->logo_id = null;
         $year->save();
     }
     $asks = ChangeAsked::where('oficial_image_id', $id)->destroy();
     return $img;
 }
示例#12
0
 public function getListasignaturasyear($profesor_id, $periodo_id)
 {
     $user = User::fromToken();
     $year = Year::de_un_periodo($periodo_id);
     $asignaturas = Profesor::asignaturas($year->id, $profesor_id);
     foreach ($asignaturas as $asignatura) {
         $asignatura->unidades = Unidad::informacionAsignatura($asignatura->asignatura_id, $periodo_id);
     }
     return $asignaturas;
 }
 /**
  * Updates an existing Monitoring1 model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $modelsStr = $model->mon1str;
     if (!Yii::$app->user->can('admin')) {
         if ($model->user_id != Yii::$app->user->id) {
             $this->redirect(['index']);
         }
     }
     if (!Yii::$app->user->can('admin')) {
         if ($model->status == 1) {
             $this->redirect(['index']);
         }
     }
     $months = Month::find()->all();
     $years = Year::find()->all();
     //        $model->user_id = Yii::$app->user->id;
     if ($model->load(Yii::$app->request->post())) {
         $model->date = date('Y-m-d', strtotime($model->date));
         if (!Monitoring1::find()->where(['date' => $model->date, 'user_id' => Yii::$app->user->id])->one()) {
             if ($model->save()) {
                 $oldIDs = ArrayHelper::map($modelsStr, 'id', 'id');
                 $modelsStr = Model::createMultiple(Mon1str::classname(), $modelsStr);
                 Model::loadMultiple($modelsStr, Yii::$app->request->post());
                 $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsStr, 'id', 'id')));
                 // ajax validation
                 if (Yii::$app->request->isAjax) {
                     Yii::$app->response->format = Response::FORMAT_JSON;
                     return ArrayHelper::merge(ActiveForm::validateMultiple($modelsStr), ActiveForm::validate($model));
                 }
                 // validate all models
                 $valid = $model->validate();
                 $valid = Model::validateMultiple($modelsStr) && $valid;
                 if ($valid) {
                     $transaction = \Yii::$app->db->beginTransaction();
                     try {
                         if ($flag = $model->save(false)) {
                             if (!empty($deletedIDs)) {
                                 Mon1str::deleteAll(['id' => $deletedIDs]);
                             }
                             foreach ($modelsStr as $modelStr) {
                                 $modelStr->monitoring1_id = $model->id;
                                 if (!($flag = $modelStr->save(false))) {
                                     $transaction->rollBack();
                                     break;
                                 }
                             }
                         }
                         if ($flag) {
                             $transaction->commit();
                             return $this->redirect(['view', 'id' => $model->id]);
                         }
                     } catch (Exception $e) {
                         $transaction->rollBack();
                     }
                 }
             }
         }
     }
     return $this->render('update', ['model' => $model, 'months' => $months, 'years' => $years, 'modelsStr' => empty($modelsStr) ? [new Mon1str()] : $modelsStr]);
 }
示例#14
0
            <i class="dropdown icon"></i>
            <div class="menu">
                <?php 
$amphurs = \App\Models\Thailand\Amphur::where("province_id", "=", "44")->get();
?>
                @foreach($amphurs as $amphur)
                    <a class="link item" href="/amphur/{{$amphur->AMPHUR_ID}}/{{$amphur->AMPHUR_NAME}}">{{$amphur->AMPHUR_NAME}}</a>
                @endforeach
            </div>
        </div>
        <div class="ui simple dropdown item">
            ปีที่ดำเนินโครงการ
            <i class="dropdown icon"></i>
            <div class="menu">
                <?php 
$years = \App\Models\Year::orderBy('year', 'desc')->get();
?>
                @foreach($years as $year)
                    <a class="link item" href="/project?year={{$year->year}}">{{$year->year}}</a>
                @endforeach

            </div>
        </div>

    </div>

    <div class="sixteen wide column">

        @yield('content')

示例#15
0
 public function getTrashed()
 {
     $years = Year::onlyTrashed()->get();
     return $years;
 }
示例#16
0
 public function getConyears()
 {
     $user = User::fromToken();
     $profesores = Profesor::fromyear($user->year_id);
     foreach ($profesores as $profesor) {
         $profesor->years = Year::de_un_profesor($profesor->id);
     }
     return $profesores;
 }
示例#17
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getYear()
 {
     return $this->hasOne(Year::className(), ['id' => 'year_id']);
 }
示例#18
0
    public function getTrashed()
    {
        $user = User::fromToken();
        $previous_year = $user->year - 1;
        $id_previous_year = 0;
        $previous_year = Year::where('year', '=', $previous_year)->first();
        $consulta = 'SELECT m2.matricula_id, a.id as alumno_id, a.no_matricula, a.nombres, a.apellidos, a.sexo, a.user_id, 
				a.fecha_nac, a.ciudad_nac, a.celular, a.direccion, a.religion,
				m2.year_id, m2.grupo_id, m2.nombregrupo, m2.abrevgrupo, IFNULL(m2.actual, -1) as currentyear,
				u.username, u.is_superuser, u.is_active
			FROM alumnos a left join 
				(select m.id as matricula_id, g.year_id, m.grupo_id, m.alumno_id, g.nombre as nombregrupo, g.abrev as abrevgrupo, 0 as actual
				from matriculas m INNER JOIN grupos g ON m.grupo_id=g.id and g.year_id=:id_previous_year
				and m.alumno_id NOT IN 
					(select m.alumno_id
					from matriculas m INNER JOIN grupos g ON m.grupo_id=g.id and g.year_id=:year_id)
					union
					select m.id as matricula_id, g.year_id, m.grupo_id, m.alumno_id, g.nombre as nombregrupo, g.abrev as abrevgrupo, 1 AS actual
					from matriculas m INNER JOIN grupos g ON m.grupo_id=g.id and g.year_id=:year2_id
				)m2 on a.id=m2.alumno_id
			left join users u on u.id=a.user_id where a.deleted_at is not null';
        return DB::select(DB::raw($consulta), array(':id_previous_year' => $id_previous_year, ':year_id' => $user->year_id, ':year2_id' => $user->year_id));
    }
示例#19
0
        <h4 class="ui dividing header">ข้อมูลพื้นฐาน</h4>

        <div class="field">
            <label>ปีที่ดำเนินโครงการ</label>
            <div class="ui selection dropdown" tabindex="0">
                <input type="hidden" name="project[year]" value="{{$project->year}}">
                @if($project->year and $project->year != 0)
                    <div class="text">{{$project->year}}</div>
                @else
                    <div class="default text" value="0">กรุณาเลือก</div>
                @endif
                <i class="dropdown icon"></i>
                <div class="menu transition hidden" tabindex="-1">
                    <?php 
$years = \App\Models\Year::all();
?>
                    @foreach($years as $year)
                        <div class="item {{ $project->year == $year->year ? "active" : ""  }}"
                             data-value="{{$year->year}}">
                            {{$year->year}}
                        </div>
                    @endforeach

                </div>
            </div>
        </div>

        <div class="field">
            <label>ชื่อโครงการภาษาไทย</label>
            <input type="text" name="project[name_th]" placeholder="ชื่อโครงการภาษาไทย" value="{{$project->name_th}}">
示例#20
0
 public function doAdd(Request $request)
 {
     $year = Year::create($request->get('year'));
     $year->save();
     return redirect('/backend/year');
 }