forked from opendocman/opendocman
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Department_class.php
66 lines (60 loc) · 2.35 KB
/
Department_class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/*
Department_class.php - Department class is an extended class of the abstract databaseData
class. The only difference is that it provides it's own constructor to handle its own
characteristics.
Copyright (C) 2002-2004 Stephen Lawrence Jr., Khoa Nguyen
Copyright (C) 2005-2015 Stephen Lawrence Jr.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
if (!defined('Department_class')) {
define('Department_class', 'true', false);
class Department extends databaseData
{
protected $connection;
/**
* @param int $id
* @param PDO $connection
*/
public function Department($id, PDO $connection)
{
$this->field_name = 'name';
$this->field_id = 'id';
$this->result_limit = 1; //there is only 1 department with a certain department_id and department_name
$this->tablename = $this->TABLE_DEPARTMENT;
databaseData::databaseData($id, $connection);
}
/**
* Function: getAllDepartments
* Get a list of department names and ids sorted by name
*
* @param PDO $pdo
* @returns array
*/
public static function getAllDepartments(PDO $pdo)
{
$departments = array();
$query = "SELECT name, id FROM {$GLOBALS['CONFIG']['db_prefix']}department ORDER by name";
$stmt = $pdo->prepare($query);
$stmt->execute();
$result = $stmt->fetchAll();
$count = 0;
foreach ($result as $row) {
$departments[$count]['id'] = $row['id'];
$departments[$count]['name'] = $row['name'];
$count++;
}
return $departments;
}
}
}