You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

43 lines
1.2 KiB

  1. <?php
  2. /**
  3. * Class helper_plugin_bureaucracy_fieldtime
  4. *
  5. * A time in the format (h)h:mm(:ss)
  6. */
  7. class helper_plugin_bureaucracy_fieldtime extends helper_plugin_bureaucracy_fieldtextbox {
  8. /**
  9. * Arguments:
  10. * - cmd
  11. * - label
  12. * - ^ (optional)
  13. *
  14. * @param array $args The tokenized definition, only split at spaces
  15. */
  16. public function initialize($args) {
  17. parent::initialize($args);
  18. $attr = array(
  19. 'class' => 'timefield edit',
  20. 'maxlength'=>'8'
  21. );
  22. if(!isset($this->opt['optional'])) {
  23. $attr['required'] = 'required';
  24. $attr['class'] .= ' required';
  25. }
  26. $this->tpl = form_makeTextField('@@NAME@@', '@@VALUE@@', '@@DISPLAY@@', '@@ID@@', '@@CLASS@@', $attr);
  27. }
  28. /**
  29. * Validate field input
  30. *
  31. * @throws Exception when empty or wrong time format
  32. */
  33. protected function _validate() {
  34. parent::_validate();
  35. $value = $this->getParam('value');
  36. if (!is_null($value) && !preg_match('/^\d{1,2}:\d{2}(?::\d{2})?$/', $value)) {
  37. throw new Exception(sprintf($this->getLang('e_time'),hsc($this->getParam('display'))));
  38. }
  39. }
  40. }