From 050578582d1698510d6203a70df6a1374211eb0e Mon Sep 17 00:00:00 2001 From: Italo Paiva Date: Sat, 15 Apr 2017 15:40:10 -0300 Subject: [PATCH] Issue #297 - Saving all documents to process on creation --- application/config/routes.php | 1 + .../controllers/ajax/Selectiveprocessajax.php | 60 ++++++++++--------- .../program/models/Selectiveprocess_model.php | 43 +++++++------ .../models/Selectiveprocessconfig_model.php | 22 +++++++ 4 files changed, 80 insertions(+), 46 deletions(-) create mode 100644 application/modules/program/models/Selectiveprocessconfig_model.php diff --git a/application/config/routes.php b/application/config/routes.php index beaea82e..be833424 100755 --- a/application/config/routes.php +++ b/application/config/routes.php @@ -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'; /* diff --git a/application/modules/program/controllers/ajax/Selectiveprocessajax.php b/application/modules/program/controllers/ajax/Selectiveprocessajax.php index 21662bf1..767143aa 100755 --- a/application/modules/program/controllers/ajax/Selectiveprocessajax.php +++ b/application/modules/program/controllers/ajax/Selectiveprocessajax.php @@ -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 "
"; - } + echo form_close(); + echo "
"; } public function updateSelectionProcess(){ diff --git a/application/modules/program/models/Selectiveprocess_model.php b/application/modules/program/models/Selectiveprocess_model.php index 6f2d9f0f..125ac8a3 100755 --- a/application/modules/program/models/Selectiveprocess_model.php +++ b/application/modules/program/models/Selectiveprocess_model.php @@ -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); } @@ -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, @@ -111,7 +117,6 @@ private function getArrayToSave($process){ ); return $processToSave; - } private function saveProcessPhases($process, $processId, $method){ @@ -197,7 +202,7 @@ public function getById($processId){ $foundProcess = $this->get(self::ID_ATTR, $processId); $selectiveProcess = $this->convertArrayToObject($foundProcess); - + return $selectiveProcess; } @@ -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; } @@ -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(); diff --git a/application/modules/program/models/Selectiveprocessconfig_model.php b/application/modules/program/models/Selectiveprocessconfig_model.php new file mode 100644 index 00000000..a1867489 --- /dev/null +++ b/application/modules/program/models/Selectiveprocessconfig_model.php @@ -0,0 +1,22 @@ +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); + } +}