Source for file class_core.php

Documentation is available at class_core.php

  1. <?php
  2. class core extends base {
  3. var $module_registry; //an array containing information about modules
  4. var $settings; //core settings
  5. var $object_types; //contains the names of all object types defined by the active modules
  6. var $relationship_types;
  7. function core() {
  8. //retrieve simple arrays from db
  9. global $db;
  10. $db->hide_errors();
  11. $modules = $db->get_results( "SELECT * FROM module_registry", ARRAY_A );
  12. $db->show_errors();
  13. if( $modules ) {
  14. foreach( $modules as $key => $module ) {
  15. $modules[$key]['module_object_types'] = unserialize( $module['module_object_types'] );
  16. }
  17. }
  18. $this->module_registry = $modules;
  19. $this->settings = $db->get_results( "SELECT * FROM core_settings", ARRAY_A );
  20. //initialize the containers
  21. $this->object_types = new container;
  22. $this->relationship_types = new container;
  23.  
  24. //and fill them
  25. $this->object_types->set_attribute('objects', $this->get_keys( "object_types" ) );
  26. $this->relationship_types->set_attribute('objects', $this->get_keys( "relationship_types" ) );
  27. }
  28. function preload() {
  29. global $db;
  30. $object_data = $db->get_results( "SELECT * FROM object_types", ARRAY_A );
  31. $relationship_data = $db->get_results( "SELECT * FROM relationship_types", ARRAY_A );
  32. //$relationships = $db->get_results( "SELECT * FROM relationships", ARRAY_A );
  33.  
  34. foreach( $object_data as $value ) {
  35. $this->object_types->objects[$value['id']] = true;
  36. $this->object_types->retrievedObjects[$value['id']] = new object_type( $value['id'], $value );
  37. }
  38. foreach( $relationship_data as $value ) {
  39. $this->relationship_types->objects[$value['id']] = true;
  40. $this->relationship_types->retrievedObjects[$value['id']] = new relationship_type( $value['id'], $value );
  41. $this->relationship_types->retrievedObjects[$value['id']]->retrieve_all();
  42. }
  43.  
  44. }
  45. function get_keys( $table ) {
  46. global $db;
  47. if( $array = $db->get_results( "SELECT id FROM ".$table, ARRAY_A ) ) {
  48. foreach( $array as $value ) {
  49. $return[ $value['id'] ] = false;
  50. }
  51. return $return;
  52. } else {
  53. return array();
  54. }
  55. }
  56. function register_object_type( &$type ) {
  57. $this->object_types->register_object( $type, $type->get_attribute( 'type_id' ) );
  58. }
  59. function &retrieve_installed_modules() {
  60. return $this->module_registry;
  61. }
  62. function retrieve_available_modules() {
  63. //returns a list of modules in the modules folder
  64. $root = get_root();
  65. // scan the modules folder for subfolders, return a list of such folders
  66. $return_array = array();
  67. if ($handle = opendir($root.'Modules')) {
  68. while (false !== ($file = readdir($handle))) {
  69. if ($file != "." && $file != ".." && is_dir( $root.'Modules/'.$file ) ) {
  70. array_push( $return_array, $file );
  71. }
  72. }
  73. closedir($handle);
  74. }
  75. return $return_array;
  76. }
  77. function core_get_active_modules( $field = NULL ) {
  78. //returns a list of active modules (modules being executed by the script)
  79. foreach( $this->module_registry as $key => $module ) {
  80. if( $module['module_activated'] ) {
  81. $array[] =& $this->module_registry[$key];
  82. }
  83. }
  84. return $array;
  85. }
  86. function &get_object_type( $typeID ) {
  87. //retrieve all the defined object types
  88. if( $to_retrieve = array_diff_key( $this->object_types->objects, $this->object_types->retrievedObjects ) ) {
  89. foreach( $to_retrieve as $key => $value ) {
  90. $object =& new object_type( $key );
  91. $this->object_types->register_object( $object, $key );
  92. }
  93. }
  94.  
  95. if( $type =& $this->get_type( $this->object_types, $typeID ) ) {
  96. return $type;
  97. } else {
  98. return $this->get_relationship_type( $this->relationship_types, $typeID );
  99. }
  100. }
  101. function &get_relationship_type( $typeID ) {
  102. //retrieve all the defined relationship types
  103. if( count($this->relationship_types->objects) != count($this->relationship_types->retrievedObjects) ) {
  104. foreach($this->relationship_types->objects as $key => $value ) {
  105. if( !$value ) {
  106. $relationship =& new relationship_type( $key );
  107. $this->relationship_types->register_object( $relationship, $key );
  108. }
  109. }
  110. }
  111. /*
  112. if( $to_retrieve = array_diff_key( $this->relationship_types->objects, $this->relationship_types->retrievedObjects ) ) {
  113. foreach( $to_retrieve as $key => $value ) {
  114. $relationship =& new relationship_type( $key );
  115. $this->relationship_types->register_object( $relationship, $key );
  116. }
  117. }
  118. */
  119. //find and return the requested type
  120. $token = strtok( $typeID, '-' );
  121. if( $foreward = strtok( '-' ) ) {
  122. return $this->get_type( $this->relationship_types, trim($foreward), trim($token) );
  123. } else {
  124. return $this->get_type( $this->relationship_types, $typeID );
  125. }
  126. //NOTE: add code for parsing text relationship type names into foreward and reverse names
  127. }
  128. function &get_type( &$type_type, $value1, $value2 = NULL ) {
  129. if( $retrieved_types =& $type_type->get_attribute( "retrievedObjects" ) ) {
  130. foreach( $retrieved_types as $key => $type ) {
  131. if( $type->get_attribute( "type_id" ) == $value1 ) { return $retrieved_types[$key]; }
  132. if( $value2 ) {
  133. if( $type->get_attribute( "type_name_foreward" ) == $value1 && $type->get_attribute( "type_name_reverse" ) == $value2 ) { return $retrieved_types[$key]; }
  134. } else {
  135. if( $type->get_attribute( "type_name" ) == $value1 ) { return $retrieved_types[$key]; }
  136. }
  137. }
  138. }
  139. return false;
  140. }
  141. function &get_module( $moduleName ) {
  142. if( $modules =& $this->core_get_active_modules() ) {
  143. foreach( $modules as $key => $module ) {
  144. if( $module['module_name'] == $moduleName ) {
  145. return $modules[$key];
  146. }
  147. }
  148. }
  149. return false;
  150. }
  151. function &get_constraints() {
  152. //NOTE: this doesn't need to be here...
  153. }
  154.  
  155. function output() {
  156. echo "objects: ";
  157. print_r( $this->object_types->objects );
  158. echo "retrieved objects: ";
  159. foreach( $this->object_types->retrievedObjects as $object ) { print_r($object); }
  160. }
  161. }
  162. ?>

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