/
CodeManager.php
73 lines (60 loc) · 1.89 KB
/
CodeManager.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
67
68
69
70
71
72
73
<?php
// Copyright (C) 2010-2011 Aron Racho <aron@mi-squred.com>
//
// 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.
/**
* Description of CodeManager
*
* @author aron
*/
class CodeManager {
const SQL_SELECT =
"SELECT id,
code,
code_text,
code_types.ct_key as code_type
FROM codes JOIN code_types on codes.code_type = code_types.ct_id";
const SQL_WHERE_SEARCH =
"WHERE id LIKE ? OR code_text LIKE ? OR code_text_short LIKE ? OR code LIKE ? OR code_types.ct_key LIKE ?";
const SQL_WHERE_GET =
"WHERE id = ?";
function __construct() {
}
/**
* Returns an array of Code
* @param string $searchTerm
*/
function search( $searchTerm ) {
$stmt = sqlStatement( self::SQL_SELECT . " " . self::SQL_WHERE_SEARCH,
array( "%$searchTerm%", "%$searchTerm%", "%$searchTerm%", "%$searchTerm%", "%$searchTerm%" ) );
$codes = array();
for($iter=0; $row=sqlFetchArray($stmt); $iter++) {
$code = new Code();
$code->code = $row['code'];
$code->text = $row['code_text'];
$code->id = $row['id'];
$code->codeType = $row['code_type'];
array_push( $codes, $code );
}
return $codes;
}
/**
* @return Code
*/
function get( $id ) {
$row = sqlQuery( self::SQL_SELECT . " " . self::SQL_WHERE_GET, array( $id ) );
if (!$row) {
return null;
}
$code = new Code();
$code->code = $row['code'];
$code->text = $row['code_text'];
$code->id = $row['id'];
$code->codeType = $row['code_type'];
return $code;
}
}
?>