1<?php 2 3/** 4 * OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures 5 * all the essential functionalities required for any enterprise. 6 * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com 7 * 8 * OrangeHRM is free software; you can redistribute it and/or modify it under the terms of 9 * the GNU General Public License as published by the Free Software Foundation; either 10 * version 2 of the License, or (at your option) any later version. 11 * 12 * OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 14 * See the GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License along with this program; 17 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * Boston, MA 02110-1301, USA 19 */ 20class TerminationReasonConfigurationDao extends BaseDao { 21 22 public function saveTerminationReason(TerminationReason $terminationReason) { 23 24 try { 25 $terminationReason->save(); 26 return $terminationReason; 27 } catch (Exception $e) { 28 throw new DaoException($e->getMessage(), $e->getCode(), $e); 29 } 30 31 } 32 33 public function getTerminationReason($id) { 34 35 try { 36 return Doctrine::getTable('TerminationReason')->find($id); 37 } catch (Exception $e) { 38 throw new DaoException($e->getMessage(), $e->getCode(), $e); 39 } 40 41 } 42 43 public function getTerminationReasonByName($name) { 44 45 try { 46 47 $q = Doctrine_Query::create() 48 ->from('TerminationReason') 49 ->where('name = ?', trim($name)); 50 51 return $q->fetchOne(); 52 53 } catch (Exception $e) { 54 throw new DaoException($e->getMessage(), $e->getCode(), $e); 55 } 56 57 } 58 59 public function getTerminationReasonList() { 60 61 try { 62 63 $q = Doctrine_Query::create()->from('TerminationReason') 64 ->orderBy('name'); 65 66 return $q->execute(); 67 68 } catch (Exception $e) { 69 throw new DaoException($e->getMessage(), $e->getCode(), $e); 70 } 71 72 } 73 74 public function deleteTerminationReasons($toDeleteIds) { 75 76 try { 77 78 $q = Doctrine_Query::create()->delete('TerminationReason') 79 ->whereIn('id', $toDeleteIds); 80 81 return $q->execute(); 82 83 } catch (Exception $e) { 84 throw new DaoException($e->getMessage(), $e->getCode(), $e); 85 } 86 87 } 88 89 public function isExistingTerminationReasonName($terminationReasonName) { 90 91 try { 92 93 $q = Doctrine_Query:: create()->from('TerminationReason rm') 94 ->where('rm.name = ?', trim($terminationReasonName)); 95 96 if ($q->count() > 0) { 97 return true; 98 } 99 100 return false; 101 102 } catch (Exception $e) { 103 throw new DaoException($e->getMessage(), $e->getCode(), $e); 104 } 105 106 } 107 108 public function isReasonInUse($idArray) { 109 110 $q = Doctrine_Query::create()->from('Employee em') 111 ->leftJoin('em.EmployeeTerminationRecord et') 112 ->leftJoin('et.TerminationReason tr') 113 ->whereIn('tr.id', $idArray); 114 115 $result = $q->fetchOne(); 116 117 if ($result instanceof Employee) { 118 return true; 119 } 120 121 return false; 122 123 } 124 125}