forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PhoneNumber.class.php
194 lines (164 loc) · 4.15 KB
/
PhoneNumber.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?php
/************************************************************************
phone_number.php - Copyright duhlman
/usr/share/apps/umbrello/headings/heading.php
This file was generated on %date% at %time%
The original location of this file is /home/duhlman/uml-generated-code/prescription.php
**************************************************************************/
define("TYPE_HOME",1);
define("TYPE_WORK",2);
define("TYPE_CELL",3);
define("TYPE_EMERGENCY",4);
define("TYPE_FAX",5);
require_once("ORDataObject.class.php");
/**
* class Address
*
*/
class PhoneNumber extends ORDataObject{
var $id;
var $foreign_id;
var $country_code;
var $area_code;
var $prefix;
var $number;
var $type_array = array("","Home", "Work", "Cell" , "Emergency" , "Fax");
/**
* Constructor sets all Prescription attributes to their default value
*/
function __construct($id = "",$foreign_id = "") {
$this->id = $id;
$this->foreign_id = $foreign_id;
$this->country_code = "+1";
$this->prefix = "";
$this->number = "";
$this->type = TYPE_HOME;
$this->_table = "phone_numbers";
if ($id != "") {
$this->populate();
}
}
static function factory_phone_numbers($foreign_id = "") {
if (empty($foreign_id)) {
$foreign_id= "like '%'";
}
else {
$foreign_id= " = '" . add_escape_custom(strval($foreign_id)) . "'";
}
$phone_numbers = array();
$p = new PhoneNumber();
$sql = "SELECT id FROM " . $p->_table . " WHERE foreign_id " .$foreign_id . " ORDER BY type";
//echo $sql . "<bR />";
$results = sqlQ($sql);
//echo "sql: $sql";
while ($row = sqlFetchArray($results) ) {
$phone_numbers[] = new PhoneNumber($row['id']);
}
return $phone_numbers;
}
function set_id ($id) {
$this->id = $id;
}
function get_id () {
return $this->id;
}
function foreign_id ($id) {
$this->foreign_id = $id;
}
function get_foreign_id () {
return $this->foreign_id;
}
function set_country_code ($ccode) {
$this->country_code = $ccode;
}
function get_country_code () {
return $this->country_code;
}
function set_area_code ($acode) {
$this->area_code = $acode;
}
function get_area_code () {
return $this->area_code;
}
function set_number ($num) {
$this->number = $num;
}
function get_number () {
return $this->number;
}
function set_type ($type) {
$this->type = $type;
}
function get_type () {
return $this->type;
}
function set_prefix ($prefix) {
$this->prefix = $prefix;
}
function get_prefix () {
return $this->prefix;
}
function get_phone_display() {
if (is_numeric($this->area_code) && is_numeric($this->prefix) && is_numeric($this->number)) {
// return "(" . $this->area_code . ") " . $this->prefix . "-" . $this->number;
return $this->area_code . "-" . $this->prefix . "-" . $this->number;
}
return "";
}
function set_phone($num) {
if (strlen($num) == 10 && is_numeric($num)) {
$this->area_code = substr ($num,0,3);
$this->prefix = substr ($num,3,3);
$this->number = substr ($num,6,4);
}
elseif (strlen($num) == 12) {
$nums = explode("-",$num);
if (count($nums) == 3) {
$this->area_code = $nums[0];
$this->prefix = $nums[1];
$this->number = $nums[2];
}
}
elseif (strlen($num) == 14 && substr($num,0,1) == "(") {
$nums[0] = substr($num,1,3);
$nums[1] = substr($num,6,3);
$nums[2] = substr($num,10,4);
foreach ($nums as $n) {
if (!is_numeric($n)) {
return false;
}
}
if (count($nums) == 3) {
$this->area_code = $nums[0];
$this->prefix = $nums[1];
$this->number = $nums[2];
}
}
}
function toString($html = false) {
$string .= "\n"
. "ID: " . $this->id."\n"
. "FID: " . $this->foreign_id."\n"
. $this->country_code . " (" . $this->area_code . ") " . $this->prefix . "-" . $this->number . " " . $this->type_array[$this->type];
if ($html) {
return nl2br($string);
}
else {
return $string;
}
}
function persist($fid ="") {
if (!empty($fid)) {
$this->foreign_id = $fid;
}
parent::persist();
}
} // end of PhoneNumber
/*$p = new PhoneNumber(1);
echo $p->toString();
$p = new PhoneNumber(true);
$ps = PhoneNumber::factory_phone_numbers(55);
foreach($ps as $p) {
echo $p->toString(true);
}*/
?>