public function SmartDateRule::getParametersArray in Smart Date 3.2.x
Same name and namespace in other branches
- 8.2 modules/smart_date_recur/src/Entity/SmartDateRule.php \Drupal\smart_date_recur\Entity\SmartDateRule::getParametersArray()
- 3.x modules/smart_date_recur/src/Entity/SmartDateRule.php \Drupal\smart_date_recur\Entity\SmartDateRule::getParametersArray()
- 3.0.x modules/smart_date_recur/src/Entity/SmartDateRule.php \Drupal\smart_date_recur\Entity\SmartDateRule::getParametersArray()
- 3.1.x modules/smart_date_recur/src/Entity/SmartDateRule.php \Drupal\smart_date_recur\Entity\SmartDateRule::getParametersArray()
- 3.3.x modules/smart_date_recur/src/Entity/SmartDateRule.php \Drupal\smart_date_recur\Entity\SmartDateRule::getParametersArray()
- 3.4.x modules/smart_date_recur/src/Entity/SmartDateRule.php \Drupal\smart_date_recur\Entity\SmartDateRule::getParametersArray()
Convert the stored parameters into an array.
1 call to SmartDateRule::getParametersArray()
- SmartDateRule::getTextRule in modules/
smart_date_recur/ src/ Entity/ SmartDateRule.php - Use the transformer to get text output of the rule.
File
- modules/
smart_date_recur/ src/ Entity/ SmartDateRule.php, line 659
Class
- SmartDateRule
- Defines the Smart date rule entity.
Namespace
Drupal\smart_date_recur\EntityCode
public function getParametersArray() {
$params = $this
->get('parameters')
->getString();
$return_array = [
'interval' => NULL,
'which' => '',
'day' => '',
'byday' => [],
'byhour' => [],
'byminute' => [],
];
if ($params && ($params = explode(';', $params))) {
foreach ($params as $param) {
list($var_name, $var_value) = explode('=', $param);
switch ($var_name) {
case 'INTERVAL':
$return_array['interval'] = (int) $var_value;
break;
case 'BYDAY':
$arr = preg_split('/(?<=[-0-9])(?=[,A-Z]+)/i', $var_value);
if ((int) $arr[0]) {
// Starts with a number, so treat as a compound value.
$return_array['which'] = $arr[0];
$return_array['day'] = $arr[1];
}
else {
// Assume this is a multi-day value.
$freq = $this
->get('freq')
->getString();
if (in_array($freq, [
'MINUTELY',
'HOURLY',
'DAILY',
'WEEKLY',
])) {
// Split into an array before returning the value.
$return_array['byday'] = explode(',', $arr[0]);
}
else {
$return_array['day'] = $arr[0];
}
}
break;
case 'BYHOUR':
$return_array['byhour'] = explode(',', $var_value);
break;
case 'BYMINUTE':
$return_array['byminute'] = explode(',', $var_value);
break;
case 'BYMONTHDAY':
$return_array['which'] = $var_value;
break;
case 'BYSETPOS':
$return_array['which'] = $var_value;
break;
}
}
}
return $return_array;
}