<?php
  /**************************************************************************\
  * phpGroupWare                                                             *
  * http://www.phpgroupware.org/                                             *
  * This file written by Patrick Walsh <patrick@phpgroupware.org>            *
  * ------------------------------------------------------------------------ *
  * Please see the documentation for these classes in the README file in     *
  * this directory.                                                          *
  * ------------------------------------------------------------------------ *
  *  This program is free software; you can redistribute it and/or modify it *
  *  under the terms of the GNU General Public License as published by the   *
  *  Free Software Foundation; either version 2 of the License, or (at your  *
  *  option) any later version.                                              *
  \**************************************************************************/

  /* $Id: entity.class.php,v 1.3 2000/11/30 23:17:35 pjw Exp $ */


/*

	Consider this class broken for the time being.

		-Patrick
*/



class cdb_entity {

  /////////////////////////////////////////////////
 ////////////// Public Variables /////////////////
/////////////////////////////////////////////////
/* These vars are declared like: 'var $varname;' */

  /////////////////////////////////////////////////
 /////////////// Local Variables /////////////////
/////////////////////////////////////////////////
	var $_ = array();
	var $dirty = array();

  /////////////////////////////////////////////////
 //////////// Constructor Functions //////////////
/////////////////////////////////////////////////
	function cdb_entity_class() {
	  $this->_=array(
	    entity_type=>'contact',   //Either 'contact' or 'organization'
	    entity_id=>0,             //The id of the loaded entity
	    organization_obj,         //if entity_type='organization' and 
                                      // loaded=true then this contains the 
                                      // loaded org data
	    contact_obj,              //if entity_type='contact' and loaded=
                                      // true then this contains the loaded
                                      // contact data
	    loaded=>false             //True when the object is already loaded
	  );
	}

  /////////////////////////////////////////////////
 ////////////// Public Functions /////////////////
/////////////////////////////////////////////////
	function get_type() {
		return $this->_[entity_type];
	}

	function let_type($new_type) {
		if (strtolower($new_type) == 'contact') {
			$this->_[entity_type] = 'contact';
		} else if (strtolower(substr($new_type,0,3)) == 'org') {
			$this->_[entity_type] = 'organization';
		}
	}

	function get_id() {
		return $this->_[entity_id];
	}

	function let_id($new_id) {
		if ($this->_[loaded] && $this->_[entity_id]<>(int) $new_id) {
			// set loaded to false if we are setting a new id
			// and we were previously loaded.
			$this->_[loaded] = false;
		}
		$this->_[entity_id] = (int) $new_id;
	}
}
?>
