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 LanguageDao extends BaseDao {
21
22    public function saveLanguage(Language $language) {
23
24        try {
25            $language->save();
26        } catch (Exception $e) {
27            throw new DaoException($e->getMessage(), $e->getCode(), $e);
28        }
29
30    }
31
32    public function getLanguageById($id) {
33
34        try {
35            return Doctrine::getTable('Language')->find($id);
36        } catch (Exception $e) {
37            throw new DaoException($e->getMessage(), $e->getCode(), $e);
38        }
39
40    }
41
42    public function getLanguageByName($name) {
43
44        try {
45
46            $q = Doctrine_Query::create()
47                                ->from('Language')
48                                ->where('name = ?', trim($name));
49
50            return $q->fetchOne();
51
52        } catch (Exception $e) {
53            throw new DaoException($e->getMessage(), $e->getCode(), $e);
54        }
55
56    }
57
58    public function getLanguageList() {
59
60        try {
61
62            $q = Doctrine_Query::create()->from('Language')
63                                         ->orderBy('name');
64
65            return $q->execute();
66
67        } catch (Exception $e) {
68            throw new DaoException($e->getMessage(), $e->getCode(), $e);
69        }
70
71    }
72
73    public function deleteLanguages($toDeleteIds) {
74
75        try {
76
77            $q = Doctrine_Query::create()->delete('Language')
78                            ->whereIn('id', $toDeleteIds);
79
80            return $q->execute();
81
82        } catch (Exception $e) {
83            throw new DaoException($e->getMessage(), $e->getCode(), $e);
84        }
85
86    }
87
88    public function isExistingLanguageName($languageName) {
89
90        try {
91
92            $q = Doctrine_Query:: create()->from('Language l')
93                            ->where('l.name = ?', trim($languageName));
94
95            if ($q->count() > 0) {
96                return true;
97            }
98
99            return false;
100
101        } catch (Exception $e) {
102            throw new DaoException($e->getMessage(), $e->getCode(), $e);
103        }
104
105    }
106
107}