Skip to content

Commit

Permalink
Issue #297 - Saving all documents to process on creation
Browse files Browse the repository at this point in the history
  • Loading branch information
italopaiva committed Apr 15, 2017
1 parent 2981156 commit 0505785
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 46 deletions.
1 change: 1 addition & 0 deletions application/config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
$route['selection_process/divulgations/(:num)'] = 'program/selectiveprocess/divulgations/$1';
$route['selection_process/download_divulgation_file/(:num)'] = 'program/selectiveprocess/downloadDivulgationFile/$1';
$route['selection_process/guest/(:num)'] = 'program/selectiveprocess/showTimeline/$1';
$route['selection_process/config/(:num)'] = 'program/selectiveprocessconfig/index/$1';


/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,45 +121,51 @@ public function newSelectionProcess(){
$process = $this->getDataToSave();

if($process !== FALSE){
// Finally saves the selection process
$this->load->model("selectiveprocess_model", "process_model");
try{
// Try to save the selection process
$processId = $this->process_model->save($process);

$processId = $this->process_model->save($process);
$courseId = $this->input->post("course");

if($process !== FALSE){
$noticeName = $process->getName();
callout("info", "O processo seletivo ".$noticeName." foi salvo com sucesso!", "Para finalizar o processo, faça o upload do edital em PDF logo abaixo.");

$courseId = $this->input->post("course");
$this->uploadNoticeFileForm($processId, $courseId);
}catch(SelectionProcessException $e){
callout("warning", $e->getMessage());
}
}
}

$hidden = array(
'selection_process_id' => base64_encode($processId),
'course' => $courseId
);
private function uploadNoticeFileForm($processId, $courseId){
$hidden = array(
'selection_process_id' => base64_encode($processId),
'course' => $courseId
);

echo form_open_multipart("program/selectiveprocess/saveNoticeFile");
echo form_open_multipart("program/selectiveprocess/saveNoticeFile");

echo form_hidden($hidden);
echo form_hidden($hidden);

$noticeFile = array(
"name" => "notice_file",
"id" => "notice_file",
"type" => "file"
);
$noticeFile = array(
"name" => "notice_file",
"id" => "notice_file",
"type" => "file",
"class" => "filestyle"
);

$submitFileBtn = array(
"id" => "open_selective_process_btn",
"class" => "btn btn-success btn-flat",
"content" => "Salvar arquivo",
"type" => "submit",
"style" => "margin-top: 5%;"
);
$submitFileBtn = array(
"id" => "open_selective_process_btn",
"class" => "btn btn-success btn-flat",
"content" => "Salvar arquivo",
"type" => "submit",
"style" => "margin-top: 5%;"
);

include(MODULESPATH."/program/views/selection_process/_upload_notice_file.php");
include(MODULESPATH."/program/views/selection_process/_upload_notice_file.php");

echo form_close();
echo "<br>";
}
echo form_close();
echo "<br>";
}

public function updateSelectionProcess(){
Expand Down
43 changes: 24 additions & 19 deletions application/modules/program/models/Selectiveprocess_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,33 @@ public function save($process){
$noticeName = $process->getName();
$previousProcess = $this->getByName($noticeName);


// Does not exists this selection process yet
if($previousProcess === FALSE){

// Saves the selection process basic data
$this->db->insert($this->TABLE, $processToSave);
$this->db->trans_start();

$savedProcess = $this->getByName($noticeName);
// Saves the selection process basic data
$this->db->insert($this->TABLE, $processToSave);

if($savedProcess !== FALSE){
$processId = $savedProcess[self::ID_ATTR];
$savedProcess = $this->getByName($noticeName);
$processId = $savedProcess[self::ID_ATTR];

$this->saveProcessPhases($process, $processId, self::INSERT_ON_DB);
$this->load->model(
'program/selectiveprocessconfig_model',
'process_config_model'
);

return $processId;
}else{
$this->saveProcessPhases($process, $processId, self::INSERT_ON_DB);
// By default, the process goes with all docs
$this->process_config_model->addAllDocumentsToProcess($processId);
$this->db->trans_complete();

if($this->db->trans_status() === FALSE){
// For some reason did not saved the selection process
throw new SelectionProcessException(self::COULDNT_SAVE_SELECTION_PROCESS);
}

return $processId;
}else{
throw new SelectionProcessException(self::REPEATED_NOTICE_NAME.$noticeName);
}
Expand Down Expand Up @@ -97,10 +105,8 @@ private function getArrayToSave($process){
$startDate = $settings->getYMDStartDate();
$endDate = $settings->getYMDEndDate();
$phasesOrder = serialize($settings->getPhasesOrder());

}


$processToSave = array(
self::COURSE_ATTR => $courseId,
self::PROCESS_TYPE_ATTR => $processType,
Expand All @@ -111,7 +117,6 @@ private function getArrayToSave($process){
);

return $processToSave;

}

private function saveProcessPhases($process, $processId, $method){
Expand Down Expand Up @@ -197,7 +202,7 @@ public function getById($processId){

$foundProcess = $this->get(self::ID_ATTR, $processId);
$selectiveProcess = $this->convertArrayToObject($foundProcess);

return $selectiveProcess;
}

Expand Down Expand Up @@ -371,7 +376,7 @@ public function getProcessDivulgationById($divulgationId){
$searchResult = $this->db->get_where('selection_process_divulgation', array('id' => $divulgationId));
$divulgation = $searchResult->row_array();
$divulgation = checkArray($divulgation);

return $divulgation;
}

Expand Down Expand Up @@ -450,12 +455,12 @@ public function getProcessTeachers($processId){

return $teachers;
}

public function getOpenSelectiveProcesses(){
$query = "SELECT DISTINCT selection_process.* FROM selection_process
JOIN selection_process_divulgation
ON ((selection_process_divulgation.date <= CURDATE())

$query = "SELECT DISTINCT selection_process.* FROM selection_process
JOIN selection_process_divulgation
ON ((selection_process_divulgation.date <= CURDATE())
AND (selection_process_divulgation.id_process = selection_process.id_process) AND (selection_process_divulgation.initial_divulgation = TRUE))
WHERE (selection_process.end_date >= CURDATE()) ORDER BY 'selection_process.id_course'";
$foundProcesses = $this->db->query($query)->result_array();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Selectiveprocessconfig_model extends CI_Model {

const AVAILABLE_DOCS_TABLE = "selection_process_available_docs";
const NEEDED_DOCS_TABLE = "selection_process_needed_docs";

public function addAllDocumentsToProcess($processId){
$allDocs = $this->getAvailableDocs();

foreach($allDocs as $doc){
$this->db->insert(self::NEEDED_DOCS_TABLE, [
'id_process' => $processId,
'id_doc' => $doc['id']
]);
}
}

public function getAvailableDocs(){
return $this->get(FALSE, FALSE, FALSE, FALSE, self::AVAILABLE_DOCS_TABLE);
}
}

0 comments on commit 0505785

Please sign in to comment.