Commit 2968ef74 authored by alissonalbuquerque's avatar alissonalbuquerque
Browse files

Add correcoes de refatoracao de query e de usuario com multiplos perfis

parent 7225f6dc
......@@ -7,6 +7,7 @@ use App\Models\Tabelas\Constants;
use App\Models\UserPad;
use App\Models\Util\MenuItemsAdmin;
use App\Models\Util\MenuItemsTeacher;
use App\Models\Util\Status;
use App\Queries\UnidadeQuery;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
......@@ -26,9 +27,9 @@ class DashboardController extends Controller
if($user->isTypeTeacher())
{
$userPads =
UserPad::find()
UserPad::initQuery()
->whereUser($user->id)
->wherePadStatus(Constants::STATUS_ATIVO)
->wherePadStatus(Status::ATIVO)
->get();
return view('dashboard', ['userPads' => $userPads, 'menu_index'=> MenuItemsTeacher::HOME]);
......
......@@ -3,11 +3,17 @@
namespace App\Http\Controllers\Dimensao\Tabelas\Ensino;
use App\Http\Controllers\Controller;
use App\Models\Avaliacao;
use App\Models\Tabelas\Constants;
use App\Models\Tabelas\Ensino\EnsinoAula;
use App\Models\UserPad;
use App\Models\Util\Avaliacao as UtilAvaliacao;
use App\Models\Util\Dimensao;
use App\Models\Util\MenuItemsTeacher;
use App\Models\Util\Modalidade;
use App\Models\Util\Nivel;
use App\Models\Util\PadTables;
use App\Models\Util\Status;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Validator;
......@@ -24,8 +30,8 @@ class EnsinoAulaController extends Controller
->get();
$niveis = Constants::listNivel();
$modalidades = Constants::listModalidade();
$niveis = Nivel::listNivel();
$modalidades = Modalidade::listModalidade();
$divs = PadTables::tablesEnsino($user_pad_id);
return view('pad.components.templates.dimensao.ensino.aulas.form_create', [
......@@ -42,8 +48,8 @@ class EnsinoAulaController extends Controller
public function edit($id) {
$model = EnsinoAula::find($id);
$niveis = Constants::listNivel();
$modalidades = Constants::listModalidade();
$niveis = Nivel::listNivel();
$modalidades = Modalidade::listModalidade();
return view('pad.components.templates.dimensao.ensino.aulas.form_update', [
'model' => $model,
......@@ -70,11 +76,25 @@ class EnsinoAulaController extends Controller
}
$user_pad_id = $request->user_pad_id;
$div_selected = 'ensino_aulas';
$model = new EnsinoAula($request->all());
$model->dimensao = Dimensao::ENSINO;
if($model->save())
{
$avaliacao = new Avaliacao([
'tarefa_id' => $model->id,
'type' => UtilAvaliacao::ENSINO_AULA,
'status' => Status::PENDENTE,
]);
if(!$avaliacao->save())
{
return redirect()
->route('ensino_aula_index', ['user_pad_id' => $user_pad_id])
->with('fail', 'Erro ao cadastrar Atividade!');
}
if($model->save()) {
return redirect()
->route('ensino_aula_index', ['user_pad_id' => $user_pad_id])
->with('success', 'Cadastro realizado com sucesso!');
......
......@@ -8,8 +8,10 @@ use App\Models\PAD;
use App\Models\Tabelas\Constants;
use App\Models\User;
use App\Models\UserPad;
use App\Models\UserType;
use App\Models\Util\MenuItemsAdmin;
use App\Models\Util\MenuItemsTeacher;
use App\Models\Util\Status;
use Database\Seeders\PadSeeder;
use Exception;
use Illuminate\Support\Facades\Auth;
......@@ -35,8 +37,8 @@ class PadController extends Controller
if(Auth::user()->isTypeTeacher()) {
$index_menu = MenuItemsTeacher::PAD;
$userPads = UserPad::find()->whereUser(Auth::user()->id)->get();
$userPads = UserPad::initQuery()->whereUser(Auth::user()->id)->get();
return view('pad.teacher.index', ['index_menu' => $index_menu, 'userPads' => $userPads]);
}
}
......@@ -58,7 +60,7 @@ class PadController extends Controller
public function create()
{
$status = [
Constants::STATUS_ATIVO => Constants::listStatus(Constants::STATUS_ATIVO)
Status::ATIVO => Status::listStatus(Status::ATIVO)
];
return view('pad.admin.create', ['status' => $status]);
}
......@@ -85,11 +87,11 @@ class PadController extends Controller
if($validated) {
$model = new Pad($request->all());
if($model->save()) {
$users = User::find()->whereType(User::TYPE_TEACHER)->get();
$users = User::initQuery()->whereType(UserType::TEACHER)->get();
foreach($users as $user) {
$modelUserPad = new UserPad();
$modelUserPad->user_id = $user->id;
......@@ -102,6 +104,7 @@ class PadController extends Controller
return redirect()->route('pad_index')->with('success', 'Erro ao cadastrar o PAD!');
}
}
}
public function anexo()
......
......@@ -9,9 +9,9 @@ class Avaliacao extends Model
{
use HasFactory;
protected $table = 'avaliador_pad';
protected $table = 'avaliacao';
protected $fillable = ['id', 'ch_semanal', 'status', 'descricao', 'tarefa_id', 'avaliador_id'];
protected $fillable = ['tarefa_id', 'avaliador_id', 'type', 'status', 'descricao', 'ch_semanal'];
public function tarefa() {
......
......@@ -2,12 +2,11 @@
namespace App\Models;
use App\Models\Tabelas\Constants;
use App\Models\Util\Status;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use PHPUnit\TextUI\XmlConfiguration\Constant;
class Pad extends Model
{
......@@ -19,8 +18,8 @@ class Pad extends Model
protected $dates = ['deleted_at'];
public function getStatusAsText() {
return Constants::listStatus($this->status);
public function statusAsString() {
return Status::listStatus($this->status);
}
public function getDateInicio() {
......
......@@ -50,7 +50,7 @@ class Planejamento extends Model
return $this->listDimensao($this->dimensao);
}
public static function find() {
public static function initQuery() {
return new PlanejamentoQuery(get_called_class());
}
......
......@@ -6,6 +6,8 @@ use App\Models\Curso;
use App\Models\Disciplina;
use App\Models\Planejamento;
use App\Models\Tabelas\Constants;
use App\Models\Util\Modalidade;
use App\Models\Util\Nivel;
use App\Queries\PlanejamentoQuery;
use App\Queries\Tabelas\Ensino\EnsinoAulaQuery;
use Illuminate\Database\Eloquent\Factories\HasFactory;
......@@ -28,15 +30,7 @@ class EnsinoAula extends Model
*
* @var array
*/
protected $fillable = ['user_pad_id', 'cod_atividade', 'componente_curricular', 'curso', 'nivel', 'modalidade', 'ch_semanal', 'ch_total'];
public function nivelAsString() {
return Constants::listNivel($this->nivel);
}
public function modalidadeAsString() {
return Constants::listModalidade($this->modalidade);
}
protected $fillable = ['user_pad_id', 'dimensao', 'cod_atividade', 'componente_curricular', 'curso', 'nivel', 'modalidade', 'ch_semanal', 'ch_total'];
/**
* cod_dimensao from planejamento table
......@@ -60,17 +54,6 @@ class EnsinoAula extends Model
];
}
/*
'user_pad_id',
'cod_atividade',
'componente_curricular',
'curso',
'nivel',
'modalidade',
'ch_semanal',
'ch_total'
*/
public static function rules()
{
return [
......@@ -95,6 +78,16 @@ class EnsinoAula extends Model
];
}
public function nivelAsString()
{
return Nivel::listNivel($this->nivel);
}
public function modalidadeAsString()
{
return Modalidade::listModalidade($this->modalidade);
}
/**
* Get PAD with pad.id = ensino_aulas.pad_id
*
......
......@@ -15,15 +15,6 @@ class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;
const TYPE_ADMIN = 1; // Administrador
const TYPE_TEACHER = 2; // Professor
const TYPE_DIRECTOR= 3; // Diretor
const TYPE_COORDINATOR = 4; // Coordenador
const STATUS_ACTIVE = 1;
const STATUS_INACTIVE = 2;
const STATUS_DELETED = 0;
protected $table = "users";
/**
......@@ -31,7 +22,7 @@ class User extends Authenticatable
*
* @var array<int, string>
*/
protected $fillable = ['name', 'email', 'password', 'document', 'type', 'status', 'curso_id', 'campus_id'];
protected $fillable = ['name', 'email', 'password', 'document', 'status', 'curso_id', 'campus_id'];
/**
* The attributes that should be hidden for serialization.
......@@ -101,42 +92,53 @@ class User extends Authenticatable
}
public function perfis()
{
return $this->hasMany(UserType::class);
}
/**
* @return bool
* @return UserType|Null
*/
public function isTypeAdmin() {
return $this->type === self::TYPE_ADMIN;
public function perfilSelected()
{
return $this->perfis()->where('selected', true)->first();
}
/**
* @return bool
*/
public function isTypeTeacher() {
return $this->type === self::TYPE_TEACHER;
public function isTypeAdmin()
{
return $this->perfilSelected()->type === UserType::ADMIN;
}
/**
* @return bool
*/
public function isTypeDirector() {
return $this->type === self::TYPE_DIRECTOR;
public function isTypeTeacher()
{
return $this->perfilSelected()->type === UserType::TEACHER;
}
/**
* @return bool
*/
public function isTypeCoordinator() {
return $this->type === self::TYPE_COORDINATOR;
public function isTypeDirector()
{
return $this->perfilSelected()->type === UserType::DIRECTOR;
}
/**
* @return string
* @return bool
*/
public function attributeName(string $attribute) {
return $this->getTable() . '-' . $attribute;
public function isTypeCoordinator()
{
return $this->perfilSelected()->type === UserType::COORDINATOR;
}
public static function find() {
public static function initQuery()
{
return new UserQuery(get_called_class());
}
......
......@@ -22,7 +22,7 @@ class UserPad extends Model
return $this->belongsTo(PAD::class);
}
public static function find() {
public static function initQuery() {
return new UserPadQuery(get_called_class());
}
}
<?php
namespace App\Models;
use App\Models\Util\Status;
use App\Queries\UserTypeQuery;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class UserType extends Model
{
const ADMIN = 1; // Administrador
const TEACHER = 2; // Professor
const DIRECTOR= 3; // Diretor
const COORDINATOR = 4; // Coordenador
protected $table = 'user_type';
protected $fillable = ['user_id', 'type', 'status', 'selected'];
public function user()
{
return $this->belongsTo(User::class);
}
public function typeAsString()
{
return self::listType($this->type);
}
public function statusAsString()
{
return Status::listStatus($this->status);
}
public function initQuery()
{
return new UserTypeQuery(get_called_class());
}
public static function listType($value = null) {
$values = [
self::ADMIN => 'Administrador',
self::TEACHER => 'Professor',
self::DIRECTOR=> 'Diretor',
self::COORDINATOR => 'Coordenador',
];
return $value !== null? $values[$value] : $values;
}
}
<?php
namespace App\Models\Util;
class Avaliacao
{
const ENSINO_AULA = 1;
const ENSINO_COORDENACAO_DISCIPLINA = 2;
const ENSINO_ORIENTACAO = 3;
const ENSINO_SUPERVISAO = 4;
const ENSINO_ATENDIMENTO_DISCENTE = 5;
const ENSINO_PROJETO = 6;
const ENSINO_PARTICIPACAO = 7;
const ENSINO_COORDENACAO_DOCENT = 8;
}
\ No newline at end of file
<?php
namespace App\Models\Util;
class Dimensao
{
const ENSINO = 1;
const PESQUISA = 2;
const EXTENSAO = 3;
const GESTAO = 4;
const ANEXO = 5;
public static function listDimensao($value = null) {
$values = [
self::ENSINO => 'Ensino',
self::PESQUISA => 'Pesquisa',
self::EXTENSAO => 'Extensão',
self::GESTAO => 'Gestão',
self::ANEXO => 'Anexo',
];
return $value !== null? $values[$value] : $values;
}
}
<?php
namespace App\Models\Util;
class Funcao
{
const COORDENADOR = 1;
const COLABORADOR = 2;
const ORIENTADOR = 4;
const CO_ORIENTADOR = 5;
const MEMBRO = 6;
/**
* @return array|string
*/
public static function listFuncaoEnsino($value = null) {
$values = [
self::COORDENADOR => 'Coordenador',
self::MEMBRO => 'Membro',
];
return $value !== null? $values[$value] : $values;
}
/**
* @return array|string
*/
public static function listFuncaoOrientador($value = null) {
$values = [
self::ORIENTADOR => 'Orientador',
self::CO_ORIENTADOR => 'Coorientador',
];
return $value !== null? $values[$value] : $values;
}
/**
* @return array|string
*/
public static function listFuncaoProjeto($value = null) {
$values = [
self::COORDENADOR => 'Coordenador',
self::COLABORADOR => 'Colaborador',
];
return $value !== null? $values[$value] : $values;
}
}
<?php
namespace App\Models\Util;
class Modalidade
{
const EAD = 1;
const PRESENCIAL = 2;
/**
* @return array|string
*/
public static function listModalidade($value = null) {
$values = [
self::EAD => 'EAD',
self::PRESENCIAL => 'Presencial',
];
return $value !== null? $values[$value] : $values;
}
}
<?php
namespace App\Models\Util;
class Natureza
{
const INOVACAO = 1;
const PEDAGOGICA = 2;
const VIVENCIA = 4;
const OUTROS = 5;
/**
* @return array|string
*/
public static function listNatureza($value = null) {
$values = [
self::INOVACAO => 'Inovação',
self::PEDAGOGICA => 'Pedagógica',
self::VIVENCIA => 'Vivência',
self::OUTROS => 'Outros'
];
return $value !== null? $values[$value] : $values;
}
}
<?php
namespace App\Models\Util;
class Nivel
{
const GRADUACAO = 1;
const POS_GRADUACAO_LATO_SENSU = 2;
const POS_GRADUACAO_STRICTO_SENSU = 3;
/**
* @return array|string
*/
public static function listNivel($value = null) {
$values = [
self::GRADUACAO => 'Graduação',
self::POS_GRADUACAO_LATO_SENSU => 'Pós-graduação Stricto Sensu',
self::POS_GRADUACAO_STRICTO_SENSU => 'Pós-Graduação Lato Sensu',
];
return $value !== null? $values[$value] : $values;
}
}
<?php
namespace App\Models\Util;
class Orientacao
{
const GRUPO = 1;
const INDIVIDUAL = 2;
/**
* @return array|string
*/
public static function listOrientacao($value = null) {
$values = [
self::GRUPO => 'Grupo',
self::INDIVIDUAL => 'Individual',
];
return $value !== null? $values[$value] : $values;
}
}
<?php
namespace App\Models\Util;
class Status
{
const ATIVO = 1;
const INATIVO = 2;
const PENDENTE = 3;
const ARQUIVADO = 4;
public static function listStatus($value = null) {
$values = [
self::ATIVO => 'Ativo',
self::INATIVO => 'Inativo',
self::PENDENTE => 'Pendente',
self::ARQUIVADO => 'Arquivado',
];
return $value !== null? $values[$value] : $values;
}
}
......@@ -17,9 +17,9 @@ class UserPadQuery extends CustomQuery
* @param integer $id
* @return UserPadQuery|Builder
*/
public function whereId($id, $expression = '=')
public function whereId($id, $operator = '=')
{
$this->query = $this->query->where('id', $expression, $id);
$this->query = $this->query->where('id', $operator, $id);
return self::$instance;
}
......@@ -27,9 +27,9 @@ class UserPadQuery extends CustomQuery
* @param integer $user_id
* @return UserPadQuery|Builder
*/
public function whereUser($user_id, $expression = '=')
public function whereUser($user_id, $operator = '=')
{
$this->query = $this->query->where('user_id', $expression, $user_id);
$this->query = $this->query->where('user_id', $operator, $user_id);
return self::$instance;
}
......@@ -37,9 +37,9 @@ class UserPadQuery extends CustomQuery
* @param integer $pad_id
* @return UserPadQuery|Builder
*/
public function wherePad($pad_id, $expression = '=')
public function wherePad($pad_id, $operator = '=')
{
$this->query = $this->query->where('pad_id', $expression, $pad_id);
$this->query = $this->query->where('pad_id', $operator, $pad_id);
return self::$instance;
}
......@@ -47,11 +47,11 @@ class UserPadQuery extends CustomQuery
* @param integer $status
* @return UserPadQuery|Builder
*/
public function wherePadStatus($status, $expression = '=') {
public function wherePadStatus($status, $operator = '=') {
$this->query =
$this->query
->leftJoin('pad', 'user_pad.pad_id', '=', 'pad.id')
->where('pad.status', $expression, $status);
->where('pad.status', $operator, $status);
return self::$instance;
}
......
......@@ -18,20 +18,33 @@ class UserQuery extends CustomQuery
* @param integer $id
* @return UserQuery|Builder
*/
public function whereId($id, $expression = '=')
public function whereId($id, $operator = '=')
{
$this->query = $this->query->where('id', $expression, $id);
$this->query = $this->query->where('id', $operator, $id);
return self::$instance;
}
/**
* @param integer $type
* @param integer $email
* @return UserQuery|Builder
*/
public function whereType($type, $expression = '=')
{
$this->query = $this->query->where('type', $expression, $type);
public function whereEmail($email, $operator = 'LIKE')
{
$this->query = $this->query->where('email', $operator, $email);
return self::$instance;
}
/**
* @param integer $type
* @return UserQuery|Builder
*/
public function whereType($type, $operator = '=')
{
$this->query =
$this->query
->join('user_type', 'users.id', '=', 'user_type.user_id')
->where('type', $operator, $type);
return self::$instance;
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment