Subversion Repositories computer_asset_manager_v2

Rev

Rev 54 | Rev 56 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

<?php

   class Camp {
      protected static $dbStructure;
      public static $myName;
      protected static $viewName = 'view_device_location_owner_type';
            
      /**
       * Gets stats for an extended class.
       * 
       * Gets number of active and inactive rows for a class, using the
       * view ($viewName)
       * 
       * @return int[] array of integers which is a count
       */
      public static function getStats () {
         global $dbConnection;
         
         $return = array();
         $restrictions = array();
         // get_called_class is the only function that will work with a static
         // call with descendants.
         $trueClass = strtolower( get_called_class() );
         
         foreach ( $_SESSION['restrictions'] as $class => $restriction ) {
            $restrictions[] = $_SESSION['restrictions'][$class];
         }
         $whereClause = count($restrictions) ? ' and ' . implode( ' and ', $restrictions) : '';
            
         $active = sprintf( 
            'select count(distinct %s) from %s where %s_removed is null %s', 
            static::$dbStructure['table']['primaryKey'],  
            self::$viewName, 
            $trueClass, 
            $whereClause );
         $inactive = sprintf( 
            'select count(distinct %s) from %s where %s_removed is not null %s', 
            static::$dbStructure['table']['primaryKey'],  
            self::$viewName, 
            $trueClass, 
            $whereClause );
         $return['active'] = $dbConnection->getOneDBValue( $active );
         $return['inactive'] = $dbConnection->getOneDBValue( $inactive );
         return $return;
      }
      
      public static function showSelectionList() {
         global $url;
         $list = self::getAll();
         foreach ( $list as $id => $name ) {
            $return[] = "<a href='$url?id=$id'>$name</a>";
         }
         return '<ul><li>' . implode( '</li><li>', $return ) . '</li></ul>';
      }
      
      public static function getAll() {
         global $activeOnly;
         global $dbConnection;
         
         $return = array();
         $query = sprintf( 'select %s id, %s name from %s', 
               self::$dbStructure['primaryKey'],
               self::$dbStructure['selectionDisplay'],
               self::$dbStructure['tableName']
               );
         if ( $activeOnly )
            $query .= ' where removed is null';
         $result = $dbConnection->doSQL( $query );
         foreach ( $result['returnData'] as $row ) {
            $return[$row['id']] = $row['name'];
         }
         return $return;
      }
         
      public function __toString() {
         return $this->name;
      }
      
   } // abstract class Camp

?>