/** * * @return int|bool */ public function clientToClass() { $dbAdapter = Zend_Db_Table_Abstract::getDefaultAdapter(); $dbAdapter->beginTransaction(); try { $dbActionPlan = App_Model_DbTable_Factory::get('Action_Plan'); $dbActionPlanBarrier = App_Model_DbTable_Factory::get('Action_Plan_Barrier'); $dbStudentClassCandidates = App_Model_DbTable_Factory::get('StudentClass_Candidates'); $dbPersonHistory = App_Model_DbTable_Factory::get('Person_History'); $dbActionPlanReferences = App_Model_DbTable_Factory::get('Action_Plan_References'); $clients = array(); $casesClient = array(); // Fetch the clients related to the case $rows = $dbActionPlan->fetchAll(array('id_action_plan IN (?)' => $this->_data['cases'])); foreach ($rows as $row) { $clients[] = $row->fk_id_perdata; $casesClient[$row->fk_id_perdata] = $row->id_action_plan; } // Fetch the class $mapperStudentClass = new StudentClass_Model_Mapper_StudentClass(); $studentClass = $mapperStudentClass->fetchRow($this->_data['idClass']); if ($studentClass->active != 1) { $this->_message->addMessage('Klase Formasaun ida ne\'e taka tiha ona, la bele tau kliente iha lista kandidatu.', App_Message::ERROR); return false; } $where = array('fk_id_fefpstudentclass = ?' => $this->_data['idClass']); $rows = $dbStudentClassCandidates->fetchAll($where); $clientsCandidates = array(); foreach ($rows as $row) { $clientsCandidates[] = $row->fk_id_perdata; } $newClients = array_diff($clients, $clientsCandidates); // If all the candidates are already in candidate list if (empty($newClients)) { $this->_message->addMessage('Kliente hotu iha Lista Kandidatu tiha ona ba klase formasaun ida ne\'e.', App_Message::ERROR); return false; } // Insert all the clients in the candidate list foreach ($newClients as $client) { // Add the client to the list candidates $row = $dbStudentClassCandidates->createRow(); $row->fk_id_fefpstudentclass = $this->_data['idClass']; $row->fk_id_perdata = $client; $row->fk_id_sysuser = Zend_Auth::getInstance()->getIdentity()->id_sysuser; $row->shortlisted = 0; $row->source = 'C'; $row->save(); // Save history to client $rowHistory = $dbPersonHistory->createRow(); $rowHistory->fk_id_perdata = $client; $rowHistory->fk_id_student_class = $this->_data['idClass']; $rowHistory->fk_id_sysuser = Zend_Auth::getInstance()->getIdentity()->id_sysuser; $rowHistory->fk_id_dec = Zend_Auth::getInstance()->getIdentity()->fk_id_dec; $rowHistory->date_time = Zend_Date::now()->toString('yyyy-MM-dd HH:mm'); $rowHistory->action = sprintf('KLIENTE SELECIONADO BA LISTA KANDIDATU TURMA TREINAMENTU NUMERO: %s ', $this->_data['idClass']); $rowHistory->description = 'KLIENTE SELECIONADO BA LISTA KANDIDATU TURMA TREINAMENTU NUMERO'; $rowHistory->save(); // Save the auditing $history = sprintf('KLIENTE BA LISTA KANDIDATU: %s - BA TURMA TREINAMENTU NUMERU: %s ', $client, $this->_data['idClass']); $this->_sysAudit($history); $whereBarrier = array('fk_id_action_plan = ?' => $casesClient[$client], 'fk_id_barrier_intervention = ?' => $this->_data['intervention']); $barrier = $dbActionPlanBarrier->fetchRow($whereBarrier); // Insert the reference to the action barrier $rowReference = $dbActionPlanReferences->createRow(); $rowReference->fk_id_perdata = $client; $rowReference->fk_id_action_plan = $casesClient[$client]; $rowReference->fk_id_action_barrier = $barrier->id_action_barrier; $rowReference->fk_id_sysuser = Zend_Auth::getInstance()->getIdentity()->id_sysuser; $rowReference->fk_id_fefpstudentclass = $this->_data['idClass']; $rowReference->save(); } $dbAdapter->commit(); return $this->_data['case_id']; } catch (Exception $e) { $dbAdapter->rollBack(); $this->_message->addMessage($this->_config->messages->error, App_Message::ERROR); return false; } }
/** * * @param type $idStudentClass * @return \App_View_Helper_StudentClassActive */ public function setStudentClass($idStudentClass) { $mapperStudentClass = new StudentClass_Model_Mapper_StudentClass(); $this->_studentClass = $mapperStudentClass->fetchRow($idStudentClass); return $this; }