Source for file functions_relationships.php

Documentation is available at functions_relationships.php

  1. <?php
  2. function relate_new_object( $constraints = NULL ) {
  3. //responds to the selection of the "new..." option in a new relationship form
  4. if( $_SESSION['new_object'] ) {
  5. //if related objects are having new objects related to them
  6. $previous = unserialize( $_SESSION['new_object']['previousReferrers'] );
  7. if( is_array($previous) ) {
  8. array_push( $previous, $_SESSION['new_object']['referrer'] );
  9. $holder = serialize( $previous );
  10. } else {
  11. $holder = serialize( array( $_SESSION['new_object']['referrer'] ) );
  12. }
  13. }
  14. //transfer POST data to the SESSION array and format redirect string
  15. $_SESSION['new_object'] = array();
  16. $_SESSION['new_object']['referrer'] = $_POST['referrer'];
  17. $_SESSION['new_object']['object'] = $_POST['object'];
  18. if( $holder ) { $_SESSION['new_object']['previousReferrers'] = $holder; }
  19. $redirectString = "Location: http://".$_SERVER['HTTP_HOST'];
  20. $redirectString .= dirname($_SERVER['PHP_SELF']);
  21. //bifurcate processing for new objects or embeds
  22. if( !$_POST['embed_type'] ) {
  23. $_SESSION['new_object']['target'] = $_POST['target'];
  24. $_SESSION['new_object']['constraints'] = serialize($constraints);
  25. $_SESSION['new_object']['typeID'] = $_POST['relationship_type'];
  26. //test for single constraint with defined object type and redirect to new page if found
  27. if( count($constraints) == 1 ) {
  28. $constraint = get_object( reset($constraints) );
  29. if( $typeTests = $constraint->get_attribute( 'object_constraints' ) ) {
  30. foreach( $typeTests as $typeTest ) {
  31. if( in_array( 'type', $typeTest ) ) {
  32. $redirectString = 'Location: '.echo_url( true, false );
  33. $redirectString .= '?object_type='.$typeTest['value'].'&object=*new*';
  34. }
  35. }
  36. }
  37. } else {
  38. //if not found redirect to new_object page for querying user about what type of object to create
  39. $redirectString .= "/new_object.php";
  40. }
  41. } else {
  42. $_SESSION['new_object']['embed_type'] = $_POST['embed_type'];
  43. $_SESSION['new_object']['embed_attribute'] = $_POST['embed_attribute'];
  44.  
  45. $redirectString .= "/new_embed.php";
  46. }
  47. //redirect and flush header
  48. header( $redirectString );
  49.  
  50. ob_end_flush();
  51. }
  52.  
  53. function relate_new_object_content() {
  54. //echos content for selecting which type of object to create
  55. $returnString;
  56. $constraints = unserialize( $_SESSION['new_object']['constraints'] );
  57. $returnString .= '
  58. <form method="post">
  59. <p>select the best description of the new object:<br>
  60. <select name="constraint">
  61. <option>select...</option>
  62. ';
  63. foreach ($constraints as $constraint) {
  64. $currentConstraint = get_constraint( $constraint );
  65.  
  66. if( $currentConstraint['object_constraints'][0]['attribute'] == "type" ) {
  67. $returnString .= '<option value="'.$constraint.'">'.$currentConstraint['name'].'</option>';
  68. }
  69. }
  70. $returnString .= '
  71. </select>
  72. <p>...or select what type of object to create<br>
  73. <select name="object_type" onchange="this.form.submit();">
  74. <option>select...</option>
  75. ';
  76. foreach( get_object_types() as $objectType ) {
  77. $returnString .= '
  78. <option value="'.$objectType['name'].'">'.$objectType['name'].'</option>
  79. ';
  80. }
  81. $returnString .= '
  82. </select>
  83. </form>
  84. ';
  85. return $returnString;
  86. }
  87. /*
  88. function get_relationships_content( $objectID = NULL ) {
  89. //outputs the table rows with form content for adding or editing a relationship
  90. $returnString;
  91. //for each possible relationship type...
  92. $relationships = get_relationships( $objectID );
  93. $relationshipTypes = get_allowed_relationship_types( $objectID );
  94.  
  95. if( count($relationshipTypes) ) {
  96. $returnString .= '<table width="100%">';
  97. }
  98.  
  99. for($i=0;$i<count($relationshipTypes);$i++) {
  100. //output any defined relationships
  101. if( ($i+1) % 2 ) {
  102. $returnString .= '<tr>';
  103. }
  104. $relatedArray = array();
  105. $relationshipType = core_get_relationship_type($relationshipTypes[$i]['relationship_typeID']);
  106. $relationshipDirection = $relationshipTypes[$i]['direction'];
  107. $relationships = get_relationships( $objectID, $relationshipType );
  108.  
  109. $returnString .= '
  110. <td width="45%" style="border-style:none;"><div>
  111. <a name="relationship_type_'.$relationshipType['id'].'">
  112. <table width="100%">
  113. <tr>
  114. <td colspan="2" bgcolor="#eeeeee" style="text-align:right;">'.$relationshipType['name'].'</td>
  115. </tr>
  116. ';
  117. for($j=0;$j<count($relationships);$j++) {
  118. $relationship = $relationships[$j];
  119. if( $relationship['typeID'] == $relationshipType['id'] ) {
  120. $related = ($relationship['primaryID'] == $objectID) ? $relationship['secondaryID'] : $relationship['primaryID'];
  121. $returnString .= '<tr><td>'.get_object_index($related).'</td>';
  122. if( allowed( "modify relationships" ) ) {
  123. $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>';
  124. }
  125. array_push($relatedArray, $related);
  126. }
  127. }
  128. if( !count($relationships) ) {
  129. $returnString .= '<tr><td>none defined</td></tr>';
  130. }
  131. //insert the select box for new relationships
  132. if( allowed( "modify relationships" ) ) {
  133. $allowedArray = array();
  134. for($j=0;$j<count($relationshipTypes[$i]['type_sets']);$j++){
  135. $allowedArray = array_merge( $allowedArray, get_constrained_objects( $relationshipTypes[$i]['type_sets'][$j][ ($relationshipDirection == 'foreward' ? 'secondary_constraintID' : 'primary_constraintID' ) ] ) );
  136. }
  137. $optionArray = array_diff( array_unique($allowedArray), $relatedArray );
  138. $returnString .= '
  139. <tr><td>
  140. <form method="post" action="'.echo_url(true).'#relationship_type_'.$relationshipType['id'].'">
  141. <input type="hidden" name="action" value="new_relationship">
  142. <input type="hidden" name="direction" value="'.$relationshipDirection.'">
  143. <input type="hidden" name="relationship_type" value="'.$relationshipType['id'].'">
  144. <input type="hidden" name="referrer" value="';echo_url();echo'">
  145. <input type="hidden" name="direction" value="'.$relationshipDirection.'">
  146. <input type="hidden" name="object" value="'.$objectID.'">
  147. <select name="related" onchange="this.form.submit();">
  148. <option>add...</option>
  149. ';
  150. for(reset($optionArray);current($optionArray);next($optionArray)) {
  151. $returnString .= '<option value='.current($optionArray).'>'.get_object_index(current($optionArray)).'</option>';
  152. }
  153. //this option value needs to specify the possible constraints the given relationship type has defined
  154. $returnString .= '
  155. <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>
  156. </select>
  157. </form>
  158. </td></tr>
  159. ';
  160. }
  161. $returnString .= '
  162. <tr><td colspan="2" bgcolor="#eeeeee" style="text-align:right;">'.$relationshipType['name'].'</td></tr>
  163. </table></div></td>&nbsp;
  164. ';
  165. if( $i % 2 ) {
  166. $returnString .= '</tr><tr><td>&nbsp;</td></tr>';
  167. }
  168. }
  169. if( count($relationshipTypes) ) {
  170. $returnString .= '</table>';
  171. }
  172. return $returnString;
  173. }
  174.  
  175. function get_relationships_noform_content( $object, $relationship ) {
  176. //echos relationships without editing capability
  177. $relatedIndex = ( $relationship['primaryID']==$object ? $relationship['secondaryID'] : $relationship['primaryID'] );
  178. return '
  179. <tr>
  180. <td bgcolor="#eeeeee">'.core_get_relationship_type($relationship['typeID']).'</td>
  181. <td>'.get_object_index($relatedIndex).'</td>
  182. <td><a href="system_management.php?p='.$_GET['p'].'&object='.$object.'&action=edit&relationship='.$relationship['id'].'" '.mouseover().'>edit</a></td>
  183. <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>
  184. <tr>
  185. ';
  186. }*/
  187. ?>

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