summaryrefslogtreecommitdiff
path: root/modules/forge/libraries/Form_Dateselect.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_Dateselect.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_Dateselect.php')
-rw-r--r--modules/forge/libraries/Form_Dateselect.php138
1 files changed, 138 insertions, 0 deletions
diff --git a/modules/forge/libraries/Form_Dateselect.php b/modules/forge/libraries/Form_Dateselect.php
new file mode 100644
index 00000000..d531b3c8
--- /dev/null
+++ b/modules/forge/libraries/Form_Dateselect.php
@@ -0,0 +1,138 @@
+<?php
+/**
+ * FORGE dateselect input library.
+ *
+ * $Id$
+ *
+ * @package Forge
+ * @author Kohana Team
+ * @copyright (c) 2007-2008 Kohana Team
+ * @license http://kohanaphp.com/license.html
+ */
+class Form_Dateselect_Core extends Form_Input {
+
+ protected $data = array
+ (
+ 'name' => '',
+ 'class' => 'dropdown',
+ );
+
+ protected $protect = array('type');
+
+ // Precision for the parts, you can use @ to insert a literal @ symbol
+ protected $parts = array
+ (
+ 'month' => array(),
+ 'day' => array(1),
+ 'year' => array(),
+ ' @ ',
+ 'hour' => array(),
+ ':',
+ 'minute' => array(5),
+ 'am_pm' => array(),
+ );
+
+ public function __construct($name)
+ {
+ // Set name
+ $this->data['name'] = $name;
+
+ // Default to the current time
+ $this->data['value'] = time();
+ }
+
+ 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;
+
+ // Get the options and default selection
+ $time = $this->time_array(arr::remove('value', $data));
+
+ // No labels or values
+ unset($data['label']);
+
+ $input = '';
+ foreach ($this->parts as $type => $val)
+ {
+ if (is_int($type))
+ {
+ // Just add the separators
+ $input .= $val;
+ continue;
+ }
+
+ // Set this input name
+ $data['name'] = $this->data['name'].'['.$type.']';
+
+ // Set the selected option
+ $selected = $time[$type];
+
+ if ($type == 'am_pm')
+ {
+ // Options are static
+ $options = array('AM' => 'AM', 'PM' => 'PM');
+ }
+ else
+ {
+ // minute(s), hour(s), etc
+ $type .= 's';
+
+ // Use the date helper to generate the options
+ $options = empty($val) ? date::$type() : call_user_func_array(array('date', $type), $val);
+ }
+
+ $input .= form::dropdown($data, $options, $selected);
+ }
+
+ return $input;
+ }
+
+ protected function time_array($timestamp)
+ {
+ $time = array_combine
+ (
+ array('month', 'day', 'year', 'hour', 'minute', 'am_pm'),
+ explode('--', date('n--j--Y--g--i--A', $timestamp))
+ );
+
+ // Minutes should always be in 5 minute increments
+ $time['minute'] = num::round($time['minute'], current($this->parts['minute']));
+
+ return $time;
+ }
+
+ protected function load_value()
+ {
+ if (is_bool($this->valid))
+ return;
+
+ $time = $this->input_value($this->name);
+
+ // Make sure all the required inputs keys are set
+ $time += $this->time_array(time());
+
+ $this->data['value'] = mktime
+ (
+ date::adjust($time['hour'], $time['am_pm']),
+ $time['minute'],
+ 0,
+ $time['month'],
+ $time['day'],
+ $time['year']
+ );
+ }
+
+} // End Form Dateselect \ No newline at end of file