diff options
Diffstat (limited to 'platform/www/lib/plugins/bureaucracy/helper/fieldtime.php')
-rw-r--r-- | platform/www/lib/plugins/bureaucracy/helper/fieldtime.php | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/platform/www/lib/plugins/bureaucracy/helper/fieldtime.php b/platform/www/lib/plugins/bureaucracy/helper/fieldtime.php new file mode 100644 index 0000000..164e71f --- /dev/null +++ b/platform/www/lib/plugins/bureaucracy/helper/fieldtime.php @@ -0,0 +1,42 @@ +<?php +/** + * Class helper_plugin_bureaucracy_fieldtime + * + * A time in the format (h)h:mm(:ss) + */ +class helper_plugin_bureaucracy_fieldtime extends helper_plugin_bureaucracy_fieldtextbox { + /** + * Arguments: + * - cmd + * - label + * - ^ (optional) + * + * @param array $args The tokenized definition, only split at spaces + */ + public function initialize($args) { + parent::initialize($args); + $attr = array( + 'class' => 'timefield edit', + 'maxlength'=>'8' + ); + if(!isset($this->opt['optional'])) { + $attr['required'] = 'required'; + $attr['class'] .= ' required'; + } + $this->tpl = form_makeTextField('@@NAME@@', '@@VALUE@@', '@@DISPLAY@@', '@@ID@@', '@@CLASS@@', $attr); + } + + /** + * Validate field input + * + * @throws Exception when empty or wrong time format + */ + protected function _validate() { + parent::_validate(); + + $value = $this->getParam('value'); + if (!is_null($value) && !preg_match('/^\d{1,2}:\d{2}(?::\d{2})?$/', $value)) { + throw new Exception(sprintf($this->getLang('e_time'),hsc($this->getParam('display')))); + } + } +} |