Skip to content

Commit

Permalink
Issue #303 - Creating change phase process
Browse files Browse the repository at this point in the history
  • Loading branch information
italopaiva committed May 1, 2017
1 parent 86af2d2 commit 8c801d2
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 19 deletions.
39 changes: 24 additions & 15 deletions application/modules/program/controllers/Selectiveprocess.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private function getCourseSelectiveProcesses($courseId){

if($selectionProcess !== FALSE){
$statusByDate = getProcessStatusByDate($selectionProcess);
$selectionProcess = $statusByDate != $process['status']
$selectionPtrocess = $statusByDate != $process['status']
? $this->changeProcessStatus($selectionProcess, $statusByDate)
: $selectionProcess;
$selectiveProcesses[] = $selectionProcess;
Expand Down Expand Up @@ -335,26 +335,35 @@ private function changeProcessStatus($selectionProcess, $statusByDate){
}

public function goToNextPhase($processId, $courseId){

$self = $this;
withPermissionAnd(
PermissionConstants::SELECTION_PROCESS_PERMISSION,
function() use ($self, $processId, $courseId){
function() use ($self, $courseId){
return checkIfUserIsSecretary($courseId);
},
function() use ($self, $processId, $courseId){
$statusByDate = $self->input->post("suggested_phase");
$changed = $self->process_model->changeProcessStatus($processId, $statusByDate);
if($changed){
$type = "success";
$message = "O processo foi avançado com sucesso.";
}
else{
$type = "danger";
$message = "Não foi possível passar para a próxima fase. Tente novamente.";

$self->load->service(
'program/SelectiveProcessPhaseChange',
'phase_change_service'
);

try{
$changed = $self
->phase_change_service
->changeProcessPhase($processId, $statusByDate);

$type = $changed ? "success" : "danger";
$message = $changed
? "O processo foi avançado com sucesso."
: "Não foi possível passar para a próxima fase. Tente novamente.";

getSession()->showFlashMessage($type, $message);
$self->courseSelectiveProcesses($courseId);
} catch (SelectionProcessException $e) {

}
getSession()->showFlashMessage($type, $message);
$self->courseSelectiveProcesses($courseId);
}
);

Expand Down Expand Up @@ -421,8 +430,8 @@ public function generatePDF(){
$data = array(
'candidates' => json_decode($candidates),
'phaseName' => $this->input->post('phaseName'),
'processName' => $process->getName(),
'processId' => $process->getId()
'processName' => $process->getName(),
'processId' => $process->getId()
);

loadTemplateSafelyByPermission(PermissionConstants::SELECTION_PROCESS_PERMISSION, "program/selection_process/phase_result", $data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,7 @@ public function getUserParticipatingProcesses($userId){

public function changeProcessStatus($processId, $newStatus){
$this->db->where('id_process', $processId);
$changed = $this->db->update($this->TABLE, ['status' => $newStatus]);

return $changed;
return $this->db->update($this->TABLE, ['status' => $newStatus]);
}

private function convertProcessesInObjects($processes){
Expand Down
136 changes: 136 additions & 0 deletions application/modules/program/services/SelectionProcessPhaseChange.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require_once(APPPATH.'exception/SelectionProcessException.php');
require_once(MODULESPATH."/program/constants/SelectionProcessConstants.php");

class SelectionProcessPhaseChange extends CI_Model {

public function __construct(){
parent::__construct();
$this->load->model(
'program/selectiveProcess_model',
'process_model'
);
$this->load->model(
'program/selectiveProcessSubscription_model',
'process_subscription_model'
);
$this->load->module("notification/notification");
}

/**
* @throws SelectionProcessException when invalid status is present on process
*/
public function changeProcessPhase($processId, $newStatus){
$process = $this->process_model->getById($processId);

if($process === FALSE){
throw new SelectionProcessException('Invalid process.');
}

$currentStatus = $process->getStatus();
switch($currentStatus){
case SelectionProcessConstants::DISCLOSED:
// It is going to subscription phase
assert(
$newStatus == SelectionProcessConstants::OPEN_FOR_SUBSCRIPTIONS,
'After process is disclosed,, the next phase should be subscription.'
);
$this->changeToSusbcriptionPhase($process);
break;

case SelectionProcessConstants::OPEN_FOR_SUBSCRIPTIONS:
// It is going to homologation phase
assert(
$newStatus == SelectionProcessConstants::IN_HOMOLOGATION_PHASE,
'After subscriptions, the next phase should be homologation.'
);
$this->changeToHomologationPhase($process);
break;

case SelectionProcessConstants::IN_HOMOLOGATION_PHASE:
$this->checkNextPhase($process, $newStatus);
$this->changeToStatus($process, $newStatus);
$this->notifyHomologationIsOver($process, $newStatus);
break;

case SelectionProcessConstants::IN_PRE_PROJECT_PHASE:
$this->checkNextPhase($process, $newStatus);
$this->changeToStatus($process, $newStatus);
$this->notifyPreProjectIsOver($process, $newStatus);
break;

case SelectionProcessConstants::IN_WRITTEN_TEST_PHASE:
$this->checkNextPhase($process, $newStatus);
$this->changeToStatus($process, $newStatus);
$this->notifyWrittenTestIsOver($process, $newStatus);
break;

case SelectionProcessConstants::IN_ORAL_TEST_PHASE:
$this->checkNextPhase($process, $newStatus);
$this->changeToStatus($process, $newStatus);
$this->notifyOralTestIsOver($process, $newStatus);
break;

default:
throw new SelectionProcessException('Invalid status for process.');
break;
}
}

private function changeToSusbcriptionPhase($process){
$this->process_model->changeProcessStatus(
$process->getId(),
SelectionProcessConstants::OPEN_FOR_SUBSCRIPTIONS
);
}

private function changeToHomologationPhase($process){
$this->process_model->changeProcessStatus(
$process->getId(),
SelectionProcessConstants::IN_HOMOLOGATION_PHASE
);
}

private function changeToStatus($process, $newStatus){
$this->process_model->changeProcessStatus(
$process->getId(),
$newStatus
);
}

private notifyHomologationIsOver($process, $newStatus){

}

private notifyPreProjectIsOver($process, $newStatus){

}

private notifyWrittenTestIsOver($process, $newStatus){

}

private notifyOralTestIsOver($process, $newStatus){

}

private function checkNextPhase($process, $newStatus){
// It should be going to next phase in process order
$phasesOrder = $process->getSettings()->getPhasesOrder();

// If the next phase is to finalize the process, this checks does not apply
if($newStatus !== SelectionProcessConstants::FINISHED){
// The new phase should be in phases order array
$phaseName = str_replace('_phase', '', $newStatus);
assert(
in_array($phaseName, $phasesOrder),
"The new phase '{$phaseName}' should be in phases order array"
);

// $newStatus should be after the homologation phase in phases order
$homologationIndex = array_search("homologation", $phasesOrder);
assert($newStatus == $processOrder[intval($homologationIndex) + 1]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ function createNextPhaseModal($process){
));
};
$processName = $process->getName();
newModal("nextphasemodal".$processId, "Passar para a próxima fase</b>", $body, $footer, $formPath);
newModal("nextphasemodal".$processId, "Passar para a próxima fase", $body, $footer, $formPath);
}

?>

0 comments on commit 8c801d2

Please sign in to comment.