summaryrefslogtreecommitdiff
path: root/modules/forge/libraries/Form_Phonenumber.php
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2008-10-31 22:12:14 +0000
committerBharat Mediratta <bharat@menalto.com>2008-10-31 22:12:14 +0000
commiteba717f95f586d2538007bd18da6e9b32b076c30 (patch)
tree15fc596a270f9de0d163c66c96e3c65fca5ee100 /modules/forge/libraries/Form_Phonenumber.php
parentfff10f8b70376ef25722bd867df26bc5aefced43 (diff)
Merge over vendor code.
git-svn-id: http://gallery.svn.sourceforge.net/svnroot/gallery/trunk/eval/gx/gallery3/trunk@18408 57fcd75e-5312-0410-8df3-f5eb6fbb1595
Diffstat (limited to 'modules/forge/libraries/Form_Phonenumber.php')
-rw-r--r--modules/forge/libraries/Form_Phonenumber.php98
1 files changed, 98 insertions, 0 deletions
diff --git a/modules/forge/libraries/Form_Phonenumber.php b/modules/forge/libraries/Form_Phonenumber.php
new file mode 100644
index 00000000..e30f47b1
--- /dev/null
+++ b/modules/forge/libraries/Form_Phonenumber.php
@@ -0,0 +1,98 @@
+<?php
+/**
+ * FORGE phone number input library.
+ *
+ * $Id$
+ *
+ * @package Forge
+ * @author Kohana Team
+ * @copyright (c) 2007-2008 Kohana Team
+ * @license http://kohanaphp.com/license.html
+ */
+class Form_Phonenumber_Core extends Form_Input {
+
+ protected $data = array
+ (
+ 'name' => '',
+ 'class' => 'phone_number',
+ );
+
+ protected $protect = array('type');
+
+ // Precision for the parts, you can use @ to insert a literal @ symbol
+ protected $parts = array
+ (
+ 'area_code' => '',
+ 'exchange' => '',
+ 'last_four' => '',
+ );
+
+ public function __construct($name)
+ {
+ // Set name
+ $this->data['name'] = $name;
+ }
+
+ public function __call($method, $args)
+ {
+ if (isset($this->parts[substr($method, 0, -1)]))
+ {
+ // Set options for date generation
+ $this->parts[substr($method, 0, -1)] = $args;
+ return $this;
+ }
+
+ return parent::__call($method, $args);
+ }
+
+ public function html_element()
+ {
+ // Import base data
+ $data = $this->data;
+
+ $input = '';
+ foreach ($this->parts as $type => $val)
+ {
+ isset($data['value']) OR $data['value'] = '';
+ $temp = $data;
+ $temp['name'] = $this->data['name'].'['.$type.']';
+ $offset = (strlen($data['value']) == 10) ? 0 : 3;
+ switch ($type)
+ {
+ case 'area_code':
+ if (strlen($data['value']) == 10)
+ {
+ $temp['value'] = substr($data['value'], 0, 3);
+ }
+ else
+ $temp['value'] = '';
+ $temp['class'] = 'area_code';
+ $input .= form::input(array_merge(array('value' => $val), $temp)).'-';
+ break;
+ case 'exchange':
+ $temp['value'] = substr($data['value'], (3-$offset), 3);
+ $temp['class'] = 'exchange';
+ $input .= form::input(array_merge(array('value' => $val), $temp)).'-';
+ break;
+ case 'last_four':
+ $temp['value'] = substr($data['value'], (6-$offset), 4);
+ $temp['class'] = 'last_four';
+ $input .= form::input(array_merge(array('value' => $val), $temp));
+ break;
+ }
+
+ }
+
+ return $input;
+ }
+
+ protected function load_value()
+ {
+ if (is_bool($this->valid))
+ return;
+
+ $data = $this->input_value($this->name, $this->data['name']);
+
+ $this->data['value'] = $data['area_code'].$data['exchange'].$data['last_four'];
+ }
+} // End Form Phonenumber \ No newline at end of file