4 * phone number class for smarty templates
7 * @link https://www.open-emr.org
9 * @author Stephen Waite <stephen.waite@cmsvt.com>
10 * @copyright Copyright (c) duhlman
11 * @copyright Copyright (c) 2021 Stephen Waite <stephen.waite@cmsvt.com>
12 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 define("TYPE_HOME", 1);
16 define("TYPE_WORK", 2);
17 define("TYPE_CELL", 3);
18 define("TYPE_EMERGENCY", 4);
19 define("TYPE_FAX", 5);
27 use OpenEMR\Common\ORDataObject\ORDataObject
;
29 class PhoneNumber
extends ORDataObject
38 var $type_array = array("","Home", "Work", "Cell" , "Emergency" , "Fax");
41 * Constructor sets all attributes to their default value
43 function __construct($id = "", $foreign_id = "")
46 $this->foreign_id
= $foreign_id;
47 $this->country_code
= "+1";
50 $this->type
= TYPE_HOME
;
51 $this->_table
= "phone_numbers";
57 static function factory_phone_numbers($foreign_id = "")
61 if (empty($foreign_id)) {
62 $foreign_id_sql = " like '%'";
64 $foreign_id_sql = " = ?";
65 $sqlArray[] = strval($foreign_id);
68 $phone_numbers = array();
69 $p = new PhoneNumber();
70 $sql = "SELECT id FROM " . escape_table_name($p->_table
) . " WHERE foreign_id " . $foreign_id_sql . " ORDER BY type";
71 //echo $sql . "<bR />";
72 $results = sqlQ($sql, $sqlArray);
74 while ($row = sqlFetchArray($results)) {
75 $phone_numbers[] = new PhoneNumber($row['id']);
78 return $phone_numbers;
91 function foreign_id($id)
93 $this->foreign_id
= $id;
96 function get_foreign_id()
98 return $this->foreign_id
;
101 function set_country_code($ccode)
103 $this->country_code
= $ccode;
106 function get_country_code()
108 return $this->country_code
;
110 function set_area_code($acode)
112 $this->area_code
= $acode;
115 function get_area_code()
117 return $this->area_code
;
120 function set_number($num)
122 $this->number
= $num;
125 function get_number()
127 return $this->number
;
131 function set_type($type)
141 function set_prefix($prefix)
143 $this->prefix
= $prefix;
146 function get_prefix()
148 return $this->prefix
;
151 function get_phone_display()
153 if (is_numeric($this->area_code
) && is_numeric($this->prefix
) && is_numeric($this->number
)) {
154 // return "(" . $this->area_code . ") " . $this->prefix . "-" . $this->number;
155 return $this->area_code
. "-" . $this->prefix
. "-" . $this->number
;
161 function set_phone($num)
163 if (strlen($num) == 10 && is_numeric($num)) {
164 $this->area_code
= substr($num, 0, 3);
165 $this->prefix
= substr($num, 3, 3);
166 $this->number
= substr($num, 6, 4);
167 } elseif (strlen($num) == 12) {
168 $nums = explode("-", $num);
169 if (count($nums) == 3) {
170 $this->area_code
= $nums[0];
171 $this->prefix
= $nums[1];
172 $this->number
= $nums[2];
174 } elseif (strlen($num) == 14 && substr($num, 0, 1) == "(") {
175 $nums[0] = substr($num, 1, 3);
176 $nums[1] = substr($num, 6, 3);
177 $nums[2] = substr($num, 10, 4);
179 foreach ($nums as $n) {
180 if (!is_numeric($n)) {
185 if (count($nums) == 3) {
186 $this->area_code
= $nums[0];
187 $this->prefix
= $nums[1];
188 $this->number
= $nums[2];
191 $this->area_code
= '';
197 function toString($html = false)
200 . "ID: " . $this->id
. "\n"
201 . "FID: " . $this->foreign_id
. "\n"
202 . $this->country_code
. " (" . $this->area_code
. ") " . $this->prefix
. "-" . $this->number
. " " . $this->type_array
[$this->type
];
204 return nl2br($string);
210 function persist($fid = "")
213 $this->foreign_id
= $fid;