Skip to content

Commit

Permalink
Issue #290 - Making teachers enrollment to process asynchronous and r…
Browse files Browse the repository at this point in the history
…efactoring
  • Loading branch information
italopaiva committed Feb 4, 2017
1 parent e86a313 commit e9389e2
Show file tree
Hide file tree
Showing 11 changed files with 514 additions and 318 deletions.
5 changes: 3 additions & 2 deletions application/config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,12 @@
$route['download_notice/(:num)/(:num)'] = 'program/selectiveprocess/downloadNotice/$1/$2';
$route['define_dates_page/(:num)/(:num)'] = 'program/selectiveprocess/loadDefineDatesPage/$1/$2';
$route['define_dates/(:num)/(:num)'] = 'program/selectiveprocess/defineDates/$1/$2';
$route['selection_process/define_teachers/(:num)/(:num)'] = 'program/selectiveprocess/defineTeachers/$1/$2';
$route['selection_process/define_teacher/(:num)/(:num)/(:num)'] = 'program/selectiveprocess/defineTeacher/$1/$2/$3';
$route['selection_process/define_teacher'] = 'program/selectiveprocess/addTeacherToProcess';
$route['selection_process/remove_teacher'] = 'program/selectiveprocess/removeTeacherFromProcess';
$route['selection_process/divulgations/(:num)'] = 'program/selectiveprocess/divulgations/$1';
$route['selection_process/download_divulgation_file/(:num)'] = 'program/selectiveprocess/downloadDivulgationFile/$1';


/*
* Enrollment routes
*/
Expand Down
99 changes: 68 additions & 31 deletions application/modules/program/controllers/Selectiveprocess.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,6 @@ public function index() {
loadTemplateSafelyByPermission(PermissionConstants::SELECTION_PROCESS_PERMISSION, "program/selection_process/index", $data);
}

public function defineTeachers($processId, $programId){

$session = getSession();
$user = $session->getUserData();
$secretaryId = $user->getId();

$this->load->model('program/program_model');
$programsTeachers = $this->program_model->getProgramTeachers($programId);

$data = array(
'teachers' => $programsTeachers,
'processId' => $processId,
'programId' => $programId
);

loadTemplateSafelyByPermission(PermissionConstants::SELECTION_PROCESS_PERMISSION, "program/selection_process/define_teachers", $data);
}

public function defineTeacher($processId, $teacherId, $programId){
$self = $this;
withPermission(PermissionConstants::SELECTION_PROCESS_PERMISSION,
function() use ($self, $processId, $teacherId, $programId){
$self->process_model->addTeacherToProcess($processId, $teacherId);
getSession()->showFlashMessage("success", "Docente vinculado com sucesso!");
redirect("selection_process/define_teachers/{$processId}/{$programId}");
}
);
}

