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