Documentation is available at class_constraint.php
- <?php
- class constraint extends b_object {
- var $name;
- var $description;
- var $object_constraints;
- var $relationship_constraints;
- var $constrained;
- function constraint( $constructID = NULL ) {
- parent::b_object( $constructID, 'constraints' );
- $this->object_constraints = unserialize( $this->object_constraints );
- $this->relationship_constraints = unserialize( $this->relationship_constraints );
- }
- function get_index() {
- return $this->name;
- }
- function get_constrained_objects() {
- //if the constrained objects have not already been determined
- if( !isset( $this->constrained ) ) {
- global $db;
- $objects = array();
- $returnArray = array();
- //if a type is specified
- if( in_array( 'type', $this->object_constraints[0] ) && $type =& $GLOBALS['core']->get_object_type( $this->object_constraints[0]['value'] )) {
- //get all objects of that type meeting the other object constraints
- foreach( $type->retrieve_all() as $object ) {
- if( core_satisfied( $this, $object ) ) {
- $returnArray[ $object->id ] = $object;
- }
- }
- /*
- foreach( $this->object_constraints as $constraint ) {
- if( $constraint['attribute'] != 'type' ) {
- $testArray[] = array( 'attribute'=>$constraint['attribute'] , 'operator'=>$constraint['operator'] ,'value'=>$constraint['value'] );
- }
- }
- if( $testArray ) {
- $objects = $type->get_byValue( $testArray );
- } else {
- $objects = $type->retrieve_all();
- }*/
- //otherwise
- } else {
- //get all defined objects which meet the object constraints
- echo 'FIXME: asdgyhgjyrasdf';
- }
- //set the class var
- $this->constrained = $returnArray;
- }
- //return the class var
- return $this->constrained;
- }
- function test_relationship_constraints( &$object ) {
- foreach( $this->relationship_constraints as $constraint ) {
- //foreach relationship constraint
- $relationshipType =& $GLOBALS['core']->get_relationship_type( $constraint['type'] );
- $base = ( ($constraint['position'] == 'primary') ? 'secondaryID' : 'primaryID' );
- $target = ( ($constraint['position'] == 'primary') ? 'primaryID' : 'secondaryID' );
- if( $relationships = $relationshipType->get_byValue( array( array( 'attribute'=>$target, 'operator'=>'=', 'value'=>$object->id ) ) ) ) {
- //if the object has relationships of that type and the object is in the correct position
- foreach( $relationships as $relationship ) {
- //for each of those relationships
- $related =& get_object( $relationship->$base );
- $trig = false;
- //recursion!!!
- foreach( $related->get_satisfied_constraints() as $satisfied){
- if( $satisfied->id == $constraint['related'] ) { $trig = true; }
- }
- if( !$trig ) { return false; }
- //if the related object doesn't meet the required constraint return false
- }
- } else {
- return false;
- }
- }
- return true;
- }
- }
- ?>
Documentation generated on Tue, 24 May 2005 03:57:28 -0400 by phpDocumentor 1.3.0RC3