-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.service.php
88 lines (83 loc) · 3.07 KB
/
class.service.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
* Created by PhpStorm.
* User: cpippert
* Date: 08.11.2018
* Time: 12:46
*/
class service
{
/**
* Get the title of the alarm message based on the alarm keyword.
* @param string $keyword given by the alarm message from TetraControl
* @param array $alarmKeywords relevant keywords from config file
* @param integer $alarmKeywords max length of field type defined in Divera API
* @return string alarm title
*/
public function getAlarmType($keyword, $alarmKeywords, $maxStrLenType){
if(is_string($keyword) && array_key_exists ( $keyword , $alarmKeywords )){
$title = $keyword." - ".$alarmKeywords[$keyword]['short'];
if (strlen($title) > $maxStrLenType)
$title = substr($title, 0, $maxStrLenType-3) . '...';
return $title;
}
else{
return $keyword;
}
}
/**
* Get the text of the alarm message based on the alarm keyword.
* @param string $keyword given by the alarm message from TetraControl
* @param array $alarmKeywords relevant keywords from config file
* @param integer $alarmKeywords max length of field type defined in Divera API
* @return string alarm title
*/
public function getAlarmText($keyword, $alarmKeywords){
if(is_string($keyword) && array_key_exists ( $keyword , $alarmKeywords )){
$title = $alarmKeywords[$keyword]['long'];
return $title;
}
else{
return "";
}
}
/**
* Get the vehicle(s) based on the alarm keyword.
* @param string $keyword given by the alarm message from TetraControl
* @param array $alarmKeywords relevant keywords from config file
* @param integer $alarmKeywords max length of field type defined in Divera API
* @return string vehicle(s) comma separated
*/
public function getVehicle($keyword, $alarmKeywords){
if(is_string($keyword) && array_key_exists ( $keyword , $alarmKeywords )){
$vehicle = $alarmKeywords[$keyword]['vehicle'];
return $vehicle;
}
else{
return "";
}
}
/**
* Find the address based on the alert message from TetraControl. Remove the district and if the last Word is a number
* then the number is removed.
* @param string $address
* @param array $districts Ortsteile von Lohfelden
* @return string
*/
public function formatAddress($address,$districts){
preg_match('/\s(\w+)$/', $address, $matchesLastWord);
preg_match('/^([\w\-]+)/', $address, $matchesFirstWord);
$returnAddress = $address;
if($matchesLastWord){
if(is_numeric ( $matchesLastWord[1])) {
$returnAddress = str_replace($matchesLastWord[0], '', $returnAddress);
}
}
if($matchesFirstWord){
if(in_array($matchesFirstWord[0], $districts)){
$returnAddress = substr_replace ($returnAddress, '', 0, strlen($matchesFirstWord[0]));
}
}
return trim($returnAddress);
}
}