Interim autoloaded library/classes via composer classmap, take 4. (#422)
[openemr.git] / library / classes / PhoneNumber.class.php
blob3e68e18a0a0876ad6093a9749b66b79a37c63c87
1 <?php
2 /************************************************************************
3 phone_number.php - Copyright duhlman
5 /usr/share/apps/umbrello/headings/heading.php
7 This file was generated on %date% at %time%
8 The original location of this file is /home/duhlman/uml-generated-code/prescription.php
9 **************************************************************************/
11 define("TYPE_HOME",1);
12 define("TYPE_WORK",2);
13 define("TYPE_CELL",3);
14 define("TYPE_EMERGENCY",4);
15 define("TYPE_FAX",5);
18 /**
19 * class Address
22 class PhoneNumber extends ORDataObject{
23 var $id;
24 var $foreign_id;
25 var $country_code;
26 var $area_code;
27 var $prefix;
28 var $number;
29 var $type_array = array("","Home", "Work", "Cell" , "Emergency" , "Fax");
31 /**
32 * Constructor sets all Prescription attributes to their default value
34 function __construct($id = "",$foreign_id = "") {
35 $this->id = $id;
36 $this->foreign_id = $foreign_id;
37 $this->country_code = "+1";
38 $this->prefix = "";
39 $this->number = "";
40 $this->type = TYPE_HOME;
41 $this->_table = "phone_numbers";
42 if ($id != "") {
43 $this->populate();
48 static function factory_phone_numbers($foreign_id = "") {
49 if (empty($foreign_id)) {
50 $foreign_id= "like '%'";
52 else {
53 $foreign_id= " = '" . add_escape_custom(strval($foreign_id)) . "'";
55 $phone_numbers = array();
56 $p = new PhoneNumber();
57 $sql = "SELECT id FROM " . $p->_table . " WHERE foreign_id " .$foreign_id . " ORDER BY type";
58 //echo $sql . "<bR />";
59 $results = sqlQ($sql);
60 //echo "sql: $sql";
61 while ($row = sqlFetchArray($results) ) {
62 $phone_numbers[] = new PhoneNumber($row['id']);
64 return $phone_numbers;
67 function set_id ($id) {
68 $this->id = $id;
71 function get_id () {
72 return $this->id;
75 function foreign_id ($id) {
76 $this->foreign_id = $id;
79 function get_foreign_id () {
80 return $this->foreign_id;
83 function set_country_code ($ccode) {
84 $this->country_code = $ccode;
87 function get_country_code () {
88 return $this->country_code;
90 function set_area_code ($acode) {
91 $this->area_code = $acode;
94 function get_area_code () {
95 return $this->area_code;
98 function set_number ($num) {
99 $this->number = $num;
102 function get_number () {
103 return $this->number;
107 function set_type ($type) {
108 $this->type = $type;
111 function get_type () {
112 return $this->type;
115 function set_prefix ($prefix) {
116 $this->prefix = $prefix;
119 function get_prefix () {
120 return $this->prefix;
123 function get_phone_display() {
124 if (is_numeric($this->area_code) && is_numeric($this->prefix) && is_numeric($this->number)) {
125 // return "(" . $this->area_code . ") " . $this->prefix . "-" . $this->number;
126 return $this->area_code . "-" . $this->prefix . "-" . $this->number;
128 return "";
131 function set_phone($num) {
132 if (strlen($num) == 10 && is_numeric($num)) {
133 $this->area_code = substr ($num,0,3);
134 $this->prefix = substr ($num,3,3);
135 $this->number = substr ($num,6,4);
137 elseif (strlen($num) == 12) {
138 $nums = explode("-",$num);
139 if (count($nums) == 3) {
140 $this->area_code = $nums[0];
141 $this->prefix = $nums[1];
142 $this->number = $nums[2];
145 elseif (strlen($num) == 14 && substr($num,0,1) == "(") {
146 $nums[0] = substr($num,1,3);
147 $nums[1] = substr($num,6,3);
148 $nums[2] = substr($num,10,4);
150 foreach ($nums as $n) {
151 if (!is_numeric($n)) {
152 return false;
156 if (count($nums) == 3) {
157 $this->area_code = $nums[0];
158 $this->prefix = $nums[1];
159 $this->number = $nums[2];
164 function toString($html = false) {
165 $string .= "\n"
166 . "ID: " . $this->id."\n"
167 . "FID: " . $this->foreign_id."\n"
168 . $this->country_code . " (" . $this->area_code . ") " . $this->prefix . "-" . $this->number . " " . $this->type_array[$this->type];
169 if ($html) {
170 return nl2br($string);
172 else {
173 return $string;
177 function persist($fid ="") {
178 if (!empty($fid)) {
179 $this->foreign_id = $fid;
181 parent::persist();
184 } // end of PhoneNumber
185 /*$p = new PhoneNumber(1);
186 echo $p->toString();
187 $p = new PhoneNumber(true);
189 $ps = PhoneNumber::factory_phone_numbers(55);
190 foreach($ps as $p) {
191 echo $p->toString(true);