phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] CVS: cdb/inc class.cdb_entity.inc.php,1.1,1.2


From: Patrick Walsh <address@hidden>
Subject: [Phpgroupware-cvs] CVS: cdb/inc class.cdb_entity.inc.php,1.1,1.2
Date: Mon, 28 Jan 2002 04:49:54 -0500

Update of /cvsroot/phpgroupware/cdb/inc
In directory subversions:/tmp/cvs-serv11606

Modified Files:
        class.cdb_entity.inc.php 
Log Message:
fleshed out all the functions

Index: class.cdb_entity.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/cdb/inc/class.cdb_entity.inc.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** class.cdb_entity.inc.php    11 Nov 2001 15:43:42 -0000      1.1
--- class.cdb_entity.inc.php    28 Jan 2002 09:49:51 -0000      1.2
***************
*** 16,71 ****
    /* $Id$ */
  
!       class cdb_entity
        {
!               var $_ = array();
!               var $dirty = array();
  
!               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
                        );
                }
  
!               function get_type()
                {
!                       return $this->_['entity_type'];
                }
  
!               function let_type($new_type)
                {
!                       if (strtolower($new_type) == 'contact')
                        {
!                               $this->_['entity_type'] = 'contact';
                        }
!                       elseif(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;
                }
!       }
  ?>
--- 16,281 ----
    /* $Id$ */
  
