Subversion Repositories computer_asset_manager_v2

Rev

Rev 72 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
53 rodolico 1
<?php
2
   require_once( 'camp.class.php' );
3
 
4
   class Location extends Camp {
5
      protected static $dbStructure = array(
6
         'table' => array( 
7
            'tableName' => 'location',
8
            'primaryKey' => 'location_id',
9
            'selectionDisplay' => 'name',
69 rodolico 10
            'inactiveField' => 'removed',
53 rodolico 11
            'fields' => array(
56 rodolico 12
                  'id' => array (
13
                     'fieldname' => 'location_id',
53 rodolico 14
                     'displayName' => 'ID',
15
                     'type' => 'int unsigned',
67 rodolico 16
                     'nullable' => false,
17
                     'canEdit' => false
53 rodolico 18
                  ),
19
                  'name' => array (
56 rodolico 20
                     'fieldname' => 'name',
21
                     'displayName' => 'Location',
53 rodolico 22
                     'type' => 'varchar',
23
                     'size' => 64,
24
                     'list' => true
25
                  ),
63 rodolico 26
                  'uuid' => array (
27
                     'fieldname' => 'uuid',
28
                     'displayName' => 'UUID',
29
                     'type' => 'varchar',
30
                     'size' => 36,
31
                     'list' => false
32
                  ),
53 rodolico 33
                  'created' => array (
56 rodolico 34
                     'fieldname' => 'created',
53 rodolico 35
                     'displayName' => 'Created',
36
                     'type' => 'date'
37
                  ),
38
                  'removed' => array(
56 rodolico 39
                     'fieldname' => 'removed',
53 rodolico 40
                     'displayName' => 'Removed',
41
                     'type' => 'date'
59 rodolico 42
                  ),
67 rodolico 43
                  'owner' => array(
44
                     'fieldname' => 'owner_id',
59 rodolico 45
                     'class' => 'Owner',
64 rodolico 46
                     'displayName' => 'Owner',
69 rodolico 47
                     'displayColumn' => 'name',
64 rodolico 48
                     'type' => '1:1H',
65 rodolico 49
                     'linkageTable' => 'owner_location',
50
                     'linkageColumn' => 'location_id',
51
                     'foreignColumn' => 'owner_id',
72 rodolico 52
                     'foreignTable' => 'owner',
53
                     'inactiveField' => 'removed',
54
                     'addedField' => 'created'
59 rodolico 55
                  ),
53 rodolico 56
            ) // fields
56 rodolico 57
         ), // table
58
         'view' => array(
59
            'viewName' => 'view_device_location_owner_type',
60
            'primaryKey' => 'location_id',
61
            'selectionDisplay' => 'location',
62
            'fields' => array(
63
               'removed' => array( 
64
                  'fieldname' => 'location_removed'
65
               )
66
            )
59 rodolico 67
         ), // view
68
         'children' => array(
69 rodolico 69
               'Device' => array(
70
                  'intermediateTable' => 'location_device',
71
                  'remoteID' => 'device_id',
72
                  'myID' => 'location_id'
73
                  )
59 rodolico 74
         ) // children
53 rodolico 75
      ); // dbStructure
59 rodolico 76
 
72 rodolico 77
      /**
78
       * Function to change the owner of the current record
79
       * 
80
       * Mainly used by calling programs to change a owner programmatically
81
       * instead of trying to push throuhg something else.
82
       * 
83
       * @parameter int $newowner The index (owner_id) to be used
84
       * @parameter string $effectiveDate Date in YYYYMMDD format. If null, uses now()
85
       */
86
      public function changeOwner( $newOwner, $effectiveDate = null ) {
87
         global $dbConnection;
88
 
89
         $effectiveDate = $effectiveDate ? "'$effectiveDate'" : 'now()';
90
         $query = sprintf( 
91
            'update %s set removed = %s where removed is null',
92
            $self::$dbStructure['table']['fields']['owner']['linkageTable'],
93
            $effectiveDate
94
         );
95
         $dbConnection->doSQL( $query );
96
         $query = sprintf(
97
            'insert into %s ( %s, %s, %s ) values (%s, %s, %s)',
98
            $self::$dbStructure['table']['fields']['owner']['linkageTable'],
99
            $self::$dbStructure['table']['fields']['owner']['foreignColumn'],
100
            $self::$dbStructure['table']['fields']['owner']['linkageColumn'],
101
            $self::$dbStructure['table']['fields']['owner']['addedField'],
102
            $newOwner,
103
            $this->id,
104
            $effectiveDate
105
         );
106
         $dbConnection->doSQL( $query );
107
      } // changeOwner
108
 
109
 
110
 
59 rodolico 111
   } // Location
53 rodolico 112
 
113
?>