Source for file core_functions_relationships.php

Documentation is available at core_functions_relationships.php

  1. <?php /*
  2. function core_get_type_sets( $field = NULL ) {
  3. //returns an array of all defined type sets - if field specified returns on that field
  4. global $db;
  5. $selectField = $field ? ( "id, ".$field ) : "*";
  6.  
  7. $return_array = $db->get_results( "SELECT ".$selectField." FROM type_sets", ARRAY_A );
  8. return $return_array;
  9. }
  10.  
  11. function core_get_type_set( $type_setID ) {
  12. //gets the specified type set's values
  13. global $db;
  14.  
  15. $return_array = $db->get_results( "SELECT * FROM type_sets WHERE id = '".$type_setID."'", ARRAY_A );
  16. return $return_array;
  17. }
  18.  
  19. function core_get_relationship_types( $field = NULL ) {
  20. //returns an array of all defined relationship types - if field specified returns on that field
  21. global $db;
  22. $selectField = $field ? ( "id, ".$field ) : "*";
  23.  
  24. $return_array = $db->get_results( "SELECT ".$selectField." FROM object_types", ARRAY_A );
  25.  
  26. return $return_array;
  27. }
  28.  
  29. function core_get_relationship_type( $relationshipID ) {
  30. //gets the specified relationship type's values
  31. global $db;
  32. $return_array = array();
  33. if( $relationshipID == "*new*" ) {
  34. $newID = new_relationship_type();
  35. return core_get_relationship_type( $newID );
  36. } else {
  37. $return_array = $db->get_results( "SELECT * FROM object_types WHERE id = '".$relationshipID."'", ARRAY_A );
  38. }
  39. return $return_array[0];
  40. }
  41.  
  42. function get_relationship_type_index( $relationshipID ) {
  43. //relationship type implementation of get_object_index()
  44. $relationshipType = core_get_relationship_type( $relationshipID );
  45.  
  46. if( $relationshipType['name'] ) {
  47. $relationshipTypeIndex = $relationshipType['name'];
  48. } else {
  49. $relationshipTypeIndex = "new user type";
  50. }
  51. return $relationshipTypeIndex;
  52. }
  53.  
  54. function get_type_set_index( $typeSetID ) {
  55. //relationship type implementation of get_object_index()
  56. $typeSet = core_get_type_set( $typeSetID );
  57.  
  58. if( $typeSet['name'] ) {
  59. $typeSetIndex = $typeSet['name'];
  60. } else {
  61. $typeSetIndex = "new type set";
  62. }
  63. return $typeSetIndex;
  64. }
  65.  
  66. function get_type_set( $typeSetID ) {
  67. //gets the specified type set's values
  68. global $db;
  69. $return_array = array();
  70. if( $typeSetID == "*new*" ) {
  71. $newID = new_type_set();
  72. return get_type_set( $newID );
  73. } else {
  74. $return_array = $db->get_results( "SELECT * FROM type_sets WHERE id = '".$typeSetID."'", ARRAY_A );
  75. }
  76. return $return_array[0];
  77. }
  78.  
  79.  
  80. function core_get_relationship_type_ID( $name = NULL, $description = NULL ) {
  81. //adds or updates a new/existing person to the person table and returns the new person's id
  82. global $db;
  83. $variableCount = 0;
  84. $selectString = "SELECT id FROM object_types";
  85. if( $name ) { $selectString = $selectString.($variableCount? " AND ":" WHERE ")."name = '".$name."'"; $variableCount++; }
  86. if( $description ) { $selectString = $selectString.($variableCount? " AND ":" WHERE ")."description = '".$description."'"; $variableCount++; }
  87. if( !$name && !$description ) {
  88. $selectString = $selectString."
  89. WHERE name is NULL
  90. AND description is NULL";
  91. }
  92. $db->hide_errors();
  93. $returnArray = $db->get_results( clean($selectString), ARRAY_A );
  94. $db->show_errors();
  95.  
  96. return $returnArray[0]['id'];
  97. }
  98. */
  99. function get_type_set_ID( $relationshipTypeID = NULL, $primaryConstraintID = NULL, $secondaryConstraintID = NULL, $biDirectional = NULL ) {
  100. //adds or updates a new/existing person to the person table and returns the new person's id
  101. global $db;
  102. $variableCount = 0;
  103. $selectString = "SELECT id FROM type_sets";
  104. if( $relationshipTypeID ) { $selectString = $selectString.($variableCount? " AND ":" WHERE ")."relationship_typeID = '".$relationshipTypeID."'"; $variableCount++; }
  105. if( $primaryConstraintID ) { $selectString = $selectString.($variableCount? " AND ":" WHERE ")."primary_constraintID = '".$primaryConstraintID."'"; $variableCount++; }
  106. if( $secondaryConstraintID ) { $selectString = $selectString.($variableCount? " AND ":" WHERE ")."secondary_constraintID = '".$secondaryConstraintID."'"; $variableCount++; }
  107. if( $biDirectional ) { $selectString = $selectString.($variableCount? " AND ":" WHERE ")."bi_directional = '".$biDirectional."'"; $variableCount++; }
  108. if( !$relationshipTypeID && !$primaryConstraintID && !$secondaryConstraintID && !$biDirectional ) {
  109. $selectString = $selectString."
  110. WHERE relationship_typeID is NULL
  111. AND primary_constraintID is NULL
  112. AND secondary_constraintID is NULL
  113. AND bi_directional is NULL
  114. ";
  115. }
  116. $db->hide_errors();
  117. $returnArray = $db->get_results( clean($selectString), ARRAY_A );
  118. $db->show_errors();
  119.  
  120. return $returnArray[0]['id'];
  121. }
  122.  
  123. /*
  124. function set_relationship_type( $id, $name, $description = NULL ) {
  125. global $db;
  126.  
  127. if( $name || $description ) {
  128. $variableCount = 0;
  129. $updateString = "UPDATE object_types SET ";
  130. if( isset($name) ) { $updateString = $updateString.($variableCount?", ":"")."name = '".clean($name)."'"; $variableCount++; }
  131. if( isset($description) ) { $updateString = $updateString.($variableCount?", ":"")."description = '".clean($description)."'"; $variableCount++; }
  132. $updateString = $updateString." WHERE id = '".$id."'";
  133. $db->query( $updateString );
  134. }
  135. }
  136.  
  137. function set_type_set( $id, $type, $primary, $secondary, $bi ) {
  138. global $db;
  139.  
  140. if( $type || $primary || $secondary || $bi ) {
  141. $variableCount = 0;
  142. $updateString = "UPDATE type_sets SET ";
  143. if( isset($type) ) { $updateString = $updateString.($variableCount?", ":"")."relationship_typeID = '".clean($type)."'"; $variableCount++; }
  144. if( isset($primary) ) { $updateString = $updateString.($variableCount?", ":"")."primary_constraintID = '".clean($primary)."'"; $variableCount++; }
  145. if( isset($secondary) ) { $updateString = $updateString.($variableCount?", ":"")."secondary_constraintID = '".clean($secondary)."'"; $variableCount++; }
  146. if( isset($bi) ) { $updateString = $updateString.($variableCount?", ":"")."bi_directional = '".clean($bi)."'"; $variableCount++; }
  147. $updateString = $updateString." WHERE id = '".$id."'";
  148. $db->query( $updateString );
  149. }
  150. }
  151.  
  152. function set_constraint( $id, $name = NULL, $description = NULL, $objectConstraints = NULL, $relationshipConstraints = NULL ) {
  153. //this function defines a new constraint
  154. global $db;
  155. $objectConstraintsString = ( is_array($objectConstraints) ? serialize( $objectConstraints ) : $objectConstraints );
  156. $relationshipConstraintsString = ( is_array($relationshipConstraints) ? serialize( $relationshipConstraints ) : $relationshipConstraints );
  157.  
  158. $db->query( "UPDATE constraints SET description = '".($description)."', object_constraints = '".$objectConstraintsString."', relationship_constraints = '".$relationshipConstraintsString."' WHERE id = '".$id."'" );
  159. }
  160.  
  161. function new_type_set( $relationshipTypeID = NULL, $primaryConstraintID = NULL, $secondaryConstraintID = NULL, $biDirectional = NULL ) {
  162. //sets the values of the given relationship type to the given values
  163. global $db;
  164. $typeSetID = get_type_set_ID( $relationshipTypeID, $primaryConstraintID, $secondaryConstraintID, $biDirectional );
  165. //if the relationship type is new, insert it into the types table
  166. if( !$typeSetID ) {
  167. $typeSetID = $db->get_var( "SELECT value FROM system_settings WHERE name = 'type_sets_counter'" );
  168. $db->query( "
  169. INSERT INTO type_sets
  170. ( id ) VALUES ( '".$typeSetID."' )
  171. " );
  172. $db->query( "UPDATE system_settings SET value = '".($typeSetID + 1)."' WHERE name = 'type_sets_counter'" );
  173. }
  174. set_type_set_withNames( $typeSetID, $relationshipTypeID, $primaryConstraintID, $secondaryConstraintID, $biDirectional );
  175.  
  176. return $typeSetID;
  177. }
  178.  
  179. function delete_type_set( $id ) {
  180. //deletes a type set
  181. global $db;
  182. }
  183.  
  184. function delete_constraint( $id ) {
  185. //deletes a type set
  186. global $db;
  187. }
  188. */
  189. ?>

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