Skip to content

Commit

Permalink
Merge pull request #718 from portabilis/portabilis-patch-2020-07-10
Browse files Browse the repository at this point in the history
[2.3] Portabilis patch 10/07/2020
  • Loading branch information
gustavomendess authored Jul 13, 2020
2 parents 4d0b7fd + e8b3310 commit dbe3047
Show file tree
Hide file tree
Showing 27 changed files with 713 additions and 100 deletions.
9 changes: 7 additions & 2 deletions 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 {--no-database=*}';
protected $signature = 'query:all {--no-database=*} {--file=}';

/**
* The console command description.
Expand All @@ -34,7 +34,7 @@ public function handle()
{
$array = [];
$data = [];
$file = file_get_contents(storage_path('query.sql'));
$file = file_get_contents($this->getFile());

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

Expand All @@ -59,4 +59,9 @@ public function handle()

$this->table($header, $array);
}

private function getFile()
{
return $this->option('file') ?: storage_path('query.sql');
}
}
40 changes: 40 additions & 0 deletions app/Http/Controllers/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Jobs\DatabaseToCsvExporter;
use App\Models\Exporter\Export;
use App\Models\Exporter\SocialAssistance;
use App\Models\Exporter\Stage;
use App\Models\Exporter\Student;
use App\Models\Exporter\Teacher;
use App\Process;
Expand Down Expand Up @@ -110,6 +111,10 @@ protected function filter(Request $request)
$data = $this->filterStudents($request, $data, 'exporter_social_assistance');
}

if ($model === Stage::class) {
$data = $this->filterStages($request, $data);
}

return $data;
}

Expand Down Expand Up @@ -190,4 +195,39 @@ public function filterTeachers(Request $request, $data)

return $data;
}

/**
* @param Request $request
* @param array $data
*
* @return array
*/
public function filterStages(Request $request, $data)
{
$data['filename'] = 'calendario.csv';

if ($year = $request->input('ano')) {
$data['filters'][] = [
'column' => 'exporter_stages.year',
'operator' => '=',
'value' => intval($year),
];
}

if ($request->input('ref_cod_escola')) {
$data['filters'][] = [
'column' => 'exporter_stages.school_id',
'operator' => 'in',
'value' => [$request->input('ref_cod_escola')]
];
} elseif ($request->user()->isSchooling()) {
$data['filters'][] = [
'column' => 'exporter_stages.school_id',
'operator' => 'in',
'value' => $request->user()->schools->pluck('cod_escola')->all(),
];
}

return $data;
}
}
1 change: 1 addition & 0 deletions app/Models/Exporter/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function getAllowedExports()
1 => new Student(),
2 => new Teacher(),
3 => new SocialAssistance(),
4 => new Stage(),
];
}

Expand Down
74 changes: 74 additions & 0 deletions app/Models/Exporter/Stage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace App\Models\Exporter;

use App\Models\Exporter\Builders\StudentEloquentBuilder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Collection;

class Stage extends Model
{
/**
* @var string
*/
protected $table = 'exporter_stages';

/**
* @var Collection
*/
protected $alias;

/**
* @param Builder $query
*
* @return StudentEloquentBuilder
*/
public function newEloquentBuilder($query)
{
return new StudentEloquentBuilder($query);
}

/**
* @return array
*/
public function getExportedColumnsByGroup()
{
return [
'Etapas' => [
'school_name' => 'Escola',
'school_class' => 'Turma',
'stage_name' => 'Tipo de etapa',
'stage_number' => 'Etapa',
'stage_start_date' => 'Data início',
'stage_end_date' => 'Data fim',
'stage_type' => 'Padrão/Turma',
'posted_data' => 'Possui lançamentos'
],
];
}

/**
* @return string
*/
public function getLabel()
{
return 'Calendário letivo';
}

/**
* @param string $column
*
* @return string
*/
public function alias($column)
{
if (empty($this->alias)) {
$this->alias = collect($this->getExportedColumnsByGroup())->flatMap(function ($item) {
return $item;
});
}

return $this->alias->get($column, $column);
}
}
8 changes: 8 additions & 0 deletions app/Models/LegacyPerson.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ public function deficiencies()
);
}

/**
* @return HasOne
*/
public function employee()
{
return $this->hasOne(Employee::class, 'cod_servidor', 'idpes');
}

/**
* @return BelongsToMany
*/
Expand Down
2 changes: 1 addition & 1 deletion app/Repositories/EducacensoRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function getDataForRecord00($school, $year)
ep.cep AS cep,
municipio.cod_ibge AS "codigoIbgeMunicipio",
districts.ibge_code AS "codigoIbgeDistrito",
l.idtlog || l.nome AS logradouro,
l.nome AS logradouro,
ep.numero AS numero,
ep.complemento AS complemento,
bairro.nome AS bairro,
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Software livre de gestão escolar",
"type": "project",
"license": "GPL-2.0-or-later",
"version": "2.3.5",
"version": "2.3.6",
"keywords": [
"Portabilis",
"i-Educar"
Expand Down
Loading

0 comments on commit dbe3047

Please sign in to comment.