diff options
Diffstat (limited to 'library/Director/PropertyModifier/PropertyModifierSubstring.php')
-rw-r--r-- | library/Director/PropertyModifier/PropertyModifierSubstring.php | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/library/Director/PropertyModifier/PropertyModifierSubstring.php b/library/Director/PropertyModifier/PropertyModifierSubstring.php new file mode 100644 index 0000000..37a2f92 --- /dev/null +++ b/library/Director/PropertyModifier/PropertyModifierSubstring.php @@ -0,0 +1,54 @@ +<?php + +namespace Icinga\Module\Director\PropertyModifier; + +use Icinga\Module\Director\Hook\PropertyModifierHook; +use Icinga\Module\Director\Web\Form\QuickForm; + +class PropertyModifierSubstring extends PropertyModifierHook +{ + public static function addSettingsFormFields(QuickForm $form) + { + $form->addElement('text', 'start', array( + 'label' => 'Start', + 'required' => true, + 'description' => sprintf( + $form->translate( + 'Please see %s for detailled instructions of how start and end work' + ), + 'http://php.net/manual/en/function.substr.php' + ) + )); + + $form->addElement('text', 'length', array( + 'label' => 'End', + 'description' => sprintf( + $form->translate( + 'Please see %s for detailled instructions of how start and end work' + ), + 'http://php.net/manual/en/function.substr.php' + ) + )); + } + + public function transform($value) + { + if ($value === null) { + return null; + } + + $length = $this->getSetting('length'); + if (is_numeric($length)) { + return substr( + $value, + (int) $this->getSetting('start'), + (int) $length + ); + } else { + return substr( + $value, + (int) $this->getSetting('start') + ); + } + } +} |