<?php

	
		

	/**
	 * @see DbObject
	 */
	class LocationAwareDbObject extends DbObject
	{
		var $_locationId;
		var $_location;
		
		function LocationAwareDbObject()
		{
			$this->_location = null;
			$this->_locationId = 0;
		}
		
		/**
		 * @return Location
		 */
		function getLocation()
		{
			if( $this->_location === null && $this->_locationId != 0 ) {
				
				$locations = new Locations();
				$this->_location = $locations->getLocation( $this->getLocationId());
			}
			
			return( $this->_location );
		}
		
		/**
		 * @param location Location
		 */
		function setLocation( $location )
		{
			$this->_location = $location;
			$this->setLocationId( $location->getId());
		}
		
		/**
		 * @return location id
		 */
		function getLocationId()
		{
			return( $this->_locationId );
		}
		
		/**
		 * Set the location id
		 */
		function setLocationId( $id )
		{
			$this->_locationId = $id;
			$this->_location = null;
		}
		
		/**
		 * @return True if this resource has location data or false otherwise
		 */
		function hasLocationData()
		{
			return( $this->getLocationId() != 0 );
		}
		
		/**
		 *
		 */
		function toJson()
		{
			$data = parent::toJson();
			if( $this->hasLocationData()) 
				$data["location"] = $this->getLocation();
				
			return( $data );
		}
	}
?>