Source for file class_constraint.php

Documentation is available at class_constraint.php

  1. <?php
  2. class constraint extends b_object {
  3.  
  4. var $name;
  5. var $description;
  6. var $object_constraints;
  7. var $relationship_constraints;
  8. var $constrained;
  9.  
  10. function constraint( $constructID = NULL ) {
  11. parent::b_object( $constructID, 'constraints' );
  12.  
  13. $this->object_constraints = unserialize( $this->object_constraints );
  14. $this->relationship_constraints = unserialize( $this->relationship_constraints );
  15. }
  16. function get_index() {
  17. return $this->name;
  18. }
  19. function get_constrained_objects() {
  20. //if the constrained objects have not already been determined
  21. if( !isset( $this->constrained ) ) {
  22. global $db;
  23. $objects = array();
  24. $returnArray = array();
  25.  
  26. //if a type is specified
  27. if( in_array( 'type', $this->object_constraints[0] ) && $type =& $GLOBALS['core']->get_object_type( $this->object_constraints[0]['value'] )) {
  28. //get all objects of that type meeting the other object constraints
  29. foreach( $type->retrieve_all() as $object ) {
  30. if( core_satisfied( $this, $object ) ) {
  31. $returnArray[ $object->id ] = $object;
  32. }
  33. }
  34. /*
  35. foreach( $this->object_constraints as $constraint ) {
  36. if( $constraint['attribute'] != 'type' ) {
  37. $testArray[] = array( 'attribute'=>$constraint['attribute'] , 'operator'=>$constraint['operator'] ,'value'=>$constraint['value'] );
  38. }
  39. }
  40. if( $testArray ) {
  41. $objects = $type->get_byValue( $testArray );
  42. } else {
  43. $objects = $type->retrieve_all();
  44. }*/
  45.  
  46. //otherwise
  47. } else {
  48. //get all defined objects which meet the object constraints
  49. echo 'FIXME: asdgyhgjyrasdf';
  50. }
  51.  
  52. //set the class var
  53. $this->constrained = $returnArray;
  54. }
  55.  
  56. //return the class var
  57. return $this->constrained;
  58. }
  59. function test_relationship_constraints( &$object ) {
  60. foreach( $this->relationship_constraints as $constraint ) {
  61. //foreach relationship constraint
  62.  
  63. $relationshipType =& $GLOBALS['core']->get_relationship_type( $constraint['type'] );
  64.  
  65. $base = ( ($constraint['position'] == 'primary') ? 'secondaryID' : 'primaryID' );
  66. $target = ( ($constraint['position'] == 'primary') ? 'primaryID' : 'secondaryID' );
  67. if( $relationships = $relationshipType->get_byValue( array( array( 'attribute'=>$target, 'operator'=>'=', 'value'=>$object->id ) ) ) ) {
  68. //if the object has relationships of that type and the object is in the correct position
  69. foreach( $relationships as $relationship ) {
  70. //for each of those relationships
  71. $related =& get_object( $relationship->$base );
  72. $trig = false;
  73. //recursion!!!
  74. foreach( $related->get_satisfied_constraints() as $satisfied){
  75. if( $satisfied->id == $constraint['related'] ) { $trig = true; }
  76. }
  77. if( !$trig ) { return false; }
  78. //if the related object doesn't meet the required constraint return false
  79. }
  80. } else {
  81. return false;
  82. }
  83. }
  84. return true;
  85. }
  86. }
  87.  
  88. ?>

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