/
MeasurementCampaign.php
executable file
·79 lines (63 loc) · 2.44 KB
/
MeasurementCampaign.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
<?php
include 'settings.php';
include_once 'CheckrouteDatabase.php';
class MeasurementCampaign
{
var $id;
var $name;
var $description;
// Konstruktor
public function __construct($id, $name, $description)
{
$this->id = $id;
$this->name = $name;
$this->description = $description;
}
// returns an array with all IDs of the measurements belonging to the campaign
public function get_measurement_ids()
{
// create and check connection
$link = CheckrouteDatabase::connect();
// query all measurements associated with a given measurement campaign
$stmt = mysqli_prepare($link, "SELECT id_measurement FROM Campaign_has_Measurement WHERE id_campaign = ? ORDER BY id_measurement ASC");
if ($stmt) {
mysqli_stmt_bind_param($stmt, "s", $this->id);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $result);
$measurements_of_campaign = array();
while (mysqli_stmt_fetch($stmt)) {
$measurements_of_campaign[] = $result;
}
mysqli_stmt_close($stmt);
}
// close database connection
mysqli_close($link);
return $measurements_of_campaign;
}
// returns an array with all IDs of the measurements belonging to the campaign
public function get_number_of_measurements()
{
return count($this->get_measurement_ids());
}
// returns an array with all measurement campaigns available in the database
public static function get_all_campaigns()
{
// create and check connection
$link = CheckrouteDatabase::connect();
// query all available measurement campaigns
$stmt = mysqli_prepare($link, "SELECT x.id, x.name, x.description, COUNT(y.id_measurement) AS 'number_of_measurements' FROM MeasurementCampaign AS x, Campaign_has_Measurement AS y WHERE x.id = y.id_campaign GROUP BY x.id");
if ($stmt) {
mysqli_stmt_execute($stmt);
//mysqli_stmt_bind_result($stmt, $result_sql);
$result = array();
while (mysqli_stmt_fetch($stmt)) {
$result[] = $result_sql;
}
mysqli_stmt_close($stmt);
}
// close database connection
mysqli_close($link);
return $result;
}
}
?>