Source for file class_relationship.php

Documentation is available at class_relationship.php

  1. <?php
  2. class relationship extends b_object {
  3. var $typeID;
  4. var $primaryID;
  5. var $secondaryID;
  6.  
  7. function relationship( $constructID = NULL, $type = NULL, $primary = NULL, $secondary = NULL ) {
  8. if( $type ) {
  9. $this->type =& $GLOBALS['core']->get_relationship_type( $type );
  10. if( !$constructID ) {
  11. //if ID isn't specified or doesn't exist in database make a new object
  12. if( $type && $primary && $secondary && !strstr( $primary, "*new*" ) && !strstr( $secondary, "*new*" ) ) {
  13. //if a new object is being instantiated with values
  14. global $db;
  15. $db->hide_errors();
  16. $defined = $db->get_results( "SELECT id FROM relationships WHERE typeID = '".$type."' AND primaryID = '".$primary."' AND secondaryID = '".$secondary."'" );
  17. if( !count($defined) ) {
  18. //if the relationship isn't already defined
  19. $this->set( array( 'typeID'=>$type, 'primaryID'=>$primary, 'secondaryID'=>$secondary ) );
  20. } else {
  21. $defined = reset($defined);
  22. if( $defined ) { $this->relationship( $defined['id'], $type ); }
  23. else { return false; }
  24. }
  25. } else {
  26. //if a new object is being created without values
  27. echo 'RELATIONSHIP INSTANTIATED WITHOUT INITIAL VALUES -> BAD!!!';
  28. }
  29. } else if( array_key_exists( $constructID, $this->type->objects ) ) {
  30. //else initialize variables
  31. $this->id = $constructID;
  32. global $db;
  33. $object_info = reset($db->get_results( "SELECT * FROM ".$this->type->type_table_name." WHERE id = '".$constructID."'", ARRAY_A ));
  34. $this->typeID = $object_info['typeID'];
  35. $this->primaryID = $object_info['primaryID'];
  36. $this->secondaryID .= $object_info['secondaryID'];
  37. }
  38. $this->type->register_object($this);
  39. unset( $this->satisfied_constraints );
  40. } else {
  41. echo "NO TYPE SPECIFIED FOR RELATIONSHIP";
  42. }
  43. }
  44. function verify_set( &$values) {
  45. if( strtok( $values['related'], '?' ) == '*new*' ) {
  46. $constraintIDs = unserialize( strtok( '?' ) );
  47. //NOTE: note sure where to go from here...
  48. } else {
  49. if( $values['typeID'] ) {
  50. if( $values['target'] = "primary" ) {
  51. $primary = $values['related']; $secondary = $values['object'];
  52. } else {
  53. $primary = $values['object']; $secondary = $values['related'];
  54. }
  55. if( $primary && $secondary ) {
  56. parent::verify_set( array( 'typeID'=>$values['typeID'], 'primaryID'=>$primary, 'secondaryID'=>$secondary ) );
  57. } else {
  58. echo 'NEW RELATIONSHIP IS MISSING CONSTITUENT ELEMENTS';
  59. }
  60. } else {
  61. echo 'NEW RELATIONSHIP IS MISSING RELATIONSHIP TYPE';
  62. }
  63. }
  64. unset( $values['action'] );
  65. unset( $values['target'] );
  66. unset( $values['typeID'] );
  67. unset( $values['referrer'] );
  68. unset( $values['object'] );
  69. unset( $values['related'] );
  70. }
  71. function set( $values ) {
  72. parent::set( $values );
  73. if( $this->primaryID == $GLOBALS['user']->id || $this->secondaryID == $GLOBALS['user']->id ) {
  74. //if the relationship involves the current user reset their satisfied constraints
  75. unset( $GLOBALS['user']->satisfied_constraints );
  76. } else if( $this->type->type_name == 'permission-constraint' ) {
  77. //if a new permission-constraint relationship is being set unset the permission
  78. $permission =& get_object( $this->primaryID );
  79. $permission->permission( $permission->id, $permission->type->type_id );
  80. unset( $GLOBALS['permissions'][$permission->name] );
  81. }
  82. }
  83. //NOTE: relationships don't really have any properties to set, they should be deleted and re-created if they need to be changed
  84. function get_index( $direction = NULL ) {
  85. return $this->type->get_index( $direction );
  86. }
  87. function get_content() {
  88. $returnString;
  89. $primary =& get_object( $this->primaryID );
  90. $secondary =& get_object( $this->secondaryID );
  91. $returnString .= '<p>relationship id: '.$this->id.'<br>';
  92. $returnString .= 'relationship type: '.$this->type->type_name.'<br>';
  93. if( $primary ) { $returnString .= 'primary object: '.$primary->get_index().'<br>'; }
  94. if( $secondary ) { $returnString .= 'secondary object: '.$secondary->get_index().'<br>'; }
  95. return $returnString;
  96. }
  97. }
  98.  
  99. ?>

Documentation generated on Tue, 24 May 2005 03:57:33 -0400 by phpDocumentor 1.3.0RC3