2015-07-23 08:29:15 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\PropertyModifier;
|
|
|
|
|
|
2016-02-17 05:11:05 -05:00
|
|
|
use Icinga\Module\Director\Hook\PropertyModifierHook;
|
2016-02-18 17:21:28 -05:00
|
|
|
use Icinga\Module\Director\Web\Form\QuickForm;
|
2015-07-23 08:29:15 -04:00
|
|
|
|
|
|
|
|
class PropertyModifierSubstring extends PropertyModifierHook
|
|
|
|
|
{
|
2015-07-23 08:42:53 -04:00
|
|
|
public static function addSettingsFormFields(QuickForm $form)
|
|
|
|
|
{
|
2016-03-05 11:04:13 -05:00
|
|
|
$form->addElement('text', 'start', array(
|
|
|
|
|
'label' => 'Start',
|
|
|
|
|
'required' => true,
|
|
|
|
|
'description' => sprintf(
|
|
|
|
|
$form->translate(
|
2016-03-05 18:37:03 -05:00
|
|
|
'Please see %s for detailled instructions of how start and end work'
|
2016-03-05 11:04:13 -05:00
|
|
|
),
|
|
|
|
|
'http://php.net/manual/en/function.substr.php'
|
|
|
|
|
)
|
2015-07-23 08:42:53 -04:00
|
|
|
));
|
2016-02-18 17:21:28 -05:00
|
|
|
|
2016-03-05 11:04:13 -05:00
|
|
|
$form->addElement('text', 'length', array(
|
|
|
|
|
'label' => 'End',
|
2016-03-05 18:37:03 -05:00
|
|
|
'description' => sprintf(
|
|
|
|
|
$form->translate(
|
|
|
|
|
'Please see %s for detailled instructions of how start and end work'
|
|
|
|
|
),
|
|
|
|
|
'http://php.net/manual/en/function.substr.php'
|
|
|
|
|
)
|
2015-07-23 08:42:53 -04:00
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-23 08:29:15 -04:00
|
|
|
public function transform($value)
|
|
|
|
|
{
|
2021-08-12 05:45:40 -04:00
|
|
|
if ($value === null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-18 15:50:20 -04:00
|
|
|
$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')
|
|
|
|
|
);
|
|
|
|
|
}
|
2015-07-23 08:29:15 -04:00
|
|
|
}
|
|
|
|
|
}
|