| 53 |
rodolico |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
class Camp {
|
|
|
4 |
protected static $dbStructure;
|
|
|
5 |
public static $myName;
|
|
|
6 |
protected static $viewName = 'view_device_location_owner_type';
|
|
|
7 |
|
|
|
8 |
public static function getStats () {
|
|
|
9 |
global $dbConnection;
|
|
|
10 |
|
|
|
11 |
$return = array();
|
|
|
12 |
$restrictions = array();
|
| 54 |
rodolico |
13 |
// get_called_class is the only function that will work with a static
|
|
|
14 |
// call with descendants.
|
|
|
15 |
$trueClass = strtolower( get_called_class() );
|
|
|
16 |
|
| 53 |
rodolico |
17 |
foreach ( $_SESSION['restrictions'] as $class => $restriction ) {
|
|
|
18 |
$restrictions[] = $_SESSION['restrictions'][$class];
|
|
|
19 |
}
|
|
|
20 |
$whereClause = count($restrictions) ? ' and ' . implode( ' and ', $restrictions) : '';
|
|
|
21 |
|
| 54 |
rodolico |
22 |
$active = sprintf(
|
|
|
23 |
'select count(distinct %s) from %s where %s_removed is null %s',
|
|
|
24 |
static::$dbStructure['table']['primaryKey'],
|
|
|
25 |
self::$viewName,
|
|
|
26 |
$trueClass,
|
|
|
27 |
$whereClause );
|
|
|
28 |
$inactive = sprintf(
|
|
|
29 |
'select count(distinct %s) from %s where %s_removed is not null %s',
|
|
|
30 |
static::$dbStructure['table']['primaryKey'],
|
|
|
31 |
self::$viewName,
|
|
|
32 |
$trueClass,
|
|
|
33 |
$whereClause );
|
|
|
34 |
$return['active'] = $dbConnection->getOneDBValue( $active );
|
|
|
35 |
$return['inactive'] = $dbConnection->getOneDBValue( $inactive );
|
| 53 |
rodolico |
36 |
return $return;
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
public static function showSelectionList() {
|
|
|
40 |
global $url;
|
|
|
41 |
$list = self::getAll();
|
|
|
42 |
foreach ( $list as $id => $name ) {
|
|
|
43 |
$return[] = "<a href='$url?id=$id'>$name</a>";
|
|
|
44 |
}
|
|
|
45 |
return '<ul><li>' . implode( '</li><li>', $return ) . '</li></ul>';
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
public static function getAll() {
|
|
|
49 |
global $activeOnly;
|
|
|
50 |
global $dbConnection;
|
|
|
51 |
|
|
|
52 |
$return = array();
|
|
|
53 |
$query = sprintf( 'select %s id, %s name from %s',
|
|
|
54 |
self::$dbStructure['primaryKey'],
|
|
|
55 |
self::$dbStructure['selectionDisplay'],
|
|
|
56 |
self::$dbStructure['tableName']
|
|
|
57 |
);
|
|
|
58 |
if ( $activeOnly )
|
|
|
59 |
$query .= ' where removed is null';
|
|
|
60 |
$result = $dbConnection->doSQL( $query );
|
|
|
61 |
foreach ( $result['returnData'] as $row ) {
|
|
|
62 |
$return[$row['id']] = $row['name'];
|
|
|
63 |
}
|
|
|
64 |
return $return;
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
public function __toString() {
|
|
|
68 |
return $this->name;
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
} // abstract class Camp
|
|
|
72 |
|
|
|
73 |
?>
|