| 78 | rodolico | 1 | <?php
 | 
        
           |  |  | 2 |   | 
        
           |  |  | 3 |    class Attribute {
 | 
        
           |  |  | 4 |   | 
        
           |  |  | 5 |       protected static $dbStructure = array(
 | 
        
           |  |  | 6 |          'Entry Point' => 'attribute_value',
 | 
        
           |  |  | 7 |          'Summary Query' => '
 | 
        
           |  |  | 8 |             select
 | 
        
           |  |  | 9 |                attribute_category.name category,
 | 
        
           |  |  | 10 |                attribute.name attribute,
 | 
        
           |  |  | 11 |                attribute_value.value
 | 
        
           |  |  | 12 |             from
 | 
        
           |  |  | 13 |                attribute_value
 | 
        
           |  |  | 14 |                join attribute using (attribute_id)
 | 
        
           |  |  | 15 |                join attribute_category using (attribute_category_id)
 | 
        
           |  |  | 16 |             where 
 | 
        
           |  |  | 17 |                1=1
 | 
        
           |  |  | 18 |                and attribute.display_in_summary
 | 
        
           |  |  | 19 |                and attribute_value.removed is null
 | 
        
           |  |  | 20 |                and entity_id = ~~id~~
 | 
        
           |  |  | 21 |                and _base_class_id = ~~class~~
 | 
        
           |  |  | 22 |             order by
 | 
        
           |  |  | 23 |                attribute_category.sort_order,
 | 
        
           |  |  | 24 |                attribute_category.name,
 | 
        
           |  |  | 25 |                attribute.sort_order,
 | 
        
           |  |  | 26 |                attribute.name,
 | 
        
           |  |  | 27 |                attribute_value.value
 | 
        
           |  |  | 28 |          ',         
 | 
        
           |  |  | 29 |          'tables' => array(
 | 
        
           |  |  | 30 |             'attribute_value' => array(
 | 
        
           |  |  | 31 |                'Primary Key' => 'attribute_value_id',
 | 
        
           |  |  | 32 |                'comment' => 'attributes for entities (devices, locations, owners)',
 | 
        
           |  |  | 33 |                'fields' => array(
 | 
        
           |  |  | 34 |                   'attribute_id' => array(
 | 
        
           |  |  | 35 |                      'type' => 'foreign key',
 | 
        
           |  |  | 36 |                      'target' => 'attribute'
 | 
        
           |  |  | 37 |                   ),
 | 
        
           |  |  | 38 |                   '_base_class_id' => array(
 | 
        
           |  |  | 39 |                      'type' => 'foreign key',
 | 
        
           |  |  | 40 |                      'target' => '_base_class'
 | 
        
           |  |  | 41 |                   ),
 | 
        
           |  |  | 42 |                   'entity' => array(
 | 
        
           |  |  | 43 |                      'type' => 'foreign key',
 | 
        
           |  |  | 44 |                      'target' => '',
 | 
        
           |  |  | 45 |                      'comment' => 'references ${_base_class}.{id}',
 | 
        
           |  |  | 46 |                   ),
 | 
        
           |  |  | 47 |                   'value' => array(
 | 
        
           |  |  | 48 |                      'type' => 'text',
 | 
        
           |  |  | 49 |                      'default' => '',
 | 
        
           |  |  | 50 |                      'comment' => 'the actual value stored'
 | 
        
           |  |  | 51 |                   ),
 | 
        
           |  |  | 52 |                   'added' => array(
 | 
        
           |  |  | 53 |                      'type'    => 'date',
 | 
        
           |  |  | 54 |                      'default' => 'now()'
 | 
        
           |  |  | 55 |                   ),
 | 
        
           |  |  | 56 |                   'removed' -> array(
 | 
        
           |  |  | 57 |                      'type' => 'date',
 | 
        
           |  |  | 58 |                      'default' => 'null'
 | 
        
           |  |  | 59 |                   )
 | 
        
           |  |  | 60 |                ) // fields
 | 
        
           |  |  | 61 |             ), // attribute_value table
 | 
        
           |  |  | 62 |             'attribute' => array(
 | 
        
           |  |  | 63 |                'Primary Key' => 'attribute_id',
 | 
        
           |  |  | 64 |                'comment' => 'stores attribute names (not values) for other tables',
 | 
        
           |  |  | 65 |                'fields' => array(
 | 
        
           |  |  | 66 |                   'name' => array(
 | 
        
           |  |  | 67 |                      'type' => 'varchar',
 | 
        
           |  |  | 68 |                      'size' => 64,
 | 
        
           |  |  | 69 |                      'null' => false,
 | 
        
           |  |  | 70 |                      'comment' => 'name for display',
 | 
        
           |  |  | 71 |                      'summary field' => true
 | 
        
           |  |  | 72 |                   ),
 | 
        
           |  |  | 73 |                   'attribute_category_id' => array(
 | 
        
           |  |  | 74 |                      'type' => 'foreign key',
 | 
        
           |  |  | 75 |                      'target' => 'attribute_category'
 | 
        
           |  |  | 76 |                   ),
 | 
        
           |  |  | 77 |                   'multiples' => array(
 | 
        
           |  |  | 78 |                      'type' => 'bool',
 | 
        
           |  |  | 79 |                      'default' => 0,
 | 
        
           |  |  | 80 |                      'comment' =>  'if set, multiple instances of the same attribute are allowed',
 | 
        
           |  |  | 81 |                   ),
 | 
        
           |  |  | 82 |                   'display_in_summary' => array(
 | 
        
           |  |  | 83 |                      'type' => 'bool',
 | 
        
           |  |  | 84 |                      'default' => 0,
 | 
        
           |  |  | 85 |                      'comment' => 'if true, indicates it should be displayed when device/site/client screen is open',
 | 
        
           |  |  | 86 |                   )
 | 
        
           |  |  | 87 |                   'added' => array(
 | 
        
           |  |  | 88 |                      'type'    => 'date',
 | 
        
           |  |  | 89 |                      'default' => 'now()'
 | 
        
           |  |  | 90 |                   ),
 | 
        
           |  |  | 91 |                   'removed' -> array(
 | 
        
           |  |  | 92 |                      'type' => 'date',
 | 
        
           |  |  | 93 |                      'default' => 'null'
 | 
        
           |  |  | 94 |                   )
 | 
        
           |  |  | 95 |                ), // fields
 | 
        
           |  |  | 96 |             ), // attributes
 | 
        
           |  |  | 97 |   | 
        
           |  |  | 98 |             'attribute_category' => array(
 | 
        
           |  |  | 99 |                'primary key' => 'attribute_category_id',
 | 
        
           |  |  | 100 |                'comment' => 'categorizes attributes',
 | 
        
           |  |  | 101 |                'fields' => array(
 | 
        
           |  |  | 102 |                   'name' => array(
 | 
        
           |  |  | 103 |                      'type' => 'varchar',
 | 
        
           |  |  | 104 |                      'size' => 64,
 | 
        
           |  |  | 105 |                      'null' => false,
 | 
        
           |  |  | 106 |                      'comment' => 'display name for category',
 | 
        
           |  |  | 107 |                   ),
 | 
        
           |  |  | 108 |                ) // fields
 | 
        
           |  |  | 109 |             ), // attribute_category
 | 
        
           |  |  | 110 |          ) // tables
 | 
        
           |  |  | 111 |       ); // $dbStructure
 | 
        
           |  |  | 112 |   | 
        
           |  |  | 113 |   | 
        
           |  |  | 114 |       /**
 | 
        
           |  |  | 115 |        * returns HTML table with summary of class for a particular entity
 | 
        
           |  |  | 116 |        * 
 | 
        
           |  |  | 117 |        * The entity ID is passed as the first class, and the class  optionally as the second, to allow
 | 
        
           |  |  | 118 |        * for classes which serve more than one base class (owner, location, device). Will return all rows
 | 
        
           |  |  | 119 |        * related to the base class.
 | 
        
           |  |  | 120 |        * 
 | 
        
           |  |  | 121 |        * @parameter $id int The entity id to retrieve for, ie device_id, owner_id, location_id
 | 
        
           |  |  | 122 |        * @parameter $class string The name of the class for which we are to retrieve values
 | 
        
           |  |  | 123 |        * 
 | 
        
           |  |  | 124 |        * @returns string An HTML table with the summary of the current entries
 | 
        
           |  |  | 125 |        */
 | 
        
           |  |  | 126 |       public static function summaryTable( $id, $class = null ) {
 | 
        
           |  |  | 127 |          $query = $this->dbStructure['Summary Query'];
 | 
        
           |  |  | 128 |   | 
        
           |  |  | 129 |       } // function summaryTable
 | 
        
           |  |  | 130 |   | 
        
           |  |  | 131 |   | 
        
           |  |  | 132 |   | 
        
           |  |  | 133 |    }
 | 
        
           |  |  | 134 |   | 
        
           |  |  | 135 | ?>
 |