Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

phonenumber-field.inc.php

Go to the documentation of this file.
00001 <?php
00008 class PhoneNumberField extends CollectionField
00009 {
00010     protected $ext = false; 
00011 
00018     public function __construct($name, Form &$parentForm, array $attribs = array())
00019     {
00020         $attribs['fields'] = array(
00021             array('TextField', "${name}_area", array_merge($attribs, array('size' => '3', 'regExp' => 'number', 'maxlength' => '3'))),
00022             array('TextField', "${name}_prefix", array_merge($attribs, array('size' => '3', 'regExp' => 'number', 'maxlength' => '3'))),
00023             array('TextField', "${name}_num", array_merge($attribs, array('size' => '4', 'regExp' => 'number', 'maxlength' => '4')))
00024         );
00025         parent::__construct($name, $parentForm, $attribs);
00026         $this->autoAdvance = true;
00027 
00028         if($this->ext)
00029         {
00030             $this->add('LabelField', 'Ext.');
00031             $this->add('TextField', "${name}_ext", array_merge($attribs, array('size' => '4', 'regExp' => 'number')));
00032         }
00033     }
00034 
00039     public function setData($value)
00040     {
00041         $value = preg_replace("/[^0-9]*/", "", $value);
00042         
00043         if(preg_match('/([0-9]{3})([0-9]{3})([0-9]{4})/', $value, $matches))
00044         {
00045             $this->fields[0]->setData($matches[1]);
00046             $this->fields[1]->setData($matches[2]);
00047             $this->fields[2]->setData($matches[3]);
00048         }
00049     }
00050 
00055     public function getData()
00056     {
00057         $num = $this->fields[0]->getData() . $this->fields[1]->getData() . $this->fields[2]->getData();
00058 
00059         if($this->ext)
00060             $num .= 'x' . $this->fields[4]->getData();
00061 
00062         return $num;
00063     }
00064 
00069     public function getSqlImpl()
00070     {
00071         return "$this->name = '" . $this->getData() . "'";
00072     }
00073 
00074 }
00075 ?>

Generated on Fri Oct 27 12:26:39 2006 for BaseJumper by doxygen 1.3.9.1