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);
22 class PhoneNumber
extends ORDataObject
30 var $type_array = array("","Home", "Work", "Cell" , "Emergency" , "Fax");
33 * Constructor sets all Prescription attributes to their default value
35 function __construct($id = "", $foreign_id = "")
38 $this->foreign_id
= $foreign_id;
39 $this->country_code
= "+1";
42 $this->type
= TYPE_HOME
;
43 $this->_table
= "phone_numbers";
49 static function factory_phone_numbers($foreign_id = "")
51 if (empty($foreign_id)) {
52 $foreign_id= "like '%'";
54 $foreign_id= " = '" . add_escape_custom(strval($foreign_id)) . "'";
57 $phone_numbers = array();
58 $p = new PhoneNumber();
59 $sql = "SELECT id FROM " . $p->_table
. " WHERE foreign_id " .$foreign_id . " ORDER BY type";
60 //echo $sql . "<bR />";
61 $results = sqlQ($sql);
63 while ($row = sqlFetchArray($results)) {
64 $phone_numbers[] = new PhoneNumber($row['id']);
67 return $phone_numbers;
80 function foreign_id($id)
82 $this->foreign_id
= $id;
85 function get_foreign_id()
87 return $this->foreign_id
;
90 function set_country_code($ccode)
92 $this->country_code
= $ccode;
95 function get_country_code()
97 return $this->country_code
;
99 function set_area_code($acode)
101 $this->area_code
= $acode;
104 function get_area_code()
106 return $this->area_code
;
109 function set_number($num)
111 $this->number
= $num;
114 function get_number()
116 return $this->number
;
120 function set_type($type)
130 function set_prefix($prefix)
132 $this->prefix
= $prefix;
135 function get_prefix()
137 return $this->prefix
;
140 function get_phone_display()
142 if (is_numeric($this->area_code
) && is_numeric($this->prefix
) && is_numeric($this->number
)) {
143 // return "(" . $this->area_code . ") " . $this->prefix . "-" . $this->number;
144 return $this->area_code
. "-" . $this->prefix
. "-" . $this->number
;
150 function set_phone($num)
152 if (strlen($num) == 10 && is_numeric($num)) {
153 $this->area_code
= substr($num, 0, 3);
154 $this->prefix
= substr($num, 3, 3);
155 $this->number
= substr($num, 6, 4);
156 } elseif (strlen($num) == 12) {
157 $nums = explode("-", $num);
158 if (count($nums) == 3) {
159 $this->area_code
= $nums[0];
160 $this->prefix
= $nums[1];
161 $this->number
= $nums[2];
163 } elseif (strlen($num) == 14 && substr($num, 0, 1) == "(") {
164 $nums[0] = substr($num, 1, 3);
165 $nums[1] = substr($num, 6, 3);
166 $nums[2] = substr($num, 10, 4);
168 foreach ($nums as $n) {
169 if (!is_numeric($n)) {
174 if (count($nums) == 3) {
175 $this->area_code
= $nums[0];
176 $this->prefix
= $nums[1];
177 $this->number
= $nums[2];
182 function toString($html = false)
185 . "ID: " . $this->id
."\n"
186 . "FID: " . $this->foreign_id
."\n"
187 . $this->country_code
. " (" . $this->area_code
. ") " . $this->prefix
. "-" . $this->number
. " " . $this->type_array
[$this->type
];
189 return nl2br($string);
195 function persist($fid = "")
198 $this->foreign_id
= $fid;
203 } // end of PhoneNumber
204 /*$p = new PhoneNumber(1);
206 $p = new PhoneNumber(true);
208 $ps = PhoneNumber::factory_phone_numbers(55);
210 echo $p->toString(true);