Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Feature importcenso #100

Merged
merged 3 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
382 changes: 191 additions & 191 deletions app/controllers/CensoController.php

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions app/libraries/Educacenso/Register20.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,21 +165,21 @@ public static function export($year)
$register[$edcensoAlias->corder] = '';
}
} else if ($edcensoAlias->corder == 34 || $edcensoAlias->corder == 35 || $edcensoAlias->corder == 36 || $edcensoAlias->corder == 37 || $edcensoAlias->corder == 38 || $edcensoAlias->corder == 39) {
if ($attributes["schooling"] == '0' || in_array($attributes['edcenso_stage_vs_modality_fk'], [1, 2, 3])) {
if ($attributes['edcenso_stage_vs_modality_fk'] == null || in_array($attributes['edcenso_stage_vs_modality_fk'], [1, 2, 3])) {
$register[$edcensoAlias->corder] = '';
} else if ($edcensoAlias->corder == 34 && !in_array($attributes['edcenso_stage_vs_modality_fk'], [14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 41, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 56, 69, 70, 71, 72, 73, 74, 67])) {
} else if ($edcensoAlias->corder == 34 && !in_array($attributes['edcenso_stage_vs_modality_fk'], [14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 41, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 64, 56, 69, 70, 71, 72, 73, 74, 67])) {
$register[34] = '0';
$register[35] = '1';
} else if ($register[34] == '0' && $edcensoAlias->corder == 35 && !in_array($attributes['edcenso_stage_vs_modality_fk'], [25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 69, 70, 71, 72, 73, 74, 67, 68])) {
} else if ($register[34] == '0' && $edcensoAlias->corder == 35 && !in_array($attributes['edcenso_stage_vs_modality_fk'], [25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 64, 69, 70, 71, 72, 73, 74, 67, 68])) {
$register[35] = '0';
$register[36] = '1';
} else if ($register[34] == '0' && $register[35] == '0' && $edcensoAlias->corder == 36 && !in_array($attributes['edcenso_stage_vs_modality_fk'], [14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 41, 56])) {
$register[36] = '0';
$register[37] = '1';
} else if ($register[34] == '0' && $register[35] == '0' && $register[36] == '0' && $edcensoAlias->corder == 37 && !in_array($attributes['edcenso_stage_vs_modality_fk'], [14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 41, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 56, 69, 70, 71, 72, 73, 74, 67, 68])) {
} else if ($register[34] == '0' && $register[35] == '0' && $register[36] == '0' && $edcensoAlias->corder == 37 && !in_array($attributes['edcenso_stage_vs_modality_fk'], [14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 41, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 64, 56, 69, 70, 71, 72, 73, 74, 67, 68])) {
$register[37] = '0';
$register[38] = '1';
} else if ($register[34] == '0' && $register[35] == '0' && $register[36] == '0' && $register[37] == '0' && $edcensoAlias->corder == 38 && !in_array($attributes['edcenso_stage_vs_modality_fk'], [14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 41, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 56, 69, 70, 71, 72, 73, 74, 67, 68])) {
} else if ($register[34] == '0' && $register[35] == '0' && $register[36] == '0' && $register[37] == '0' && $edcensoAlias->corder == 38 && !in_array($attributes['edcenso_stage_vs_modality_fk'], [14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 41, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 64, 56, 69, 70, 71, 72, 73, 74, 67, 68])) {
$register[38] = '0';
$register[39] = '1';
}
Expand Down
59 changes: 59 additions & 0 deletions app/migrations/2.12.3_substituir_deletes_por_renames/2022-06-20
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
ALTER TABLE schedule RENAME TO _unusedtable_schedule;
ALTER TABLE class_faults RENAME TO _unusedtable_class_faults;
ALTER TABLE class_has_content RENAME TO _unusedtable_class_has_content;
ALTER TABLE class_class_objective RENAME TO _unusedtable_class_class_objective;
ALTER TABLE `class` RENAME TO _unusedtable_class;

CREATE TABLE `schedule` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`instructor_fk` int(11) DEFAULT NULL,
`discipline_fk` int(11) NOT NULL,
`classroom_fk` int(11) NOT NULL,
`day` int(11) NOT NULL,
`month` int(11) NOT NULL,
`week` int(11) NOT NULL,
`week_day` int(11) NOT NULL,
`schedule` int(11) DEFAULT NULL,
`turn` int(11) DEFAULT NULL,
`unavailable` int(11) NOT NULL,
`fkid` varchar(40) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

ALTER TABLE `schedule`
ADD FOREIGN KEY (`instructor_fk`) REFERENCES `instructor_identification` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE `schedule`
ADD FOREIGN KEY (`discipline_fk`) REFERENCES `edcenso_discipline` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE `schedule`
ADD FOREIGN KEY (`classroom_fk`) REFERENCES `classroom` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

CREATE TABLE `class_faults` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`student_fk` int(11) NOT NULL,
`schedule_fk` int(11) NOT NULL,
`fkid` varchar(40) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id_UNIQUE` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

ALTER TABLE `class_faults`
ADD FOREIGN KEY (`student_fk`) REFERENCES `student_enrollment` (`student_fk`) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE `class_faults`
ADD FOREIGN KEY (`schedule_fk`) REFERENCES `schedule` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

CREATE TABLE `class_has_content` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`schedule_fk` int(11) NOT NULL,
`content_fk` int(11) NOT NULL,
`fkid` varchar(40) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

ALTER TABLE `class_has_content`
ADD FOREIGN KEY (`content_fk`) REFERENCES `class_resource` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE `class_has_content`
ADD FOREIGN KEY (`schedule_fk`) REFERENCES `schedule` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
96 changes: 54 additions & 42 deletions app/models/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,15 @@ public function importRegister20($lines, $year){
$classroomModel = new Classroom();

foreach ($fields as $field) {
$columnName = $field->attr;
$collumnOrder = $field->corder -1;

if(isset($line[$collumnOrder]) && $line[$collumnOrder] != "" && in_array($columnName, $attributes)){
$classroomModel->{$columnName} = utf8_encode($line[$collumnOrder]);
$hasModified = true;
}
if ($field->attr !== "id") {
$columnName = $field->attr;
$collumnOrder = $field->corder -1;

if(isset($line[$collumnOrder]) && $line[$collumnOrder] != "" && in_array($columnName, $attributes)){
$classroomModel->{$columnName} = utf8_encode($line[$collumnOrder]);
$hasModified = true;
}
}
}

if($hasModified){
Expand Down Expand Up @@ -213,26 +215,29 @@ public function importRegister301($line, $year){
$studentDocumentModel = new StudentDocumentsAndAddress();

foreach ($fields as $field) {
$columnName = $field->attr;
$collumnOrder = $field->corder -1;
$modelType = $field->stable;
if ($field->attr !== "id") {
$columnName = $field->attr;
$collumnOrder = $field->corder - 1;
$modelType = $field->stable;

if(is_null($modelType)){
continue;
}
if (is_null($modelType)) {
continue;
}

$model = $modelType == self::STUDENT_IDENTIFICATION ? $studentIdentificationModel : $studentDocumentModel;
$model = $modelType == self::STUDENT_IDENTIFICATION ? $studentIdentificationModel : $studentDocumentModel;

if(isset($line[$collumnOrder]) && $line[$collumnOrder] != "" && in_array($columnName, $model->attributeNames())){
$model->{$columnName} = utf8_encode($line[$collumnOrder]);
}
if (isset($line[$collumnOrder]) && $line[$collumnOrder] != "" && in_array($columnName, $model->attributeNames())) {
$model->{$columnName} = utf8_encode($line[$collumnOrder]);
}
}
}

$studentIdentificationModel->send_year = $this->year;
$studentDocumentModel->school_inep_id_fk = $studentIdentificationModel->school_inep_id_fk;
if($studentIdentificationModel->validate() && $studentDocumentModel->validate()){
if($studentIdentificationModel->save(false)){
$studentDocumentModel->student_fk = $studentIdentificationModel->id;
$studentDocumentModel->student_fk = $studentIdentificationModel->inep_id;
$studentDocumentModel->id = $studentIdentificationModel->id;
$studentDocumentModel->save();
return;
}
Expand All @@ -249,24 +254,27 @@ public function importRegister302($line, $year){
$instructorDocumentModel = new InstructorDocumentsAndAddress(InstructorDocumentsAndAddress::SCENARIO_IMPORT);

foreach ($fields as $field) {
$columnName = $field->attr;
$collumnOrder = $field->corder -1;
$modelType = $field->stable;
if ($field->attr !== "id") {
$columnName = $field->attr;
$collumnOrder = $field->corder - 1;
$modelType = $field->stable;

if(is_null($modelType)){
continue;
}
if (is_null($modelType)) {
continue;
}

$model = $modelType == self::INSTRUCTOR_IDENTIFICATION ? $instructorIdentificationModel : $instructorDocumentModel;
$model = $modelType == self::INSTRUCTOR_IDENTIFICATION ? $instructorIdentificationModel : $instructorDocumentModel;

if(isset($line[$collumnOrder]) && $line[$collumnOrder] != "" && in_array($columnName, $model->attributeNames())){
$model->{$columnName} = utf8_encode($line[$collumnOrder]);
}
if (isset($line[$collumnOrder]) && $line[$collumnOrder] != "" && in_array($columnName, $model->attributeNames())) {
$model->{$columnName} = utf8_encode($line[$collumnOrder]);
}
}
}

$instructorDocumentModel->school_inep_id_fk = $instructorIdentificationModel->school_inep_id_fk;
if($instructorIdentificationModel->validate() && $instructorDocumentModel->validate()){
if($instructorIdentificationModel->save(false)){
$instructorDocumentModel->id = $instructorIdentificationModel->id;
$instructorDocumentModel->save();
return;
}
Expand Down Expand Up @@ -343,13 +351,15 @@ public function importRegister50($lines, $year){
$instructorTeachingModel = new InstructorTeachingData(InstructorTeachingData::SCENARIO_IMPORT);

foreach ($fields as $field) {
$columnName = $field->attr;
$collumnOrder = $field->corder -1;

if(isset($line[$collumnOrder]) && $line[$collumnOrder] != "" && in_array($columnName, $attributes)){
$instructorTeachingModel->{$columnName} = utf8_encode($line[$collumnOrder]);
$hasModified = true;
}
if ($field->attr !== "instructor_fk") {
$columnName = $field->attr;
$collumnOrder = $field->corder - 1;

if (isset($line[$collumnOrder]) && $line[$collumnOrder] != "" && in_array($columnName, $attributes)) {
$instructorTeachingModel->{$columnName} = utf8_encode($line[$collumnOrder]);
$hasModified = true;
}
}
}

if($hasModified){
Expand Down Expand Up @@ -397,13 +407,15 @@ public function importRegister60($lines, $year){
$studentEnrollmentModel = new StudentEnrollment();

foreach ($fields as $field) {
$columnName = $field->attr;
$collumnOrder = $field->corder -1;

if(isset($line[$collumnOrder]) && $line[$collumnOrder] != "" && in_array($columnName, $attributes)){
$studentEnrollmentModel->{$columnName} = utf8_encode($line[$collumnOrder]);
$hasModified = true;
}
if ($field->attr !== "student_fk") {
$columnName = $field->attr;
$collumnOrder = $field->corder - 1;

if (isset($line[$collumnOrder]) && $line[$collumnOrder] != "" && in_array($columnName, $attributes)) {
$studentEnrollmentModel->{$columnName} = utf8_encode($line[$collumnOrder]);
$hasModified = true;
}
}
}

if($hasModified){
Expand Down
6 changes: 3 additions & 3 deletions app/models/InstructorDocumentsAndAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function rules()
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('school_inep_id_fk, cpf, area_of_residence', 'required'),
array('school_inep_id_fk', 'required'),
array('area_of_residence, edcenso_uf_fk, edcenso_city_fk, diff_location', 'numerical', 'integerOnly'=>true),
array('register_type', 'length', 'max'=>2),
array('school_inep_id_fk, cep', 'length', 'max'=>8),
Expand Down Expand Up @@ -110,8 +110,8 @@ public function attributeLabels()
'school_inep_id_fk' => Yii::t('default', 'School Inep Id Fk'),
'inep_id' => Yii::t('default', 'Inep'),
'id' => Yii::t('default', 'ID'),
'cpf' => Yii::t('default', 'Cpf'),
'area_of_residence' => Yii::t('default', 'Area Of Residence'),
'cpf' => Yii::t('default', 'Cpf') . " *",
'area_of_residence' => Yii::t('default', 'Area Of Residence') . " *",
'cep' => Yii::t('default', 'Cep'),
'address' => Yii::t('default', 'Address'),
'address_number' => Yii::t('default', 'Address Number'),
Expand Down
36 changes: 22 additions & 14 deletions app/modules/wizard/controllers/ConfigurationController.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<?php

class ConfigurationController extends Controller {
class ConfigurationController extends Controller
{

public function actionIndex() {
public function actionIndex()
{
$this->render('index');
}

public function actionSchool() {
public function actionSchool()
{
$year = Yii::app()->user->school;
$model = SchoolConfiguration::model()->findByAttributes(array("school_inep_id_fk" => $year));

Expand All @@ -26,7 +29,8 @@ public function actionSchool() {
$this->render('school', array('model' => $model));
}

public function actionClassroom() {
public function actionClassroom()
{
if (isset($_POST['Classrooms'])) {
$Classrooms_ids = $_POST['Classrooms'];
$year = Yii::app()->user->year;
Expand Down Expand Up @@ -67,35 +71,38 @@ public function actionClassroom() {

Log::model()->saveAction("wizard_classroom", $logYear, "C", $logYear);
Yii::app()->user->setFlash('success', Yii::t('default', 'Turmas reutilizadas com sucesso!'));
}
else {
$this->redirect('?r=classroom');
} else {
Yii::app()->user->setFlash('error', Yii::t('default', 'Erro na reutilização das Turmas.'));
$this->render('classrooms', array(
'title' => Yii::t('default', 'Reaproveitamento das Turmas')
));
}
$this->render('index');
return true;
}
$this->render('classrooms', array(
'title' => Yii::t('default', 'Reaproveitamento das Turmas')
));
}

public function actionStudent() {
public function actionStudent()
{
if (isset($_POST["Classrooms"], $_POST["StudentEnrollment"])) {
$save = true;
$logYear = "";
foreach ($_POST["Classrooms"] as $classroom) {
$emrollments = StudentEnrollment::model()->findAll("classroom_fk = :c", array("c" => $classroom));
$logYear = Classroom::model()->findByPk($classroom)->school_year;
foreach($emrollments as $e){
foreach ($emrollments as $e) {
$enrollment = new StudentEnrollment();
$enrollment->attributes = $_POST["StudentEnrollment"];

$st = StudentIdentification::model()->findByPk($e->student_fk);
$c = Classroom::model()->findByPk($enrollment->classroom_fk);
$exist = StudentEnrollment::model()->findAll("classroom_fk = :c AND student_fk = :s",
array("c" => $c->id, "s"=>$st->id));
array("c" => $c->id, "s" => $st->id));
//Se não existe, cadastra
if(count($exist)==0){
if (count($exist) == 0) {
$enrollment->school_inep_id_fk = Yii::app()->user->school;
$enrollment->student_fk = $st->id;
$enrollment->classroom_fk = $c->id;
Expand All @@ -108,18 +115,19 @@ public function actionStudent() {
if ($save) {
Log::model()->saveAction("wizard_student", $logYear, "C", $logYear);
Yii::app()->user->setFlash('success', Yii::t('default', 'Alunos matriculados com sucesso!'));
}else {
} else {
Yii::app()->user->setFlash('error', Yii::t('default', 'Erro na matrícula dos Alunos.'));
}
$this->render('index');
}else {
} else {
$this->render('students', array(
'title' => Yii::t('default', 'Student Configuration')
));
}
}

public function actionGetStudents() {
public function actionGetStudents()
{
if (isset($_POST["Classrooms"]) && !empty($_POST["Classrooms"])) {
$id = $_POST["Classrooms"];
$criteria = new CDbCriteria();
Expand Down
Loading