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 Location extends Camp {
protected static $dbStructure = array(
'table' => array(
'tableName' => 'location',
'primaryKey' => 'location_id',
'selectionDisplay' => 'name',
'inactiveField' => 'removed',
'fields' => array(
'id' => array (
'fieldname' => 'location_id',
'displayName' => 'ID',
'type' => 'int unsigned',
'nullable' => false,
'canEdit' => false
),
'name' => array (
'fieldname' => 'name',
'displayName' => 'Location',
'type' => 'varchar',
'size' => 64,
'list' => true
),
'uuid' => array (
'fieldname' => 'uuid',
'displayName' => 'UUID',
'type' => 'varchar',
'size' => 36,
'list' => false
),
'created' => array (
'fieldname' => 'created',
'displayName' => 'Created',
'type' => 'date'
),
'removed' => array(
'fieldname' => 'removed',
'displayName' => 'Removed',
'type' => 'date'
),
'owner' => array(
'fieldname' => 'owner_id',
'class' => 'Owner',
'displayName' => 'Owner',
'displayColumn' => 'name',
'type' => '1:1H',
'linkageTable' => 'owner_location',
'linkageColumn' => 'location_id',
'foreignColumn' => 'owner_id',
'foreignTable' => 'owner',
'inactiveField' => 'removed',
'addedField' => 'created'
),
) // fields
), // table
'view' => array(
'viewName' => 'view_device_location_owner_type',
'primaryKey' => 'location_id',
'selectionDisplay' => 'location',
'fields' => array(
'removed' => array(
'fieldname' => 'location_removed'
)
)
), // view
'children' => array(
'Device' => array(
'intermediateTable' => 'location_device',
'remoteID' => 'device_id',
'myID' => 'location_id'
)
) // children
); // dbStructure
/**
* 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
} // Location
?>