MCPcopy Create free account
hub / github.com/Rello/analytics / replaceTextVariablesSingle

Method replaceTextVariablesSingle

lib/Service/VariableService.php:96–116  ·  view source on GitHub ↗

* replace variables in single field or dimension * used in StorageService when data is loaded or entered manually * * @param $field * @return array */

($field)

Source from the content-addressed store, hash-verified

94 * @return array
95 */
96 public function replaceTextVariablesSingle($field) {
97 if ($field !== null) {
98 preg_match_all("/%.*?%/", $field, $matches);
99 if (count($matches[0]) > 0) {
100 foreach ($matches[0] as $match) {
101 $replace = null;
102 if ($match === '%currentDate%') {
103 $replace = date("Y-m-d");
104 } elseif ($match === '%currentTime%') {
105 $replace = $this->IDateTimeFormatter->formatTime(time(), 'short');
106 } elseif ($match === '%now%') {
107 $replace = time();
108 }
109 if ($replace !== null) {
110 $field = preg_replace('/' . $match . '/', $replace, $field);
111 }
112 }
113 }
114 }
115 return $field;
116 }
117
118 /**
119 * replace variables in single field

Callers 2

updateMethod · 0.45

Calls 1

formatTimeMethod · 0.80

Tested by 1