Repository navigation
Expand file tree
/
Copy pathhelper.php
More file actions
88 lines (76 loc) · 2.46 KB
/
Copy pathhelper.php
File metadata and controls
88 lines (76 loc) · 2.46 KB
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
/**
* Provides a collection of usevel methods for our application
*/
class Helper {
/*
* Get the URL Get Query Parameter or null
*/
public static function getURLGETParameter($name) {
return (isset($_GET[$name])) ? urldecode($_GET[$name]) : null;
}
/**
* Retrieve the device ID based on the UID
*/
public static function getDeviceID($deviceUID) {
$qb = new QueryBuilder();
$r = $qb
->table('devices')
->fields(['id'])
->where(["uid = $deviceUID"])
->select();
if (count($r->values) == 0)
throw new HttpException(404, "Device not found");
return $r->values[0]->id;
}
/**
* Retrieve the sensor ID based on the UID and it's device UID
*/
public static function getSensorID($deviceUID, $sensorUID) {
$device_id = self::getDeviceID($deviceUID);
$qb = new QueryBuilder();
$r = $qb
->table('sensors')
->fields(['id'])
->where(["devices_id = $device_id AND uid = $sensorUID"])
->select();
if (count($r->values) == 0)
throw new HttpException(404, "Sensor not found");
return $r->values[0]->id;
}
/**
* Local LOG function
*/
public static function log($message) {
try {
$qb = new QueryBuilder();
$r = $qb
->table('log')
->fields(['timestamp', 'calling', 'message'])
->insert([date('Y-m-d H:i:s'), self::getCallingFunctionName(2), $message]);
} catch (Exception $e) {
$data = $message.PHP_EOL;
$fp = fopen('exception_log.txt', 'a');
fwrite($fp, $data);
}
}
/**
* Get the name of the last called function. $level tell us if we want the last
* parent caller, or the last-last parent caller, so on...
* $level = 0, is the same function
* $level = 1, is the function before
* $level = 2, is the function before before
* $level = 3, ... etc.
*/
private static function getCallingFunctionName($level) {
// Create an exception
$ex = new Exception();
// Call getTrace() function
$trace = $ex->getTrace();
// Position 0 would be the line
// that called this function
$final_call = $trace[$level];
// Display associative array
return print_r($final_call, true);
}
}