Skip to content

Commit

Permalink
Merge pull request #716 from portabilis/portabilis-patch-2020-07-03
Browse files Browse the repository at this point in the history
[2.3] Portabilis patch 03/07/2020
  • Loading branch information
gustavomendess authored Jul 6, 2020
2 parents e518b7d + 7065c1f commit 4d0b7fd
Show file tree
Hide file tree
Showing 116 changed files with 2,468 additions and 1,298 deletions.
8 changes: 7 additions & 1 deletion app/Console/Commands/QueryAllCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class QueryAllCommand extends Command
*
* @var string
*/
protected $signature = 'query:all';
protected $signature = 'query:all {--no-database=*}';

/**
* The console command description.
Expand All @@ -36,7 +36,13 @@ public function handle()
$data = [];
$file = file_get_contents(storage_path('query.sql'));

$excludedDatabases = $this->option('no-database');

foreach ($this->getConnections() as $connection) {
if (in_array($connection, $excludedDatabases)) {
continue;
}

try {
$data = (array) DB::connection($connection)->selectOne($file);
} catch (Exception $exception) {
Expand Down
113 changes: 113 additions & 0 deletions app/Http/Controllers/EducacensoController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php

namespace App\Http\Controllers;

use App\Models\LegacyInstitution;
use App\Repositories\EducacensoRepository;
use ComponenteCurricular_Model_CodigoEducacenso;
use Illuminate\Http\Request;
use Illuminate\View\View;

class EducacensoController extends Controller
{
/**
* @param LegacyInstitution $institution
* @param array $records
* @param null $paginate
*
* @return View
*/
private function view(LegacyInstitution $institution, $records = [], $paginate = null)
{
$this->breadcrumb('Consulta 1ª fase - Matrícula inicial', [
url('intranet/educar_educacenso_index.php') => 'Educacenso',
]);

$this->menu(70);

$schools = $institution->schools()->with('person')->get()->sortBy(function ($school) {
return $school->name;
});

return view('educacenso.consult', [
'institution' => $institution,
'schools' => $schools,
'paginate' => $paginate,
'record20' => $records['record20'] ?? null,
'record40' => $records['record40'] ?? null,
'record50' => $records['record50'] ?? null,
'record60' => $records['record60'] ?? null,
]);
}

/**
* @param Request $request
* @param EducacensoRepository $repository
* @param LegacyInstitution $institution
*
* @return View
*/
public function consult(
Request $request,
EducacensoRepository $repository,
LegacyInstitution $institution
) {
$record = $request->query('record');
$school = $request->query('ref_cod_escola');
$year = $request->query('year');

if (empty($record) || empty($school) || empty($year)) {
return $this->view($institution);
}

$records = [];

if ($record == '20') {
$paginate = $repository->getBuilderForRecord20($year, $school)
->orderBy('nomeTurma')
->paginate();

$records['record20'] = $paginate->items();
}

if ($record == '40') {
$paginate = $repository->getBuilderForRecord40($school)
->orderBy('nomePessoa')
->paginate();

$records['record40'] = $paginate->items();
}

if ($record == '50') {
require_once base_path('ieducar/modules/ComponenteCurricular/Model/CodigoEducacenso.php');

$paginate = $repository->getBuilderForRecord50($year, $school)
->paginate();

$records['record50'] = collect($paginate->items())
->map(function ($item) {
$disciplines = explode(',', substr($item->componentes, 1, -1));

$item->componentes = collect($disciplines)->unique()->map(function ($discipline) {
return ComponenteCurricular_Model_CodigoEducacenso::getDescription($discipline);
})->toArray();

return $item;
})
->sortBy(function ($data) {
return "{$data->nomeDocente}{$data->nomeTurma}";
})
->values();
}

if ($record == '60') {
$paginate = $repository->getBuilderForRecord60($year, $school)
->orderBy('nomeAluno')
->paginate();

$records['record60'] = $paginate->items();
}

return $this->view($institution, $records, $paginate);
}
}
20 changes: 19 additions & 1 deletion app/Models/LegacyInstitution.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use DateTime;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;

/**
Expand All @@ -14,6 +15,7 @@
* @property string $city Noda da cidade da instituição
* @property string $state Sigla do estado da instituição
* @property DateTime $relocation_date Data base para remanejamento
* @property DateTime $educacenso_date Data de corte do Educacenso
*/
class LegacyInstitution extends Model
{
Expand All @@ -39,7 +41,7 @@ class LegacyInstitution extends Model
* @var array
*/
protected $dates = [
'data_base_remanejamento'
'data_base_remanejamento', 'data_educacenso',
];

/**
Expand Down Expand Up @@ -97,6 +99,14 @@ public function getRelocationDateAttribute()
return $this->data_base_remanejamento;
}

/**
* @return DateTime
*/
public function getEducacensoDateAttribute()
{
return $this->data_educacenso;
}

/**
* Indica se os campos do Censo são obrigatórios.
*
Expand All @@ -119,4 +129,12 @@ public function getAllowRegistrationOutAcademicYearAttribute()
{
return boolval($this->permitir_matricula_fora_periodo_letivo);
}

/**
* @return HasMany
*/
public function schools()
{
return $this->hasMany(LegacySchool::class, 'ref_cod_instituicao', 'cod_instituicao');
}
}
15 changes: 10 additions & 5 deletions app/Models/LegacySchool.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
/**
* LegacySchool
*
* @property string $name
*
* @property LegacyInstitution $institution
*/
class LegacySchool extends Model
Expand Down Expand Up @@ -71,6 +73,14 @@ public function getIdAttribute()
return $this->cod_escola;
}

/**
* @return string
*/
public function getNameAttribute()
{
return $this->person->nome;
}

/**
* Relacionamento com a instituição.
*
Expand Down Expand Up @@ -110,11 +120,6 @@ public function organization()
return $this->belongsTo(LegacyOrganization::class, 'ref_idpes');
}

public function getNameAttribute()
{
return DB::selectOne('SELECT relatorio.get_nome_escola(:escola) AS nome', ['escola' => $this->id])->nome;
}

/**
* @return HasOne
*/
Expand Down
Loading

0 comments on commit 4d0b7fd

Please sign in to comment.