public function programCourses($programId){

$session = getSession();
Expand Down Expand Up @@ -359,9 +330,59 @@ private function getCourseSelectiveProcesses($courseId){
return $selectiveProcesses;
}

public function addTeacherToProcess(){
$processId = $this->input->post('processId');
$teacherId = $this->input->post('teacherId');
$programId = $this->input->post('programId');
$self = $this;
withPermission(PermissionConstants::SELECTION_PROCESS_PERMISSION,
function() use ($self, $processId, $teacherId, $programId){
$self->process_model->addTeacherToProcess($processId, $teacherId);
$self->updateDefineTeacherTables($processId, $programId);
}
);
}

public function edit($processId, $courseId){
public function removeTeacherFromProcess(){
$processId = $this->input->post('processId');
$teacherId = $this->input->post('teacherId');
$programId = $this->input->post('programId');
$self = $this;
withPermission(PermissionConstants::SELECTION_PROCESS_PERMISSION,
function() use ($self, $processId, $teacherId, $programId){
$self->process_model->removeTeacherFromProcess($processId, $teacherId);
$self->updateDefineTeacherTables($processId, $programId);
}
);
}

private function updateDefineTeacherTables($processId, $programId){
$data = $this->getDefineTeachersViewData($processId, $programId);
$teachers = $data['teachers'];
$processTeachers = $data['processTeachers'];
include(MODULESPATH.'program/views/selection_process/define_teachers_tables.php');
}

private function getDefineTeachersViewData($processId, $programId){

$session = getSession();
$user = $session->getUserData();
$secretaryId = $user->getId();

$this->load->model('program/program_model');
$programsTeachers = $this->program_model->getProgramTeachers($programId);

$processTeachers = $this->process_model->getProcessTeachers($processId);

$data = array(
'teachers' => $programsTeachers,
'processTeachers' => $processTeachers
);

return $data;
}

private function getEditProcessViewData($processId, $courseId){
$selectiveProcess = $this->process_model->getById($processId);
$this->load->module("program/phase");
$allPhases = $this->phase->getAllPhases();
Expand All @@ -374,15 +395,31 @@ public function edit($processId, $courseId){

$divulgation = $this->process_model->getProcessDivulgations($processId, TRUE);

$data = array(
$editProcessData = array(
'selectiveprocess' => $selectiveProcess,
'processId' => $processId,
'courseId' => $courseId,
'phasesNames' => $phases['phasesNames'],
'phasesWeights' => $phases['phasesWeights'],
'noticeFileName' => $noticeFileName,
'divulgation' => $divulgation
);

return $editProcessData;
}

public function edit($processId, $courseId){

$editProcessData = $this->getEditProcessViewData($processId, $courseId);

$this->load->model("program/course_model");
$course = $this->course_model->getCourseById($courseId);
$defineTeacherData = $this->getDefineTeachersViewData($processId, $course['id_program']);

$data = $editProcessData + $defineTeacherData;

$data['programId'] = $course['id_program'];

loadTemplateSafelyByPermission(PermissionConstants::SELECTION_PROCESS_PERMISSION, "program/selection_process/edit", $data);
}

Expand Down
2 changes: 1 addition & 1 deletion application/modules/program/models/Program_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function getSecretaryPrograms($secretaryId){
}

public function getProgramTeachers($program){
$this->db->select('users.id, users.name, users.name, users.email, program.program_name');
$this->db->select('users.id, users.name, users.name, users.email');
$this->db->from('users');
$this->db->join('teacher_course', 'users.id = teacher_course.id_user');
$this->db->join('course', 'teacher_course.id_course = course.id_course');
Expand Down
17 changes: 17 additions & 0 deletions application/modules/program/models/Selectiveprocess_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,4 +423,21 @@ public function addTeacherToProcess($processId, $teacherId){
'id_teacher' => $teacherId
]);
}

public function removeTeacherFromProcess($processId, $teacherId){
$this->db->delete("teacher_selection_process", [
'id_process' => $processId,
'id_teacher' => $teacherId
]);
}

public function getProcessTeachers($processId){
$this->db->select('users.id, users.name, users.email');
$this->db->from('users');
$this->db->join('teacher_selection_process', 'users.id = teacher_selection_process.id_teacher');
$this->db->where('teacher_selection_process.id_process', $processId);
$teachers = checkArray($this->db->get()->result_array());

return $teachers;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@


<div align='right'>
<i class='fa fa-eye'> Visualizar </i> &nbsp&nbsp
<i class='fa fa-edit'> Editar </i> &nbsp&nbsp
<i class='fa fa-calendar'> Definir datas </i> &nbsp&nbsp
<i class='fa fa-group'> Definir docentes </i> &nbsp&nbsp
<i class='fa fa-bullhorn'> Divulgações </i>
<i class='fa fa-eye'> Visualizar </i> &nbsp&nbsp
<i class='fa fa-edit'> Editar </i> &nbsp&nbsp
<i class='fa fa-calendar'> Definir datas </i> &nbsp&nbsp
<i class='fa fa-bullhorn'> Divulgações </i>
</div>

<?php
Expand Down Expand Up @@ -57,8 +56,6 @@
echo anchor("edit_selection_process/{$processId}/{$course[Course_model::ID_ATTR]}", "<i class='fa fa-edit'></i>", "class='btn btn-primary'");
echo "&nbsp";
echo anchor("define_dates_page/{$processId}/{$course[Course_model::ID_ATTR]}", "<i class='fa fa-calendar'></i>", "class='btn btn-warning'");
echo "&nbsp";
echo anchor("selection_process/define_teachers/{$processId}/{$course['id_program']}", "<i class='fa fa-group'></i>", "class='btn btn-info'");

echo "&nbsp";
echo anchor("selection_process/divulgations/{$processId}", "<i class='fa fa-bullhorn'></i>", "class='btn bg-olive'");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,50 @@
<h2 class="principal">Vincular docentes ao processo seletivo </h2>

<?php buildTableDeclaration(); ?>
<?php
buildTableHeaders([
'Nome',
'E-mail',
'Programa',
'Ações'
]);
?>
<div id="define_teachers_tables" class="row">
<?php include('define_teachers_tables.php'); ?>;
</div>

<?php if(!empty($teachers)): ?>
<?php foreach ($teachers as $teacher): ?>
<style type="text/css">
#add_teachers_to_process_table, #teachers_added_to_process_table {
height: 400px;
overflow-y: auto;
}
</style>

<tr>
<td><?= $teacher['name'] ?></td>
<td><?= $teacher['email'] ?></td>
<td><?= $teacher['program_name'] ?></td>
<td>
<?= anchor(
"selection_process/define_teacher/{$processId}/{$teacher['id']}/{$programId}",
"<i class='fa fa-plus'></i> Vincular docente",
"class='btn btn-primary'"
) ?>
</td>
</tr>
<script>
function addTeacherToProcess(event, processId, teacherId, programId){
event.preventDefault();

<?php endforeach ?>
<?php else: ?>
<?= callout('info', 'Nenhum docente cadastrado nos cursos deste programa.') ?>
<?php endif ?>
var siteUrl = $("#site_url").val();
var urlToPost = siteUrl + "/selection_process/define_teacher"
$.post(
urlToPost,
{
processId: processId,
teacherId: teacherId,
programId: programId
},
function(data){
$("#define_teachers_tables").html(data);
}
);
}

<?php buildTableEndDeclaration(); ?>
function removeTeacherFromProcess(event, processId, teacherId, programId){
event.preventDefault();

var siteUrl = $("#site_url").val();
var urlToPost = siteUrl + "/selection_process/remove_teacher"
$.post(
urlToPost,
{
processId: processId,
teacherId: teacherId,
programId: programId
},
function(data){
$("#define_teachers_tables").html(data);
}
);
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?= "<h4><i class='fa fa-list'></i> Docentes do programa:</h4>" ?>

<?php if(!empty($teachers)): ?>

<?php buildTableDeclaration("add_teachers_to_process_table");

buildTableHeaders([
'Nome',
'E-mail',
'Ações'
]);
?>

<?php foreach ($teachers as $teacher): ?>

<tr>
<td><?= $teacher['name'] ?></td>
<td><?= $teacher['email'] ?></td>
<td>
<?php if(!$processTeachers || !in_array($teacher, $processTeachers)): ?>
<?= anchor(
"#",
"<i class='fa fa-plus'></i> Vincular docente",
"class='btn btn-primary' onClick='addTeacherToProcess(event, {$processId}, {$teacher['id']}, {$programId});'"
) ?>
<?php else: ?>
<?= "<span class='label label-success'>Docente vinculado!</span>" ?>
<?php endif; ?>
</td>
</tr>

<?php endforeach ?>

<?php buildTableEndDeclaration(); ?>
<?php else: ?>
<?= callout('info', 'Nenhum docente cadastrado nos cursos deste programa.') ?>
<?php endif ?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?= "<h4><i class='fa fa-plus-square'></i> Docentes adicionados ao processo:</h4>" ?>


<?php if(!empty($processTeachers)): ?>

<?php buildTableDeclaration("teachers_added_to_process_table");
buildTableHeaders([
'Nome',
'E-mail',
'Ações'
]);
?>

<?php foreach ($processTeachers as $teacher): ?>

<tr>
<td><?= $teacher['name'] ?></td>
<td><?= $teacher['email'] ?></td>
<td>
<?= anchor(
"#",
"<i class='fa fa-minus'></i> Desvincular docente",
"class='btn btn-danger' onClick='removeTeacherFromProcess(event, {$processId}, {$teacher['id']}, {$programId});'"
) ?>
</td>
</tr>

<?php endforeach ?>

<?php buildTableEndDeclaration(); ?>

<?php else: ?>
<?= callout('info', 'Nenhum docente vinculado a este processo.') ?>
<?php endif ?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="col-md-6">
<?php
call_user_func(function() use($teachers, $processTeachers, $processId, $programId){
include('define_teachers_add_table.php');
});
?>
</div>
<div class="col-md-6">
<?php
call_user_func(function() use($processTeachers, $processId, $programId){
include('define_teachers_remove_table.php');
});
?>
</div>
Loading

0 comments on commit e9389e2

Please sign in to comment.