Subversion Repositories computer_asset_manager_v2

Rev

Blame | Last modification | View Log | Download | RSS feed

<?php

   class Attribute {

      protected static $dbStructure = array(
         'Entry Point' => 'attribute_value',
         'Summary Query' => '
            select
               attribute_category.name category,
               attribute.name attribute,
               attribute_value.value
            from
               attribute_value
               join attribute using (attribute_id)
               join attribute_category using (attribute_category_id)
            where 
               1=1
               and attribute.display_in_summary
               and attribute_value.removed is null
               and entity_id = ~~id~~
               and _base_class_id = ~~class~~
            order by
               attribute_category.sort_order,
               attribute_category.name,
               attribute.sort_order,
               attribute.name,
               attribute_value.value
         ',         
         'tables' => array(
            'attribute_value' => array(
               'Primary Key' => 'attribute_value_id',
               'comment' => 'attributes for entities (devices, locations, owners)',
               'fields' => array(
                  'attribute_id' => array(
                     'type' => 'foreign key',
                     'target' => 'attribute'
                  ),
                  '_base_class_id' => array(
                     'type' => 'foreign key',
                     'target' => '_base_class'
                  ),
                  'entity' => array(
                     'type' => 'foreign key',
                     'target' => '',
                     'comment' => 'references ${_base_class}.{id}',
                  ),
                  'value' => array(
                     'type' => 'text',
                     'default' => '',
                     'comment' => 'the actual value stored'
                  ),
                  'added' => array(
                     'type'    => 'date',
                     'default' => 'now()'
                  ),
                  'removed' -> array(
                     'type' => 'date',
                     'default' => 'null'
                  )
               ) // fields
            ), // attribute_value table
            'attribute' => array(
               'Primary Key' => 'attribute_id',
               'comment' => 'stores attribute names (not values) for other tables',
               'fields' => array(
                  'name' => array(
                     'type' => 'varchar',
                     'size' => 64,
                     'null' => false,
                     'comment' => 'name for display',
                     'summary field' => true
                  ),
                  'attribute_category_id' => array(
                     'type' => 'foreign key',
                     'target' => 'attribute_category'
                  ),
                  'multiples' => array(
                     'type' => 'bool',
                     'default' => 0,
                     'comment' =>  'if set, multiple instances of the same attribute are allowed',
                  ),
                  'display_in_summary' => array(
                     'type' => 'bool',
                     'default' => 0,
                     'comment' => 'if true, indicates it should be displayed when device/site/client screen is open',
                  )
                  'added' => array(
                     'type'    => 'date',
                     'default' => 'now()'
                  ),
                  'removed' -> array(
                     'type' => 'date',
                     'default' => 'null'
                  )
               ), // fields
            ), // attributes

            'attribute_category' => array(
               'primary key' => 'attribute_category_id',
               'comment' => 'categorizes attributes',
               'fields' => array(
                  'name' => array(
                     'type' => 'varchar',
                     'size' => 64,
                     'null' => false,
                     'comment' => 'display name for category',
                  ),
               ) // fields
            ), // attribute_category
         ) // tables
      ); // $dbStructure
      
      
      /**
       * returns HTML table with summary of class for a particular entity
       * 
       * The entity ID is passed as the first class, and the class  optionally as the second, to allow
       * for classes which serve more than one base class (owner, location, device). Will return all rows
       * related to the base class.
       * 
       * @parameter $id int The entity id to retrieve for, ie device_id, owner_id, location_id
       * @parameter $class string The name of the class for which we are to retrieve values
       * 
       * @returns string An HTML table with the summary of the current entries
       */
      public static function summaryTable( $id, $class = null ) {
         $query = $this->dbStructure['Summary Query'];
         
      } // function summaryTable
               


   }

?>