Documentation is available at functions_relationships.php
- <?php
- function relate_new_object( $constraints = NULL ) {
- //responds to the selection of the "new..." option in a new relationship form
- if( $_SESSION['new_object'] ) {
- //if related objects are having new objects related to them
- $previous = unserialize( $_SESSION['new_object']['previousReferrers'] );
- if( is_array($previous) ) {
- array_push( $previous, $_SESSION['new_object']['referrer'] );
- $holder = serialize( $previous );
- } else {
- $holder = serialize( array( $_SESSION['new_object']['referrer'] ) );
- }
- }
- //transfer POST data to the SESSION array and format redirect string
- $_SESSION['new_object'] = array();
- $_SESSION['new_object']['referrer'] = $_POST['referrer'];
- $_SESSION['new_object']['object'] = $_POST['object'];
- if( $holder ) { $_SESSION['new_object']['previousReferrers'] = $holder; }
- $redirectString = "Location: http://".$_SERVER['HTTP_HOST'];
- $redirectString .= dirname($_SERVER['PHP_SELF']);
- //bifurcate processing for new objects or embeds
- if( !$_POST['embed_type'] ) {
- $_SESSION['new_object']['target'] = $_POST['target'];
- $_SESSION['new_object']['constraints'] = serialize($constraints);
- $_SESSION['new_object']['typeID'] = $_POST['relationship_type'];
- //test for single constraint with defined object type and redirect to new page if found
- if( count($constraints) == 1 ) {
- $constraint = get_object( reset($constraints) );
- if( $typeTests = $constraint->get_attribute( 'object_constraints' ) ) {
- foreach( $typeTests as $typeTest ) {
- if( in_array( 'type', $typeTest ) ) {
- $redirectString = 'Location: '.echo_url( true, false );
- $redirectString .= '?object_type='.$typeTest['value'].'&object=*new*';
- }
- }
- }
- } else {
- //if not found redirect to new_object page for querying user about what type of object to create
- $redirectString .= "/new_object.php";
- }
- } else {
- $_SESSION['new_object']['embed_type'] = $_POST['embed_type'];
- $_SESSION['new_object']['embed_attribute'] = $_POST['embed_attribute'];
- $redirectString .= "/new_embed.php";
- }
- //redirect and flush header
- header( $redirectString );
- ob_end_flush();
- }
- function relate_new_object_content() {
- //echos content for selecting which type of object to create
- $returnString;
- $constraints = unserialize( $_SESSION['new_object']['constraints'] );
- $returnString .= '
- <form method="post">
- <p>select the best description of the new object:<br>
- <select name="constraint">
- <option>select...</option>
- ';
- foreach ($constraints as $constraint) {
- $currentConstraint = get_constraint( $constraint );
- if( $currentConstraint['object_constraints'][0]['attribute'] == "type" ) {
- $returnString .= '<option value="'.$constraint.'">'.$currentConstraint['name'].'</option>';
- }
- }
- $returnString .= '
- </select>
- <p>...or select what type of object to create<br>
- <select name="object_type" onchange="this.form.submit();">
- <option>select...</option>
- ';
- foreach( get_object_types() as $objectType ) {
- $returnString .= '
- <option value="'.$objectType['name'].'">'.$objectType['name'].'</option>
- ';
- }
- $returnString .= '
- </select>
- </form>
- ';
- return $returnString;
- }
- /*
- function get_relationships_content( $objectID = NULL ) {
- //outputs the table rows with form content for adding or editing a relationship
- $returnString;
- //for each possible relationship type...
- $relationships = get_relationships( $objectID );
- $relationshipTypes = get_allowed_relationship_types( $objectID );
- if( count($relationshipTypes) ) {
- $returnString .= '<table width="100%">';
- }
- for($i=0;$i<count($relationshipTypes);$i++) {
- //output any defined relationships
- if( ($i+1) % 2 ) {
- $returnString .= '<tr>';
- }
- $relatedArray = array();
- $relationshipType = core_get_relationship_type($relationshipTypes[$i]['relationship_typeID']);
- $relationshipDirection = $relationshipTypes[$i]['direction'];
- $relationships = get_relationships( $objectID, $relationshipType );
- $returnString .= '
- <td width="45%" style="border-style:none;"><div>
- <a name="relationship_type_'.$relationshipType['id'].'">
- <table width="100%">
- <tr>
- <td colspan="2" bgcolor="#eeeeee" style="text-align:right;">'.$relationshipType['name'].'</td>
- </tr>
- ';
- for($j=0;$j<count($relationships);$j++) {
- $relationship = $relationships[$j];
- if( $relationship['typeID'] == $relationshipType['id'] ) {
- $related = ($relationship['primaryID'] == $objectID) ? $relationship['secondaryID'] : $relationship['primaryID'];
- $returnString .= '<tr><td>'.get_object_index($related).'</td>';
- if( allowed( "modify relationships" ) ) {
- $returnString .= '<td bgcolor="#F2B5B3"><a href="system_management.php?p='.$_GET['p'].'&page='.$_GET['page'].'&object='.$objectID.'&action=delete_relationship&relationship='.$relationship['id'].'" '.mouseover( "#fff", "#B90000").' style="color:#fff;">delete</a></td></tr>';
- }
- array_push($relatedArray, $related);
- }
- }
- if( !count($relationships) ) {
- $returnString .= '<tr><td>none defined</td></tr>';
- }
- //insert the select box for new relationships
- if( allowed( "modify relationships" ) ) {
- $allowedArray = array();
- for($j=0;$j<count($relationshipTypes[$i]['type_sets']);$j++){
- $allowedArray = array_merge( $allowedArray, get_constrained_objects( $relationshipTypes[$i]['type_sets'][$j][ ($relationshipDirection == 'foreward' ? 'secondary_constraintID' : 'primary_constraintID' ) ] ) );
- }
- $optionArray = array_diff( array_unique($allowedArray), $relatedArray );
- $returnString .= '
- <tr><td>
- <form method="post" action="'.echo_url(true).'#relationship_type_'.$relationshipType['id'].'">
- <input type="hidden" name="action" value="new_relationship">
- <input type="hidden" name="direction" value="'.$relationshipDirection.'">
- <input type="hidden" name="relationship_type" value="'.$relationshipType['id'].'">
- <input type="hidden" name="referrer" value="';echo_url();echo'">
- <input type="hidden" name="direction" value="'.$relationshipDirection.'">
- <input type="hidden" name="object" value="'.$objectID.'">
- <select name="related" onchange="this.form.submit();">
- <option>add...</option>
- ';
- for(reset($optionArray);current($optionArray);next($optionArray)) {
- $returnString .= '<option value='.current($optionArray).'>'.get_object_index(current($optionArray)).'</option>';
- }
- //this option value needs to specify the possible constraints the given relationship type has defined
- $returnString .= '
- <option value="*new*?';for($k=0;$k<count($relationshipTypes[$i]['type_sets']);$k++){echo ($k?"&":"").$relationshipTypes[$i]['type_sets'][$k][($relationshipDirection == 'foreward' ? 'secondary_constraintID' : 'primary_constraintID' )];};echo'">new...</option>
- </select>
- </form>
- </td></tr>
- ';
- }
- $returnString .= '
- <tr><td colspan="2" bgcolor="#eeeeee" style="text-align:right;">'.$relationshipType['name'].'</td></tr>
- </table></div></td>
- ';
- if( $i % 2 ) {
- $returnString .= '</tr><tr><td> </td></tr>';
- }
- }
- if( count($relationshipTypes) ) {
- $returnString .= '</table>';
- }
- return $returnString;
- }
- function get_relationships_noform_content( $object, $relationship ) {
- //echos relationships without editing capability
- $relatedIndex = ( $relationship['primaryID']==$object ? $relationship['secondaryID'] : $relationship['primaryID'] );
- return '
- <tr>
- <td bgcolor="#eeeeee">'.core_get_relationship_type($relationship['typeID']).'</td>
- <td>'.get_object_index($relatedIndex).'</td>
- <td><a href="system_management.php?p='.$_GET['p'].'&object='.$object.'&action=edit&relationship='.$relationship['id'].'" '.mouseover().'>edit</a></td>
- <td bgcolor="#F2B5B3"><a href="system_management.php?p='.$_GET['p'].'&object='.$object.'$action=delete&relationship='.$relationship['id'].'" '.mouseover( "#fff", "#B90000").' style="color:#fff;">delete</a></td>
- <tr>
- ';
- }*/
- ?>
Documentation generated on Tue, 24 May 2005 03:58:04 -0400 by phpDocumentor 1.3.0RC3