Subversion Repositories computer_asset_manager_v2

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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