34
34
*/
35
35
class SagresConsultModel
36
36
{
37
- private $ dbCommand ;
38
-
39
-
40
-
41
-
42
- public function __construct ()
43
- {
44
- $ this ->dbCommand = Yii::app ()->db ->createCommand ();
45
- }
46
37
47
38
public function cleanInconsistences ()
48
39
{
@@ -349,7 +340,7 @@ classroom c
349
340
':referenceYear ' => $ referenceYear
350
341
];
351
342
352
- $ turmas = $ this -> dbCommand ->setText ($ query )
343
+ $ turmas = Yii:: app ()-> db -> createCommand () ->setText ($ query )
353
344
->bindValues ($ params )
354
345
->queryAll ();
355
346
@@ -999,7 +990,7 @@ public function getMenuList($schoolId, $year, $month)
999
990
$ inconsistencyModel ->insert ();
1000
991
}
1001
992
1002
- if (!$ this ->validateDate ($ menuType ->getData (), ' Y-m-d ' , 2 )) {
993
+ if (!$ this ->validateDate ($ menuType ->getData (), 2 )) {
1003
994
$ inconsistencyModel = new ValidationSagresModel ();
1004
995
$ inconsistencyModel ->enrollment = 'CARDÁPIO ' ;
1005
996
$ inconsistencyModel ->school = $ schoolRes ['name ' ];
@@ -1189,6 +1180,7 @@ public function getEnrollments($classId, $referenceYear, $month, $finalClass, $i
1189
1180
left join schedule s on cf.schedule_fk = s.id
1190
1181
WHERE
1191
1182
se.classroom_fk = :classId AND
1183
+ se.status = 1 AND
1192
1184
c.school_year = :referenceYear
1193
1185
GROUP BY se.id;
1194
1186
" ;
@@ -1203,7 +1195,8 @@ public function getEnrollments($classId, $referenceYear, $month, $finalClass, $i
1203
1195
1204
1196
foreach ($ enrollments as $ enrollment ) {
1205
1197
1206
- if (DateTime::createFromFormat ("d/m/Y " , $ enrollment ['birthdate ' ]) === false ) {
1198
+ $ convertedBirthdate = $ this ->convertBirthdate ($ enrollment ['birthdate ' ]);
1199
+ if ($ convertedBirthdate === false ) {
1207
1200
$ inconsistencyModel = new ValidationSagresModel ();
1208
1201
$ inconsistencyModel ->enrollment = '<strong>ESTUDANTE<strong> ' ;
1209
1202
$ inconsistencyModel ->school = $ school ->name ;
@@ -1227,7 +1220,7 @@ public function getEnrollments($classId, $referenceYear, $month, $finalClass, $i
1227
1220
$ studentType = new AlunoTType ();
1228
1221
$ studentType
1229
1222
->setNome ($ enrollment ['name ' ])
1230
- ->setDataNascimento (DateTime:: createFromFormat ( " d/m/Y " , $ enrollment [ ' birthdate ' ]) )
1223
+ ->setDataNascimento ($ convertedBirthdate )
1231
1224
->setCpfAluno (!empty ($ cpf ) ? $ cpf : null )
1232
1225
->setPcd ($ enrollment ['deficiency ' ])
1233
1226
->setSexo ($ enrollment ['gender ' ]);
@@ -1270,7 +1263,7 @@ public function getEnrollments($classId, $referenceYear, $month, $finalClass, $i
1270
1263
$ inconsistencyModel ->insert ();
1271
1264
}
1272
1265
1273
- if (!$ this ->validateDate ($ studentType ->getDataNascimento (), ' Y-m-d ' , 1 )) {
1266
+ if (!$ this ->validateDate ($ studentType ->getDataNascimento (), 1 )) {
1274
1267
$ inconsistencyModel = new ValidationSagresModel ();
1275
1268
$ inconsistencyModel ->enrollment = '<strong>ESTUDANTE<strong> ' ;
1276
1269
$ inconsistencyModel ->school = $ school ->name ;
@@ -1377,7 +1370,7 @@ public function getEnrollments($classId, $referenceYear, $month, $finalClass, $i
1377
1370
$ inconsistencyModel ->insert ();
1378
1371
}
1379
1372
1380
- if (!$ this ->validateDate ($ enrollmentType ->getDataMatricula (), ' Y-m-d ' , 2 )) {
1373
+ if (!$ this ->validateDate ($ enrollmentType ->getDataMatricula (), 2 )) {
1381
1374
$ inconsistencyModel = new ValidationSagresModel ();
1382
1375
$ inconsistencyModel ->enrollment = 'MATRÍCULA ' ;
1383
1376
$ inconsistencyModel ->school = $ school ->name ;
@@ -1413,9 +1406,10 @@ public function getEnrollments($classId, $referenceYear, $month, $finalClass, $i
1413
1406
}
1414
1407
} else {
1415
1408
$ studentType = new AlunoTType ();
1409
+ $ convertedBirthdate = $ this ->convertBirthdate ($ enrollment ['birthdate ' ]);
1416
1410
$ studentType
1417
1411
->setNome ($ enrollment ['name ' ])
1418
- ->setDataNascimento (DateTime:: createFromFormat ( " d/m/Y " , $ enrollment [ ' birthdate ' ]) )
1412
+ ->setDataNascimento ($ convertedBirthdate )
1419
1413
->setCpfAluno (!empty ($ cpf ) ? $ cpf : null )
1420
1414
->setPcd ($ enrollment ['deficiency ' ])
1421
1415
->setSexo ($ enrollment ['gender ' ]);
@@ -1458,7 +1452,7 @@ public function getEnrollments($classId, $referenceYear, $month, $finalClass, $i
1458
1452
$ inconsistencyModel ->insert ();
1459
1453
}
1460
1454
1461
- if (!$ this ->validateDate ($ studentType ->getDataNascimento (), ' Y-m-d ' , 1 )) {
1455
+ if (!$ this ->validateDate ($ studentType ->getDataNascimento (), 1 )) {
1462
1456
$ inconsistencyModel = new ValidationSagresModel ();
1463
1457
$ inconsistencyModel ->enrollment = '<strong>ESTUDANTE<strong> ' ;
1464
1458
$ inconsistencyModel ->school = $ school ->name ;
@@ -1564,7 +1558,7 @@ public function getEnrollments($classId, $referenceYear, $month, $finalClass, $i
1564
1558
$ inconsistencyModel ->insert ();
1565
1559
}
1566
1560
1567
- if (!$ this ->validateDate ($ enrollmentType ->getDataMatricula (), ' Y-m-d ' , 2 )) {
1561
+ if (!$ this ->validateDate ($ enrollmentType ->getDataMatricula (), 2 )) {
1568
1562
$ inconsistencyModel = new ValidationSagresModel ();
1569
1563
$ inconsistencyModel ->enrollment = 'MATRÍCULA ' ;
1570
1564
$ inconsistencyModel ->school = $ school ->name ;
@@ -1603,7 +1597,22 @@ public function getEnrollments($classId, $referenceYear, $month, $finalClass, $i
1603
1597
return $ enrollmentList ;
1604
1598
}
1605
1599
1606
- public function getStudentSituation ($ situation )
1600
+ public function convertBirthdate ($ birthdate ) {
1601
+
1602
+ $ date = DateTime::createFromFormat ('Y-m-d ' , $ birthdate );
1603
+ if ($ date && $ date ->format ('Y-m-d ' ) === $ birthdate ) {
1604
+ return $ date ->format ('d/m/Y ' );
1605
+ }
1606
+
1607
+ $ date = DateTime::createFromFormat ('d/m/Y ' , $ birthdate );
1608
+ if ($ date && $ date ->format ('d/m/Y ' ) === $ birthdate ) {
1609
+ return $ birthdate ;
1610
+ }
1611
+
1612
+ return false ;
1613
+ }
1614
+
1615
+ public function getStudentSituation ($ situation ): bool
1607
1616
{
1608
1617
$ situations = [
1609
1618
0 => false , // Não frequentou
@@ -1725,17 +1734,28 @@ public function convertTurn($turn)
1725
1734
}
1726
1735
}
1727
1736
1728
- public function validateDate ($ date , $ format , $ type )
1737
+ public function validateDate ($ date , int $ type ): bool
1729
1738
{
1730
- $ type = (int ) $ type ;
1739
+ $ format = 'Y-m-d ' ;
1740
+ if ($ date === null )
1741
+ return false ;
1742
+
1731
1743
if ($ date instanceof Datetime) {
1732
1744
$ dat = $ date ->format ('Y-m-d ' );
1733
1745
} else {
1734
- $ dt = new DateTime ($ date );
1746
+
1747
+ $ dt = DateTime::createFromFormat ($ format , $ date );
1748
+ if ($ dt === false ) {
1749
+ return false ;
1750
+ }
1751
+
1735
1752
$ dat = $ dt ->format ('Y-m-d ' );
1736
1753
}
1737
1754
1738
1755
$ d = DateTime::createFromFormat ($ format , $ dat );
1756
+ if ($ d === false ) {
1757
+ return false ;
1758
+ }
1739
1759
$ year = intval ($ d ->format ('Y ' ));
1740
1760
$ currentYear = intval (date ('Y ' ));
1741
1761
@@ -1756,11 +1776,12 @@ public function validateDate($date, $format, $type)
1756
1776
return $ d && $ d ->format ($ format ) == $ dat ;
1757
1777
}
1758
1778
1759
- public function validaCPF ($ cpf )
1779
+
1780
+ public function validaCPF (String $ cpf ): bool
1760
1781
{
1761
1782
$ cpf = preg_replace ('/[^0-9]/is ' , '' , $ cpf );
1762
1783
1763
- if (strlen ($ cpf ) != 11 ) {
1784
+ if (! $ this -> cpfLength ($ cpf )) {
1764
1785
return false ;
1765
1786
}
1766
1787
0 commit comments