Documentation is available at class_relationship.php
- <?php
- class relationship extends b_object {
- var $typeID;
- var $primaryID;
- var $secondaryID;
- function relationship( $constructID = NULL, $type = NULL, $primary = NULL, $secondary = NULL ) {
- if( $type ) {
- $this->type =& $GLOBALS['core']->get_relationship_type( $type );
- if( !$constructID ) {
- //if ID isn't specified or doesn't exist in database make a new object
- if( $type && $primary && $secondary && !strstr( $primary, "*new*" ) && !strstr( $secondary, "*new*" ) ) {
- //if a new object is being instantiated with values
- global $db;
- $db->hide_errors();
- $defined = $db->get_results( "SELECT id FROM relationships WHERE typeID = '".$type."' AND primaryID = '".$primary."' AND secondaryID = '".$secondary."'" );
- if( !count($defined) ) {
- //if the relationship isn't already defined
- $this->set( array( 'typeID'=>$type, 'primaryID'=>$primary, 'secondaryID'=>$secondary ) );
- } else {
- $defined = reset($defined);
- if( $defined ) { $this->relationship( $defined['id'], $type ); }
- else { return false; }
- }
- } else {
- //if a new object is being created without values
- echo 'RELATIONSHIP INSTANTIATED WITHOUT INITIAL VALUES -> BAD!!!';
- }
- } else if( array_key_exists( $constructID, $this->type->objects ) ) {
- //else initialize variables
- $this->id = $constructID;
- global $db;
- $object_info = reset($db->get_results( "SELECT * FROM ".$this->type->type_table_name." WHERE id = '".$constructID."'", ARRAY_A ));
- $this->typeID = $object_info['typeID'];
- $this->primaryID = $object_info['primaryID'];
- $this->secondaryID .= $object_info['secondaryID'];
- }
- $this->type->register_object($this);
- unset( $this->satisfied_constraints );
- } else {
- echo "NO TYPE SPECIFIED FOR RELATIONSHIP";
- }
- }
- function verify_set( &$values) {
- if( strtok( $values['related'], '?' ) == '*new*' ) {
- $constraintIDs = unserialize( strtok( '?' ) );
- //NOTE: note sure where to go from here...
- } else {
- if( $values['typeID'] ) {
- if( $values['target'] = "primary" ) {
- $primary = $values['related']; $secondary = $values['object'];
- } else {
- $primary = $values['object']; $secondary = $values['related'];
- }
- if( $primary && $secondary ) {
- parent::verify_set( array( 'typeID'=>$values['typeID'], 'primaryID'=>$primary, 'secondaryID'=>$secondary ) );
- } else {
- echo 'NEW RELATIONSHIP IS MISSING CONSTITUENT ELEMENTS';
- }
- } else {
- echo 'NEW RELATIONSHIP IS MISSING RELATIONSHIP TYPE';
- }
- }
- unset( $values['action'] );
- unset( $values['target'] );
- unset( $values['typeID'] );
- unset( $values['referrer'] );
- unset( $values['object'] );
- unset( $values['related'] );
- }
- function set( $values ) {
- parent::set( $values );
- if( $this->primaryID == $GLOBALS['user']->id || $this->secondaryID == $GLOBALS['user']->id ) {
- //if the relationship involves the current user reset their satisfied constraints
- unset( $GLOBALS['user']->satisfied_constraints );
- } else if( $this->type->type_name == 'permission-constraint' ) {
- //if a new permission-constraint relationship is being set unset the permission
- $permission =& get_object( $this->primaryID );
- $permission->permission( $permission->id, $permission->type->type_id );
- unset( $GLOBALS['permissions'][$permission->name] );
- }
- }
- //NOTE: relationships don't really have any properties to set, they should be deleted and re-created if they need to be changed
- function get_index( $direction = NULL ) {
- return $this->type->get_index( $direction );
- }
- function get_content() {
- $returnString;
- $primary =& get_object( $this->primaryID );
- $secondary =& get_object( $this->secondaryID );
- $returnString .= '<p>relationship id: '.$this->id.'<br>';
- $returnString .= 'relationship type: '.$this->type->type_name.'<br>';
- if( $primary ) { $returnString .= 'primary object: '.$primary->get_index().'<br>'; }
- if( $secondary ) { $returnString .= 'secondary object: '.$secondary->get_index().'<br>'; }
- return $returnString;
- }
- }
- ?>
Documentation generated on Tue, 24 May 2005 03:57:33 -0400 by phpDocumentor 1.3.0RC3