Skip to content

Commit

Permalink
fix sagres status and EJA classes
Browse files Browse the repository at this point in the history
  • Loading branch information
igorgoncalves committed Dec 26, 2024
1 parent a7b3743 commit 73b6013
Show file tree
Hide file tree
Showing 6 changed files with 349 additions and 226 deletions.
80 changes: 59 additions & 21 deletions app/components/utils/TagUtils.php
Original file line number Diff line number Diff line change
@@ -1,47 +1,83 @@
<?php

class TagUtils extends CApplicationComponent {
class TagUtils extends CApplicationComponent
{


public static function isInstructor(){
return (bool)Yii::app()->getAuthManager()->checkAccess('instructor', Yii::app()->user->loginInfos->id);
public static function isInstructor()
{
return (bool) Yii::app()->getAuthManager()->checkAccess('instructor', Yii::app()->user->loginInfos->id);
}

public static function isManager(){
public static function isManager()
{
$criteria = new CDbCriteria();
$criteria->condition = 't.userid = :id';
$criteria->params = array(':id' => Yii::app()->user->loginInfos->id);
$authAssignment = AuthAssignment::model()->find($criteria);

if($authAssignment->itemname == "manager") {
if ($authAssignment->itemname == "manager") {
return true;
}
return false;
}

public static function isStageMinorEducation($stage){
public static function isStageMinorEducation($stage)
{
$refMinorStages = [
'1', '2', '3', '4', '5', '6', '7', '8', '14', '15', '16', '17', '18'
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'14',
'15',
'16',
'17',
'18'
];
$stages = new CList($refMinorStages, true);
return $stages->contains(strval($stage));
}
public static function isStageChildishEducation($stage){
public static function isStageChildishEducation($stage)
{
$refMinorStages = [
'1', '2', '3'
'1',
'2',
'3'
];
$stages = new CList($refMinorStages, true);
return $stages->contains(strval($stage));
}
public static function isMultiStage($stage){

public static function isStageEJA($stage): bool
{
$refMinorStages = ["43","44","45","46","47","48","51","58","60","61","62","63","65","66","69","70","71","72","73","74"];
$stages = new CList($refMinorStages, true);
return $stages->contains(strval($stage));
}

public static function isMultiStage($stage)
{
$refMinorStages = [
'12','13','22','23','24','56','83', '84'
'12',
'13',
'22',
'23',
'24',
'56',
'83',
'84'
];
$stages = new CList($refMinorStages, true);
return $stages->contains(strval($stage));
}
public static function convertDateFormat($date) {
// Remove espaços em branco do início e do fim da string
public static function convertDateFormat($date)
{
// Remove espaços em branco do início e do fim da string
$date = trim($date);

// Verifica se a date é vazia ou nula
Expand All @@ -67,10 +103,11 @@ public static function convertDateFormat($date) {
return $date;
}

public static function isInstance($instance){
public static function isInstance($instance)
{

if(is_array($instance)){
$instances = array_map(function ($element){
if (is_array($instance)) {
$instances = array_map(function ($element) {
return strtoupper($element);
}, $instance);

Expand All @@ -83,17 +120,18 @@ public static function isInstance($instance){
/**
* @var CActiveRecord $record
*/
public static function stringfyValidationErrors($record){
public static function stringfyValidationErrors($record)
{
$errors = $record->getErrors();
$result = array_map(function($key, $messages) use ($record) {
$message = Yii::t("default", $record->getAttributeLabel($key)) .": \n";
$result = array_map(function ($key, $messages) use ($record) {
$message = Yii::t("default", $record->getAttributeLabel($key)) . ": \n";
foreach ($messages as $value) {
$message .= "- ".$value."\n";
$message .= "- " . $value . "\n";
}
return $message;
}, array_keys($errors), array_values($errors));

return implode("\n", $result);
return implode("\n", $result);
}
}

Expand Down
2 changes: 2 additions & 0 deletions app/messages/pt_br/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,8 @@
'Differentiated Operating Place' => 'Local de Funcionamento Diferenciado',
'Complementary Activity' => 'Atividade Complementar',
'AEE' => 'Atendimento Educacional Especializado (AEE)',
"Ignore On Sagres" => 'Excluir da exportação do SAGRES',
'Period' => 'Periodo',

//Student Identification
'Nis' => 'Nº de Identificação Social (INEP)',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE classroom ADD period SMALLINT DEFAULT 0 NOT NULL;
ALTER TABLE classroom ADD ignore_on_sagres TINYINT DEFAULT 0 NOT NULL;
39 changes: 36 additions & 3 deletions app/models/Classroom.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
* @property string $sedsp_acronym
* @property integer $sedsp_school_unity_fk
* @property integer $sedsp_max_physical_capacity
* @property integer $ignore_on_sagres
* @property integer $period
*
* The followings are the available model relations:
* @property ClassBoard[] $classBoards
Expand All @@ -94,6 +96,35 @@
* @property StudentEnrollment[] $studentEnrollments
* @property StudentEnrollment[] $activeStudentEnrollments
*/




enum PeriodOptions: int {
case ANUALY = 0;
case FIRST_SEMESTER = 1;
case SECOND_SEMESTER = 2;
public function label(): string {
return static::getLabel($this);
}

public static function getLabel(self $value): string {
return match ($value) {
PeriodOptions::ANUALY => 'Anual',
PeriodOptions::FIRST_SEMESTER => '1° Semestre',
PeriodOptions::SECOND_SEMESTER => '2º Semestre',
};
}

public static function asArray(): array {
$options = [];
foreach (self::cases() as $case) {
$options[$case->value] = $case->label();
}
return $options;
}
}

class Classroom extends AltActiveRecord
{

Expand Down Expand Up @@ -139,7 +170,7 @@ public function rules()
// will receive user inputs.
return array(
array('name, edcenso_stage_vs_modality_fk, modality, school_inep_fk, initial_hour, initial_minute, final_hour, final_minute, week_days_sunday, week_days_monday, week_days_tuesday, week_days_wednesday, week_days_thursday, week_days_friday, week_days_saturday, school_year, pedagogical_mediation_type', 'required'),
array('pedagogical_mediation_type, week_days_sunday, week_days_monday, week_days_tuesday, week_days_wednesday, week_days_thursday, week_days_friday, week_days_saturday, assistance_type, mais_educacao_participator, complementary_activity_type_1, complementary_activity_type_2, complementary_activity_type_3, complementary_activity_type_4, complementary_activity_type_5, complementary_activity_type_6, modality, edcenso_professional_education_course_fk, school_year, calendar_fk, schooling, diff_location, course, complementary_activity, aee, aee_braille, aee_optical_nonoptical, aee_cognitive_functions, aee_mobility_techniques, aee_libras, aee_caa, aee_curriculum_enrichment, aee_soroban, aee_accessible_teaching, aee_portuguese, aee_autonomous_life, sedsp_school_unity_fk, sedsp_sync, sedsp_max_physical_capacity', 'numerical', 'integerOnly' => true),
array('pedagogical_mediation_type, week_days_sunday, week_days_monday, week_days_tuesday, week_days_wednesday, week_days_thursday, week_days_friday, week_days_saturday, assistance_type, mais_educacao_participator, complementary_activity_type_1, complementary_activity_type_2, complementary_activity_type_3, complementary_activity_type_4, complementary_activity_type_5, complementary_activity_type_6, modality, edcenso_professional_education_course_fk, school_year, calendar_fk, schooling, diff_location, course, complementary_activity, aee, aee_braille, aee_optical_nonoptical, aee_cognitive_functions, aee_mobility_techniques, aee_libras, aee_caa, aee_curriculum_enrichment, aee_soroban, aee_accessible_teaching, aee_portuguese, aee_autonomous_life, sedsp_school_unity_fk, sedsp_sync, sedsp_max_physical_capacity, ignore_on_sagres, period', 'numerical', 'integerOnly' => true),
array('register_type, initial_hour, initial_minute, final_hour, final_minute, sedsp_acronym', 'length', 'max' => 2),
array('sedsp_classnumber', 'length', 'max' => 3),
array('edcenso_stage_vs_modality_fk', 'length', 'max' => 6),
Expand All @@ -150,7 +181,7 @@ public function rules()
array('hash', 'length', 'max' => 40),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('register_type, school_inep_fk, inep_id, id, name, pedagogical_mediation_type, initial_hour, initial_minute, final_hour, final_minute, week_days_sunday, week_days_monday, week_days_tuesday, week_days_wednesday, week_days_thursday, week_days_friday, week_days_saturday, assistance_type, mais_educacao_participator, complementary_activity_type_1, complementary_activity_type_2, complementary_activity_type_3, complementary_activity_type_4, complementary_activity_type_5, complementary_activity_type_6, aee_braille, , modality, edcenso_stage_vs_modality_fk, edcenso_professional_education_course_fk, discipline_chemistry, discipline_physics, discipline_mathematics, discipline_biology, discipline_science, discipline_language_portuguese_literature, discipline_foreign_language_english, discipline_foreign_language_spanish, discipline_foreign_language_franch, discipline_foreign_language_other, discipline_arts, discipline_physical_education, discipline_history, discipline_geography, discipline_philosophy, discipline_social_study, discipline_sociology, discipline_informatics, discipline_professional_disciplines, discipline_special_education_and_inclusive_practices, discipline_sociocultural_diversity, discipline_libras, discipline_pedagogical, discipline_religious, discipline_native_language, discipline_others, school_year, turn, create_date, fkid, calendar_fk, sedsp_sync, sedsp_acronym, sedsp_school_unity_fk, sedsp_classnumber, sedsp_max_physical_capacity', 'safe', 'on' => 'search'),
array('register_type, school_inep_fk, inep_id, id, name, pedagogical_mediation_type, initial_hour, initial_minute, final_hour, final_minute, week_days_sunday, week_days_monday, week_days_tuesday, week_days_wednesday, week_days_thursday, week_days_friday, week_days_saturday, assistance_type, mais_educacao_participator, complementary_activity_type_1, complementary_activity_type_2, complementary_activity_type_3, complementary_activity_type_4, complementary_activity_type_5, complementary_activity_type_6, aee_braille, , modality, edcenso_stage_vs_modality_fk, edcenso_professional_education_course_fk, discipline_chemistry, discipline_physics, discipline_mathematics, discipline_biology, discipline_science, discipline_language_portuguese_literature, discipline_foreign_language_english, discipline_foreign_language_spanish, discipline_foreign_language_franch, discipline_foreign_language_other, discipline_arts, discipline_physical_education, discipline_history, discipline_geography, discipline_philosophy, discipline_social_study, discipline_sociology, discipline_informatics, discipline_professional_disciplines, discipline_special_education_and_inclusive_practices, discipline_sociocultural_diversity, discipline_libras, discipline_pedagogical, discipline_religious, discipline_native_language, discipline_others, school_year, turn, create_date, fkid, calendar_fk, sedsp_sync, sedsp_acronym, sedsp_school_unity_fk, sedsp_classnumber, sedsp_max_physical_capacity, ignore_on_sagres, period', 'safe', 'on' => 'search'),
);
}

Expand Down Expand Up @@ -288,7 +319,9 @@ public function attributeLabels()
'sedsp_school_unity_fk' => 'Sedsp School Unity Fk',
'sedsp_classnumber' => 'Sedsp Classnumber',
'sedsp_max_physical_capacity' => "Sedsp Max Physical Capacity",
'gov_id' => "GOV ID"
'gov_id' => "GOV ID",
'ignore_on_sagres' => "Ignore On Sagres",
'period' => "Período"
);
}

Expand Down
66 changes: 46 additions & 20 deletions app/modules/sagres/models/SagresConsultModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ public function getSchools($referenceYear, $month, $finalClass, $withoutCpf)

private function enrolledSimultaneouslyInRegularClasses(int $year)
{
$acceptedStatus = $this->getAcceptedEnrollmentStatus();

$query = "SELECT DISTINCT student_fk
FROM student_enrollment se
Expand All @@ -357,14 +356,13 @@ private function enrolledSimultaneouslyInRegularClasses(int $year)
SELECT se.student_fk
FROM student_enrollment se
JOIN classroom c ON c.id = se.classroom_fk
WHERE c.school_year = :year AND (se.status in (:statusList) or se.status is null)
WHERE c.school_year = :year AND (se.status = 1 or se.status is null)
GROUP BY student_fk
HAVING COUNT(*) > 1
);";

$command = Yii::app()->db->createCommand($query);
$command->bindValue(":year", $year);
$command->bindValue(":statusList", $acceptedStatus);
$students = $command->queryAll();

$processedStudents = [];
Expand All @@ -384,16 +382,14 @@ private function enrolledSimultaneouslyInRegularClasses(int $year)

private function getCountOfClassrooms($student, $infoStudent, $year)
{
$acceptedStatus = $this->getAcceptedEnrollmentStatus();
$query = "SELECT complementary_activity, aee, school_inep_id_fk, c.name
FROM student_enrollment se
JOIN classroom c ON se.classroom_fk = c.id
WHERE se.student_fk = :student_fk and (se.status in (:statusList) or se.status is null) and c.school_year = :year and modality = 1;";
WHERE se.student_fk = :student_fk and (se.status = 1 or se.status is null) and c.school_year = :year and modality = 1;";

$command = Yii::app()->db->createCommand($query);
$command->bindValue(":student_fk", $student['student_fk']);
$command->bindValue(":year", $year);
$command->bindValue(":statusList", $acceptedStatus);
$result = $command->queryAll();

$count = count($result);
Expand Down Expand Up @@ -446,17 +442,17 @@ private function checkStudentEnrollment($studentfk, $year, $infoStudent)
{

$acceptedStatus = $this->getAcceptedEnrollmentStatus();
$strAcceptedStatus = implode(",", $acceptedStatus);
// Query to get the modalities
$sql = "SELECT c.modality, c.complementary_activity, se.classroom_fk, se.school_inep_id_fk
FROM student_enrollment se
JOIN classroom c ON se.classroom_fk = c.id
WHERE se.student_fk = :student_fk
AND (se.status in (:statusList) or se.status is null)
AND (se.status in ($strAcceptedStatus) or se.status is null)
AND c.school_year = :year";

$command = Yii::app()->db->createCommand($sql);
$command->bindParam(":student_fk", $studentfk);
$command->bindParam(":statusList", $acceptedStatus);
$command->bindParam(":year", $year);
$results = $command->queryAll();

Expand Down Expand Up @@ -682,9 +678,13 @@ public function getClasses($inepId, $referenceYear, $month, $finalClass, $withou
c.school_inep_fk AS schoolInepFk,
c.id AS classroomId,
c.name AS classroomName,
c.turn AS classroomTurn
c.turn AS classroomTurn,
COALESCE(esvm.edcenso_associated_stage_id, c.edcenso_stage_vs_modality_fk) as stage,
c.period,
c.ignore_on_sagres
FROM
classroom c
join edcenso_stage_vs_modality esvm on c.edcenso_stage_vs_modality_fk = esvm.id
WHERE
c.school_inep_fk = :schoolInepFk
AND c.school_year = :referenceYear";
Expand Down Expand Up @@ -713,16 +713,40 @@ classroom c
}

foreach ($turmas as $turma) {


if ($turma["ignore_on_sagres"] == 1) {
continue;
}

$classType = new TurmaTType();
$classId = $turma['classroomId'];

if($classId == 1111){
\CVarDumper::dump($turma, 10, true);
}

if (\TagUtils::isStageEJA(stage: $turma["stage"]) && $turma["period"] == \PeriodOptions::ANUALY->value) {
$inconsistencyModel = new ValidationSagresModel();
$inconsistencyModel->enrollment = TURMA_STRONG;
$inconsistencyModel->school = $schoolRes['name'];
$inconsistencyModel->description = 'A turma <strong>' . $classType->getDescricao() . '</strong> é do tipo EJA, mas o perído está selecionado como anual.';
$inconsistencyModel->action = 'Altere o periodo para 1º ou 2º semestre: ' . $classType->getDescricao();
$inconsistencyModel->identifier = '10';
$inconsistencyModel->idClass = $classId;
$inconsistencyModel->idSchool = $inepId;
$inconsistencyModel->insert();
}


$matriculas = $this->getEnrollments($classId, $referenceYear, $month, $finalClass, $inepId, $withoutCpf);

if ($matriculas === null)
if ($matriculas === null){
continue;
}

$classType
->setPeriodo(0) //0 - Anual
->setPeriodo($turma["period"]) //0 - Anual
->setDescricao($turma["classroomName"])
->setTurno($this->convertTurn($turma['classroomTurn']))
->setSerie($this->getSeries($classId, $inepId))
Expand Down Expand Up @@ -1511,10 +1535,11 @@ public function getProfessionals($referenceYear, $month)
->setEspecialidade($professional['especialidade'])
->setIdEscola($professional['idEscola'])
->setFundeb($professional['fundeb'])
->setAtendimento($this->getAttendances(
$professional['id_professional'],
$referenceYear,
$month
->setAtendimento(
$this->getAttendances(
$professional['id_professional'],
$referenceYear,
$month
)
);

Expand Down Expand Up @@ -1585,7 +1610,8 @@ public function getAttendances($professionalId, $referenceYear, $month)

return $attendanceList;
}
private function getAcceptedEnrollmentStatus(): array{
private function getAcceptedEnrollmentStatus(): array
{
return [
\StudentEnrollment::getStatusId(\StudentEnrollment::STATUS_ACTIVE),
\StudentEnrollment::getStatusId(\StudentEnrollment::STATUS_APPROVED),
Expand All @@ -1607,7 +1633,7 @@ public function getEnrollments($classId, $referenceYear, $month, $finalClass, $i

$acceptedStatus = $this->getAcceptedEnrollmentStatus();

$strAcceptedStatus = implode( ",", $acceptedStatus);
$strAcceptedStatus = implode(",", $acceptedStatus);


$query = "SELECT
Expand Down Expand Up @@ -1653,14 +1679,14 @@ public function getEnrollments($classId, $referenceYear, $month, $finalClass, $i
left join schedule s on cf.schedule_fk = s.id
WHERE
se.classroom_fk = :classId AND
(se.status in (:statusList) or se.status is null) AND
(se.status in ($strAcceptedStatus) or se.status is null) AND
c.school_year = :referenceYear
GROUP BY se.id;
GROUP BY se.id
order by si.name asc;
";

$command = Yii::app()->db->createCommand($query);
$command->bindValues([
':statusList' => $strAcceptedStatus,
':classId' => $classId,
':referenceYear' => $referenceYear,
]);
Expand Down
Loading

0 comments on commit 73b6013

Please sign in to comment.