Skip to content

Commit

Permalink
Merge pull request #750 from portabilis/portabilis-patch-2021-01-26
Browse files Browse the repository at this point in the history
[2.5] Portabilis patch 26/01/2021
  • Loading branch information
edersoares authored Jan 27, 2021
2 parents 3ac4090 + 32fb90d commit 122c317
Show file tree
Hide file tree
Showing 19 changed files with 379 additions and 23 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ name: tests

on:
push:
branches: 2.*
branches:
- 2.*
- master
pull_request:
branches: 2.*
branches:
- 2.*
- master

jobs:
default:
Expand Down
31 changes: 31 additions & 0 deletions app/Http/Controllers/Api/StudentController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Http\Requests\Api\UpdateStateRegistrationRequest;
use App\Models\LegacyStudent;
use Throwable;

class StudentController extends Controller
{
/**
* Atualiza a inscrição estadual de um aluno.
*
* @param UpdateStateRegistrationRequest $request
* @param LegacyStudent $student
*
* @throws Throwable
* @return array
*/
public function updateStateRegistration(UpdateStateRegistrationRequest $request, LegacyStudent $student)
{
$student->state_registration_id = $request->getStateRegistration();
$student->saveOrFail();

return [
'id' => $student->getKey(),
'state_registration_id' => $student->state_registration_id,
];
}
}
5 changes: 5 additions & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class Kernel extends HttpKernel
'api' => [
'bindings',
],

'api:rest' => [
'bindings',
\App\Http\Middleware\CheckToken::class,
],
];

/**
Expand Down
29 changes: 29 additions & 0 deletions app/Http/Middleware/CheckToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Validation\UnauthorizedException;

class CheckToken
{
/**
* Handle an incoming request.
*
* @param Request $request
* @param Closure $next
*
* @return mixed
*/
public function handle($request, Closure $next)
{
$token = $request->bearerToken();

if ($token && config('legacy.apis.access_key') === $token) {
return $next($request);
}

throw new UnauthorizedException();
}
}
43 changes: 43 additions & 0 deletions app/Http/Requests/Api/UpdateStateRegistrationRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace App\Http\Requests\Api;

use App\Rules\StateRegistrationFormatRule;
use App\Rules\StateRegistrationUniqueRule;
use Illuminate\Foundation\Http\FormRequest;

class UpdateStateRegistrationRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'state_registration_id' => [
new StateRegistrationFormatRule(),
new StateRegistrationUniqueRule($this->student),
],
];
}

/**
* @return string
*/
public function getStateRegistration()
{
return $this->input('state_registration_id');
}
}
10 changes: 10 additions & 0 deletions app/Models/LegacyStudent.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ public function getInepNumberAttribute()
return $this->inep ? $this->inep->number : null;
}

public function getStateRegistrationIdAttribute()
{
return $this->aluno_estado_id;
}

public function setStateRegistrationIdAttribute($value)
{
$this->aluno_estado_id = $value;
}

public function inep()
{
return $this->hasOne(StudentInep::class, 'cod_aluno', 'cod_aluno');
Expand Down
31 changes: 31 additions & 0 deletions app/Rules/StateRegistrationFormatRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;

class StateRegistrationFormatRule implements Rule
{
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
*
* @return bool
*/
public function passes($attribute, $value)
{
return preg_match('/[0-9]{3}\.[0-9]{3}\.[0-9]{3}(\-[0-9]{1})?/', $value);
}

/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return 'O número de inscrição é inválido.';
}
}
48 changes: 48 additions & 0 deletions app/Rules/StateRegistrationUniqueRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace App\Rules;

use App\Models\LegacyStudent;
use Illuminate\Contracts\Validation\Rule;

class StateRegistrationUniqueRule implements Rule
{
private $studentToIgnore;

/**
* Create a new rule instance.
*
* @param LegacyStudent $studentToIgnore
*/
public function __construct($studentToIgnore = null)
{
$this->studentToIgnore = $studentToIgnore;
}

/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
return LegacyStudent::query()
->where('aluno_estado_id', $value)
->when($this->studentToIgnore, function ($query) use ($value) {
$query->where('cod_aluno', '<>', $this->studentToIgnore->getKey());
})
->doesntExist();
}