! /*!
!               @class cdb_entity
!               @abstract Root Entity Class
!               @discussion This class is a container that holds either an 
organization
!               class object or a contact class object.
!               @syntax CreateObject('cdb.cdb_entity');
!               @example $x = CreateObject('cdb.cdb_entity'); 
!               @example x->let_type("contact");
!               @example x->get_contact_data();
!               @author mr_e
!               @copyright GPL
!               @package cdb
!               @access public
! */
!       class cdb_entity extends cdb_generic
        {
!                 /////////////////////////////////////////////////
!                /////////////// Local Variables /////////////////
!               /////////////////////////////////////////////////
!               /* PHP does not support local vars.  Use         */
!               /* 'var $_varname;' to signify local vars.       */
!               var $_contact;  // my contact subclass
!               var $_org;              // my org subclass
  
!               function cdb_entity()
                {
+                       $this->_db = $GLOBALS['phpgw']->db;
                        $this->_ = array(
!                               //Either 'contact' or 'organization'
!                               'entity_type' => 'contact',     
!                               //if entity_type='organization' and loaded=true 
then this 
!                               //contains the loaded org data
!                               'organization_obj' => '',       
!                               //if entity_type='contact' and loaded==true 
then this contains
!                               //the loaded contact data
!                               'contact_obj' => '',            
!                               //True when the object is already loaded
!                               'loaded'      => FALSE          
                        );
                }
  
!               /*!
!               @function load
!               @abstract Loads an entity into the entity object
!               @discussion Loads an entity into the entity object
!               @syntax int load(int entity_id)
!               @example1 $x->load($entity_id)
!               @param entity_id int-the global entity id (not org id or 
contact id)
!               */
!               function load($entity_id)
                {
!                       // Unload everything first
!                       unset $this->_org;
!                       unset $this->_contact;
!                       $this->_let('loaded',FALSE);
!                       $this->_id = 0;
! 
!                       $sql = 'SELECT * FROM cdb_entity_id WHERE ';
!                       $sql .= 'entity_id="'.$entity_id.'"';
!                       $this->_db->query($sql,__LINE__,__FILE__);
!                       if ($this->_db->next_record())
!                       {
!                               $contact_id = $this->_db->f('contact_id');
!                               $org_id = $this->_db->f('organization_id');
!                               $this->_id = $entity_id;
!                               if ($contact_id) 
!                               {
!                                       $this->_let('entity_type','contact');
!                                       $this->_contact = 
CreateObject('cdb.cdb_contact');
!                                       if ($this->_contact->load($contact_id))
!                                       {
!                                               $this->_let('loaded',TRUE);
!                                               return $this->id();
!                                       }
!                                       else
!                                       {
!                                               return FALSE;
!                                       }
!                               }
!                               else if ($org_id)
!                               {
!                                       
$this->_let('entity_type','organization');
!                                       $this->_org = 
CreateObject('cdb.cdb_organization');
!                                       if ($this->_org->load($org_id))
!                                       {
!                                               $this->_let('loaded',TRUE);
!                                               return $this->id();
!                                       }
!                                       else
!                                       {
!                                               return FALSE;
!                                       }
!                               }
!                               else
!                               {
!                                       return FALSE;
!                               }
!                       }
!                       else
!                       {
!                               return FALSE;
!                       }
                }
  
!               /*!
!               @function create
!               @abstract Creates a new entity
!               @discussion Creates a new entity of type specified
!               @syntax int create(str entity_type)
!               @example1 $x->create('organization')
!               @param entity_type str-either "contact" or "organization"
!               */
!               function create($entity_type)
                {
!                       unset $this->_org;
!                       unset $this->_contact;
!                       $this->_let('loaded',FALSE);
!                       $this->_id = 0;
! 
!                       if ($entity_type == 'contact')
!                       {
!                               $this->_let('entity_type','contact');
!                               $this->_contact = 
CreateObject('cdb.cdb_contact');
!                               if ($this->_contact->create(''))
!                               {
!                                       $this->_id = $this->_contact->id();
!                                       $this->_let('loaded',TRUE);
!                                       return $this->id();
!                               }
!                               else
!                               {
!                                       // TODO: raise phpgw error
!                                       return FALSE;
!                               }
!                       }
!                       else if ($entity_type == 'organization')
                        {
!                               $this->_let('entity_type','organization');
!                               $this->_org = 
CreateObject('cdb.cdb_organization');
!                               if ($org_id = $this->_org->create(''))
!                               {
!                                       $sql = 'INSERT INO cdb_entity_id 
("organization_id") VALUES ("' . $org_id . '")';
!                                       
$this->_db->query($sql,__LINE__,__FILE__);
!                                       $this->_id = 
$this->_db->get_last_insert_id('cdb_entity_id','entity_id');
!                                       $this->_let('loaded',TRUE);
!                                       return $this->id();
!                               }
!                               else
!                               {
!                                       return FALSE;
!                               }
                        }
!                       else
                        {
!                               //TODO raise a phpgw error
!                               return FALSE;
                        }
                }
  
!               /*!function delete
!               @abstract Move the entity to the trashcan
!               @discussion Mark the entity as deleted
!               */
!               function delete()
!               {
!                       //TODO: call contact.delete or org.delete
!               }
! 
!           function exists($entity_id)
!       {
!               if (!is_int($entity_id))
!               {
!               $entity_id = $this->id();
!               }
!               $sql='SELECT * FROM cdb_entity_id WHERE 
entity_id="'.$entity_id.'"';
!               $this->_db->query($sql,__LINE__,__FILE__);
!               if ($this->_db->num_rows() > 0)
!               {
!               return TRUE;
!               }
!               else
!               {
!               return FALSE;
!               }
!       }
! 
!               /*!
!               @function get_type
!               @abstract Get's the entity type
!               @discussion Returns either "contact" or "organization"
!               */
!               function get_type()
!               {
!                       return $this->_get('entity_type');
!               }
! 
!               /*!
!               @function get_organization_data
!               @abstract Returns the loaded org class, if one exists
!               @discussion This is an alias of get_org_data
!               */
!               function get_organization_data() 
                {
!                       return get_org_data();
                }
  
!               /*!
!               @function get_loaded
!               @abstract Returns true if a entity is loaded in memory
!               */
!               function get_loaded()
                {
!                       return $this->_get('loaded');
!               }
! 
!               /*!
!               @function get_org_data
!               @abstract Returns the loaded org class, if one exists
!               */
!               function get_org_data
!               {
!                       if ($this->get_loaded() && 
$this->get_type()=='organization') 
!                       {
!                               return $_org;
!                       }
!                       else
!                       {
!                               return FALSE;
!                       {
!               }
!               
!               /*!
!               @function get_contact_data
!               @abstract Returns the loaded contact class, if one exists
!               */
!               function get_contact_data()
!               {
!                       if ($this->get_loaded() && $this->get_type()=='contact')
!                       {
!                               return $_contact;
!                       }
!                       else
!                       {
!                               return FALSE;
!                       }
!               }
! 
!               /*!
!               @function get_data
!               @abstract Returns whichever class is loaded or null if neither
!               */
!               function get_data()
!               {
!                       if ($this->get_type() == "contact") 
!                       {
!                               return get_contact_data();
!                       } 
!                       else 
                        {
!                               return get_org_data();
                        }
                }
!       } // end class
  ?>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]