Rev 69 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
<?php
require_once( 'camp.class.php' );
class Device extends Camp {
protected static $dbStructure = array(
'table' => array(
'tableName' => 'device',
'primaryKey' => 'device_id',
'selectionDisplay' => 'name',
'inactiveField' => 'removed',
'fields' => array(
'id' => array (
'fieldname' => 'device_id',
'displayName' => 'ID',
'type' => 'int unsigned',
'nullable' => false,
'canEdit' => false
),
'name' => array (
'fieldname' => 'name',
'displayName' => 'Name',
'type' => 'varchar',
'size' => 64,
'list' => true
),
'uuid' => array (
'fieldname' => 'uuid',
'displayName' => 'UUID',
'type' => 'varchar',
'size' => 36,
'list' => false
),
'serial' => array (
'fieldname' => 'serial',
'displayName' => 'Serial',
'type' => 'varchar',
'size' => 36,
'list' => false
),
'created' => array (
'fieldname' => 'created',
'displayName' => 'Created',
'type' => 'date'
),
'removed' => array(
'fieldname' => 'removed',
'displayName' => 'Removed',
'type' => 'date'
),
'device_types' => array(
'fieldname' => 'device_types',
'displayName' => 'Device Type',
'type' => '1:M',
'linkageTable' => 'device_device_type',
'linkageColumn' => 'device_id',
'foreignTable' => 'device_type',
'foreignColumn' => 'device_type_id',
'foreignDisplayColumn' => 'name',
'displayView' => array (
'viewName' => 'device_device_types',
'myField' => 'device_id',
'displayField' => 'device_types'
)
),
'parent' => array(
'displayQuery' => 'select b.device_id id, b.name display from device_device a join device b on (a.parent_id = b.device_id) where a.removed is null and a.device_id = ~~id~~',
'fieldname' => 'parent_id',
'class' => 'Device',
'displayName' => 'Parent',
'displayColumn' => 'name',
'type' => '1:1H',
'linkageTable' => 'device_device',
'linkageColumn' => 'device_id',
'foreignColumn' => 'parent_id',
'foreignTable' => 'device',
'inactiveField' => 'removed',
'addedField' => 'created'
),
'owner' => array(
'fieldname' => 'owner_id',
'class' => 'Owner',
'displayName' => 'Owner',
'displayColumn' => 'name',
'type' => '1:1H',
'linkageTable' => 'owner_device',
'linkageColumn' => 'device_id',
'foreignColumn' => 'owner_id',
'foreignTable' => 'owner',
'inactiveField' => 'removed',
'addedField' => 'created'
),
'location' => array(
'fieldname' => 'location_id',
'class' => 'Location',
'displayName' => 'Location',
'displayColumn' => 'name',
'type' => '1:1H',
'linkageTable' => 'location_device',
'linkageColumn' => 'device_id',
'foreignColumn' => 'location_id',
'foreignTable' => 'location',
'inactiveField' => 'removed',
'addedField' => 'created'
),
) // fields
), // table
'children' => array(
'Device' => array(
'name' => 'Children',
'class' => 'Device',
'query' => 'select device_id id,name name from device where device_id in (select device_id from device_device where removed is null and parent_id = ~~device_id~~) order by name',
'noAdd' => true
)
) // children
); // dbStructure
/**
* Function to change the location of the current record
*
* Mainly used by calling programs to change a location programmatically
* instead of trying to push throuhg something else.
*
* @parameter int $newLocation The index (location_id) to be used
* @parameter string $effectiveDate Date in YYYYMMDD format. If null, uses now()
*/
public function changeLocation( $newLocation, $effectiveDate = null ) {
global $dbConnection;
$effectiveDate = $effectiveDate ? "'$effectiveDate'" : 'now()';
$query = sprintf(
'update %s set removed = %s where removed is null',
$self::$dbStructure['table']['fields']['location']['linkageTable'],
$effectiveDate
);
$dbConnection->doSQL( $query );
$query = sprintf(
'insert into %s ( %s, %s, %s ) values (%s, %s, %s)',
$self::$dbStructure['table']['fields']['location']['linkageTable'],
$self::$dbStructure['table']['fields']['location']['foreignColumn'],
$self::$dbStructure['table']['fields']['location']['linkageColumn'],
$self::$dbStructure['table']['fields']['location']['addedField'],
$newLocation,
$this->id,
$effectiveDate
);
$dbConnection->doSQL( $query );
} // changeLocation
/**
* Function to change the owner of the current record
*
* Mainly used by calling programs to change a owner programmatically
* instead of trying to push throuhg something else.
*
* @parameter int $newowner The index (owner_id) to be used
* @parameter string $effectiveDate Date in YYYYMMDD format. If null, uses now()
*/
public function changeOwner( $newOwner, $effectiveDate = null ) {
global $dbConnection;
$effectiveDate = $effectiveDate ? "'$effectiveDate'" : 'now()';
$query = sprintf(
'update %s set removed = %s where removed is null',
$self::$dbStructure['table']['fields']['owner']['linkageTable'],
$effectiveDate
);
$dbConnection->doSQL( $query );
$query = sprintf(
'insert into %s ( %s, %s, %s ) values (%s, %s, %s)',
$self::$dbStructure['table']['fields']['owner']['linkageTable'],
$self::$dbStructure['table']['fields']['owner']['foreignColumn'],
$self::$dbStructure['table']['fields']['owner']['linkageColumn'],
$self::$dbStructure['table']['fields']['owner']['addedField'],
$newOwner,
$this->id,
$effectiveDate
);
$dbConnection->doSQL( $query );
} // changeOwner
/**
* Function to change the parent of the current record
*
* Mainly used by calling programs to change a parent programmatically
* instead of trying to push through something else.
*
* @parameter int $newParent The index (parent_id) to be used
* @parameter string $effectiveDate Date in YYYYMMDD format. If null, uses now()
*/
public function changeParent( $newParent, $effectiveDate = null ) {
global $dbConnection;
$effectiveDate = $effectiveDate ? "'$effectiveDate'" : 'now()';
$query = sprintf(
'update %s set removed = %s where removed is null',
$self::$dbStructure['table']['fields']['parent']['linkageTable'],
$effectiveDate
);
$dbConnection->doSQL( $query );
$query = sprintf(
'insert into %s ( %s, %s, %s ) values (%s, %s, %s)',
$self::$dbStructure['table']['fields']['parent']['linkageTable'],
$self::$dbStructure['table']['fields']['parent']['foreignColumn'],
$self::$dbStructure['table']['fields']['parent']['linkageColumn'],
$self::$dbStructure['table']['fields']['parent']['addedField'],
$newParent,
$this->id,
$effectiveDate
);
$dbConnection->doSQL( $query );
} // changeParent
} // class Device
?>