Subversion Repositories computer_asset_manager_v2

Rev

Rev 70 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

<?php

   require_once( 'camp.class.php' );
   
   class DeviceType extends Camp {
      
      protected static $dbStructure = array(
         'table' => array( 
            'tableName' => 'device_type',
            'primaryKey' => 'device_type_id',
            'selectionDisplay' => 'name',
            'displayOrder' => 'name',
            'fields' => array(
                  'id' => array (
                     'fieldname' => 'device_type_id',
                     'displayName' => 'ID',
                     'type' => 'autoincrement',
                     'nullable' => false,
                     'canEdit' => false
                  ),
                  'name' => array (
                     'fieldname' => 'name',
                     'displayName' => 'Name',
                     'type' => 'varchar',
                     'size' => 64
                  ),
                  'created' => array (
                     'fieldname' => 'created',
                     'displayName' => 'Created',
                     'type' => 'date'
                  ),
                  'removed' => array(
                     'fieldname' => 'removed',
                     'displayName' => 'Removed',
                     'type' => 'date'
                  )
               ) // fields,
            )
         ); // $tableStructure
         /*
         public function __construct( $id = 0 ) {
            if ( $id ) {
               //load from database
            } else {
               foreach ( self::$tableStructure['fields'] as $name => $definition ) {
                  switch ( $definition['type'] ) {
                     case 'autoincrement':
                        $this->data[$name] = 0;
                        break;
                     case 'date':
                        $this->data['name'] = 'null';
                        break;
                     default: $this->data['name'] = '';
                  } // switch
               } // foreach
            } // if..else
         } // constructor
         
         public static function makeSelectionMenu( $query, $template = '', $before = '', $after = '' ) {
            global $dbConnection;
            
            if ( ! $template ) {
               $template = "<a href='$_SERVER[PHP_SELF]?id=~~id~~'>~~Name~~</a>";
            }
            
            $results = $dbConnection->doSQL( $query, array( 'returnType' => 'associative' ) );
            $list = array();
            
            if ( $results['rowsAffected'] ) {
               foreach ( $results['returnData'] as $row ) {
                  $list[] = $dbConnection->templateReplace ( $template, $row );
               }
            } else {
               $list[] = 'No Entries';
            }
            $list[] = $dbConnection->templateReplace ( $template, array( 'Name' => '<b>Add New</b>', 'id' => '0' ) );
            return $before . implode( '', $list ) . $after;
         }
         
         public static function showList ( $template = '', $before = '', $after = '' ) {
            $fieldList = array();
            $order = array();
            $fieldList[] = self::$tableStructure['primaryKey'] . ' id';
            
            foreach ( self::$tableStructure['selectionDisplay'] as $field ) {
               $fieldList[] = self::$tableStructure['fields'][$field]['fieldname'] . ' ' . ( self::$tableStructure['fields'][$field]['displayName'] ? self::$tableStructure['fields'][$field]['displayName'] : self::$tableStructure['fields'][$field]['fieldname'] );
            }
            foreach ( self::$tableStructure['displayOrder'] as $field ) {
               $order[] = self::$tableStructure['fields'][$field]['fieldname'];
            }
            
            $query = sprintf( 
               'select %s from  %s %s %s', 
               implode( ',', $fieldList ), self::$tableStructure['tableName'],
               camp::makeWhereClause( array(), array(), self::$tableStructure['tableName'] ),
               $order ? 'order by ' . implode( ',', $order ) : ''
                );
            return self::makeSelectionMenu( $query, $template, $before, $after );
         } // showList
         
         public function edit( $variables = array() ) {
         } // edit
         
         public function post( $variables = array() ) {
         } // post
         */
      } // class DeviceType
?>