/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return 'Já existe uma aluno com este número de inscrição.';
}
}
1 change: 1 addition & 0 deletions app/Services/CyclicRegimeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function getAllRegistrationsOfCycle($registration)
foreach ($grades as $grade) {
$result = LegacyRegistration::where('ref_ref_cod_serie', $grade->getKey())
->where('ref_cod_aluno', $registration->ref_cod_aluno)
->where('ano', $registration->ano)
->active()
->get()
->first();
Expand Down
30 changes: 18 additions & 12 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion database/sqls/views/public.info_enrollment.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ from pmieducar.matricula_turma enturmacao
inner join pmieducar.matricula matricula on true
and matricula.cod_matricula = enturmacao.ref_cod_matricula
inner join pmieducar.turma turma on true
and turma.cod_turma = enturmacao.ref_cod_turma;
and turma.cod_turma = enturmacao.ref_cod_turma
and turma.ativo = 1;
9 changes: 5 additions & 4 deletions ieducar/intranet/educar_matricula_det.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function Gerar()
$situacao = App_Model_MatriculaSituacao::getSituacao($registro['aprovado']);
$this->addDetalhe(['Situação', $situacao]);

if ($registro['aprovado'] == 4) {
if ($registro['aprovado'] == App_Model_MatriculaSituacao::TRANSFERIDO) {
$obj_transferencia = new clsPmieducarTransferenciaSolicitacao();

$lst_transferencia = $obj_transferencia->lista(null, null, null, null, null, $registro['cod_matricula'], null, null, null, null, null, 1, null, null, $registro['ref_cod_aluno'], false);
Expand All @@ -236,23 +236,24 @@ public function Gerar()
$this->addDetalhe(['Estado escola destino', $det_transferencia['estado_escola_destino_externa']]);
$this->addDetalhe(['Município escola destino', $det_transferencia['municipio_escola_destino_externa']]);
}
$this->addDetalhe(['Observação', $det_transferencia['observacao']]);
}

if ($registro['aprovado'] == App_Model_MatriculaSituacao::FALECIDO) {
$this->addDetalhe(['Observação', Portabilis_String_Utils::toLatin1($registro['observacao'])]);
$this->addDetalhe(['Observação', $registro['observacao']]);
}

if ($existeSaidaEscola) {
$this->addDetalhe(['Saída da escola', 'Sim']);
$this->addDetalhe(['Data de saída da escola', Portabilis_Date_Utils::pgSQLToBr($registro['data_saida_escola'])]);
$this->addDetalhe(['Observação', Portabilis_String_Utils::toLatin1($registro['observacao'])]);
$this->addDetalhe(['Observação', $registro['observacao']]);
}

if ($registro['aprovado'] == App_Model_MatriculaSituacao::ABANDONO) {
$tipoAbandono = new clsPmieducarAbandonoTipo($registro['ref_cod_abandono_tipo']);
$tipoAbandono = $tipoAbandono->detalhe();

$observacaoAbandono = Portabilis_String_Utils::toLatin1($registro['observacao']);
$observacaoAbandono = $registro['observacao'];

$this->addDetalhe(['Motivo do Abandono', $tipoAbandono['nome']]);
$this->addDetalhe(['Observação', $observacaoAbandono]);
Expand Down
2 changes: 1 addition & 1 deletion ieducar/intranet/educar_serie_cad.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function Inicializar()
],[
'serie' => $this->cod_serie
],
[],
['ano_letivo' => 'DESC'],
false
);
}
Expand Down
2 changes: 1 addition & 1 deletion ieducar/intranet/educar_transferencia_solicitacao_cad.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function Gerar()
$ref_cod_instituicao = $det_matricula['ref_cod_instituicao'];

$this->inputsHelper()->dynamic(['instituicao'], ['required' => false]);
$this->inputsHelper()->dynamic(['escola'], ['label_hint' => 'Destino do aluno', 'required' => false]);
$this->inputsHelper()->dynamic(['escolaSemFiltroPorUsuario'], ['label_hint' => 'Destino do aluno', 'required' => false]);
$this->inputsHelper()->checkbox('escola_em_outro_municipio', ['label' => 'Escola em outro municipio?', ]);
$this->campoTexto('escola_destino_externa', 'Nome da escola ', '', 30, 255, false, false, false, '');
$this->campoTexto('estado_escola_destino_externa', 'Estado da escola ', '', 20, 50, false, false, false, '');
Expand Down
Loading

0 comments on commit 122c317

Please sign in to comment.